Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/01/2023 08:17:11 AM (3 years ago)
Author:
imath
Message:

BP Rewrites: introduce the bp_rewrites_get_url() function

Its role is to build every BuddyPress URL using the BP Rewrites API.

This commit also deprecates softly some key functions like bp_get_root_domain() to let us review (thanks to deprecated notices) all BuddyPress links during 12.0 development cycle and make them use the introduced bp_rewrites_get_url() function or a wrapper of it. Once all replacements achieved, we'll need to fully deprecate:

  • bp_get_root_domain()
  • bp_root_domain()
  • bp_core_get_root_domain()

Slug constants have also been completely deprecated as we will be able to customize every slugs from the future "URL" tab of the BuddyPress settings page.

The $bp->root_domain BuddyPress global has been deprecated in favor of $bp->root_url.

Finally, the Components $rewrite_ids properties are now in place and corresponding rewrite rules are successfully generated.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13417 r13432  
    14001400
    14011401/**
     1402 * Gets the BP root blog's URL.
     1403 *
     1404 * @since 12.0.0
     1405 *
     1406 * @return string The BP root blog's URL.
     1407 */
     1408function bp_get_root_url() {
     1409        $bp = buddypress();
     1410
     1411        if ( ! empty( $bp->root_url ) ) {
     1412                $url = $bp->root_url;
     1413        } else {
     1414                $url          = bp_rewrites_get_root_url();
     1415                $bp->root_url = $url;
     1416        }
     1417
     1418        /**
     1419         * Filters the "root url", the URL of the BP root blog.
     1420         *
     1421         * @since 12.0.0
     1422         *
     1423         * @param string $url URL of the BP root blog.
     1424         */
     1425        return apply_filters( 'bp_get_root_url', $url );
     1426}
     1427
     1428/**
     1429 * Output the "root url", the URL of the BP root blog.
     1430 *
     1431 * @since 12.0.0
     1432 */
     1433function bp_root_url() {
     1434        echo esc_url( bp_get_root_url() );
     1435}
     1436
     1437/**
    14021438 * Output the "root domain", the URL of the BP root blog.
    14031439 *
    14041440 * @since 1.1.0
     1441 * @deprecated 12.0.0
    14051442 */
    14061443function bp_root_domain() {
    1407         echo bp_get_root_domain();
     1444        _deprecated_function( __FUNCTION__, '12.0.0', 'bp_root_url()' );
     1445        bp_root_url();
    14081446}
    14091447        /**
     
    14111449         *
    14121450         * @since 1.1.0
     1451         * @deprecated 12.0.0
    14131452         *
    14141453         * @return string URL of the BP root blog.
    14151454         */
    14161455        function bp_get_root_domain() {
    1417                 $bp = buddypress();
    1418 
    1419                 if ( ! empty( $bp->root_domain ) ) {
    1420                         $domain = $bp->root_domain;
    1421                 } else {
    1422                         $domain          = bp_core_get_root_domain();
    1423                         $bp->root_domain = $domain;
    1424                 }
     1456                /*
     1457                 * This function is used at many places and we need to review all this
     1458                 * places during the 12.0 development cycle. Using BP Rewrites means we
     1459                 * cannot concatenate URL chunks to build our URL anymore. We now need
     1460                 * to use `bp_rewrites_get_url( $array )` and make sure to use the right
     1461                 * arguments inside this `$array`.
     1462                 *
     1463                 * @todo Once every link reviewed, we'll be able to remove this check
     1464                 *       and let PHPUnit tell us the one we forgot, eventually!
     1465                 */
     1466                if ( ! buddypress()->is_phpunit_running ) {
     1467                        _deprecated_function( __FUNCTION__, '12.0.0', 'bp_get_root_url()' );
     1468                }
     1469
     1470                $domain = bp_get_root_url();
    14251471
    14261472                /**
    1427                  * Filters the "root domain", the URL of the BP root blog.
     1473                 *  Filters the "root domain", the URL of the BP root blog.
    14281474                 *
    14291475                 * @since 1.2.4
     1476                 * @deprecated 12.0.0 Use {@see 'bp_get_root_url'} instead.
    14301477                 *
    14311478                 * @param string $domain URL of the BP root blog.
    14321479                 */
    1433                 return apply_filters( 'bp_get_root_domain', $domain );
     1480                return apply_filters_deprecated( 'bp_core_get_root_domain', array( $domain ), '12.0.0', 'bp_get_root_url' );
    14341481        }
    14351482
Note: See TracChangeset for help on using the changeset viewer.