Disable filters during refresh

This commit is contained in:
Cooper Dalrymple
2026-01-21 20:13:10 -06:00
parent ed82ea7ad9
commit 604911be84

View File

@@ -88,6 +88,15 @@ final class Sort {
// Post Updating
add_action('save_post', [$this, 'save_post'], 10, 3);
// Ajax
add_action('wp_ajax_ogre_sort', [$this, 'sort']);
$this->enable();
}
protected function enable():void {
if (empty($this->relationships)) return;
// Post Types
add_action('pre_get_posts', [$this, 'pre_get_posts'], 10, 1);
add_filter('get_previous_post_where', [$this, 'previous_post_where']);
@@ -101,9 +110,24 @@ final class Sort {
add_filter('wp_get_object_terms', [$this, 'wp_get_object_terms'], 10, 4);
add_filter('get_terms', [$this, 'get_terms'], 10, 4);
add_action('create_term', [$this, 'add_term_relationship'], 10, 3);
}
// Ajax
add_action('wp_ajax_ogre_sort', [$this, 'sort']);
protected function disable():void {
if (empty($this->relationships)) return;
// Post Types
remove_action('pre_get_posts', [$this, 'pre_get_posts'], 10, 1);
remove_filter('get_previous_post_where', [$this, 'previous_post_where']);
remove_filter('get_previous_post_sort', [$this, 'previous_post_sort']);
remove_filter('get_next_post_where', [$this, 'next_post_where']);
remove_filter('get_next_post_sort', [$this, 'next_post_sort']);
// Taxonomy
remove_filter('terms_clauses', [$this, 'terms_clauses'], 10, 3);
remove_filter('get_terms_orderby', [$this, 'get_terms_orderby'], 10, 3);
remove_filter('wp_get_object_terms', [$this, 'wp_get_object_terms'], 10, 4);
remove_filter('get_terms', [$this, 'get_terms'], 10, 4);
remove_action('create_term', [$this, 'add_term_relationship'], 10, 3);
}
public function current_screen() {
@@ -705,6 +729,8 @@ final class Sort {
public function refresh($relationship) {
global $wpdb;
$this->disable();
switch ($relationship['type']) {
case 'term':
@@ -841,6 +867,8 @@ final class Sort {
}
$this->enable();
return true;
}