Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/27/2023 06:19:06 PM (13 months ago)
Author:
imath
Message:

Improve Components Member's single item navigation generation

  • Edit the BP_Component Class so that it globalize navigation items before registering it.
  • Introduce bp_get_component_navigations(), a new function that will be used to get Member's single navigation customizable slugs within the BuddyPress settings area.
  • Perform all remaining bp_loggedin_user_domain() replacements (55) in favor of the bp_loggedin_user_url() function which uses BP Rewrites to build URLs.
  • Improve bp_loggedin_user_link() by adding a new $chunks array of arguments to output escaped URL in templates.
  • Adapt some PHPUnit testcases.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/78
See #4954

File:
1 edited

Legend:

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

    r13436 r13442  
    13351335        global $messages_template;
    13361336
     1337        $message_slug        = bp_get_messages_slug();
     1338        $custom_message_slug = bp_rewrites_get_slug( 'members', 'member_' . $message_slug, $message_slug );
     1339        $url                 = wp_nonce_url(
     1340            bp_loggedin_user_url(
     1341                array(
     1342                    'single_item_component'        => $custom_message_slug,
     1343                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices', 'notices' ),
     1344                    'single_item_action_variables' => array(
     1345                        bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices_delete', 'delete' ),
     1346                        $messages_template->thread->id,
     1347                    ),
     1348                )
     1349            ),
     1350            'messages_delete_notice'
     1351        );
     1352
    13371353        /**
    13381354         * Filters the URL for deleting the current notice.
     
    13401356         * @since 1.0.0
    13411357         *
    1342          * @param string $value URL for deleting the current notice.
    1343          * @param string $value Text indicating action being executed.
    1344          */
    1345         return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/delete/' . $messages_template->thread->id ), 'messages_delete_notice' ) );
     1358         * @param string $url   URL for deleting the current notice.
     1359         */
     1360        return apply_filters( 'bp_get_message_notice_delete_link', $url );
    13461361    }
    13471362
     
    13621377        global $messages_template;
    13631378
     1379        $message_slug        = bp_get_messages_slug();
     1380        $custom_message_slug = bp_rewrites_get_slug( 'members', 'member_' . $message_slug, $message_slug );
     1381        $path_chunks         = array(
     1382            'single_item_component' => $custom_message_slug,
     1383            'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices', 'notices' ),
     1384        );
     1385
    13641386        if ( 1 === (int) $messages_template->thread->is_active ) {
    1365             $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
     1387            $nonce                                       = 'messages_deactivate_notice';
     1388            $path_chunks['single_item_action_variables'] = array(
     1389                bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices_deactivate', 'deactivate' ),
     1390                $messages_template->thread->id,
     1391            );
    13661392        } else {
    1367             $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
     1393            $nonce                                       = 'messages_activate_notice';
     1394            $path_chunks['single_item_action_variables'] = array(
     1395                bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices_activate', 'activate' ),
     1396                $messages_template->thread->id,
     1397            );
    13681398        }
     1399
     1400        $link = wp_nonce_url( bp_loggedin_user_url( $path_chunks ), $nonce );
    13691401
    13701402        /**
     
    14251457     */
    14261458    function bp_get_message_notice_dismiss_link() {
    1427 
    1428         $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/dismiss/' ), 'messages_dismiss_notice' );
     1459        $message_slug        = bp_get_messages_slug();
     1460        $custom_message_slug = bp_rewrites_get_slug( 'members', 'member_' . $message_slug, $message_slug );
     1461        $link                = wp_nonce_url(
     1462            bp_loggedin_user_url(
     1463                array(
     1464                    'single_item_component'        => $custom_message_slug,
     1465                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices', 'notices' ),
     1466                    'single_item_action_variables' => array( bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices_dismiss', 'dismiss' ) ),
     1467                )
     1468            ),
     1469            'messages_dismiss_notice'
     1470        );
    14291471
    14301472        /**
     
    15131555        }
    15141556
     1557        $message_slug        = bp_get_messages_slug();
     1558        $custom_message_slug = bp_rewrites_get_slug( 'members', 'member_' . $message_slug, $message_slug );
     1559        $url                 = wp_nonce_url(
     1560            add_query_arg(
     1561                'r',
     1562                bp_members_get_user_slug( bp_displayed_user_id() ),
     1563                bp_loggedin_user_url(
     1564                    array(
     1565                        'single_item_component' => $custom_message_slug,
     1566                        'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_compose', 'compose' ),
     1567                    )
     1568                )
     1569
     1570            )
     1571        );
     1572
    15151573        /**
    15161574         * Filters the URL for the Private Message link in member profile headers.
     
    15181576         * @since 1.2.10
    15191577         *
    1520          * @param string $value URL for the Private Message link in member profile headers.
    1521          */
    1522         return apply_filters( 'bp_get_send_private_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_members_get_user_slug( bp_displayed_user_id() ) ) );
     1578         * @param string $url URL for the Private Message link in member profile headers.
     1579         */
     1580        return apply_filters( 'bp_get_send_private_message_link', $url );
    15231581    }
    15241582
Note: See TracChangeset for help on using the changeset viewer.