Skip to content

Instantly share code, notes, and snippets.

@gschoppe
Created November 1, 2016 19:24
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 gschoppe/21d50d6b76ae905c6a445549f22c0269 to your computer and use it in GitHub Desktop.
Save gschoppe/21d50d6b76ae905c6a445549f22c0269 to your computer and use it in GitHub Desktop.
mu-plugin to defer term counting on all bulk edits
<?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