Quantcast
Viewing latest article 5
Browse Latest Browse All 8

Delete Cron Jobs from WordPress

I recently had the struggle of deleting cron jobs from a site within a Multisite network. None of the delete cron functions seemed to work for me, so I wrote a function to brute-force it.

I’m all ears for a better way Image may be NSFW.
Clik here to view.
:D

//Removes a cron based on a hook name
function delete_cron_hooks( $hooks = array(), $blog_id = 0 ) {
	if ( is_multisite() && $blog_id != 0 ) {				
		switch_to_blog( $blog_id );
	}
	$crons = get_option( 'cron' );
	if ( !$crons ) return false;
	foreach ( $crons as $timestamp => $cron ) {
		foreach ( $hooks as $hook ) {
			if ( isset( $cron[ $hook ] ) ) {
				unset( $crons[ $timestamp ] );
			}
		}
	}

	update_option( 'cron', $crons );
	
	
} //end delete_cron

The post Delete Cron Jobs from WordPress appeared first on WordPress and Ajax.


Viewing latest article 5
Browse Latest Browse All 8

Trending Articles