├── README.md ├── composer.json └── quickrest.php /README.md: -------------------------------------------------------------------------------- 1 | # QuickREST 2 | 3 | A WordPress plugin which speeds up REST API requests by selective loading of plugins. 4 | 5 | ## Installation 6 | 7 | QuickRest needs to be installed as a Must Use plugin. 8 | 9 | Install via Composer (`composer require deliciousmedia/quickrest`), or just clone/copy the files to your mu-plugins folder. 10 | 11 | ## Usage 12 | 13 | By default, the plugin will prevent any regular WordPress plugins from loading when a request is made to any REST API endpoint. 14 | 15 | Plugins can be enabled on a per-namespace basis by filtering `quickrest_plugin_map`, for example: 16 | 17 | ``` 18 | function my_plugin_map_function( $map ) { 19 | $new_map = [ 20 | 'someplugin' => [ 'some-plugin/some-plugin.php' ], 21 | 'wp' => [ 'plugin-one/plugin-one.php', 'plugin-two/plugin-two.php' ] 22 | ]; 23 | return array_merge_recursive( $map, $new_map ); 24 | } 25 | add_filter( 'quickrest_plugin_map', 'my_plugin_map_function', 15, 1 ); 26 | ``` 27 | 28 | If nothing exists within the array for the current namespace, the plugin will fallback to the `_default` element which you can choose to enable. 29 | 30 | If you want the default (or any other plugin) to load all active plugins, you can do this: 31 | 32 | ``` 33 | add_filter( 34 | 'quickrest_plugin_map', 35 | function( $map ) { 36 | // Remove our filter so we don't get stuck in a loop when getting the active_plugins option. 37 | remove_filter( 'option_active_plugins', 'quickrest_filter_plugins', PHP_INT_MAX - 1 ); 38 | $new_map = [ 39 | '_default' => get_option( 'active_plugins' ), 40 | ]; 41 | add_filter( 'option_active_plugins', 'quickrest_filter_plugins', PHP_INT_MAX - 1 ); 42 | return array_merge_recursive( $map, $new_map ); 43 | }, 44 | 10, 45 | 1 46 | ); 47 | ``` 48 | 49 | --- 50 | Built by the team at [Delicious Media](https://www.deliciousmedia.co.uk/), a specialist WordPress development agency based in Sheffield, UK. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deliciousmedia/quickrest", 3 | "description": "QuickREST - a WordPress plugin which speeds up REST API requests by selective loading of plugins.", 4 | "homepage": "https://github.com/DeliciousMedia/quickrest", 5 | "license": "GPL-3.0-or-later", 6 | "type": "wordpress-muplugin", 7 | "require": 8 | { 9 | "php": ">=7.0", 10 | "composer/installers": "^1.0 || ^2.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /quickrest.php: -------------------------------------------------------------------------------- 1 | [] ] ); 29 | 30 | // Split out the request URI, we're interested in element [2] which will be the namespace. 31 | $url_parts = explode( '/', trailingslashit( $_SERVER['REQUEST_URI'] ) ); 32 | 33 | // Return early if no namespace has been specified. 34 | if ( ! isset( $url_parts[2] ) ) { 35 | return $plugins; 36 | } 37 | 38 | // If we have something for this namespace, use that, otherwise fallback to a default. 39 | $plugins_allowed = isset( $plugin_whitelist[ $url_parts[2] ] ) ? $plugin_whitelist[ $url_parts[2] ] : $plugin_whitelist['_default']; 40 | 41 | // Return only plugins which are active and in our whitelist. 42 | return array_intersect( $plugins, (array) $plugins_allowed ); 43 | } 44 | add_filter( 'option_active_plugins', 'quickrest_filter_plugins', PHP_INT_MAX - 1, 1 ); 45 | --------------------------------------------------------------------------------