Requiring a file using relative path is never a good idea, that because wp content folder can be easily changed and that make your code fail.
You should convert your file into a MU plugin (you only need to save it wp-content/mu-plugins
folder) and change it to something like:
add_action( 'wp_ajax_super_custom_stuff', 'my_super_custom_stuff' );
add_action( 'wp_ajax_nopriv_super_custom_stuff', 'my_super_custom_stuff' );
function my_super_custom_stuff() {
// additional html stuff
do_action('my_custom_hook');
exit();
}
After that, to make the script run, instead of calling the url
http://example.com/wp-content/plugins/my-plugin-slug/script.php
you can call
http://example.com/wp-admin/admin-ajax.php?action=super_custom_stuff
This will always work because wp-admin
folder, unlike wp-content
, can’t be changed because it is hardcoded in a lot of places.
You can run the script from a linux crontab using something like:
wget -q --spider "http://example.com/wp-admin/admin-ajax.php?action=super_custom_stuff"