Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
14b57c7
Fix: Gallery Block: Append images alt in aria-label attribute.
donmhico Aug 20, 2019
e5e571e
Fix: InnerBlocks template sync only on direct locked all (#16973)
jorgefilipecosta Aug 20, 2019
ca4c21c
Check to ensure focus has intentionally left the wrapped component in…
getdave Aug 20, 2019
c413f03
Fix: Required block appender styles are set on edit post (#16943)
jorgefilipecosta Aug 20, 2019
32819b8
Document server functions in block style variations section (#16997)
jorgefilipecosta Aug 20, 2019
3bcf6aa
[RNMobile] update mobile to not use ListEdit (#17070)
mchowning Aug 20, 2019
91b9104
Typewriter experience (#16460)
ellatrix Aug 20, 2019
af23ee6
[RNMobile] Hide replaceable block when adding block (#16931)
mchowning Aug 20, 2019
a2688c0
Update video player style on mobile
maxme Jul 25, 2019
3b74d9c
Add: Disabled block count in the block manager (#17103)
jorgefilipecosta Aug 21, 2019
1b05159
Use `400` as a valid `font-weight`
ntwb Aug 15, 2019
ac95cf6
Writing Flow/Quote: allow splitting (#17121)
ellatrix Aug 21, 2019
a2d0609
Build: remove global install of latest npm since we want to use the p…
gwwar Aug 22, 2019
b89271b
Project automation: Rewrite actions using JavaScript (#17080)
noisysocks Aug 22, 2019
b77291b
Writing Flow: allow undo of patterns with BACKSPACE and ESC (#14776)
ellatrix Aug 22, 2019
e832a89
Apply box-sizing border-box properly to the notices components (#17066)
youknowriad Aug 22, 2019
6146930
Fix: Converting an image using an external source to a gallery does n…
jorgefilipecosta Aug 22, 2019
ccea4f2
Editor: Update the store to use Core Data entities. (#16932)
epiqueras Aug 22, 2019
be881a3
Add callbacks to ServerSideRenderer to handle failures with custom re…
mikejolley Aug 22, 2019
393e01e
[RNMobile] Insure tapping at end of post inserts at end
mchowning Aug 6, 2019
5d21cd0
Project management automation: Fix 'add first time contributor label'…
noisysocks Aug 23, 2019
05b173c
Scripts: Improve recommended settings included in the package (#17027)
gziolo Aug 23, 2019
3386f46
Project management automation: Fix 'add milestone' (#17157)
noisysocks Aug 23, 2019
b5a6978
chore: Remove unused css from ColorPalette component (#17152)
jorgefilipecosta Aug 23, 2019
e1ef1c9
Add the block example API and use it for inserter and switcher previe…
youknowriad Aug 23, 2019
555f726
Fix: Block toolbar appears above sidebar on medium viewports (#17108)
jorgefilipecosta Aug 23, 2019
1f6c3b4
eslint BaseControl fix for TypeError: Cannot read property 'name' of …
bfintal Aug 24, 2019
253eaa3
Docs: Fix creating-dynamic-blocks typo (#17172)
jrchamp Aug 24, 2019
1011b19
remove selection toggle on image (#17175)
senadir Aug 25, 2019
42e2f0c
Add circle-crop variation to Image block. (#16475)
Aug 25, 2019
a356b79
Add: Option to select the style that is automatically applied (#16465)
jorgefilipecosta Aug 26, 2019
c2188c0
Enable an optional namespace parameter for hasAction & hasFilter (#15…
adamsilverstein Aug 26, 2019
190de96
Add get_item_schema function to WP_REST_Widget_Areas_Controller (#15981)
jorgefilipecosta Aug 26, 2019
666cbd7
fix(scripts): Use the SCSS shared stylelint-config-wordpress config (…
ntwb Aug 26, 2019
5319aea
Add option to resize Cover Block (#17143)
senadir Aug 26, 2019
539ec35
Fix: Empty Classic Editor inside innerBlock fatal error (#17164)
donmhico Aug 26, 2019
d562340
Allow directly setting a background to Cover (#17041)
senadir Aug 26, 2019
a0d228b
Bump plugin version to 6.4.0-rc.1
jorgefilipecosta Aug 26, 2019
422d812
Update the post schedule label to correctly reflect the date and (#15…
brentswisher Aug 26, 2019
503a804
Use the image alt logic in image block to determine the aria-labels i…
donmhico Aug 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable an optional namespace parameter for hasAction & hasFilter (#15362
)

* from https://github.com/WordPress/packages/pull/106/files

* Update packages/hooks/src/createHasHook.js

Co-Authored-By: Pascal Birchler <pascal.birchler@gmail.com>

* clean up docblock spacing

* add changelog entry for new namespace parameter for hasAction & hasFilter

* Update packages/hooks/CHANGELOG.md

Co-Authored-By: Grzegorz (Greg) Ziółkowski <grzegorz@gziolo.pl>

* break out tests

* update readme

* Apply suggestions from code review

Co-Authored-By: Daniel Richards <daniel.richards@automattic.com>

* Update CHANGELOG.md
  • Loading branch information
adamsilverstein authored and donmhico committed Aug 27, 2019
commit c2188c0d72e23d81c00db31c817cfaf4217b0542
8 changes: 7 additions & 1 deletion packages/hooks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
## Master

### New Feature

- Enable an optional namespace parameter for `hasAction` & `hasFilter`. When checking if an action or filter exists, `hasAction` and `hasFilter` now accept an optional paramter to limit matches by namespace.

## 2.4.0 (2019-06-12)

### New Feature

- Enable support for the 'all' hook in non production environments.
- Enable support for the 'all' hook in non production environments.

## 2.0.4 (2019-01-03)

Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ In the WordPress context, API functions can be called via the global `wp.hooks`
* `doingFilter( 'hookName' )`
* `didAction( 'hookName' )`
* `didFilter( 'hookName' )`
* `hasAction( 'hookName' )`
* `hasFilter( 'hookName' )`
* `hasAction( 'hookName', 'namespace' )`
* `hasFilter( 'hookName', 'namespace' )`
* `actions`
* `filters`

Expand Down
16 changes: 12 additions & 4 deletions packages/hooks/src/createHasHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@
* @param {Object} hooks Stored hooks, keyed by hook name.
*
* @return {Function} Function that returns whether any handlers are
* attached to a particular hook.
* attached to a particular hook and optional namespace.
*/
function createHasHook( hooks ) {
/**
* Returns how many handlers are attached for the given hook.
* Returns whether any handlers are attached for the given hookName and optional namespace.
*
* @param {string} hookName The name of the hook to check for.
* @param {string} hookName The name of the hook to check for.
* @param {?string} namespace Optional. The unique namespace identifying the callback
* in the form `vendor/plugin/function`.
*
* @return {boolean} Whether there are handlers that are attached to the given hook.
*/
return function hasHook( hookName ) {
return function hasHook( hookName, namespace ) {
// Use the namespace if provided.
if ( 'undefined' !== typeof namespace ) {
return hookName in hooks &&
hooks[ hookName ].handlers.some( ( hook ) => hook.namespace === namespace );
}

return hookName in hooks;
};
}
Expand Down
35 changes: 35 additions & 0 deletions packages/hooks/src/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,38 @@ test( 'add multiple all actions and run it any hook to trigger them by priority'
expect( window.actionValue ).toBe( 'ba' );
} );

test( 'checking hasAction with named callbacks and removing', () => {
addAction( 'test.action', 'my_callback', () => {} );
expect( hasAction( 'test.action', 'not_my_callback' ) ).toBe( false );
expect( hasAction( 'test.action', 'my_callback' ) ).toBe( true );
removeAction( 'test.action', 'my_callback' );
expect( hasAction( 'test.action', 'my_callback' ) ).toBe( false );
} );

test( 'checking hasAction with named callbacks and removeAllActions', () => {
addAction( 'test.action', 'my_callback', () => {} );
addAction( 'test.action', 'my_second_callback', () => {} );
expect( hasAction( 'test.action', 'my_callback' ) ).toBe( true );
expect( hasAction( 'test.action', 'my_callback' ) ).toBe( true );
removeAllActions( 'test.action' );
expect( hasAction( 'test.action', 'my_callback' ) ).toBe( false );
expect( hasAction( 'test.action', 'my_callback' ) ).toBe( false );
} );

test( 'checking hasFilter with named callbacks and removing', () => {
addFilter( 'test.filter', 'my_callback', () => {} );
expect( hasFilter( 'test.filter', 'not_my_callback' ) ).toBe( false );
expect( hasFilter( 'test.filter', 'my_callback' ) ).toBe( true );
removeFilter( 'test.filter', 'my_callback' );
expect( hasFilter( 'test.filter', 'my_callback' ) ).toBe( false );
} );

test( 'checking hasFilter with named callbacks and removeAllActions', () => {
addFilter( 'test.filter', 'my_callback', () => {} );
addFilter( 'test.filter', 'my_second_callback', () => {} );
expect( hasFilter( 'test.filter', 'my_callback' ) ).toBe( true );
expect( hasFilter( 'test.filter', 'my_second_callback' ) ).toBe( true );
removeAllFilters( 'test.filter' );
expect( hasFilter( 'test.filter', 'my_callback' ) ).toBe( false );
expect( hasFilter( 'test.filter', 'my_second_callback' ) ).toBe( false );
} );