Skip to:
Content

BuddyPress.org

Changeset 13432


Ignore:
Timestamp:
03/01/2023 08:17:11 AM (2 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

Location:
trunk
Files:
1 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-component.php

    r13414 r13432  
    179179     * Set up component global variables.
    180180     *
    181      * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for
    182      * backwards compatibility.
     181     * The BP_ACTIVITY_SLUG constant is deprecated.
    183182     *
    184183     * @since 1.5.0
     
    189188     */
    190189    public function setup_globals( $args = array() ) {
    191         $bp = buddypress();
    192 
    193         // Define a slug, if necessary.
    194         if ( ! defined( 'BP_ACTIVITY_SLUG' ) ) {
    195             define( 'BP_ACTIVITY_SLUG', $this->id );
     190        $bp           = buddypress();
     191        $default_slug = $this->id;
     192
     193        // @deprecated.
     194        if ( defined( 'BP_ACTIVITY_SLUG' ) ) {
     195            _doing_it_wrong( 'BP_ACTIVITY_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     196            $default_slug = BP_ACTIVITY_SLUG;
    196197        }
    197198
     
    214215        // Note that global_tables is included in this array.
    215216        $args = array(
    216             'slug'                  => BP_ACTIVITY_SLUG,
    217             'root_slug'             => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
     217            'slug'                  => $default_slug,
     218            'root_slug'             => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : $default_slug,
    218219            'has_directory'         => true,
     220            'rewrite_ids'           => array(
     221                'directory'                    => 'activities',
     222                'single_item_action'           => 'activity_action',
     223                'single_item_action_variables' => 'activity_action_variables',
     224            ),
    219225            'directory_title'       => isset( $bp->pages->activity->title ) ? $bp->pages->activity->title : $default_directory_title,
    220226            'notification_callback' => 'bp_activity_format_notifications',
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r13414 r13432  
    4444     * Set up global settings for the blogs component.
    4545     *
    46      * The BP_BLOGS_SLUG constant is deprecated, and only used here for
    47      * backwards compatibility.
     46     * The BP_BLOGS_SLUG constant is deprecated.
    4847     *
    4948     * @since 1.5.0
     
    5453     */
    5554    public function setup_globals( $args = array() ) {
    56         $bp = buddypress();
    57 
    58         if ( ! defined( 'BP_BLOGS_SLUG' ) ) {
    59             define ( 'BP_BLOGS_SLUG', $this->id );
     55        $bp           = buddypress();
     56        $default_slug = $this->id;
     57
     58        // @deprecated.
     59        if ( defined( 'BP_BLOGS_SLUG' ) ) {
     60            _doing_it_wrong( 'BP_BLOGS_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     61            $default_slug = BP_BLOGS_SLUG;
    6062        }
    6163
     
    7678        // All globals for blogs component.
    7779        $args = array(
    78             'slug'                  => BP_BLOGS_SLUG,
    79             'root_slug'             => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
     80            'slug'                  => $default_slug,
     81            'root_slug'             => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : $default_slug,
    8082            'has_directory'         => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site.
     83            'rewrite_ids'           => array(
     84                'directory'                    => 'blogs',
     85                'single_item_action'           => 'blogs_action',
     86                'single_item_action_variables' => 'blogs_action_variables',
     87            ),
    8188            'directory_title'       => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title,
    8289            'notification_callback' => 'bp_blogs_format_notifications',
  • trunk/src/bp-core/bp-core-functions.php

    r13431 r13432  
    744744            $page_ids_sql     = implode( ',', wp_parse_id_list( $page_ids ) );
    745745            $page_stati_sql   = '\'' . implode( '\', \'', array_map( 'sanitize_key', bp_core_get_directory_pages_stati() ) ) . '\'';
    746             $page_names       = $wpdb->get_results( "SELECT ID, post_name, post_parent, post_title FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status IN ({$page_stati_sql}) " );
     746            $page_names       = $wpdb->get_results( "SELECT ID, post_name, post_parent, post_title, post_status FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status IN ({$page_stati_sql}) " );
    747747
    748748            foreach ( (array) $page_ids as $component_id => $page_id ) {
     
    765765                        }
    766766
    767                         $pages->{$component_id}->slug = implode( '/', array_reverse( (array) $slug ) );
     767                        $pages->{$component_id}->slug         = implode( '/', array_reverse( (array) $slug ) );
     768                        $pages->{$component_id}->custom_slugs = get_post_meta( $page_name->ID, '_bp_component_slugs', true );
     769                        $pages->{$component_id}->visibility   = $page_name->post_status;
    768770                    }
    769771
     
    11081110 *
    11091111 * @since 1.0.0
     1112 * @deprecated 12.0.0
    11101113 *
    11111114 * @return string The domain URL for the blog.
    11121115 */
    11131116function bp_core_get_root_domain() {
    1114 
    1115     $domain = get_home_url( bp_get_root_blog_id() );
     1117    _deprecated_function( __FUNCTION__, '12.0.0', 'bp_rewrites_get_root_url()' );
     1118
     1119    $domain = bp_rewrites_get_root_url();
    11161120
    11171121    /**
     
    11191123     *
    11201124     * @since 1.0.1
     1125     * @deprecated 12.0.0 Use {@see 'bp_rewrites_get_root_url'} instead.
    11211126     *
    11221127     * @param string $domain The domain URL for the blog.
    11231128     */
    1124     return apply_filters( 'bp_core_get_root_domain', $domain );
     1129    return apply_filters_deprecated( 'bp_core_get_root_domain', array( $domain ), '12.0.0', 'bp_rewrites_get_root_url' );
    11251130}
    11261131
  • trunk/src/bp-core/bp-core-rewrites.php

    r13422 r13432  
    4444    );
    4545}
     46
     47/**
     48 * Delete rewrite rules, so that they are automatically rebuilt on
     49 * the subsequent page load.
     50 *
     51 * @since 12.0.0
     52 */
     53function bp_delete_rewrite_rules() {
     54    delete_option( 'rewrite_rules' );
     55}
     56
     57/**
     58 * Are Pretty URLs active?
     59 *
     60 * @since 12.0.0
     61 *
     62 * @return bool True if Pretty URLs are on. False otherwise.
     63 */
     64function bp_has_pretty_urls() {
     65    $has_plain_urls = ! get_option( 'permalink_structure', '' );
     66    return ! $has_plain_urls;
     67}
     68
     69/**
     70 * Returns the slug to use for the view belonging to the requested component.
     71 *
     72 * @since 12.0.0
     73 *
     74 * @param string $component_id The BuddyPress component's ID.
     75 * @param string $rewrite_id   The view rewrite ID.
     76 * @param string $default_slug The view default slug.
     77 * @return string The slug to use for the view belonging to the requested component.
     78 */
     79function bp_rewrites_get_slug( $component_id = '', $rewrite_id = '', $default_slug = '' ) {
     80    $directory_pages = bp_core_get_directory_pages();
     81    $slug            = $default_slug;
     82
     83    if ( ! isset( $directory_pages->{$component_id}->custom_slugs ) || ! $rewrite_id ) {
     84        return $slug;
     85    }
     86
     87    $custom_slugs = (array) $directory_pages->{$component_id}->custom_slugs;
     88    if ( isset( $custom_slugs[ $rewrite_id ] ) && $custom_slugs[ $rewrite_id ] ) {
     89        $slug = $custom_slugs[ $rewrite_id ];
     90    }
     91
     92    return $slug;
     93}
     94
     95/**
     96 * Builds a BuddyPress link using the WP Rewrite API.
     97 *
     98 * @since 12.0.0
     99 *
     100 * @param array $args {
     101 *      Optional. An array of arguments.
     102 *
     103 *      @type string $component_id                The BuddyPress component ID. Defaults ''.
     104 *      @type string $directory_type              Whether it's an object type URL. Defaults ''.
     105 *                                                Accepts '' (no object type), 'members' or 'groups'.
     106 *      @type string $single_item                 The BuddyPress single item's URL chunk. Defaults ''.
     107 *                                                Eg: the member's user nicename for Members or the group's slug for Groups.
     108 *      @type string $single_item_component       The BuddyPress single item's component URL chunk. Defaults ''.
     109 *                                                Eg: the member's Activity page.
     110 *      @type string $single_item_action          The BuddyPress single item's action URL chunk. Defaults ''.
     111 *                                                Eg: the member's Activity mentions page.
     112 *      @type array $single_item_action_variables The list of BuddyPress single item's action variable URL chunks. Defaults [].
     113 * }
     114 * @return string The BuddyPress link.
     115 */
     116function bp_rewrites_get_url( $args = array() ) {
     117    $bp   = buddypress();
     118    $url = get_home_url( bp_get_root_blog_id() );
     119
     120    $r = bp_parse_args(
     121        $args,
     122        array(
     123            'component_id'                 => '',
     124            'directory_type'               => '',
     125            'single_item'                  => '',
     126            'single_item_component'        => '',
     127            'single_item_action'           => '',
     128            'single_item_action_variables' => array(),
     129        )
     130    );
     131
     132    if ( $r['component_id'] && isset( $bp->{$r['component_id']}->rewrite_ids ) ) {
     133        $component = $bp->{$r['component_id']};
     134        unset( $r['component_id'] );
     135
     136        // Using plain links.
     137        if ( ! bp_has_pretty_urls() ) {
     138            if ( ! isset( $r['member_register'] ) && ! isset( $r['member_activate'] ) ) {
     139                $r['directory'] = 1;
     140            }
     141
     142            $r  = array_filter( $r );
     143            $qv = array();
     144
     145            foreach ( $component->rewrite_ids as $key => $rewrite_id ) {
     146                if ( ! isset( $r[ $key ] ) ) {
     147                    continue;
     148                }
     149
     150                $qv[ $rewrite_id ] = $r[ $key ];
     151            }
     152
     153            $url = add_query_arg( $qv, $url );
     154
     155            // Using pretty URLs.
     156        } else {
     157            if ( ! isset( $component->rewrite_ids['directory'] ) || ! isset( $component->directory_permastruct ) ) {
     158                return $url;
     159            }
     160
     161            if ( isset( $r['member_register'] ) ) {
     162                $url = str_replace( '%' . $component->rewrite_ids['member_register'] . '%', '', $component->register_permastruct );
     163                unset( $r['member_register'] );
     164            } elseif ( isset( $r['member_activate'] ) ) {
     165                $url = str_replace( '%' . $component->rewrite_ids['member_activate'] . '%', '', $component->activate_permastruct );
     166                unset( $r['member_activate'] );
     167            } elseif ( isset( $r['create_single_item'] ) ) {
     168                $create_slug = 'create';
     169                if ( 'groups' === $component->id ) {
     170                    $create_slug = bp_rewrites_get_slug( 'groups', 'bp_group_create', 'create' );
     171                }
     172
     173                $url = str_replace( '%' . $component->rewrite_ids['directory'] . '%', $create_slug, $component->directory_permastruct );
     174                unset( $r['create_single_item'] );
     175            } else {
     176                $url = str_replace( '%' . $component->rewrite_ids['directory'] . '%', $r['single_item'], $component->directory_permastruct );
     177
     178                // Remove the members directory slug when root profiles are on.
     179                if ( bp_core_enable_root_profiles() && 'members' === $component->id && isset( $r['single_item'] ) && $r['single_item'] ) {
     180                    $url = str_replace( $bp->members->root_slug . '/', '', $url );
     181                }
     182
     183                unset( $r['single_item'] );
     184            }
     185
     186            $r = array_filter( $r );
     187
     188            if ( isset( $r['directory_type'] ) && $r['directory_type'] ) {
     189                if ( 'members' === $component->id ) {
     190                    array_unshift( $r, bp_get_members_member_type_base() );
     191                } elseif ( 'groups' === $component->id && bp_is_active( 'groups' ) ) {
     192                    array_unshift( $r, bp_get_groups_group_type_base() );
     193                } else {
     194                    unset( $r['directory_type'] );
     195                }
     196            }
     197
     198            if ( isset( $r['single_item_action_variables'] ) && $r['single_item_action_variables'] ) {
     199                $r['single_item_action_variables'] = join( '/', (array) $r['single_item_action_variables'] );
     200            }
     201
     202            if ( isset( $r['create_single_item_variables'] ) && $r['create_single_item_variables'] ) {
     203                $r['create_single_item_variables'] = join( '/', (array) $r['create_single_item_variables'] );
     204            }
     205
     206            $url = get_home_url( bp_get_root_blog_id(), user_trailingslashit( '/' . rtrim( $url, '/' ) . '/' . join( '/', $r ) ) );
     207        }
     208    }
     209
     210    /**
     211     * Filter here to edit any BudyPress URL.
     212     *
     213     * @since 12.0.0
     214     *
     215     * @param string $url The BudyPress URL.
     216     * @param array  $r {
     217     *      Optional. An array of arguments.
     218     *
     219     *      @type string $component_id                The BuddyPress component ID. Defaults ''.
     220     *      @type string $directory_type              Whether it's an object type URL. Defaults ''.
     221     *                                                Accepts '' (no object type), 'members' or 'groups'.
     222     *      @type string $single_item                 The BuddyPress single item's URL chunk. Defaults ''.
     223     *                                                Eg: the member's user nicename for Members or the group's slug for Groups.
     224     *      @type string $single_item_component       The BuddyPress single item's component URL chunk. Defaults ''.
     225     *                                                Eg: the member's Activity page.
     226     *      @type string $single_item_action          The BuddyPress single item's action URL chunk. Defaults ''.
     227     *                                                Eg: the member's Activity mentions page.
     228     *      @type array $single_item_action_variables The list of BuddyPress single item's action variable URL chunks. Defaults [].
     229     * }
     230     */
     231    return apply_filters( 'bp_rewrites_get_url', $url, $r );
     232}
     233
     234/**
     235 * Gets the BP root site URL, using BP Rewrites.
     236 *
     237 * @since 12.0.0
     238 *
     239 * @return string The BP root site URL.
     240 */
     241function bp_rewrites_get_root_url() {
     242    $url = bp_rewrites_get_url( array() );
     243
     244    /**
     245     * Filter here to edit the BP root site URL.
     246     *
     247     * @since 12.0.0
     248     *
     249     * @param string $url The BP root site URL.
     250     */
     251    return apply_filters( 'bp_rewrites_get_root_url', $url );
     252}
  • 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
  • trunk/src/bp-core/bp-core-update.php

    r13431 r13432  
    862862
    863863        // Finally make sure to rebuilt permalinks at next page load.
    864         delete_option( 'rewrite_rules' );
     864        bp_delete_rewrite_rules();
    865865    }
    866866}
  • trunk/src/bp-core/classes/class-bp-component.php

    r13431 r13432  
    11241124        $queried_object = $query->get_queried_object();
    11251125
    1126         if ( $queried_object instanceof \WP_Post && 'buddypress' === get_post_type( $queried_object ) ) {
     1126        if ( $queried_object instanceof WP_Post && 'buddypress' === get_post_type( $queried_object ) ) {
    11271127            // Only include the queried directory post into returned posts.
    11281128            $retval = array( $queried_object );
  • trunk/src/bp-core/classes/class-bp-core.php

    r13431 r13432  
    218218        }
    219219
    220         // The domain for the root of the site where the main blog resides.
    221         if ( empty( $bp->root_domain ) ) {
    222             $bp->root_domain = bp_core_get_root_domain();
     220        // The URL for the root of the site where the main blog resides.
     221        if ( empty( $bp->root_url ) ) {
     222            $bp->root_url = bp_rewrites_get_root_url();
    223223        }
    224224
  • trunk/src/bp-core/deprecated/12.0.php

    r13431 r13432  
    140140    _deprecated_function( __FUNCTION__, '12.0.0' );
    141141}
     142
     143/**
     144 * Define the slug constants for the Members component.
     145 *
     146 * Handles the three slug constants used in the Members component -
     147 * BP_MEMBERS_SLUG, BP_REGISTER_SLUG, and BP_ACTIVATION_SLUG. If these
     148 * constants are not overridden in wp-config.php or bp-custom.php, they are
     149 * defined here to match the slug of the corresponding WP pages.
     150 *
     151 * In general, fallback values are only used during initial BP page creation,
     152 * when no slugs have been explicitly defined.
     153 *
     154 * @since 1.5.0
     155 * @deprecated 12.0.0
     156 */
     157function bp_core_define_slugs() {
     158    _deprecated_function( __FUNCTION__, '12.0.0' );
     159}
  • trunk/src/bp-friends/classes/class-bp-friends-component.php

    r13414 r13432  
    101101     * Set up bp-friends global settings.
    102102     *
    103      * The BP_FRIENDS_SLUG constant is deprecated, and only used here for
    104      * backwards compatibility.
     103     * The BP_FRIENDS_SLUG constant is deprecated.
    105104     *
    106105     * @since 1.5.0
     
    111110     */
    112111    public function setup_globals( $args = array() ) {
    113         $bp = buddypress();
    114 
    115         // Deprecated. Do not use.
    116         // Defined conditionally to support unit tests.
    117         if ( ! defined( 'BP_FRIENDS_DB_VERSION' ) ) {
    118             define( 'BP_FRIENDS_DB_VERSION', '1800' );
    119         }
    120 
    121         // Define a slug, if necessary.
    122         if ( ! defined( 'BP_FRIENDS_SLUG' ) ) {
    123             define( 'BP_FRIENDS_SLUG', $this->id );
     112        $bp           = buddypress();
     113        $default_slug = $this->id;
     114
     115        // @deprecated.
     116        if ( defined( 'BP_FRIENDS_DB_VERSION' ) ) {
     117            _doing_it_wrong( 'BP_FRIENDS_DB_VERSION', esc_html__( 'This constants is not used anymore.', 'buddypress' ), 'BuddyPress 12.0.0' );
     118        }
     119
     120        // @deprecated.
     121        if ( defined( 'BP_FRIENDS_SLUG' ) ) {
     122            _doing_it_wrong( 'BP_FRIENDS_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     123            $default_slug = BP_FRIENDS_SLUG;
    124124        }
    125125
     
    133133        // Note that global_tables is included in this array.
    134134        $args = array(
    135             'slug'                  => BP_FRIENDS_SLUG,
     135            'slug'                  => $default_slug,
    136136            'has_directory'         => false,
    137137            'search_string'         => __( 'Search Friends...', 'buddypress' ),
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r13414 r13432  
    439439     * Set up component global data.
    440440     *
    441      * The BP_GROUPS_SLUG constant is deprecated, and only used here for
    442      * backwards compatibility.
     441     * The BP_GROUPS_SLUG constant is deprecated.
    443442     *
    444443     * @since 1.5.0
     
    449448     */
    450449    public function setup_globals( $args = array() ) {
    451         $bp = buddypress();
    452 
    453         // Define a slug, if necessary.
    454         if ( ! defined( 'BP_GROUPS_SLUG' ) ) {
    455             define( 'BP_GROUPS_SLUG', $this->id );
     450        $bp           = buddypress();
     451        $default_slug = $this->id;
     452
     453        // @deprecated.
     454        if ( defined( 'BP_GROUPS_SLUG' ) ) {
     455            _doing_it_wrong( 'BP_GROUPS_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     456            $default_slug = BP_GROUPS_SLUG;
    456457        }
    457458
     
    475476        // Note that global_tables is included in this array.
    476477        $args = array(
    477             'slug'                  => BP_GROUPS_SLUG,
    478             'root_slug'             => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,
     478            'slug'                  => $default_slug,
     479            'root_slug'             => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : $default_slug,
    479480            'has_directory'         => true,
     481            'rewrite_ids'           => array(
     482                'directory'                    => 'groups',
     483                'directory_type'               => 'groups_type',
     484                'create_single_item'           => 'group_create',
     485                'create_single_item_variables' => 'group_create_variables',
     486                'single_item'                  => 'group',
     487                'single_item_action'           => 'group_action',
     488                'single_item_action_variables' => 'group_action_variables',
     489            ),
    480490            'directory_title'       => isset( $bp->pages->groups->title ) ? $bp->pages->groups->title : $default_directory_title,
    481491            'notification_callback' => 'groups_format_notifications',
  • trunk/src/bp-members/bp-members-functions.php

    r13395 r13432  
    2525    return (bool) ! empty( $bp->pages->members->id );
    2626}
    27 
    28 /**
    29  * Define the slug constants for the Members component.
    30  *
    31  * Handles the three slug constants used in the Members component -
    32  * BP_MEMBERS_SLUG, BP_REGISTER_SLUG, and BP_ACTIVATION_SLUG. If these
    33  * constants are not overridden in wp-config.php or bp-custom.php, they are
    34  * defined here to match the slug of the corresponding WP pages.
    35  *
    36  * In general, fallback values are only used during initial BP page creation,
    37  * when no slugs have been explicitly defined.
    38  *
    39  * @since 1.5.0
    40  */
    41 function bp_core_define_slugs() {
    42     $bp = buddypress();
    43 
    44     // No custom members slug.
    45     if ( !defined( 'BP_MEMBERS_SLUG' ) ) {
    46         if ( !empty( $bp->pages->members ) ) {
    47             define( 'BP_MEMBERS_SLUG', $bp->pages->members->slug );
    48         } else {
    49             define( 'BP_MEMBERS_SLUG', 'members' );
    50         }
    51     }
    52 
    53     // No custom registration slug.
    54     if ( !defined( 'BP_REGISTER_SLUG' ) ) {
    55         if ( !empty( $bp->pages->register ) ) {
    56             define( 'BP_REGISTER_SLUG', $bp->pages->register->slug );
    57         } else {
    58             define( 'BP_REGISTER_SLUG', 'register' );
    59         }
    60     }
    61 
    62     // No custom activation slug.
    63     if ( !defined( 'BP_ACTIVATION_SLUG' ) ) {
    64         if ( !empty( $bp->pages->activate ) ) {
    65             define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug );
    66         } else {
    67             define( 'BP_ACTIVATION_SLUG', 'activate' );
    68         }
    69     }
    70 }
    71 add_action( 'bp_setup_globals', 'bp_core_define_slugs', 11 );
    7227
    7328/**
     
    15481503    );
    15491504
    1550     // Core constants.
     1505    // @todo replace slug constants with custom slugs.
    15511506    $slug_constants = array(
    1552         'BP_GROUPS_SLUG',
    1553         'BP_MEMBERS_SLUG',
    15541507        'BP_FORUMS_SLUG',
    1555         'BP_BLOGS_SLUG',
    1556         'BP_ACTIVITY_SLUG',
    1557         'BP_XPROFILE_SLUG',
    1558         'BP_FRIENDS_SLUG',
    15591508        'BP_SEARCH_SLUG',
    1560         'BP_SETTINGS_SLUG',
    1561         'BP_NOTIFICATIONS_SLUG',
    1562         'BP_REGISTER_SLUG',
    1563         'BP_ACTIVATION_SLUG',
    15641509    );
    15651510    foreach ( $slug_constants as $constant ) {
  • trunk/src/bp-members/bp-members-template.php

    r13395 r13432  
    214214     */
    215215    function bp_get_signup_slug() {
    216         $bp = buddypress();
     216        $bp   = buddypress();
     217        $slug = 'register';
    217218
    218219        if ( ! empty( $bp->pages->register->slug ) ) {
    219220            $slug = $bp->pages->register->slug;
    220         } elseif ( defined( 'BP_REGISTER_SLUG' ) ) {
    221             $slug = BP_REGISTER_SLUG;
    222         } else {
    223             $slug = 'register';
    224221        }
    225222
     
    250247     */
    251248    function bp_get_activate_slug() {
    252         $bp = buddypress();
     249        $bp   = buddypress();
     250        $slug = 'activate';
    253251
    254252        if ( ! empty( $bp->pages->activate->slug ) ) {
    255253            $slug = $bp->pages->activate->slug;
    256         } elseif ( defined( 'BP_ACTIVATION_SLUG' ) ) {
    257             $slug = BP_ACTIVATION_SLUG;
    258         } else {
    259             $slug = 'activate';
    260254        }
    261255
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r13414 r13432  
    276276     * Set up bp-members global settings.
    277277     *
    278      * The BP_MEMBERS_SLUG constant is deprecated, and only used here for
    279      * backwards compatibility.
     278     * The BP_MEMBERS_SLUG constant is deprecated.
    280279     *
    281280     * @since 1.5.0
     
    288287        global $wpdb;
    289288
    290         $bp = buddypress();
     289        $bp           = buddypress();
     290        $default_slug = $this->id;
    291291
    292292        /** Component Globals ************************************************
    293293         */
    294294
    295         // Define a slug, as a fallback for backpat.
    296         if ( !defined( 'BP_MEMBERS_SLUG' ) ) {
    297             define( 'BP_MEMBERS_SLUG', $this->id );
     295        // @deprecated.
     296        if ( defined( 'BP_MEMBERS_SLUG' ) ) {
     297            _doing_it_wrong( 'BP_MEMBERS_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     298            $default_slug = BP_MEMBERS_SLUG;
    298299        }
    299300
     
    304305        // Override any passed args.
    305306        $args = array(
    306             'slug'            => BP_MEMBERS_SLUG,
    307             'root_slug'       => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG,
     307            'slug'            => $default_slug,
     308            'root_slug'       => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : $default_slug,
    308309            'has_directory'   => true,
     310            'rewrite_ids'     => array(
     311                'directory'                    => 'members',
     312                'directory_type'               => 'members_type',
     313                'single_item'                  => 'member',
     314                'single_item_component'        => 'member_component',
     315                'single_item_action'           => 'member_action',
     316                'single_item_action_variables' => 'member_action_variables',
     317                'member_register'              => 'register',
     318                'member_activate'              => 'activate',
     319                'member_activate_key'          => 'activate_key',
     320            ),
    309321            'directory_title' => isset( $bp->pages->members->title ) ? $bp->pages->members->title : $default_directory_title,
    310322            'search_string'   => __( 'Search Members...', 'buddypress' ),
  • trunk/src/bp-messages/classes/class-bp-messages-component.php

    r13414 r13432  
    146146     * Set up globals for the Messages component.
    147147     *
    148      * The BP_MESSAGES_SLUG constant is deprecated, and only used here for
    149      * backwards compatibility.
     148     * The BP_MESSAGES_SLUG constant is deprecated.
    150149     *
    151150     * @since 1.5.0
     
    154153     */
    155154    public function setup_globals( $args = array() ) {
    156         $bp = buddypress();
    157 
    158         // Define a slug, if necessary.
    159         if ( ! defined( 'BP_MESSAGES_SLUG' ) ) {
    160             define( 'BP_MESSAGES_SLUG', $this->id );
     155        $bp           = buddypress();
     156        $default_slug = $this->id;
     157
     158        // @deprecated.
     159        if ( defined( 'BP_MESSAGES_SLUG' ) ) {
     160            _doing_it_wrong( 'BP_MESSAGES_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     161            $default_slug = BP_MESSAGES_SLUG;
    161162        }
    162163
     
    179180        // Note that global_tables is included in this array.
    180181        parent::setup_globals( array(
    181             'slug'                  => BP_MESSAGES_SLUG,
     182            'slug'                  => $default_slug,
    182183            'has_directory'         => false,
    183184            'notification_callback' => 'messages_format_notifications',
  • trunk/src/bp-notifications/classes/class-bp-notifications-component.php

    r13414 r13432  
    100100     */
    101101    public function setup_globals( $args = array() ) {
    102         $bp = buddypress();
    103 
    104         // Define a slug, if necessary.
    105         if ( ! defined( 'BP_NOTIFICATIONS_SLUG' ) ) {
    106             define( 'BP_NOTIFICATIONS_SLUG', $this->id );
     102        $bp           = buddypress();
     103        $default_slug = $this->id;
     104
     105        // @deprecated.
     106        if ( defined( 'BP_NOTIFICATIONS_SLUG' ) ) {
     107            _doing_it_wrong( 'BP_NOTIFICATIONS_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     108            $default_slug = BP_NOTIFICATIONS_SLUG;
    107109        }
    108110
     
    121123        // Note that global_tables is included in this array.
    122124        $args = array(
    123             'slug'          => BP_NOTIFICATIONS_SLUG,
     125            'slug'          => $default_slug,
    124126            'has_directory' => false,
    125127            'search_string' => __( 'Search Notifications...', 'buddypress' ),
  • trunk/src/bp-settings/classes/class-bp-settings-component.php

    r13414 r13432  
    9595     * Setup globals.
    9696     *
    97      * The BP_SETTINGS_SLUG constant is deprecated, and only used here for
    98      * backwards compatibility.
     97     * The BP_SETTINGS_SLUG constant is deprecated.
    9998     *
    10099     * @since 1.5.0
     
    105104     */
    106105    public function setup_globals( $args = array() ) {
    107 
    108         // Define a slug, if necessary.
    109         if ( ! defined( 'BP_SETTINGS_SLUG' ) ) {
    110             define( 'BP_SETTINGS_SLUG', $this->id );
     106        $default_slug = $this->id;
     107
     108        // @deprecated.
     109        if ( defined( 'BP_SETTINGS_SLUG' ) ) {
     110            _doing_it_wrong( 'BP_SETTINGS_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     111            $default_slug = BP_SETTINGS_SLUG;
    111112        }
    112113
    113114        // All globals for settings component.
    114115        parent::setup_globals( array(
    115             'slug'          => BP_SETTINGS_SLUG,
     116            'slug'          => $default_slug,
    116117            'has_directory' => false,
    117118        ) );
  • trunk/src/bp-settings/screens/general.php

    r13090 r13432  
    3737function bp_settings_remove_email_subnav() {
    3838    if ( ! has_action( 'bp_notification_settings' ) ) {
    39         bp_core_remove_subnav_item( BP_SETTINGS_SLUG, 'notifications' );
     39        bp_core_remove_subnav_item( bp_get_settings_slug(), 'notifications' );
    4040    }
    4141}
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php

    r13414 r13432  
    129129     * Setup globals.
    130130     *
    131      * The BP_XPROFILE_SLUG constant is deprecated, and only used here for
    132      * backwards compatibility.
     131     * The BP_XPROFILE_SLUG constant is deprecated.
    133132     *
    134133     * @since 1.5.0
     
    137136     */
    138137    public function setup_globals( $args = array() ) {
    139         $bp = buddypress();
    140 
    141         // Define a slug, if necessary.
    142         if ( ! defined( 'BP_XPROFILE_SLUG' ) ) {
    143             define( 'BP_XPROFILE_SLUG', 'profile' );
     138        $bp           = buddypress();
     139        $default_slug = 'profile';
     140
     141        // @deprecated.
     142        if ( defined( 'BP_XPROFILE_SLUG' ) ) {
     143            _doing_it_wrong( 'BP_XPROFILE_SLUG', esc_html__( 'Slug constants are deprecated.', 'buddypress' ), 'BuddyPress 12.0.0' );
     144            $default_slug = BP_XPROFILE_SLUG;
    144145        }
    145146
     
    209210
    210211        $globals = array(
    211             'slug'                  => BP_XPROFILE_SLUG,
     212            'slug'                  => $default_slug,
    212213            'has_directory'         => false,
    213214            'notification_callback' => 'xprofile_format_notifications',
  • trunk/src/class-buddypress.php

    r13431 r13432  
    307307     */
    308308    public function __get( $key ) {
    309         return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
     309        $valid_key = $key;
     310        if ( 'root_domain' === $key ) {
     311            _doing_it_wrong( 'root_domain', __( 'The root_domain BuddyPress main class property is deprecated since 12.0.0, please use the root_url property instead.', 'buddypress' ), 'BuddyPress 12.0.0' );
     312            $valid_key = 'root_url';
     313        }
     314
     315        return isset( $this->data[ $valid_key ] ) ? $this->data[ $valid_key ] : null;
    310316    }
    311317
     
    319325     */
    320326    public function __set( $key, $value ) {
    321         $this->data[ $key ] = $value;
     327        $valid_key = $key;
     328        if ( 'root_domain' === $key ) {
     329            _doing_it_wrong( 'root_domain', __( 'The root_domain BuddyPress main class property is deprecated since 12.0.0, please use the root_url property instead.', 'buddypress' ), 'BuddyPress 12.0.0' );
     330            $valid_key = 'root_url';
     331        }
     332
     333        $this->data[ $valid_key ] = $value;
    322334    }
    323335
Note: See TracChangeset for help on using the changeset viewer.