deliciousmedia/quickrest

QuickREST - a WordPress plugin which speeds up REST API requests by selective loading of plugins.

Installs: 803

Dependents: 0

Suggesters: 0

Security: 0

Stars: 20

Watchers: 4

Forks: 4

Open Issues: 0

Type:wordpress-muplugin

2.1.2 2024-01-09 15:34 UTC

This package is auto-updated.

Last update: 2024-05-09 16:17:54 UTC


README

A WordPress plugin which speeds up REST API requests by selective loading of plugins.

Installation

QuickRest needs to be installed as a Must Use plugin.

Install via Composer (composer require deliciousmedia/quickrest), or just clone/copy the files to your mu-plugins folder.

Usage

By default, the plugin will prevent any regular WordPress plugins from loading when a request is made to any REST API endpoint.

Plugins can be enabled on a per-namespace basis by filtering quickrest_plugin_map, for example:

function my_plugin_map_function( $map ) {
  $new_map = [
    'someplugin' => [ 'some-plugin/some-plugin.php' ],
    'wp'         => [ 'plugin-one/plugin-one.php', 'plugin-two/plugin-two.php' ]
   ];
  return array_merge_recursive( $map, $new_map );
}
add_filter( 'quickrest_plugin_map', 'my_plugin_map_function', 15, 1 );

If nothing exists within the array for the current namespace, the plugin will fallback to the _default element which you can choose to enable.

If you want the default (or any other plugin) to load all active plugins, you can do this:

add_filter(
  'quickrest_plugin_map',
  function( $map ) {
    // Remove our filter so we don't get stuck in a loop when getting the active_plugins option.
    remove_filter( 'option_active_plugins', 'quickrest_filter_plugins', PHP_INT_MAX - 1 );
    $new_map = [
      '_default' => get_option( 'active_plugins' ),
    ];
    add_filter( 'option_active_plugins', 'quickrest_filter_plugins', PHP_INT_MAX - 1 );
    return array_merge_recursive( $map, $new_map );
  },
  10,
  1
);

Built by the team at Delicious Media, a specialist WordPress development agency based in Sheffield, UK.