0

i'm trying to improve the performance of Wordpress API custom endpoints.
I created a plugin, simple file under plugin/PLUGIN_NAME folder where I call "register_rest_route" function to set the endpoints.
To improve the performance I am trying to load not all the plugins, but only what I need, Wordpress CORE to query users and posts and Ultimate Members. That's my code:

define('SHORTINIT', true);
require_once dirname(__FILE__) . '/../../../wp-load.php';
require_once dirname(__FILE__) . '/../ultimate-member/ultimate-member.php';

add_action('rest_api_init', function () {

  register_rest_route( 'my-api/v1', 'test/me',array(
              'methods'  => 'POST',
              'callback' => 'test'
     }
  ));
...
...

It work, but the problem is that works also if I not load "wp-load.php" script. In my test method I use WP_User_Query, WP_Query and ultimate member method like um_user().
It seems like SHORTINIT didn't work.
What I wrong ?

  • That code isn’t doing anything. WordPress has already loaded by the time this code runs. How do you think your plugin is loading and registering it’s endpoint. – Jacob Peattie Sep 20 at 12:48
  • I solve using Plugin Loader Filter, it's simple and it work for me: wordpress.org/plugins/plugin-load-filter – enfix Sep 22 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.