Go to file
Jonathan Desrosiers 34e3de7b7f REST API: Encourage proper usage of `register_rest_route()`.
Calling `register_rest_route()` too early in the loading process has the potential to cause some unintentional problems and pitfalls. Because `register_rest_route()` calls `rest_get_server()` (which creates the `WP_REST_Server` instance), calling the function directly and/or before `rest_api_init` should be discouraged.

For example, if `register_rest_route ()` is called on `init`, the REST API server instance is set up (and all functions added to `rest_api_init` and other related hooks are invoked), even though the current request may not be a REST request. Also, if `register_rest_route()` is called even earlier (say, in an `mu-plugin` file), required endpoints may be missing since normal plugins have not yet been loaded and have not had a chance to register their own action hooks.

This adds a `_doing_it_wrong()` notice the first time `register_rest_route()` is called before `rest_api_init` in a request to encourage best practices for registering REST API routes.

Props kraftbj, desrosj, timothyblynjacobs.
Fixes #45265.

git-svn-id: https://develop.svn.wordpress.org/trunk@44568 602fd350-edb4-49c9-b593-d223f7449a82
2019-01-11 18:18:41 +00:00
src REST API: Encourage proper usage of `register_rest_route()`. 2019-01-11 18:18:41 +00:00
tests REST API: Encourage proper usage of `register_rest_route()`. 2019-01-11 18:18:41 +00:00
tools Build tools: Allow building WordPress to `src`. 2018-12-24 13:28:22 +00:00
.editorconfig General: Instruct file editors not to trim trailing whitespace in markdown files. 2018-03-20 22:14:53 +00:00
.gitignore Build/Test Tools: Update `.gitignore` to exclude `twentynineteen` and `twentysixteen`. 2019-01-09 13:44:30 +00:00
.jshintrc Build tools: Fix the `travis:js` build. 2018-12-24 13:53:11 +00:00
.npmrc Once upon a midnight dreary, while I coded, weak and weary, 2018-05-23 10:04:22 +00:00
.nvmrc Once upon a midnight dreary, while I coded, weak and weary, 2018-05-23 10:04:22 +00:00
.travis.yml Build Tools: Switch to Node 10.13.0. 2018-12-16 01:42:24 +00:00
Gruntfile.js Build Tools: Copy unminified JS files to `src`. 2019-01-10 01:38:22 +00:00
composer.json Coding Standards: Upgrade WPCS to 1.0.0 2018-08-17 01:50:26 +00:00
composer.lock Coding Standards: Upgrade WPCS to 1.0.0 2018-08-17 01:50:26 +00:00
jsdoc.conf.json Build Tools: Fix JSDoc configuration include paths. 2018-06-14 12:45:06 +00:00
package-lock.json Block Editor: Upgrade the `@wordpress/` packages. 2019-01-10 01:53:38 +00:00
package.json Block Editor: Upgrade the `@wordpress/` packages. 2019-01-10 01:53:38 +00:00
phpcs.xml.dist Coding Standards: Add exceptions for `WordPress.Files.FileName.NotHyphenatedLowercase`. 2019-01-11 06:16:35 +00:00
phpunit.xml.dist REST API: Introduce Autosaves controller and endpoint. 2018-12-13 22:41:47 +00:00
webpack.config.js Build tools: Allow building WordPress to `src`. 2018-12-24 13:28:22 +00:00
wp-cli.yml Build/Tests: Default to running unit tests from `src`. 2019-01-09 10:09:02 +00:00
wp-config-sample.php General: Replace "Happy blogging" with "Happy publishing". 2019-01-08 04:29:06 +00:00
wp-tests-config-sample.php Tests: Revert [44509]. 2019-01-09 11:13:03 +00:00