Socket
Socket
Sign inDemoInstall

@wordpress/hooks

Package Overview
Dependencies
Maintainers
4
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/hooks - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

build-module/createAddHook.js
import validateNamespace from './validateNamespace.js';
import validateHookName from './validateHookName.js';
import { doAction } from './';

@@ -73,2 +74,6 @@ /**

}
if (hookName !== 'hookAdded') {
doAction('hookAdded', hookName, namespace, callback, priority);
}
};

@@ -75,0 +80,0 @@ }

4

build-module/createRemoveHook.js
import validateNamespace from './validateNamespace.js';
import validateHookName from './validateHookName.js';
import { doAction } from './';

@@ -71,2 +72,5 @@ /**

}
if (hookName !== 'hookRemoved') {
doAction('hookRemoved', hookName, namespace);
}

@@ -73,0 +77,0 @@ return handlersRemoved;

@@ -15,2 +15,4 @@ 'use strict';

var _ = require('./');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -87,2 +89,6 @@

}
if (hookName !== 'hookAdded') {
(0, _.doAction)('hookAdded', hookName, namespace, callback, priority);
}
};

@@ -89,0 +95,0 @@ }

@@ -15,2 +15,4 @@ 'use strict';

var _ = require('./');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -85,2 +87,5 @@

}
if (hookName !== 'hookRemoved') {
(0, _.doAction)('hookRemoved', hookName, namespace);
}

@@ -87,0 +92,0 @@ return handlersRemoved;

15

package.json
{
"name": "@wordpress/hooks",
"version": "1.0.1",
"version": "1.1.0",
"description": "WordPress Hooks library",
"author": "WordPress",
"license": "GPL-2.0+",
"keywords": [
"hooks"
],
"homepage": "https://github.com/WordPress/packages/tree/master/packages/hooks/README.md",
"repository": {

@@ -8,7 +15,7 @@ "type": "git",

},
"description": "WordPress Hooks library",
"bugs": {
"url": "https://github.com/WordPress/packages/issues"
},
"main": "build/index.js",
"module": "build-module/index.js",
"author": "WordPress",
"license": "GPL-2.0+",
"publishConfig": {

@@ -15,0 +22,0 @@ "access": "public"

@@ -25,3 +25,3 @@ # @wordpress/hooks

* `removeAction( 'hookName', 'functionName' )`
* `removeFilter( 'hookName', 'functionName' )`
* `removeFilter( 'hookName', 'functionName' )`
* `removeAllActions( 'hookName' )`

@@ -45,2 +45,9 @@ * `removeAllFilters( 'hookName' )`

API functions are then be called: `myObject.hooks.addAction()`...
API functions are then be called: `myObject.hooks.addAction()`.
### Events on action/filter add or remove
Whenever an action or filter is added or removed, a matching `hookAdded` or `hookRemoved` action is triggered.
* `hookAdded` action is triggered when `addFilter()` or `addAction()` method is called, passing values for `hookName`, `functionName`, `callback` and `priority`.
* `hookRemoved` action is triggered when `removeFilter()` or `removeAction()` method is called, passing values for `hookName` and `functionName`.
import validateNamespace from './validateNamespace.js';
import validateHookName from './validateHookName.js';
import { doAction } from './';

@@ -71,2 +72,6 @@ /**

}
if ( hookName !== 'hookAdded' ) {
doAction( 'hookAdded', hookName, namespace, callback, priority );
}
};

@@ -73,0 +78,0 @@ }

import validateNamespace from './validateNamespace.js';
import validateHookName from './validateHookName.js';
import { doAction } from './';

@@ -68,2 +69,5 @@ /**

}
if ( hookName !== 'hookRemoved' ) {
doAction( 'hookRemoved', hookName, namespace );
}

@@ -70,0 +74,0 @@ return handlersRemoved;

@@ -623,1 +623,64 @@ /* eslint-disable no-console */

} );
const setupActionListener = ( hookName, callback ) =>
addAction( hookName, 'my_callback', callback );
test( 'adding an action triggers a hookAdded action passing all callback details', () => {
const hook_added_spy = jest.fn();
setupActionListener( 'hookAdded', hook_added_spy );
addAction( 'testAction', 'my_callback2', action_a, 9 );
expect( hook_added_spy ).toHaveBeenCalledTimes( 1 );
expect( hook_added_spy ).toHaveBeenCalledWith(
'testAction',
'my_callback2',
action_a,
9
);
} );
test( 'adding a filter triggers a hookAdded action passing all callback details', () => {
const hook_added_spy = jest.fn();
setupActionListener( 'hookAdded', hook_added_spy );
addFilter( 'testFilter', 'my_callback3', filter_a, 8 );
expect( hook_added_spy ).toHaveBeenCalledTimes( 1 );
expect( hook_added_spy ).toHaveBeenCalledWith(
'testFilter',
'my_callback3',
filter_a,
8
);
} );
test( 'removing an action triggers a hookRemoved action passing all callback details', () => {
const hook_removed_spy = jest.fn();
setupActionListener( 'hookRemoved', hook_removed_spy );
addAction( 'testAction', 'my_callback2', action_a, 9 );
removeAction( 'testAction', 'my_callback2' );
expect( hook_removed_spy ).toHaveBeenCalledTimes( 1 );
expect( hook_removed_spy ).toHaveBeenCalledWith(
'testAction',
'my_callback2'
);
} );
test( 'removing a filter triggers a hookRemoved action passing all callback details', () => {
const hook_removed_spy = jest.fn();
setupActionListener( 'hookRemoved', hook_removed_spy );
addFilter( 'testFilter', 'my_callback3', filter_a, 8 );
removeFilter( 'testFilter', 'my_callback3' );
expect( hook_removed_spy ).toHaveBeenCalledTimes( 1 );
expect( hook_removed_spy ).toHaveBeenCalledWith(
'testFilter',
'my_callback3'
);
} );
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc