$intent Intent. * * @return array */ public function get_rest_api_intent( $intent ) { global $wp; $rest_route = $wp->query_vars['rest_route']; $endpoint_parts = explode( '/', str_replace( '/wp/v2/', '', $rest_route ) ); // Set the custom search intent. if ( isset( $wp->query_vars['search'] ) ) { $intent['search'] = sanitize_title( $wp->query_vars['search'] ); } if ( 'unknown' === $intent['type'] && 'docs' === $intent['name'] ) { // If we have a post type or taxonomy, the name is the first part (posts, categories). $post_type = sanitize_key( $endpoint_parts[0] ); if ( 'docs' === $post_type ) { $intent['type'] = 'post_type'; } } // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( isset( $_REQUEST['post_type'] ) && is_string( $_REQUEST['post_type'] ) ) { $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ); // Check if any ct_forced_* request aregs are set. If so we should use the post type intent. if ( strpos( $post_type, 'ct_forced_' ) !== false ) { $intent['type'] = 'post_type'; $post_type = str_replace( 'ct_forced_', '', $post_type ); $intent['name'] = array_values( array_filter( array_map( 'sanitize_key', explode( ':', $post_type ) ) ) ); } } // phpcs:enable WordPress.Security.NonceVerification.Recommended return $intent; } }