From ed82ea7ad91bf05d6ed89ff663d3b07af54c08b5 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Wed, 21 Jan 2026 20:12:49 -0600 Subject: [PATCH 1/2] Add manual refresh plugin action --- inc/class-refresh.php | 69 +++++++++++++++++++++++++++++++++++++++++++ ogre-sort.php | 1 + 2 files changed, 70 insertions(+) create mode 100644 inc/class-refresh.php diff --git a/inc/class-refresh.php b/inc/class-refresh.php new file mode 100644 index 0000000..37d1649 --- /dev/null +++ b/inc/class-refresh.php @@ -0,0 +1,69 @@ +%s', + esc_url(add_query_arg([ + '_wpnonce' => wp_create_nonce(self::ACTION), + ], self::get_url())), + esc_html(Plugin::__('Refresh')) + )); + } + return $links; + } + + public function handle_action():void { + if (!current_user_can(self::CAPABILITY)) wp_die(Plugin::__('Invalid request.')); + check_admin_referer(self::ACTION); + + Sort::instance()->refresh_all(); + + wp_redirect(add_query_arg([ + self::ACTION => '1', + ], Settings::get_url())); + exit; + } + + public function handle_notices():void { + if (!current_user_can(self::CAPABILITY) || $_GET['page'] != Plugin::get_id() || !isset($_GET[self::ACTION])) return; + printf( + '

%s

', + Plugin::esc_html__('All sort relationships successfully refreshed!') + ); + } + + public static function get_url():string { + return admin_url('admin-post.php?action=' . self::ACTION); + } + +} + +Refresh::instance(); diff --git a/ogre-sort.php b/ogre-sort.php index 40eef69..1f32484 100644 --- a/ogre-sort.php +++ b/ogre-sort.php @@ -41,6 +41,7 @@ final class Sort extends Plugin { $this->add_files([ 'inc/class-settings.php', 'inc/class-sort.php', + 'inc/class-refresh.php', ]); } -- 2.39.5 From 604911be84d6b6c4b902e89a732401a5fd4ea0d8 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Wed, 21 Jan 2026 20:13:10 -0600 Subject: [PATCH 2/2] Disable filters during refresh --- inc/class-sort.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/inc/class-sort.php b/inc/class-sort.php index 2c3c036..273fe68 100644 --- a/inc/class-sort.php +++ b/inc/class-sort.php @@ -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; } -- 2.39.5