Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/15/2023 08:16:46 AM (13 months ago)
Author:
imath
Message:

Make more BuddyPress generated links ready for BP Rewrites

  • Improve the Members component adding permastructs and custom rewrite

rules for registration and activation pages.

  • Improve the Blogs component adding custom rewrite rule to handle the

Blogs create page.

  • Make a huge progress about replacing all occurrences of

bp_get_root_domain() (45 replacements were performed).

  • Deprecate bp_groups_directory_permalink(),

bp_get_groups_directory_permalink(), bp_blogs_directory_permalink() &
bp_get_blogs_directory_permalink() and replace them with these new
functions: bp_groups_directory_url(), bp_get_groups_directory_url(),
bp_blogs_directory_url() & bp_get_blogs_directory_url().

  • Although bp_loggedin_user_domain() & bp_displayed_user_domain()

should also be deprecated, we're leaving them as aliases of the right
functions to use. Plugin authors shouldn't use them to build other links
than member's profile home url.

NB: these deprecations are required because these functions were used
to build BuddyPress URLs concatenating URL chunks. Once the BP Classic
plugin will be built we will adapt the code to remove these deprecation
notices.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13433 r13436  
    9696
    9797/**
     98 * Output Groups directory's URL.
     99 *
     100 * @since 12.0.0
     101 */
     102function bp_groups_directory_url() {
     103    echo esc_url( bp_get_groups_directory_url() );
     104}
     105
     106/**
     107 * Returns the Groups directory's URL.
     108 *
     109 * @since 12.0.0
     110 *
     111 * @param array $path_chunks {
     112 *     An array of arguments. Optional.
     113 *
     114 *     @type int   $create_single_item `1` to get the create a group URL.
     115 *     @type array $directory_type     The group type slug.
     116 * }
     117 * @return string The URL built for the BP Rewrites URL parser.
     118 */
     119function bp_get_groups_directory_url( $path_chunks = array() ) {
     120    $supported_chunks = array_fill_keys( array( 'create_single_item', 'directory_type' ), true );
     121
     122    $path_chunks = bp_parse_args(
     123        array_intersect_key( $path_chunks, $supported_chunks ),
     124        array(
     125            'component_id' => 'groups'
     126        )
     127    );
     128
     129    $url = bp_rewrites_get_url( $path_chunks );
     130
     131    /**
     132     * Filters the Groups directory's URL.
     133     *
     134     * @since 12.0.0
     135     *
     136     * @param string  $url The Groups directory's URL.
     137     * @param array   $path_chunks {
     138     *     An array of arguments. Optional.
     139     *
     140     *      @type int   $create_single_item `1` to get the create a group URL.
     141     *      @type array $directory_type     The group type slug.
     142     * }
     143     */
     144    return apply_filters( 'bp_get_groups_directory_url', $url, $path_chunks );
     145}
     146
     147/**
    98148 * Output group directory permalink.
    99149 *
    100150 * @since 1.5.0
     151 * @deprecated 12.0.0
    101152 */
    102153function bp_groups_directory_permalink() {
    103     echo esc_url( bp_get_groups_directory_permalink() );
     154    _deprecated_function( __FUNCTION__, '12.0.0', 'bp_groups_directory_url()' );
     155    bp_groups_directory_url();
    104156}
    105157    /**
     
    107159     *
    108160     * @since 1.5.0
     161     * @deprecated 12.0.0
    109162     *
    110163     * @return string
    111164     */
    112165    function bp_get_groups_directory_permalink() {
     166        /*
     167         * This function is used at many places and we need to review all this
     168         * places during the 12.0 development cycle. Using BP Rewrites means we
     169         * cannot concatenate URL chunks to build our URL anymore. We now need
     170         * to use `bp_get_groups_directory_url( $array )` and make sure to use
     171         * the right arguments inside this `$array`. Morevover as this function
     172         * is also used to build a single group URL, we need to create a new
     173         * function to create single group URLs using BP Rewrites.
     174         *
     175         * @todo Once every link reviewed, we'll be able to remove this check
     176         *       and let PHPUnit tell us the one we forgot, eventually!
     177         */
     178        if ( ! buddypress()->is_phpunit_running ) {
     179            _deprecated_function( __FUNCTION__, '12.0.0', 'bp_get_groups_directory_url()' );
     180        }
     181
     182        $url = bp_get_groups_directory_url();
    113183
    114184        /**
     
    116186         *
    117187         * @since 1.5.0
    118          *
    119          * @param string $value Permalink for the group directory.
    120          */
    121         return apply_filters( 'bp_get_groups_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) );
     188         * @deprecated 12.0.0
     189         *
     190         * @param string $url Permalink for the group directory.
     191         */
     192        return apply_filters_deprecated( 'bp_get_groups_directory_permalink', array( $url ), '12.0.0', 'bp_get_groups_directory_url' );
    122193    }
    123194
Note: See TracChangeset for help on using the changeset viewer.