Commit Graph

141 Commits

Author SHA1 Message Date
Adam Silverstein
f36cccde7e Add wp.hooks - JavaScript actions and filters.
Add a JavaScript hooks library with an API that mirrors the WordPress Plugin API; provides similar functionality and API to PHP hooks.

Called via the global `wp.hooks`, eg: `wp.hooks.addAction()`, etc. Adds:

* `addAction( 'hook', 'vendor/plugin/function', callback, priority )`
* `addFilter( 'hook', 'vendor/plugin/function', callback, priority )`
* `removeAction( 'hook', 'vendor/plugin/function' )`
* `removeFilter( 'hook',  'vendor/plugin/function' )`
* `removeAllActions( 'hook' )`
* `removeAllFilters( 'hook' )`
* `doAction( 'hook', arg1, arg2, moreArgs, finalArg )`
* `applyFilters( 'hook', content, arg1, arg2, moreArgs, finalArg )`
* `doingAction( 'hook' )`
* `doingFilter( 'hook' )`
* `didAction( 'hook' )`
* `didFilter( 'hook' )`
* `hasAction( 'hook' )`
* `hasFilter( 'hook' )`

Props adamsilverstein, jnylen0, aduth, kadamwhite, youknowriad, schlessera, mikeschinkel, azaozz, vhauri, CaptainN, scribu, carldanley, chetanchauhan, mgibbs189, stephenharris, justnorris, koopersmith, gcorne, TV productions, atimmer.

Fixes #21170.


Built from https://develop.svn.wordpress.org/trunk@41375


git-svn-id: http://core.svn.wordpress.org/trunk@41208 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-09-12 12:54:45 +00:00
Drew Jaynes
fabca552aa Docs: Clarify the expected usage of the $args parameter as an array in the DocBlock for apply_filters_deprecated(), including an example.
See #41017.

Built from https://develop.svn.wordpress.org/trunk@41308


git-svn-id: http://core.svn.wordpress.org/trunk@41139 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-08-23 15:52:46 +00:00
John Blackbourn
28eda6f4bc General: Improve terminology used when referring to installations of WordPress and its extensions.
"Install" is not a noun, and while it might be acceptable to use the verb as a noun, it is not correct. Using the correct
noun, "installation", increases clarity, especially for non-native English speakers.

This change fixes the usage in user-facing text and in developer documentation.

Fixes #41620

Built from https://develop.svn.wordpress.org/trunk@41289


git-svn-id: http://core.svn.wordpress.org/trunk@41129 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-08-22 11:52:48 +00:00
Gary Pendergast
4dcb7a0fa9 Bootstrap: Use dirname() when loading class-wp-hook.php from plugin.php.
To allow `plugin.php` to be loaded before the rest of WordPress is loaded, it cannot rely on WordPress constants, such as `ABSPATH` and `WPINC`.

Instead, we can assume that `class-wp-hook.php` will be in the same directory as `plugin.php`, so `dirname( __FILE__ )` will give us the correct path to load from.

Props pento, dd32.
Fixes #37707.


Built from https://develop.svn.wordpress.org/trunk@38589


git-svn-id: http://core.svn.wordpress.org/trunk@38532 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-09-12 01:50:30 +00:00
Gary Pendergast
5a632be944 Hooks: Add the new class WP_Hook, and modify hook handling to make use of it.
Filters and actions have been the basis of WordPress' plugin functionality since time immemorial, they've always been a reliable method for acting upon the current state of WordPress, and will continue to be so.

Over the years, however, edge cases have cropped up. Particularly when it comes to recursively executing hooks, or a hook adding and removing itself, the existing implementation struggled to keep up with more complex use cases.

And so, we introduce `WP_Hook`. By changing `$wp_filter` from an array of arrays, to an array of objects, we reduce the complexity of the hook handling code, as the processing code (see `::apply_filters()`) only needs to be aware of itself, rather than the state of all hooks. At the same time, we're able te handle more complex use cases, as the object can more easily keep track of its own state than an array ever could.

Props jbrinley for the original architecture and design of this patch.
Props SergeyBiryukov, cheeserolls, Denis-de-Bernardy, leewillis77, wonderboymusic, nacin, jorbin, DrewAPicture, ocean90, dougwollison, khag7, pento, noplanman and aaroncampbell for their testing, suggestions, contributions, patch maintenance, cajoling and patience as we got through this.
Fixes #17817.


Built from https://develop.svn.wordpress.org/trunk@38571


git-svn-id: http://core.svn.wordpress.org/trunk@38514 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-09-08 03:55:31 +00:00
Aaron Jorbin
a138374ec8 Bootstrap/Load: Include Plugin API via require_once
Currently, auto-prepended files need to directly modify the globals in order to add filters and actions. This is a bad idea. Globals are bad. You should never directly interact with the Plugin globals.

Fixes #37707.


Built from https://develop.svn.wordpress.org/trunk@38282


git-svn-id: http://core.svn.wordpress.org/trunk@38223 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-08-19 04:10:30 +00:00
Aaron Jorbin
7e14c27bb9 Bootstrap/Load: Revert Plugin Global restoration around advance-cache.php.
First added in [37588] and later modified in [38224], the idea was to ensure that filters/actions added before `advance-cache.php` would not disappear if `advance-cache.php` overloaded the filters/actions with code such as `$wp_filter = array()`. This is an edge case and one that there is no documented case of existing.

This restores the behavior from WordPress 4.5 and before. It is strongly encouraged that developers using `advance-cache.php` to use the Plugins API that is available before the loading of `advance-cache.php` rather than directly interacting with any of the globals.

Props azaozz, jorbin, dd32 for review, pento for review, westi for investigation, ipstenu for research.
See #36819.


Built from https://develop.svn.wordpress.org/trunk@38251


git-svn-id: http://core.svn.wordpress.org/trunk@38192 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-08-13 16:00:33 +00:00
Gary Pendergast
4ac3feaa64 Boostrap/Load: Improve forward compatiblity of plugin global backup methods.
[37588] added methods to backup the plugin globals, for ensuring that advanced cache drop-ins don't overwrite hooks that've been added earlier in the load process.

The method for restoring the plugin globals wasn't compatible with the implementation of `WP_Hook` in #17817. `WP_Hook` implements `ArrayAccess`, so `_restore_plugin_globals()` was treating it as an array, and inadvertantly overwriting the `WP_Hook` object with a plain array.

To avoid having to re-write this code as part of #17817, we now use `add_filter()` to restore any hooks that were added by cache drop-ins, which `WP_Hook` correctly supports.

Props pento, jorbin.
See #36819.


Built from https://develop.svn.wordpress.org/trunk@38223


git-svn-id: http://core.svn.wordpress.org/trunk@38164 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-08-09 01:45:29 +00:00
Drew Jaynes
e6267dcf19 Docs: Fix formatting, tense, verb conjugation, and other syntax for wp-includes/* elements introduced or changed in 4.6.
Part 2/2.

Fixes #37318.

Built from https://develop.svn.wordpress.org/trunk@38125


git-svn-id: http://core.svn.wordpress.org/trunk@38066 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-07-20 19:33:30 +00:00
Drew Jaynes
d8a6dee52c Docs: Update a cross-reference in the DocBlock for wp_register_plugin_realpath() from plugin_basename() to wp_normalize_path().
Props zuige.
Fixes #37357.

Built from https://develop.svn.wordpress.org/trunk@38061


git-svn-id: http://core.svn.wordpress.org/trunk@38002 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-07-13 19:22:28 +00:00
Sergey Biryukov
139387b7e5 Docs: Use 3-digit, x.x.x-style semantic versioning for _doing_it_wrong(), _deprecated_function(), _deprecated_argument(), and _deprecated_file() throughout core.
Props metodiew.
Fixes #36495.
Built from https://develop.svn.wordpress.org/trunk@37985


git-svn-id: http://core.svn.wordpress.org/trunk@37926 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-07-06 12:40:29 +00:00
Dominik Schilling
dc994f5db5 Plugins: In plugin_basename() sort plugin paths before resolving symlinks.
`arsort()` sorts the paths reverse-alphabetically while preserving the keys. It results in a longer path being listed before a shorter one with the same base directory(ies).

Props jdgrimes, ocean90.
Fixes #28441.
Built from https://develop.svn.wordpress.org/trunk@37983


git-svn-id: http://core.svn.wordpress.org/trunk@37924 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-07-06 09:45:27 +00:00
Dominik Schilling
e210ea830b Plugins: Return the original value in apply_filters_deprecated() if no filter is registered for the tag.
Props flixos90.
Fixes #10441.
Built from https://develop.svn.wordpress.org/trunk@37911


git-svn-id: http://core.svn.wordpress.org/trunk@37852 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-29 13:22:27 +00:00
Jeremy Felt
6f3f00ea97 Multisite: Change WP_Network id property to an integer.
For consistency and developer sanity.

Props flixos90.
Fixes #37050.

Built from https://develop.svn.wordpress.org/trunk@37870


git-svn-id: http://core.svn.wordpress.org/trunk@37811 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-26 14:26:29 +00:00
Peter Wilson
47d26cd9fb DOCS: Replace HTTP links with HTTPS.
Replaces unsecure links in documentation and translator comments with their secure versions.

Props johnpgreen, netweb

Fixes #36993

Built from https://develop.svn.wordpress.org/trunk@37674


git-svn-id: http://core.svn.wordpress.org/trunk@37640 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-06-10 04:50:33 +00:00
Aaron Jorbin
95cbf8922b Bootstrap/Load: Load plugin.php earlier in wp-settings.php
In order to allow non-web initializations of WordPress (such as through wp-cli) to modify things like the check for maintenance mode, plugins.php and the associated functions must be available much earlier. The use of these functions earlier than the loading of plugins is not recommended in most use cases.

Fixes #36819. See #34936.
Props jorbin, danielbachhuber for documentation.

Built from https://develop.svn.wordpress.org/trunk@37588


git-svn-id: http://core.svn.wordpress.org/trunk@37556 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-05-27 19:20:29 +00:00
Drew Jaynes
fe3b007fdd Docs: Remove inline @see tags from function, class, and method references in inline docs.
Known functions, classes, and methods are now auto-linked in Code Reference pages following #meta1483.

Note: Hook references are still linked via inline `@see` tags due to the unlikelihood of reliably matching for known hooks based on a RegEx pattern.

See #32246.

Built from https://develop.svn.wordpress.org/trunk@37342


git-svn-id: http://core.svn.wordpress.org/trunk@37308 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-05-02 04:00:28 +00:00
Dominik Schilling
4b51bc18cc Plugins: In plugin_basename() normalize the file path before unresolving symlinks.
`$wp_plugin_paths` contains normalized paths, see `wp_register_plugin_realpath()`.

Props jdgrimes, voldemortensen, flyingdr, ocean90.
Fixes #29154.
Built from https://develop.svn.wordpress.org/trunk@37332


git-svn-id: http://core.svn.wordpress.org/trunk@37298 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-04-30 15:09:27 +00:00
Dominik Schilling
f3c20d5011 Docs: Fix indentation in add_filter() example.
See #32246.
Built from https://develop.svn.wordpress.org/trunk@36392


git-svn-id: http://core.svn.wordpress.org/trunk@36359 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-01-25 18:58:27 +00:00
John Blackbourn
7e43e20436 Docs: @see != @since.
See #32246

Built from https://develop.svn.wordpress.org/trunk@36073


git-svn-id: http://core.svn.wordpress.org/trunk@36038 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-12-23 07:13:26 +00:00
John Blackbourn
c2248060fe Add missing variadic markers to the optional parameters of do_action() and apply_filters().
See #32246

Built from https://develop.svn.wordpress.org/trunk@35912


git-svn-id: http://core.svn.wordpress.org/trunk@35876 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-12-14 02:36:25 +00:00
John Blackbourn
2984cdf457 Revert [35910].
Built from https://develop.svn.wordpress.org/trunk@35911


git-svn-id: http://core.svn.wordpress.org/trunk@35875 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-12-14 02:35:26 +00:00
John Blackbourn
de7ccd262a Built from https://develop.svn.wordpress.org/trunk@35910
git-svn-id: http://core.svn.wordpress.org/trunk@35874 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-12-14 02:33:25 +00:00
John Blackbourn
aa35e473f7 callback is not a valid type in PHP, PSR-5, or phpDocumentor. callable should be used instead.
Fixes #34032

Built from https://develop.svn.wordpress.org/trunk@34566


git-svn-id: http://core.svn.wordpress.org/trunk@34530 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 23:58:25 +00:00
Drew Jaynes
33a1c0fc16 Docs: Clarify the significance of the $accepted_args parameter value in the documentation for add_filter().
Adds a couple of examples to illustrate callbacks accepting a variable number of arguments.

Fixes #33862.

Built from https://develop.svn.wordpress.org/trunk@34288


git-svn-id: http://core.svn.wordpress.org/trunk@34252 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-18 14:53:28 +00:00
Scott Taylor
ef87172270 foreach is a statement, not a function.
See #33491.

Built from https://develop.svn.wordpress.org/trunk@33734


git-svn-id: http://core.svn.wordpress.org/trunk@33702 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-08-25 20:28:22 +00:00
Scott Taylor
a0e373ef80 For doc block types, favor bool over the few remaining booleans
See #32444.

Built from https://develop.svn.wordpress.org/trunk@32964


git-svn-id: http://core.svn.wordpress.org/trunk@32935 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-06-27 01:03:25 +00:00
John Blackbourn
768d8507e5 Correct a typo in the inline docs for add_action().
Props nabil_kadimi, swissspidy
Fixes #32697

Built from https://develop.svn.wordpress.org/trunk@32829


git-svn-id: http://core.svn.wordpress.org/trunk@32800 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-06-18 08:37:25 +00:00
Scott Taylor
19a3aacc94 Add @static* annotations where they are missing.
Initialize all static vars that are not, most to `null`.

See #32444.

Built from https://develop.svn.wordpress.org/trunk@32650


git-svn-id: http://core.svn.wordpress.org/trunk@32620 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-05-29 15:43:29 +00:00
Scott Taylor
fd04235a04 Add missing doc blocks to plugin.php.
`has_filter()` can use strict comparison when checking `$has` internally.

See #32444.

Built from https://develop.svn.wordpress.org/trunk@32615


git-svn-id: http://core.svn.wordpress.org/trunk@32585 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-05-27 15:56:26 +00:00
Scott Taylor
af7a017f46 When calling unset(), it is unnecessary to immediately precede it with a call to isset().
See #32444.

Built from https://develop.svn.wordpress.org/trunk@32545


git-svn-id: http://core.svn.wordpress.org/trunk@32515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-05-22 05:47:25 +00:00
Dominik Schilling
64fc7294b6 Use HTTPS URLs for codex.wordpress.org.
see #27115.
Built from https://develop.svn.wordpress.org/trunk@32116


git-svn-id: http://core.svn.wordpress.org/trunk@32095 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-04-12 21:29:32 +00:00
Drew Jaynes
31d731cfe4 Fix a typo in the description for the _wp_filter_build_unique_id() DocBlock.
Props lamosty.
Fixes #31732.

Built from https://develop.svn.wordpress.org/trunk@31859


git-svn-id: http://core.svn.wordpress.org/trunk@31838 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-03-22 22:56:27 +00:00
Scott Taylor
b4869ed42f Avoid function calls on each iteration of a for loop.
See #30799.

Built from https://develop.svn.wordpress.org/trunk@31678


git-svn-id: http://core.svn.wordpress.org/trunk@31659 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-03-08 23:01:26 +00:00
Scott Taylor
60b0cd7943 The keyword elseif should be used instead of else if so that all control keywords look like single words.
This was a mess, is now standardized across the codebase, except for a few 3rd-party libs. 

See #30799.

Built from https://develop.svn.wordpress.org/trunk@31090


git-svn-id: http://core.svn.wordpress.org/trunk@31071 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-08 07:05:25 +00:00
Boone Gorges
36f36dca77 In remove_all_filters(), only remove callbacks that match the $priority parameter.
Props GeertDD, valendesigns.
Fixes #20920.
Built from https://develop.svn.wordpress.org/trunk@31014


git-svn-id: http://core.svn.wordpress.org/trunk@30995 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-12-31 19:07:24 +00:00
Drew Jaynes
188e47869f Ensure inline code is markdown-escaped as such, HTML tags are removed from summaries, and that code snippets in descriptions are properly indented.
Affects DocBlocks for the following core elements:
* Markdown-indent a code snippet in the description for `wp_salt()`
* Backtick-escape inline code in the return description for `get_avatar()`
* Various markdown formatting in the description for `add_filter()`
* Markdown-indent a code snippet in the description for `apply_filters()`
* Backtick-escape inline code in the `@see` description for `apply_filters_ref_array()`
* Backtick-escape inline code in the description for `do_action()`
* Backtick-escape variables in the parameter and return descriptions for `do_action_ref_array()`
* Various markdown formatting in the description for `get_plugin_data()`

Props rarst.
See #30473.

Built from https://develop.svn.wordpress.org/trunk@30544


git-svn-id: http://core.svn.wordpress.org/trunk@30533 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-24 06:05:23 +00:00
Drew Jaynes
f8657d5890 Remove redundant and erroneous @uses tag from most core inline documentation.
Per our inline documentation standards, no further use of the `@uses` tag is recommended as used and used-by relationships can be derived through other means. This removes most uses of the tag in core documentation, with remaining tags to be converted to `@global` or `@see` as they apply.

Fixes #30191.

Built from https://develop.svn.wordpress.org/trunk@30105


git-svn-id: http://core.svn.wordpress.org/trunk@30105 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-30 01:05:24 +00:00
Mark Jaquith
e1f2b3b9e2 Use HTTPS URLs for trac.wordpress.org (and use core.trac.wordpress.org)
see #27115
Built from https://develop.svn.wordpress.org/trunk@29789


git-svn-id: http://core.svn.wordpress.org/trunk@29561 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-09-29 13:37:16 +00:00
Andrew Nacin
b5f0a32baa Unit tests for has_filter() not resetting the array pointer.
props pento.
fixes #29070. see [29472].

Built from https://develop.svn.wordpress.org/trunk@29665


git-svn-id: http://core.svn.wordpress.org/trunk@29439 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-09-02 06:50:15 +00:00
Scott Taylor
d45cde548e After [29422], make sure the internal array counter is not reset for the $wp_filter global.
Props kovshenin.
See #29070.

Built from https://develop.svn.wordpress.org/trunk@29472


git-svn-id: http://core.svn.wordpress.org/trunk@29250 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-08-12 14:47:17 +00:00
Scott Taylor
8f73ec76d1 After [28883], ensure that priorities have callbacks before returning true in has_filter().
Adds unit tests.

Props boonebgorges.
Fixes #29070.

Built from https://develop.svn.wordpress.org/trunk@29422


git-svn-id: http://core.svn.wordpress.org/trunk@29200 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-08-07 02:30:20 +00:00
Drew Jaynes
e7f7fcbab8 General phpDoc fixes in wp-includes/plugin.php.
See #28516.

Built from https://develop.svn.wordpress.org/trunk@28891


git-svn-id: http://core.svn.wordpress.org/trunk@28690 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-29 09:19:15 +00:00
Sergey Biryukov
341eca6024 List the expected @param type first.
see #28516.
Built from https://develop.svn.wordpress.org/trunk@28889


git-svn-id: http://core.svn.wordpress.org/trunk@28688 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-29 08:47:14 +00:00
Sergey Biryukov
7bb7693dd1 More tweaks to @param docs in wp-includes/plugin.php.
see #28516.
Built from https://develop.svn.wordpress.org/trunk@28888


git-svn-id: http://core.svn.wordpress.org/trunk@28687 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-29 08:42:16 +00:00
Scott Taylor
62075239b8 Update @param docs in plugin.php
Props dkotter.
Fixes #28516.

Built from https://develop.svn.wordpress.org/trunk@28886


git-svn-id: http://core.svn.wordpress.org/trunk@28685 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-28 04:50:15 +00:00
Scott Taylor
0289b98648 After [28883], remove_filter() should set $GLOBALS['wp_filter'][ $tag ] to array() when empty.
Props wonderboymusic, sphoid.
Fixes #28142.

Built from https://develop.svn.wordpress.org/trunk@28884


git-svn-id: http://core.svn.wordpress.org/trunk@28683 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-28 04:38:15 +00:00
Scott Taylor
9275c87190 remove_all_filters() should set to array(), not call unset().
Props nacin, c3mdigital.
Fixes #19306.

Built from https://develop.svn.wordpress.org/trunk@28883


git-svn-id: http://core.svn.wordpress.org/trunk@28682 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-28 04:27:15 +00:00
Drew Jaynes
320b3751a3 Add a missing @since 3.9.0 to the PHPDoc for wp_register_plugin_realpath().
See #16953, #27700.

Built from https://develop.svn.wordpress.org/trunk@28011


git-svn-id: http://core.svn.wordpress.org/trunk@27841 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-04-07 21:34:14 +00:00
Drew Jaynes
4ed628a7c6 Improve inline documentation for functionality in wp-includes/plugin.php added in 3.9.
See #14994, #27700.

Built from https://develop.svn.wordpress.org/trunk@28010


git-svn-id: http://core.svn.wordpress.org/trunk@27840 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-04-07 21:30:14 +00:00