Skip to:
Content

bbPress.org

Changeset 7077


Ignore:
Timestamp:
04/05/2020 07:24:25 PM (8 weeks ago)
Author:
johnjamesjacoby
Message:

Search/Rewrites: unslash search terms inside bbp_get_search_terms().

This commit ensures that search terms appear correctly inside of template output, without additional slashes.

It also eliminates a few repeated calls to bbp_get_search_rewrite_id(), and more strictly compares rewrite rule query vars to null results for improved code clarity & consistency.

Props dd32, johnjamesjacoby.

Fixes #3357. 2.6 branch, for 2.6.5.

Location:
branches/2.6/src/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/common/shortcodes.php

    r6791 r7077  
    672672
    673673        // Set passed attribute to $search_terms for clarity
    674         $search_terms = empty( $attr['search'] ) ? bbp_get_search_terms() : $attr['search'];
     674        $search_terms = empty( $attr['search'] )
     675            ? bbp_get_search_terms()
     676            : $attr['search'];
     677
     678        // Get the rewrite ID (one time, to avoid repeated calls)
     679        $rewrite_id = bbp_get_search_rewrite_id();
    675680
    676681        // Unset globals
     
    678683
    679684        // Set terms for query
    680         set_query_var( bbp_get_search_rewrite_id(), $search_terms );
    681 
    682         // Start output buffer
    683         $this->start( bbp_get_search_rewrite_id() );
     685        set_query_var( $rewrite_id, $search_terms );
     686
     687        // Start output buffer
     688        $this->start( $rewrite_id );
    684689
    685690        // Output template
  • branches/2.6/src/includes/common/template.php

    r7068 r7077  
    871871    $wp_query = bbp_get_wp_query();
    872872
     873    // Get the rewrite ID (one time, to avoid repeated calls)
     874    $rewrite_id = bbp_get_search_rewrite_id();
     875
    873876    // Check query
    874877    if ( ! empty( $wp_query->bbp_is_search ) && ( true === $wp_query->bbp_is_search ) ) {
     
    877880
    878881    // Check query name
    879     if ( empty( $retval ) && bbp_is_query_name( bbp_get_search_rewrite_id() ) ) {
     882    if ( empty( $retval ) && bbp_is_query_name( $rewrite_id ) ) {
    880883        $retval = true;
    881884    }
    882885
    883886    // Check $_GET
    884     if ( empty( $retval ) && isset( $_REQUEST[ bbp_get_search_rewrite_id() ] ) && empty( $_REQUEST[ bbp_get_search_rewrite_id() ] ) ) {
     887    if ( empty( $retval ) && isset( $_REQUEST[ $rewrite_id ] ) && empty( $_REQUEST[ $rewrite_id ] ) ) {
    885888        $retval = true;
    886889    }
  • branches/2.6/src/includes/core/template-functions.php

    r6930 r7077  
    536536    }
    537537
    538     // Get query variables
    539     $bbp_view = $posts_query->get( bbp_get_view_rewrite_id() );
    540     $bbp_user = $posts_query->get( bbp_get_user_rewrite_id() );
    541     $is_edit  = $posts_query->get( bbp_get_edit_rewrite_id() );
     538    // Get query variables (default to null if not set)
     539    $bbp_view  = $posts_query->get( bbp_get_view_rewrite_id(),   null );
     540    $bbp_user  = $posts_query->get( bbp_get_user_rewrite_id(),   null );
     541    $is_edit   = $posts_query->get( bbp_get_edit_rewrite_id(),   null );
     542    $is_search = $posts_query->get( bbp_get_search_rewrite_id(), null );
    542543
    543544    // It is a user page - We'll also check if it is user edit
    544     if ( ! empty( $bbp_user ) ) {
     545    if ( ! is_null( $bbp_user ) ) {
    545546
    546547        /** Find User *********************************************************/
     
    573574
    574575        // View or edit?
    575         if ( ! empty( $is_edit ) ) {
     576        if ( ! is_null( $is_edit ) ) {
    576577
    577578            // We are editing a profile
     
    645646
    646647    // View Page
    647     } elseif ( ! empty( $bbp_view ) ) {
     648    } elseif ( ! is_null( $bbp_view ) ) {
    648649
    649650        // Check if the view exists by checking if there are query args are set
     
    666667
    667668    // Search Page
    668     } elseif ( isset( $posts_query->query_vars[ bbp_get_search_rewrite_id() ] ) ) {
     669    } elseif ( ! is_null( $is_search ) ) {
    669670
    670671        // Check if there are search query args set
     
    684685
    685686    // Forum/Topic/Reply Edit Page
    686     } elseif ( ! empty( $is_edit ) ) {
     687    } elseif ( ! is_null( $is_edit ) ) {
    687688
    688689        // Get the post type from the main query loop
  • branches/2.6/src/includes/search/template.php

    r6903 r7077  
    298298
    299299            // Global
    300             if ( get_query_var( bbp_get_search_rewrite_id() ) ) {
    301                 $search_terms = get_query_var( bbp_get_search_rewrite_id() );
     300            $search_terms = get_query_var( bbp_get_search_rewrite_id(), null );
     301
     302            // Searching globally
     303            if ( ! is_null( $search_terms )  ) {
     304                $search_terms = wp_unslash( $search_terms );
    302305
    303306            // Other searches
Note: See TracChangeset for help on using the changeset viewer.