Running a cron job on a WP plugin

I’ve slightly modified a wp-plugin that I had in order to make it work automatically.

The address is http://www.example.com/wp-admin/admin.php?page=wp_posts&add=add

Read More

The problem is that I can’t get it to work and my cron is giving me an error when im using it.

I call it with

wget -O /dev/null http://www.example.com/wp-admin/admin.php?page=wp_posts&add=add

and as a result I get

--2015-04-23 10:00:01--  http://www.example.com/wp-admin/admin.php?page=wp_posts
Resolving www.example.com... 46.105.40.207
Connecting to www.example.com|46.105.40.207|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://www.example.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.example.com%2Fwp-admin%2Fadmin.php%3Fpage%3Dwp_posts&reauth=1 [following]
--2015-04-23 10:00:03--  http://www.example.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.example.com%2Fwp-admin%2Fadmin.php%3Fpage%3Dwp_posts&reauth=1
Reusing existing connection to www.example.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “/dev/null”

 0K ...                                                     237M=0s

 2015-04-23 10:00:03 (237 MB/s) - “/dev/null” saved [3180]

So it seems that since this is admin restricted, i have no way to run it.

Any idea on how I can change that ?

Related posts

Leave a Reply

1 comment

  1. You can use this snippet in your functions.php file, and you can run it via public url eg http://example.com/cron

    function my_CronJob() {
        global $wp;
        // Check that we are getting "cron" slug from url.
        if($wp->request == 'cron'){
            // Run you cron script here.  
    
            die();
        }
    }
    
    add_filter('template_redirect', 'my_CronJob');
    

    Or if you want to use wordpress actual standards you can check this article.

    Hope it helps you.