| @@ -1,16 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace WPDeveloper\BetterDocs\Core; |
| 3 | 4 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | - exit; | |
| 6 | -} | |
| 7 | - | |
| 8 | -// FAQ-by-category lookups require tax_query / meta_key filters by design. | |
| 9 | -// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key | |
| 10 | -// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query | |
| 11 | -// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_tax_query | |
| 12 | - | |
| 13 | 5 | use WP_Error; |
| 14 | 6 | use WP_Query; |
| 15 | 7 | use WPDeveloper\BetterDocs\Utils\Base; |
| 16 | 8 | use WPDeveloper\BetterDocs\Utils\Helper; |
| @@ -172,14 +164,14 @@ | ||
| 172 | 164 | * Get the maximum order for this taxonomy. This will be applied to terms that don't have a tax position. |
| 173 | 165 | */ |
| 174 | 166 | private function get_max_taxonomy_order( $tax_slug ) { |
| 175 | 167 | global $wpdb; |
| 176 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- live max-order needed when assigning new terms; cache would be stale. | |
| 168 | + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.QuotedSimplePlaceholder | |
| 177 | 169 | $max_term_order = $wpdb->get_col( |
| 178 | 170 | $wpdb->prepare( |
| 179 | 171 | "SELECT MAX( CAST( tm.meta_value AS UNSIGNED ) ) |
| 180 | 172 | FROM $wpdb->terms t |
| 181 | - JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id AND tt.taxonomy = %s | |
| 173 | + JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id AND tt.taxonomy = '%s' | |
| 182 | 174 | JOIN $wpdb->termmeta tm ON tm.term_id = t.term_id WHERE tm.meta_key = 'order'", |
| 183 | 175 | $tax_slug |
| 184 | 176 | ) |
| 185 | 177 | ); |
| @@ -253,11 +245,9 @@ | ||
| 253 | 245 | '/faq/posts/(?P<type>\S+)', |
| 254 | 246 | [ |
| 255 | 247 | 'methods' => [ 'GET' ], |
| 256 | 248 | 'callback' => [ $this, 'fetch_faq_posts' ], |
| 257 | - 'permission_callback' => function () { | |
| 258 | - return current_user_can( 'edit_others_posts' ); | |
| 259 | - } | |
| 249 | + 'permission_callback' => '__return_true' | |
| 260 | 250 | ] |
| 261 | 251 | ); |
| 262 | 252 | |
| 263 | 253 | register_rest_route( |
| @@ -373,11 +363,9 @@ | ||
| 373 | 363 | '/faq/uncategorised', |
| 374 | 364 | [ |
| 375 | 365 | 'methods' => [ 'GET' ], |
| 376 | 366 | 'callback' => [ $this, 'get_uncategorised_faq' ], |
| 377 | - 'permission_callback' => function () { | |
| 378 | - return current_user_can( 'edit_others_posts' ); | |
| 379 | - } | |
| 367 | + 'permission_callback' => '__return_true' | |
| 380 | 368 | ] |
| 381 | 369 | ); |
| 382 | 370 | |
| 383 | 371 | register_rest_route( |
| @@ -385,16 +373,13 @@ | ||
| 385 | 373 | '/faq/category_search', |
| 386 | 374 | [ |
| 387 | 375 | 'methods' => [ 'GET' ], |
| 388 | 376 | 'callback' => [ $this, 'category_search' ], |
| 389 | - 'permission_callback' => function () { | |
| 390 | - return current_user_can( 'edit_others_posts' ); | |
| 391 | - }, | |
| 377 | + 'permission_callback' => '__return_true', | |
| 392 | 378 | 'args' => [ |
| 393 | 379 | 'title' => [ |
| 394 | - 'type' => 'string', | |
| 395 | - 'required' => true, | |
| 396 | - 'sanitize_callback' => 'sanitize_text_field' | |
| 380 | + 'type' => 'string', | |
| 381 | + 'required' => true | |
| 397 | 382 | ] |
| 398 | 383 | ] |
| 399 | 384 | ] |
| 400 | 385 | ); |
| @@ -633,9 +618,8 @@ | ||
| 633 | 618 | ); |
| 634 | 619 | |
| 635 | 620 | if ( $taxonomy_objects && ! is_wp_error( $taxonomy_objects ) ) : |
| 636 | 621 | foreach ( $taxonomy_objects as $term ) : |
| 637 | - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- core FAQ-by-category query; tax filtering is required functionality. | |
| 638 | 622 | $args = [ |
| 639 | 623 | 'post_type' => 'betterdocs_faq', |
| 640 | 624 | 'post_status' => 'publish', |
| 641 | 625 | 'post_per_page' => -1, |
| @@ -681,13 +665,12 @@ | ||
| 681 | 665 | ] |
| 682 | 666 | ) |
| 683 | 667 | ); |
| 684 | 668 | |
| 685 | - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- intentional NOT-IN scan to find FAQs without any category assignment. | |
| 686 | 669 | return get_posts( |
| 687 | 670 | [ |
| 688 | 671 | 'post_type' => 'betterdocs_faq', |
| 689 | - 'post_status' => current_user_can( 'edit_others_posts' ) ? [ 'publish', 'draft' ] : 'publish', | |
| 672 | + 'post_status' => [ 'publish', 'draft' ], | |
| 690 | 673 | 'posts_per_page' => -1, |
| 691 | 674 | 'tax_query' => [ |
| 692 | 675 | 'relation' => 'AND', |
| 693 | 676 | [ |
| @@ -736,9 +719,8 @@ | ||
| 736 | 719 | |
| 737 | 720 | public function faq_category_orderby_meta( $args, $request ) { |
| 738 | 721 | if ( $args['taxonomy'] === 'betterdocs_faq_category' ) { |
| 739 | 722 | $args['orderby'] = 'meta_value_num'; |
| 740 | - // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- ordering by user-assigned 'order' meta is required UX. | |
| 741 | 723 | $args['meta_key'] = 'order'; |
| 742 | 724 | } |
| 743 | 725 | return $args; |
| 744 | 726 | } |