Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/17/2023 09:01:08 AM (9 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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.