Trying to avoid including wp-load.php

Add a rewrite endpoint to give your plugin a public URL-

function wpa_my_endpoint(){
    add_rewrite_endpoint( 'my_api', EP_ROOT );
}
add_action( 'init', 'wpa_my_endpoint' );

After you flush rewrite rules, you’ll have the URL available for the scheduler to ping.

http://example.com/my_api/do/something/

Then catch those requests on the parse_query action to invoke your plugin action:

function wpa_parse_query( $query ){
    if( isset( $query->query_vars['my_api'] ) ){
        include( plugin_dir_path( __FILE__ ) . 'stuff/things.php');
        exit;
    }
}
add_action( 'parse_query', 'wpa_parse_query' );

Leave a Comment