Bootstrapping WordPress from a direct PHP file hit is not a good idea in general, the repository maintainers are right. It is pretty simple to add a custom endpoint using the Rewrite API, so there’s no reason you shouldn’t.
add_action( 'init', function() {
/** Add a custom path and set a custom query argument. */
add_rewrite_rule( '^your/custom/path/?$', 'index.php?custom_action=1', 'top' );
} );
add_filter( 'query_vars', function( $query_vars ) {
/** Make sure WordPress knows about this custom action. */
$query_vars []= 'custom_action';
return $query_vars;
} );
add_action( 'wp', function() {
/** This is an call for our custom action. */
if ( get_query_var( 'custom_action' ) ) {
// your code here
}
} );
Now hit https://yoursite.com/your/custom/path/ WordPress will load and call your code.
An even simpler way would be to use a $_GET
parameter.
add_action( 'init', function() {
if ( !empty( $_GET['custom_action'] ) ) {
// your code here
}
} );
And then hit https://yoursite.com/?custom_action=1
Your pick, depending on whether you want a nice URL or you’re satisfied with a less beautiful GET parameter.