diff --git a/includes/Classifai/Admin/SimilarTermsListTable.php b/includes/Classifai/Admin/SimilarTermsListTable.php index d6b6a6616..c5cdff648 100644 --- a/includes/Classifai/Admin/SimilarTermsListTable.php +++ b/includes/Classifai/Admin/SimilarTermsListTable.php @@ -66,14 +66,34 @@ public function get_columns() { */ public function prepare_items() { $per_page = $this->get_items_per_page( 'edit_post_per_page' ); - $current = $this->get_pagenum(); - $offset = ( $current - 1 ) * $per_page; $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); + $search = isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : ''; $this->_column_headers = array( $columns, $hidden, $sortable ); + $total = wp_count_terms( + [ + 'taxonomy' => $this->taxonomy, + 'hide_empty' => false, + 'meta_key' => 'classifai_similar_terms', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + 'meta_compare' => 'EXISTS', + 'search' => $search, + ] + ); + + $this->set_pagination_args( + array( + 'total_items' => $total, // WE have to calculate the total number of items. + 'per_page' => $per_page, // WE have to determine how many items to show on a page. + 'total_pages' => ceil( $total / $per_page ), // WE have to calculate the total number of pages. + ) + ); + + $current = $this->get_pagenum(); + $offset = ( $current - 1 ) * $per_page; + $terms = get_terms( [ 'taxonomy' => $this->taxonomy, @@ -85,6 +105,7 @@ public function prepare_items() { 'meta_compare' => 'EXISTS', 'number' => $per_page, 'offset' => $offset, + 'search' => $search, ] ); @@ -116,23 +137,7 @@ public function prepare_items() { } } - $total = wp_count_terms( - [ - 'taxonomy' => $this->taxonomy, - 'hide_empty' => false, - 'meta_key' => 'classifai_similar_terms', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key - 'meta_compare' => 'EXISTS', - ] - ); - $this->items = $items; - $this->set_pagination_args( - array( - 'total_items' => $total, // WE have to calculate the total number of items. - 'per_page' => $per_page, // WE have to determine how many items to show on a page. - 'total_pages' => ceil( $total / $per_page ), // WE have to calculate the total number of pages. - ) - ); } /** @@ -149,6 +154,8 @@ public function generate_term_html( $term, $similar_term, $score = null ) { 'taxonomy' => $this->taxonomy, 'from' => $similar_term->term_id, 'to' => $term->term_id, + 'paged' => $this->get_pagenum(), + 's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : false, ); $merge_url = add_query_arg( $args, wp_nonce_url( admin_url( 'admin-post.php' ), 'classifai_merge_term' ) ); $score = $score ? ( $score > 1 ? $score - 1 : $score ) : ''; @@ -215,6 +222,8 @@ public function column_actions( $item ) { 'taxonomy' => $this->taxonomy, 'term' => $term->term_id, 'similar_term' => $similar_term->term_id, + 'paged' => $this->get_pagenum(), + 's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : false, ); $skip_url = add_query_arg( $args, wp_nonce_url( admin_url( 'admin-post.php' ), 'classifai_skip_similar_term' ) ); diff --git a/includes/Classifai/Features/TermCleanup.php b/includes/Classifai/Features/TermCleanup.php index 64e85a540..2f82b2f15 100644 --- a/includes/Classifai/Features/TermCleanup.php +++ b/includes/Classifai/Features/TermCleanup.php @@ -988,10 +988,17 @@ public function render_similar_terms( $taxonomy ) { printf( esc_html__( 'Similar %s', 'classifai' ), esc_html( $label ) ); ?> +
+ + + prepare_items(); + $list_table->search_box( esc_html__( 'Search', 'classifai' ), 'search-term' ); + $list_table->display(); + ?> +
prepare_items(); - $list_table->display(); } } @@ -1060,7 +1067,12 @@ public function merge_term() { $from = isset( $_GET['from'] ) ? absint( wp_unslash( $_GET['from'] ) ) : 0; $to_term = get_term( $to, $taxonomy ); $from_term = get_term( $from, $taxonomy ); - $redirect = add_query_arg( 'tax', $taxonomy, $this->setting_page_url ); + $args = [ + 'tax' => $taxonomy, + 's' => isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : false, + 'paged' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : false, + ]; + $redirect = add_query_arg( $args, $this->setting_page_url ); if ( empty( $taxonomy ) || empty( $to ) || empty( $from ) ) { $this->add_notice( @@ -1127,7 +1139,12 @@ public function skip_similar_term() { $taxonomy = isset( $_GET['taxonomy'] ) ? sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ) : ''; $term = isset( $_GET['term'] ) ? absint( wp_unslash( $_GET['term'] ) ) : 0; $similar_term = isset( $_GET['similar_term'] ) ? absint( wp_unslash( $_GET['similar_term'] ) ) : 0; - $redirect = add_query_arg( 'tax', $taxonomy, $this->setting_page_url ); + $args = [ + 'tax' => $taxonomy, + 's' => isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : false, + 'paged' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : false, + ]; + $redirect = add_query_arg( $args, $this->setting_page_url ); // SKip/Ignore the similar term. $term_meta = get_term_meta( $term, 'classifai_similar_terms', true );