Skip to:
Content

BuddyPress.org

Changeset 11644


Ignore:
Timestamp:
07/13/2017 07:11:00 PM (7 years ago)
Author:
boonebgorges
Message:

Restore default behavior of message link generating functions.

Prior to [11578], functions for generating links in the context of
messages (Mark Read, Delete, etc) were generated relative to the
logged-in user. This made it impossible for an administrator to
manage another user's messages. [11578] changed the default behavior
of these functions to reference the displayed user. But this change
breaks backward compatibility for functions expecting the prior
behavior, including BP's own message notification format functions.

We work around the limitation by introducing $user_id parameters
to the functions in question. $user_id defaults to the logged-in
user (for backward compatibilty), and the bp-legacy template passes
in the displayed user ID as appropriate.

Fixes #7096.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r11643 r11644  
    274274 * Output the permalink for a particular thread.
    275275 *
     276 * @since 2.9.0 Introduced `$user_id` parameter.
     277 *
    276278 * @param int $thread_id Optional. ID of the thread. Default: current thread
    277279 *                       being iterated on in the loop.
    278  */
    279 function bp_message_thread_view_link( $thread_id = 0 ) {
    280     echo bp_get_message_thread_view_link( $thread_id );
     280 * @param int $user_id   Optional. ID of the user relative to whom the link
     281 *                       should be generated. Default: ID of logged-in user.
     282 */
     283function bp_message_thread_view_link( $thread_id = 0, $user_id = null ) {
     284    echo bp_get_message_thread_view_link( $thread_id, $user_id );
    281285}
    282286    /**
    283287     * Get the permalink of a particular thread.
     288     *
     289     * @since 2.9.0 Introduced `$user_id` parameter.
    284290     *
    285291     * @param int $thread_id Optional. ID of the thread. Default: current
    286292     *                       thread being iterated on in the loop.
    287      * @return string
    288      */
    289     function bp_get_message_thread_view_link( $thread_id = 0 ) {
     293     * @param int $user_id   Optional. ID of the user relative to whom the link
     294     *                       should be generated. Default: ID of logged-in user.
     295     * @return string
     296     */
     297    function bp_get_message_thread_view_link( $thread_id = 0, $user_id = null ) {
    290298        global $messages_template;
    291299
     
    296304        }
    297305
     306        if ( null === $user_id ) {
     307            $user_id = bp_loggedin_user_id();
     308        }
     309
     310        $domain = bp_core_get_user_domain( $user_id );
     311
    298312        /**
    299313         * Filters the permalink of a particular thread.
     
    301315         * @since 1.0.0
    302316         * @since 2.6.0 Added the `$thread_id` parameter.
     317         * @since 2.9.0 Added the `$user_id` parameter.
    303318         *
    304319         * @param string $value     Permalink of a particular thread.
    305320         * @param int    $thread_id ID of the thread.
    306          */
    307         return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id ), $thread_id );
     321         * @param int    $user_id   ID of the user.
     322         */
     323        return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( $domain . bp_get_messages_slug() . '/view/' . $thread_id ), $thread_id, $user_id );
    308324    }
    309325
    310326/**
    311327 * Output the URL for deleting the current thread.
    312  */
    313 function bp_message_thread_delete_link() {
    314     echo esc_url( bp_get_message_thread_delete_link() );
     328 *
     329 * @since 2.9.0 Introduced `$user_id` parameter.
     330 *
     331 * @param int $user_id Optional. ID of the user relative to whom the link
     332 *                     should be generated. Default: ID of logged-in user.
     333 */
     334function bp_message_thread_delete_link( $user_id = null ) {
     335    echo esc_url( bp_get_message_thread_delete_link( $user_id ) );
    315336}
    316337    /**
    317338     * Generate the URL for deleting the current thread.
    318339     *
    319      * @return string
    320      */
    321     function bp_get_message_thread_delete_link() {
     340     * @since 2.9.0 Introduced `$user_id` parameter.
     341     *
     342     * @param int $user_id Optional. ID of the user relative to whom the link
     343     *                     should be generated. Default: ID of logged-in user.
     344     * @return string
     345     */
     346    function bp_get_message_thread_delete_link( $user_id = null ) {
    322347        global $messages_template;
    323348
     349        if ( null === $user_id ) {
     350            $user_id = bp_loggedin_user_id();
     351        }
     352
     353        $domain = bp_core_get_user_domain( $user_id );
     354
    324355        /**
    325356         * Filters the URL for deleting the current thread.
     
    327358         * @since 1.0.0
    328359         *
    329          * @param string $value URL for deleting the current thread.
    330          * @param string $value Text indicating action being executed.
    331          */
    332         return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ) );
     360         * @param string $value   URL for deleting the current thread.
     361         * @param int    $user_id ID of the user relative to whom the link should be generated.
     362         */
     363        return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ), $user_id );
    333364    }
    334365
     
    339370 *
    340371 * @since 2.2.0
    341  */
    342 function bp_the_message_thread_mark_unread_url() {
    343     echo esc_url( bp_get_the_message_thread_mark_unread_url() );
     372 * @since 2.9.0 Introduced `$user_id` parameter.
     373 *
     374 * @param int $user_id Optional. ID of the user relative to whom the link
     375 *                     should be generated. Default: ID of logged-in user.
     376 */
     377function bp_the_message_thread_mark_unread_url( $user_id = null ) {
     378    echo esc_url( bp_get_the_message_thread_mark_unread_url( $user_id ) );
    344379}
    345380    /**
     
    347382     *
    348383     * @since 2.2.0
    349      *
    350      * @return string
    351      */
    352     function bp_get_the_message_thread_mark_unread_url() {
     384     * @since 2.9.0 Introduced `$user_id` parameter.
     385     *
     386     * @param int $user_id Optional. ID of the user relative to whom the link
     387     *                     should be generated. Default: ID of logged-in user.
     388     * @return string
     389     */
     390    function bp_get_the_message_thread_mark_unread_url( $user_id = null ) {
    353391
    354392        // Get the message ID.
     
    361399        );
    362400
     401        if ( null === $user_id ) {
     402            $user_id = bp_loggedin_user_id();
     403        }
     404
     405        $domain = bp_core_get_user_domain( $user_id );
     406
    363407        // Base unread URL.
    364         $url = trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
     408        $url = trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
    365409
    366410        // Add the args to the URL.
     
    374418         *
    375419         * @since 2.2.0
    376          *
    377          * @param string $url URL used for marking a single message thread as unread.
    378          */
    379         return apply_filters( 'bp_get_the_message_thread_mark_unread_url', $url );
     420         * @since 2.9.0 Added `$user_id` parameter.
     421         *
     422         * @param string $url     URL used for marking a single message thread as unread.
     423         * @param int    $user_id ID of the user relative to whom the link should be generated.
     424         */
     425        return apply_filters( 'bp_get_the_message_thread_mark_unread_url', $url, $user_id );
    380426    }
    381427
     
    386432 *
    387433 * @since 2.2.0
    388  */
    389 function bp_the_message_thread_mark_read_url() {
    390     echo esc_url( bp_get_the_message_thread_mark_read_url() );
     434 * @since 2.9.0 Introduced `$user_id` parameter.
     435 *
     436 * @param int $user_id Optional. ID of the user relative to whom the link
     437 *                     should be generated. Default: ID of logged-in user.
     438 */
     439function bp_the_message_thread_mark_read_url( $user_id = null ) {
     440    echo esc_url( bp_get_the_message_thread_mark_read_url( $user_id ) );
    391441}
    392442    /**
     
    394444     *
    395445     * @since 2.2.0
    396      *
    397      * @return string
    398      */
    399     function bp_get_the_message_thread_mark_read_url() {
     446     * @since 2.9.0 Introduced `$user_id` parameter.
     447     *
     448     * @param int $user_id Optional. ID of the user relative to whom the link
     449     *                     should be generated. Default: ID of logged-in user.
     450     * @return string
     451     */
     452    function bp_get_the_message_thread_mark_read_url( $user_id = null ) {
    400453
    401454        // Get the message ID.
     
    408461        );
    409462
     463        if ( null === $user_id ) {
     464            $user_id = bp_loggedin_user_id();
     465        }
     466
     467        $domain = bp_core_get_user_domain( $user_id );
     468
    410469        // Base read URL.
    411         $url = trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
     470        $url = trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
    412471
    413472        // Add the args to the URL.
     
    422481         * @since 2.2.0
    423482         *
    424          * @param string $url URL used for marking a single message thread as read.
     483         * @param string $url     URL used for marking a single message thread as read.
     484         * @param int    $user_id ID of the user relative to whom the link should be generated.
    425485         */
    426486        return apply_filters( 'bp_get_the_message_thread_mark_read_url', $url );
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/messages/messages-loop.php

    r11591 r11644  
    116116
    117117                        <td class="thread-info">
    118                             <p><a href="<?php bp_message_thread_view_link(); ?>" class="bp-tooltip" data-bp-tooltip="<?php esc_attr_e( "View Message", 'buddypress' ); ?>" aria-label="<?php esc_attr_e( "View Message", 'buddypress' ); ?>"><?php bp_message_thread_subject(); ?></a></p>
     118                            <p><a href="<?php bp_message_thread_view_link( bp_get_message_thread_id(), bp_displayed_user_id() ); ?>" class="bp-tooltip" data-bp-tooltip="<?php esc_attr_e( "View Message", 'buddypress' ); ?>" aria-label="<?php esc_attr_e( "View Message", 'buddypress' ); ?>"><?php bp_message_thread_subject(); ?></a></p>
    119119                            <p class="thread-excerpt"><?php bp_message_thread_excerpt(); ?></p>
    120120                        </td>
     
    140140                        <td class="thread-options">
    141141                            <?php if ( bp_message_thread_has_unread() ) : ?>
    142                                 <a class="read" href="<?php bp_the_message_thread_mark_read_url();?>"><?php _e( 'Read', 'buddypress' ); ?></a>
     142                                <a class="read" href="<?php bp_the_message_thread_mark_read_url( bp_displayed_user_id() );?>"><?php _e( 'Read', 'buddypress' ); ?></a>
    143143                            <?php else : ?>
    144                                 <a class="unread" href="<?php bp_the_message_thread_mark_unread_url();?>"><?php _e( 'Unread', 'buddypress' ); ?></a>
     144                                <a class="unread" href="<?php bp_the_message_thread_mark_unread_url( bp_displayed_user_id() );?>"><?php _e( 'Unread', 'buddypress' ); ?></a>
    145145                            <?php endif; ?>
    146146                             |
    147                             <a class="delete" href="<?php bp_message_thread_delete_link(); ?>"><?php _e( 'Delete', 'buddypress' ); ?></a>
     147                            <a class="delete" href="<?php bp_message_thread_delete_link( bp_displayed_user_id() ); ?>"><?php _e( 'Delete', 'buddypress' ); ?></a>
    148148
    149149                            <?php
Note: See TracChangeset for help on using the changeset viewer.