How to use @wordpress/hooks - 10 common examples

To help you get started, we’ve selected a few @wordpress/hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
hooks.addFilter('my-filter', 'my/namespace', (foo: string, bar: number) => `${foo}${bar}`);
hooks.addFilter('my-filter', 'my/namespace', (foo: number, bar: number) => bar, 23);

hooks.removeAction('my-action', 'my/namespace');
hooks.removeFilter('my-filter', 'my/namespace');

// $ExpectType boolean
hooks.hasAction('my-action');
// $ExpectType boolean
hooks.hasFilter('my-filter');

hooks.removeAllActions('my-action', 'my/namespace');
hooks.removeAllFilters('my-filter', 'my/namespace');

// $ExpectType unknown
hooks.doAction('my-action');
// $ExpectType string
hooks.doAction('my-action', 'foo');

// $ExpectType unknown
hooks.applyFilters('my-filter');
// $ExpectType number
hooks.applyFilters('my-action', 123);
// $ExpectType (string | number)[]
hooks.applyFilters('my-action', [123, '456']);

// $ExpectType string | null
hooks.currentAction();
// $ExpectType string | null
hooks.currentFilter();

// $ExpectType boolean
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
import * as hooks from '@wordpress/hooks';

hooks.addAction('my-action', 'my/namespace', () => {});
hooks.addAction('my-action', 'my/namespace', () => {}, 20);

hooks.addFilter('my-filter', 'my/namespace', (foo: string, bar: number) => `${foo}${bar}`);
hooks.addFilter('my-filter', 'my/namespace', (foo: number, bar: number) => bar, 23);

hooks.removeAction('my-action', 'my/namespace');
hooks.removeFilter('my-filter', 'my/namespace');

// $ExpectType boolean
hooks.hasAction('my-action');
// $ExpectType boolean
hooks.hasFilter('my-filter');

hooks.removeAllActions('my-action', 'my/namespace');
hooks.removeAllFilters('my-filter', 'my/namespace');

// $ExpectType unknown
hooks.doAction('my-action');
// $ExpectType string
hooks.doAction('my-action', 'foo');

// $ExpectType unknown
github pento / testpress / src / services / grunt / index.js View on Github external
// We only need to run `grunt watch` on WordPress folder updates.
	if ( folderPref && 'wordpress-folder' !== folderPref ) {
		return;
	}

	setStatus( 'grunt', 'building' );

	debug( 'Preparing to run `grunt watch`' );

	if ( watchProcess ) {
		debug( 'Ending previous `grunt watch` process' );
		watchProcess.kill();
		watchProcess = null;
	}

	if ( ! didAction( 'npm_install_finished' ) ) {
		debug( "Bailing, `npm install` isn't finished" );
		return;
	}

	if ( ! cwd ) {
		debug( "Bailing, WordPress folder isn't set" );
		return;
	}

	const grunt = cwd + '/node_modules/grunt/bin/grunt';

	debug( 'Starting `grunt watch`' );
	watchProcess = spawn( NODE_BIN, [
		grunt,
		'watch',
		'--dev',
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
// $ExpectType string | null
hooks.currentAction();
// $ExpectType string | null
hooks.currentFilter();

// $ExpectType boolean
hooks.doingAction();
// $ExpectType boolean
hooks.doingAction('my-action');
// $ExpectType boolean
hooks.doingFilter();
// $ExpectType boolean
hooks.doingFilter('my-action');

// $ExpectType number
hooks.didAction('my-action');
// $ExpectType number
hooks.didFilter('my-filter');

// $ExpectType HookMap
hooks.actions;
// $ExpectType HookMap
hooks.filters;

(() => {
    const {
        // $ExpectType HookMap
        actions,
        // $ExpectType HookMap
        filters,
    } = hooks.createHooks();
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
import * as hooks from '@wordpress/hooks';

hooks.addAction('my-action', 'my/namespace', () => {});
hooks.addAction('my-action', 'my/namespace', () => {}, 20);

hooks.addFilter('my-filter', 'my/namespace', (foo: string, bar: number) => `${foo}${bar}`);
hooks.addFilter('my-filter', 'my/namespace', (foo: number, bar: number) => bar, 23);

hooks.removeAction('my-action', 'my/namespace');
hooks.removeFilter('my-filter', 'my/namespace');

// $ExpectType boolean
hooks.hasAction('my-action');
// $ExpectType boolean
hooks.hasFilter('my-filter');

hooks.removeAllActions('my-action', 'my/namespace');
hooks.removeAllFilters('my-filter', 'my/namespace');

// $ExpectType unknown
hooks.doAction('my-action');
// $ExpectType string
hooks.doAction('my-action', 'foo');

// $ExpectType unknown
hooks.applyFilters('my-filter');
// $ExpectType number
hooks.applyFilters('my-action', 123);
// $ExpectType (string | number)[]
hooks.applyFilters('my-action', [123, '456']);
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
import * as hooks from '@wordpress/hooks';

hooks.addAction('my-action', 'my/namespace', () => {});
hooks.addAction('my-action', 'my/namespace', () => {}, 20);

hooks.addFilter('my-filter', 'my/namespace', (foo: string, bar: number) => `${foo}${bar}`);
hooks.addFilter('my-filter', 'my/namespace', (foo: number, bar: number) => bar, 23);

hooks.removeAction('my-action', 'my/namespace');
hooks.removeFilter('my-filter', 'my/namespace');

// $ExpectType boolean
hooks.hasAction('my-action');
// $ExpectType boolean
hooks.hasFilter('my-filter');

hooks.removeAllActions('my-action', 'my/namespace');
hooks.removeAllFilters('my-filter', 'my/namespace');

// $ExpectType unknown
hooks.doAction('my-action');
// $ExpectType string
hooks.doAction('my-action', 'foo');

// $ExpectType unknown
hooks.applyFilters('my-filter');
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
import * as hooks from '@wordpress/hooks';

hooks.addAction('my-action', 'my/namespace', () => {});
hooks.addAction('my-action', 'my/namespace', () => {}, 20);

hooks.addFilter('my-filter', 'my/namespace', (foo: string, bar: number) => `${foo}${bar}`);
hooks.addFilter('my-filter', 'my/namespace', (foo: number, bar: number) => bar, 23);

hooks.removeAction('my-action', 'my/namespace');
hooks.removeFilter('my-filter', 'my/namespace');

// $ExpectType boolean
hooks.hasAction('my-action');
// $ExpectType boolean
hooks.hasFilter('my-filter');

hooks.removeAllActions('my-action', 'my/namespace');
hooks.removeAllFilters('my-filter', 'my/namespace');

// $ExpectType unknown
hooks.doAction('my-action');
// $ExpectType string
hooks.doAction('my-action', 'foo');

// $ExpectType unknown
hooks.applyFilters('my-filter');
// $ExpectType number
hooks.applyFilters('my-action', 123);
// $ExpectType (string | number)[]
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
hooks.addAction('my-action', 'my/namespace', () => {});
hooks.addAction('my-action', 'my/namespace', () => {}, 20);

hooks.addFilter('my-filter', 'my/namespace', (foo: string, bar: number) => `${foo}${bar}`);
hooks.addFilter('my-filter', 'my/namespace', (foo: number, bar: number) => bar, 23);

hooks.removeAction('my-action', 'my/namespace');
hooks.removeFilter('my-filter', 'my/namespace');

// $ExpectType boolean
hooks.hasAction('my-action');
// $ExpectType boolean
hooks.hasFilter('my-filter');

hooks.removeAllActions('my-action', 'my/namespace');
hooks.removeAllFilters('my-filter', 'my/namespace');

// $ExpectType unknown
hooks.doAction('my-action');
// $ExpectType string
hooks.doAction('my-action', 'foo');

// $ExpectType unknown
hooks.applyFilters('my-filter');
// $ExpectType number
hooks.applyFilters('my-action', 123);
// $ExpectType (string | number)[]
hooks.applyFilters('my-action', [123, '456']);

// $ExpectType string | null
hooks.currentAction();
// $ExpectType string | null
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
// $ExpectType boolean
hooks.doingAction();
// $ExpectType boolean
hooks.doingAction('my-action');
// $ExpectType boolean
hooks.doingFilter();
// $ExpectType boolean
hooks.doingFilter('my-action');

// $ExpectType number
hooks.didAction('my-action');
// $ExpectType number
hooks.didFilter('my-filter');

// $ExpectType HookMap
hooks.actions;
// $ExpectType HookMap
hooks.filters;

(() => {
    const {
        // $ExpectType HookMap
        actions,
        // $ExpectType HookMap
        filters,
    } = hooks.createHooks();

    // $ExpectType ActionCallback[]
    actions.__current;

    // $ExpectType FilterCallback[]
    filters.__current;
github DefinitelyTyped / DefinitelyTyped / types / wordpress__hooks / wordpress__hooks-tests.ts View on Github external
hooks.removeAllFilters('my-filter', 'my/namespace');

// $ExpectType unknown
hooks.doAction('my-action');
// $ExpectType string
hooks.doAction('my-action', 'foo');

// $ExpectType unknown
hooks.applyFilters('my-filter');
// $ExpectType number
hooks.applyFilters('my-action', 123);
// $ExpectType (string | number)[]
hooks.applyFilters('my-action', [123, '456']);

// $ExpectType string | null
hooks.currentAction();
// $ExpectType string | null
hooks.currentFilter();

// $ExpectType boolean
hooks.doingAction();
// $ExpectType boolean
hooks.doingAction('my-action');
// $ExpectType boolean
hooks.doingFilter();
// $ExpectType boolean
hooks.doingFilter('my-action');

// $ExpectType number
hooks.didAction('my-action');
// $ExpectType number
hooks.didFilter('my-filter');