Skip to content

Instantly share code, notes, and snippets.

@adampatterson
Last active January 25, 2017 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adampatterson/d0ea36c6a570af8cf5553742ed0a9d8c to your computer and use it in GitHub Desktop.
Save adampatterson/d0ea36c6a570af8cf5553742ed0a9d8c to your computer and use it in GitHub Desktop.
Call WordPress CRONs properly, removes event based cron functionality.
<?php
/*
* Since WordPress is event driven, the wp-cron's will run on every single page load.
* This means if you have a larger WordPress site your doing a lot of extra leg work for noreason.
* This fixes that on Multsites
*
* Add this file to the root of your WordPress site and then add define('DISABLE_WP_CRON', 'true');
* to your wp-config.php
*
* Make sure that you create a true CRON job that will call your site URL via curl
* http://www.site.com/wp-multisite-cron.php?doing_wp_cron
* at whatever introverts you think is acceptible.
*
* TIMES:
* hourly
* twicedaily
* daily
* weekly
*
* https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-on-a-vps
*/
require( './wp-load.php' );
$blogs = get_sites( 0, 'all' );
foreach ( $blogs as $blog ) {
$site_url = $blog->domain . $blog->path;
if ( is_ssl() ) {
$site_path = "https://$site_url/wp-cron.php?doing_wp_cron";
} else {
$site_path = "http://$site_url/wp-cron.php?doing_wp_cron";
}
$ch = curl_init( $site_path );
$rc = curl_setopt( $ch, CURLOPT_TIMEOUT, 200 );
$rc = curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
$rc = curl_exec( $ch );
curl_close( $ch );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment