Running script/plugin directly with server cron?

Just googled it & didn’t get answer in first 10 pages – everything was about WP-cron.

How to directly run plugin/PHP file with server-cron?
Or do you always have to hook your plugin with WP-cron & then hook it with server cron?

Read More

There are 2 options in my server’s cronjob panel: interval and command. Command is currently containg URL to WP-cron.

  • Do I replace it with my plugin URL path?
  • If that’s the case, I imagine plugin doesn’t have to be activated?

Why I ask this?
Server cron just activates WP-cron that checks if it has to run something. That means that those two crons & time when “check” occurs has to be syncronized if I want something to be precise. That doesn’t sound very pleasant, especially if there was a way to directly hook my plugin to server cron. All this also seems too risky to just try and see what happens.

Related posts

1 comment

  1. you can launch the plugin action with the AJAX helper of WordPress like that

    add_action("wp_ajax_nopriv_cleanDB", function () {
        // code to clean the DB
    });
    

    then in your server cron you can call this URL :
    http://server/wp-admin/admin-ajax.php?action=cleanDB

    the command to call an URL depends of the hoster, it can be e.g. wget or curl

Comments are closed.