Skip to:
Content

BuddyPress.org

Changeset 13520


Ignore:
Timestamp:
07/17/2023 09:01:08 AM (21 months ago)
Author:
imath
Message:

Use BP Rewrites API functions instead of home_url() to build links

See #4954
Fixes #8937
Closes https://github.com/buddypress/buddypress/pull/131

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-template.php

    r13503 r13520  
    421421        global $activities_template;
    422422
    423         $url            = bp_get_requested_url();
     423        $url            = remove_query_arg( 'ac', bp_get_requested_url() );
    424424        $load_more_args = array(
    425425            $activities_template->pag_arg => $activities_template->pag_page + 1,
     
    26102610        global $activities_template;
    26112611
     2612        $query_vars = array();
     2613
     2614        if ( isset( $_GET['acpage'] ) ) {
     2615            $query_vars['acpage'] = (int) wp_unslash( $_GET['acpage'] );
     2616        }
     2617
     2618        if ( isset( $_GET['offset_lower'] ) ) {
     2619            $query_vars['offset_lower'] = (int) wp_unslash( $_GET['offset_lower'] );
     2620        }
     2621
     2622        // This needs to be the last query var.
     2623        $query_vars['ac'] = $activities_template->activity->id;
     2624
     2625        $url = add_query_arg( $query_vars, bp_get_activity_directory_permalink() );
     2626
    26122627        /**
    26132628         * Filters the comment link for the current activity comment.
     
    26152630         * @since 1.2.0
    26162631         *
    2617          * @param string $value Constructed URL parameters with activity IDs.
    2618          */
    2619         return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
     2632         * @param string $url Constructed URL parameters with activity IDs.
     2633         */
     2634        return apply_filters( 'bp_get_activity_comment_link', $url . '/#ac-form-' . $activities_template->activity->id );
    26202635    }
    26212636
     
    26512666
    26522667/**
     2668 * Outputs the URL to cancel a comment.
     2669 *
     2670 * @since 12.0.0
     2671 */
     2672function bp_activity_comment_cancel_url() {
     2673    echo esc_url( bp_get_activity_comment_cancel_url() );
     2674}
     2675
     2676/**
     2677 * Returns the URL to cancel a comment.
     2678 *
     2679 * @since 12.0.0
     2680 *
     2681 * @return string The URL to cancel a comment.
     2682 */
     2683function bp_get_activity_comment_cancel_url() {
     2684    $query_vars = array();
     2685
     2686    if ( isset( $_GET['acpage'] ) ) {
     2687        $query_vars['acpage'] = (int) wp_unslash( $_GET['acpage'] );
     2688    }
     2689
     2690    if ( isset( $_GET['offset_lower'] ) ) {
     2691        $query_vars['offset_lower'] = (int) wp_unslash( $_GET['offset_lower'] );
     2692    }
     2693
     2694    $url = add_query_arg( $query_vars, bp_get_activity_directory_permalink() );
     2695
     2696    /**
     2697     * Filters the cancel comment link for the current activity comment.
     2698     *
     2699     * @since 12.0.0
     2700     *
     2701     * @param string $url Constructed URL parameters with activity IDs.
     2702     */
     2703    return apply_filters( 'bp_get_activity_comment_cancel_url', $url );
     2704}
     2705
     2706/**
    26532707 * Output the activity comment form action.
    26542708 *
     
    26572711 */
    26582712function bp_activity_comment_form_action() {
    2659     echo bp_get_activity_comment_form_action();
     2713    echo esc_url( bp_get_activity_comment_form_action() );
    26602714}
    26612715
     
    26652719     * @since 1.2.0
    26662720     *
    2667      *
    26682721     * @return string The activity comment form action.
    26692722     */
    26702723    function bp_get_activity_comment_form_action() {
     2724        $url  = bp_rewrites_get_url(
     2725            array(
     2726                'component_id'       => 'activity',
     2727                'single_item_action' => 'reply',
     2728            )
     2729        );
    26712730
    26722731        /**
     
    26752734         * @since 1.2.0
    26762735         *
    2677          * @param string $value URL to use in the comment form's action attribute.
    2678          */
    2679         return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );
     2736         * @param string $url URL to use in the comment form's action attribute.
     2737         */
     2738        return apply_filters( 'bp_get_activity_comment_form_action', $url );
    26802739    }
    26812740
     
    28032862        global $activities_template;
    28042863
     2864        $url = bp_rewrites_get_url(
     2865            array(
     2866                'component_id'                 => 'activity',
     2867                'single_item_action'           => 'favorite',
     2868                'single_item_action_variables' => array( $activities_template->activity->id ),
     2869            )
     2870        );
     2871
     2872        $url = wp_nonce_url( $url, 'mark_favorite' );
     2873
    28052874        /**
    28062875         * Filters the activity favorite link.
     
    28082877         * @since 1.2.0
    28092878         *
    2810          * @param string $value Constructed link for favoriting the activity comment.
    2811          */
    2812         return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
     2879         * @param string $url Constructed link for favoriting the activity comment.
     2880         */
     2881        return apply_filters( 'bp_get_activity_favorite_link', $url );
    28132882    }
    28142883
     
    28352904        global $activities_template;
    28362905
     2906        $url = bp_rewrites_get_url(
     2907            array(
     2908                'component_id'                 => 'activity',
     2909                'single_item_action'           => 'unfavorite',
     2910                'single_item_action_variables' => array( $activities_template->activity->id ),
     2911            )
     2912        );
     2913
     2914        $url = wp_nonce_url( $url, 'unmark_favorite' );
     2915
    28372916        /**
    28382917         * Filters the activity unfavorite link.
     
    28402919         * @since 1.2.0
    28412920         *
    2842          * @param string $value Constructed link for unfavoriting the activity comment.
    2843          */
    2844         return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
     2921         * @param string $url Constructed link for unfavoriting the activity comment.
     2922         */
     2923        return apply_filters( 'bp_get_activity_unfavorite_link', $url );
    28452924    }
    28462925
     
    35893668     */
    35903669    function bp_get_activity_post_form_action() {
     3670        $url  = bp_rewrites_get_url(
     3671            array(
     3672                'component_id'       => 'activity',
     3673                'single_item_action' => 'post',
     3674            )
     3675        );
    35913676
    35923677        /**
     
    35953680         * @since 1.2.0
    35963681         *
    3597          * @param string $value URL to be used for the activity post form.
    3598          */
    3599         return apply_filters( 'bp_get_activity_post_form_action', home_url( bp_get_activity_root_slug() . '/post/' ) );
     3682         * @param string $url URL to be used for the activity post form.
     3683         */
     3684        return apply_filters( 'bp_get_activity_post_form_action', $url );
    36003685    }
    36013686
  • trunk/src/bp-core/bp-core-functions.php

    r13514 r13520  
    25342534    }
    25352535
     2536    // Set default search URL.
     2537    $url = bp_get_root_url();
     2538
    25362539    if ( empty( $_POST['search-terms'] ) ) {
    2537         bp_core_redirect( bp_get_root_url() );
     2540        bp_core_redirect( $url );
    25382541        return;
    25392542    }
    25402543
    2541     $search_terms = stripslashes( $_POST['search-terms'] );
    2542     $search_which = !empty( $_POST['search-which'] ) ? $_POST['search-which'] : '';
    2543     $query_string = '/?s=';
     2544    $search_terms         = sanitize_text_field( wp_unslash( $_POST['search-terms'] ) );
     2545    $encoded_search_terms = urlencode( $search_terms );
     2546    $search_which         = '';
     2547
     2548    if ( ! empty( $_POST['search-which'] ) ) {
     2549        $search_which = sanitize_key( wp_unslash( $_POST['search-which'] ) );
     2550    }
    25442551
    25452552    if ( empty( $slug ) ) {
    25462553        switch ( $search_which ) {
    25472554            case 'posts':
    2548                 $slug = '';
    2549                 $var  = '/?s=';
     2555                $url = home_url();
    25502556
    25512557                // If posts aren't displayed on the front page, find the post page's slug.
    2552                 if ( 'page' == get_option( 'show_on_front' ) ) {
     2558                if ( 'page' === get_option( 'show_on_front' ) ) {
    25532559                    $page = get_post( get_option( 'page_for_posts' ) );
    25542560
    2555                     if ( !is_wp_error( $page ) && !empty( $page->post_name ) ) {
     2561                    if ( ! is_wp_error( $page ) && ! empty( $page->post_name ) ) {
    25562562                        $slug = $page->post_name;
    2557                         $var  = '?s=';
     2563                        $url  = get_post_permalink( $page );
    25582564                    }
    25592565                }
     2566
     2567                $url = add_query_arg( 's', $encoded_search_terms, $url );
    25602568                break;
    25612569
    25622570            case 'activity':
    2563                 $slug = bp_is_active( 'activity' )  ? bp_get_activity_root_slug()  : '';
     2571                if ( bp_is_active( 'activity' ) ) {
     2572                    $slug = bp_get_activity_root_slug();
     2573                    $url  = add_query_arg( 'activity_search', $encoded_search_terms, bp_get_activity_directory_permalink() );
     2574                }
    25642575                break;
    25652576
    25662577            case 'blogs':
    2567                 $slug = bp_is_active( 'blogs' )  ? bp_get_blogs_root_slug()  : '';
     2578                if ( bp_is_active( 'blogs' ) ) {
     2579                    $slug = bp_get_blogs_root_slug();
     2580                    $url  = add_query_arg( 'sites_search', $encoded_search_terms, bp_get_blogs_directory_url() );
     2581                }
    25682582                break;
    25692583
    25702584            case 'groups':
    2571                 $slug = bp_is_active( 'groups' ) ? bp_get_groups_root_slug() : '';
     2585                if ( bp_is_active( 'groups' ) ) {
     2586                    $slug = bp_get_groups_root_slug();
     2587                    $url  = add_query_arg( 'groups_search', $encoded_search_terms, bp_get_groups_directory_url() );
     2588                }
    25722589                break;
    25732590
     
    25752592            default:
    25762593                $slug = bp_get_members_root_slug();
     2594                $url  = add_query_arg( 'members_search', $encoded_search_terms, bp_get_members_directory_permalink() );
    25772595                break;
    25782596        }
    25792597
    2580         if ( empty( $slug ) && 'posts' != $search_which ) {
     2598        if ( empty( $slug ) && 'posts' !== $search_which ) {
    25812599            bp_core_redirect( bp_get_root_url() );
    25822600            return;
     
    25892607     * @since 1.0.0
    25902608     *
    2591      * @param string $value        URL for use with site searching.
     2609     * @param string $url        URL for use with site searching.
    25922610     * @param array  $search_terms Array of search terms.
    25932611     */
    2594     bp_core_redirect( apply_filters( 'bp_core_search_site', home_url( $slug . $query_string . urlencode( $search_terms ) ), $search_terms ) );
     2612    bp_core_redirect( apply_filters( 'bp_core_search_site', $url, $search_terms ) );
    25952613}
    25962614
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r13503 r13520  
    935935            break;
    936936        default:
    937             $feed_url = home_url( bp_get_activity_root_slug() . '/feed/' );
     937            $feed_url = bp_rewrites_get_url(
     938                array(
     939                    'component_id'       => 'activity',
     940                    'single_item_action' => 'feed',
     941                )
     942            );
    938943            break;
    939944    }
  • trunk/src/bp-templates/bp-legacy/buddypress/activity/entry.php

    r13183 r13520  
    99 * @subpackage bp-legacy
    1010 * @since 3.0.0
    11  * @version 10.0.0
     11 * @version 12.0.0
    1212 */
    1313
     
    134134                            <textarea id="ac-input-<?php bp_activity_id(); ?>" class="ac-input bp-suggestions" name="ac_input_<?php bp_activity_id(); ?>"></textarea>
    135135                        </div>
    136                         <input type="submit" name="ac_form_submit" value="<?php esc_attr_e( 'Post', 'buddypress' ); ?>" /> &nbsp; <a href="#" class="ac-reply-cancel"><?php _e( 'Cancel', 'buddypress' ); ?></a>
     136                        <input type="submit" name="ac_form_submit" value="<?php esc_attr_e( 'Post', 'buddypress' ); ?>" /> &nbsp; <a href="<?php bp_activity_comment_cancel_url(); ?>" class="ac-reply-cancel"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a>
    137137                        <input type="hidden" name="comment_form_id" value="<?php bp_activity_id(); ?>" />
    138138                    </div>
Note: See TracChangeset for help on using the changeset viewer.