multisite | Business, Marketing & SEO Forums https://support.shorturl.gg Knowledge Help Portal | Business and Marketing SEO Forums. Find your answers here Fri, 03 Feb 2023 19:54:05 +0000 en-US hourly 1 https://support.shorturl.gg/wp-content/uploads/2020/08/url-chain-32px.png multisite | Business, Marketing & SEO Forums https://support.shorturl.gg 32 32 You Are Using WP Cron Incorrectly In Your WordPress Multisite! https://support.shorturl.gg/business-marketing-and-seo-forums/topic/you-are-using-wp-cron-incorrectly-in-wordpress-multisite/ Tue, 09 Aug 2022 16:10:34 +0000 https://support.shorturl.gg/business-marketing-and-seo-forums/topic/you-are-using-wp-cron-incorrectly-on-wordpress-multisite/ Why You are using WP Cron Incorrectly on WordPress Multiste and how to fix it.

Updated 21-01-2023 with code corrections by WPMU Dev. Multisite cron script code  are now compliant with PHP 8.x.x.

Why You Are Running WP Cron The Wrong Way in WPMU

So you have installed your new shiny WordPress website and then converted it to an awesome WordPress Multisite network with all the bells and whistles; you have configured the WordPress cron job either though C-Panel with wp.cron.php or through a plugin. All happy days right?

Nope!

Why?
Well while this is perfectly fine and good when it comes to single stand-alone WordPress installation it is just not good enough to WordPress Multisite and it doesn’t apply if you run a WordPress Multisite installation. Actually all the generic common advice you can find on the internet about configuring WordPress cron is absolutely incorrect!

This is because there is a little dirty WordPress secret that you cannot find even on WordPress.org’s own website. And “what is that secret” you might ask?

Well the secret is that thew wp-cron.php file only fire and run on your main site in Multisite and not on all your sub-sites in WordPress Multisite so all the scheduled tasks that you might setup for any sub-site in the WordPress Multisite network will never ever run correctly.. Crazy isn’t it?

So we thought too and therefore created a fix for it.

In WordPress you have a small file called wp-cron.php, which simulates normal cron-jobs. except this file isn’t executed every x amount of minutes. Instead WP-Cron will execute when someone visit the website. This will in normal single site fire when either user visits the website which then in turn will run the scheduled tasks. Now there is problem with this method in two ways of course. The first reason is that if you have low traffic site, then wp-cron will almost never fire and the task will not run all the time and two; on high traffic site it be very problematic due to it can generate too many cron tasks that it quickly uses all the server memory and crash the server. So for that reason most WP cron tutorials suggest that you disable wp-cron in your WordPress installation:


and then you set up a manual cron job. This is all good so far. The issue starts when you using WordPress Multisite and the cron job only run by default for the primary website aka. site ID 1. We have coded a this a fix for this issue and our script called “wp-cron-multisite.php” which will enable cron to run on all websites in the WordPress Multisite network with a short delay of 10000000 microseconds between each site in the system.

What you need to do to fix this:

Download our wp-cron-multisite.php and wp-croncustom.php script to your computer and save it as wp-cron-multisite.php and then upload it to your root folder of your WordPress installation:

wp-cron-mulitiste.php

wp-cron-custom.php


After that you will need to disable wp-cron in your wp-config.php file if you haven’t already done that:


and enable alternative cron for our custom WordPress Multisite cron job script.

Once you have completed this step then head over to your hosting control panel and create the cron job manually:


or you could alternative use a online cron service to call the script for you if you prefer that. I suggest this website www.cron-job.org which is totally free to use and just works flawlessly.

What happens when you fire the wp-cron-multisite.php is that it run alongside with the other file and that will call ‘wp-cron-custom.php’ which is a modification of ‘wp-cron.php’ file.

You should now have smoothly working WordPress Multisite network that just works with its scheduled task.

You can also if you want to test run the script your browsers to confirm that it is working properly:
https://yourwebsite.com/wp-cron-multisite.php
Hit enter and wait a little while and you should see the response that it is starting to fire up the cron jobs individually for each website which you have in the WordPress Multisite network.

All right; that’s it good folks for now and I’m out of here!

Comment here in this SEO forum thread if you want and share this with your with anyone you think might have good use of this.

]]>