Created
November 1, 2016 19:24
-
-
Save gschoppe/21d50d6b76ae905c6a445549f22c0269 to your computer and use it in GitHub Desktop.
mu-plugin to defer term counting on all bulk edits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if(!defined('ABSPATH')) { die(); } // Include in all php files, to prevent direct execution | |
if( !class_exists('SpeedUpBulkEdit') ) { | |
class SpeedUpBulkEdit { | |
private static $_this; | |
private $is_bulk = false; | |
public static function Instance() { | |
static $instance = null; | |
if ($instance === null) { | |
$instance = new self(); | |
} | |
return $instance; | |
} | |
private function __construct() { | |
add_filter( 'wp_insert_post_empty_content', array( $this, 'turn_off_bulk_counts' ) ); | |
add_action( 'shutdown', array( $this, 'shutdown' ) ); | |
} | |
public function turn_off_bulk_counts( $filter_data ) { | |
if( isset( $_REQUEST['bulk_edit'] ) && $_REQUEST['bulk_edit'] ) { | |
$this->is_bulk = true; | |
wp_defer_term_counting( true ); | |
} | |
return $filter_data; | |
} | |
public function shutdown() { | |
if( $this->is_bulk ) { | |
wp_defer_term_counting( false ); | |
} | |
} | |
} | |
SpeedUpBulkEdit::Instance(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment