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-members/bp-members-template.php

    r13433 r13436  
    141141     */
    142142    function bp_get_members_directory_permalink() {
     143        $url = bp_rewrites_get_url(
     144            array(
     145                'component_id' => 'members',
     146            )
     147        );
    143148
    144149        /**
     
    147152         * @since 1.5.0
    148153         *
    149          * @param string $value Members directory permalink.
    150          */
    151         return apply_filters( 'bp_get_members_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) );
     154         * @param string $url Members directory permalink.
     155         */
     156        return apply_filters( 'bp_get_members_directory_permalink', $url );
    152157    }
    153158
     
    186191        }
    187192
     193        $url = bp_rewrites_get_url(
     194            array(
     195                'component_id'   => 'members',
     196                'directory_type' => $type->directory_slug,
     197            )
     198        );
     199
    188200        /**
    189201         * Filters the member type directory permalink.
     
    191203         * @since 2.5.0
    192204         *
    193          * @param string $value       Member type directory permalink.
     205         * @param string $url         Member type directory permalink.
    194206         * @param object $type        Member type object.
    195207         * @param string $member_type Member type name, as passed to the function.
    196208         */
    197         return apply_filters( 'bp_get_member_type_directory_permalink', trailingslashit( bp_get_members_directory_permalink() . bp_get_members_member_type_base() . '/' . $type->directory_slug ), $type, $member_type );
     209        return apply_filters( 'bp_get_member_type_directory_permalink', $url, $type, $member_type );
    198210    }
    199211
     
    14581470
    14591471    // Always add a log out list item to the end of the navigation.
    1460     $logout_link = '<li><a id="wp-logout" href="' .  wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
     1472    $logout_link = '<li><a id="wp-logout" href="' .  wp_logout_url( bp_get_root_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
    14611473
    14621474    echo apply_filters( 'bp_logout_nav_link', $logout_link );
     
    18521864
    18531865/**
    1854  * Output the link for the logged-in user's profile.
    1855  *
    1856  * @since 1.2.4
    1857  */
    1858 function bp_loggedin_user_link() {
    1859     echo esc_url( bp_get_loggedin_user_link() );
    1860 }
    1861     /**
    1862      * Get the link for the logged-in user's profile.
    1863      *
    1864      * @since 1.0.0
    1865      *
    1866      * @return string
    1867      */
    1868     function bp_get_loggedin_user_link() {
    1869 
    1870         /**
    1871          * Filters the link for the logged-in user's profile.
    1872          *
    1873          * @since 1.2.4
    1874          *
    1875          * @param string $value Link for the logged-in user's profile.
    1876          */
    1877         return apply_filters( 'bp_get_loggedin_user_link', bp_loggedin_user_domain() );
    1878     }
    1879 
    1880 /**
    1881  * Output the link for the displayed user's profile.
    1882  *
    1883  * @since 1.2.4
    1884  */
    1885 function bp_displayed_user_link() {
    1886     echo esc_url( bp_get_displayed_user_link() );
    1887 }
    1888     /**
    1889      * Get the link for the displayed user's profile.
    1890      *
    1891      * @since 1.0.0
    1892      *
    1893      * @return string
    1894      */
    1895     function bp_get_displayed_user_link() {
    1896 
    1897         /**
    1898          * Filters the link for the displayed user's profile.
    1899          *
    1900          * @since 1.2.4
    1901          *
    1902          * @param string $value Link for the displayed user's profile.
    1903          */
    1904         return apply_filters( 'bp_get_displayed_user_link', bp_displayed_user_domain() );
    1905     }
    1906 
    1907     /**
    1908      * Alias of {@link bp_displayed_user_domain()}.
    1909      *
    1910      * @deprecated
    1911      */
    1912     function bp_user_link() {
    1913         bp_displayed_user_domain();
    1914     }
    1915 
    1916 /**
    19171866 * Alias of {@link bp_displayed_user_id()}.
    19181867 *
     
    19241873
    19251874/**
     1875 * Output the link for the displayed user's profile.
     1876 *
     1877 * @since 1.2.4
     1878 */
     1879function bp_displayed_user_link() {
     1880    echo esc_url( bp_displayed_user_url() );
     1881}
     1882
     1883/**
     1884 * Builds the logged-in user's profile URL.
     1885 *
     1886 * @since 12.0.0
     1887 *
     1888 * @param array $path_chunks {
     1889 *     An array of arguments. Optional.
     1890 *
     1891 *     @type string $single_item_component        The component slug the action is relative to.
     1892 *     @type string $single_item_action           The slug of the action to perform.
     1893 *     @type array  $single_item_action_variables An array of additional informations about the action to perform.
     1894 * }
     1895 * @return string The logged-in user's profile URL.
     1896 */
     1897function bp_displayed_user_url( $path_chunks = array() ) {
     1898    $bp  = buddypress();
     1899    $url = '';
     1900
     1901    if ( isset( $bp->displayed_user->domain ) ) {
     1902        $url = $bp->displayed_user->domain;
     1903    }
     1904
     1905    if ( $path_chunks ) {
     1906        $url = bp_members_get_user_url( bp_displayed_user_id(), $path_chunks );
     1907    }
     1908
     1909    /**
     1910     * Filter here to edit the displayed user's profile URL.
     1911     *
     1912     * @since 12.0.0
     1913     *
     1914     * @param string $url         The displayed user's profile URL.
     1915     * @param array  $path_chunks {
     1916     *     An array of arguments. Optional.
     1917     *
     1918     *     @type string $single_item_component        The component slug the action is relative to.
     1919     *     @type string $single_item_action           The slug of the action to perform.
     1920     *     @type array  $single_item_action_variables An array of additional informations about the action to perform.
     1921     * }
     1922     */
     1923    return apply_filters( 'bp_displayed_user_url', $url, $path_chunks );
     1924}
     1925
     1926/**
    19261927 * Generate the link for the displayed user's profile.
    19271928 *
    19281929 * @since 1.0.0
    1929  *
     1930 * @since 12.0.0 This function is now an alias of `bp_displayed_user_url()`.
     1931 *               You should only use it to get the "home" URL of the displayed
     1932 *               user's profile page. If you need to build an URL to reach another
     1933 *               page, we strongly advise you to use `bp_displayed_user_url()`.
     1934 *
     1935 * @todo Deprecating this function would be safer.
    19301936 * @return string
    19311937 */
    19321938function bp_displayed_user_domain() {
    1933     $bp = buddypress();
     1939    $url = bp_displayed_user_url();
    19341940
    19351941    /**
     
    19381944     * @since 1.0.0
    19391945     *
    1940      * @param string $value Generated link for the displayed user's profile.
    1941      */
    1942     return apply_filters( 'bp_displayed_user_domain', isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : '' );
     1946     * @param string $url Generated link for the displayed user's profile.
     1947     */
     1948    return apply_filters( 'bp_displayed_user_domain',$url );
     1949}
     1950
     1951/**
     1952 * Output the link for the logged-in user's profile.
     1953 *
     1954 * @since 1.2.4
     1955 */
     1956function bp_loggedin_user_link() {
     1957    echo esc_url( bp_loggedin_user_url() );
     1958}
     1959
     1960/**
     1961 * Builds the logged-in user's profile URL.
     1962 *
     1963 * @since 12.0.0
     1964 *
     1965 * @param array $path_chunks {
     1966 *     An array of arguments. Optional.
     1967 *
     1968 *     @type string $single_item_component        The component slug the action is relative to.
     1969 *     @type string $single_item_action           The slug of the action to perform.
     1970 *     @type array  $single_item_action_variables An array of additional informations about the action to perform.
     1971 * }
     1972 * @return string The logged-in user's profile URL.
     1973 */
     1974function bp_loggedin_user_url( $path_chunks = array() ) {
     1975    $bp  = buddypress();
     1976    $url = '';
     1977
     1978    if ( isset( $bp->loggedin_user->domain ) ) {
     1979        $url = $bp->loggedin_user->domain;
     1980    }
     1981
     1982    if ( $path_chunks ) {
     1983        $url = bp_members_get_user_url( bp_loggedin_user_id(), $path_chunks );
     1984    }
     1985
     1986    /**
     1987     * Filter here to edit the logged-in user's profile URL.
     1988     *
     1989     * @since 12.0.0
     1990     *
     1991     * @param string $url         The logged-in user's profile URL.
     1992     * @param array  $path_chunks {
     1993     *     An array of arguments. Optional.
     1994     *
     1995     *     @type string $single_item_component        The component slug the action is relative to.
     1996     *     @type string $single_item_action           The slug of the action to perform.
     1997     *     @type array  $single_item_action_variables An array of additional informations about the action to perform.
     1998     * }
     1999     */
     2000    return apply_filters( 'bp_loggedin_user_url', $url, $path_chunks );
    19432001}
    19442002
     
    19472005 *
    19482006 * @since 1.0.0
    1949  *
     2007 * @since 12.0.0 This function is now an alias of `bp_loggedin_user_url()`.
     2008 *               You should only use it to get the "home" URL of the logged-in
     2009 *               user's profile page. If you need to build an URL to reach another
     2010 *               page, we strongly advise you to use `bp_loggedin_user_url()`.
     2011 *
     2012 * @todo Deprecating this function would be safer.
    19502013 * @return string
    19512014 */
    19522015function bp_loggedin_user_domain() {
    1953     $bp = buddypress();
     2016    $url = bp_loggedin_user_url();
    19542017
    19552018    /**
     
    19582021     * @since 1.0.0
    19592022     *
    1960      * @param string $value Generated link for the logged-in user's profile.
    1961      */
    1962     return apply_filters( 'bp_loggedin_user_domain', isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '' );
     2023     * @param string $url Generated link for the logged-in user's profile.
     2024     */
     2025    return apply_filters( 'bp_loggedin_user_domain', $url );
    19632026}
    19642027
     
    23472410    function bp_get_signup_page() {
    23482411        if ( bp_has_custom_signup_page() ) {
    2349             $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_signup_slug() );
     2412            $page = bp_rewrites_get_url(
     2413                array(
     2414                    'component_id'    => 'members',
     2415                    'member_register' => 1,
     2416                )
     2417            );
     2418
    23502419        } else {
    2351             $page = bp_get_root_domain() . '/wp-signup.php';
     2420            $page = trailingslashit( bp_get_root_url() ) . 'wp-signup.php';
    23522421        }
    23532422
     
    23962465    function bp_get_activation_page() {
    23972466        if ( bp_has_custom_activation_page() ) {
    2398             $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_activate_slug() );
     2467            $page = bp_rewrites_get_url(
     2468                array(
     2469                    'component_id'    => 'members',
     2470                    'member_activate' => 1,
     2471                )
     2472            );
     2473
    23992474        } else {
    2400             $page = trailingslashit( bp_get_root_domain() ) . 'wp-activate.php';
     2475            $page = trailingslashit( bp_get_root_url() ) . 'wp-activate.php';
    24012476        }
    24022477
     
    35663641        if ( 0 === $user_id ) {
    35673642            $user_id = bp_loggedin_user_id();
    3568             $domain  = bp_loggedin_user_domain();
    3569         } else {
    3570             $domain = bp_members_get_user_url( (int) $user_id );
    3571         }
    3572 
    3573         $retval = trailingslashit( $domain . bp_get_members_invitations_slug() . '/list-invites' );
     3643        }
     3644
     3645        $retval = bp_members_get_user_url(
     3646            (int) $user_id,
     3647            array(
     3648                'single_item_component' => bp_rewrites_get_slug( 'members', 'member_invitations', bp_get_members_invitations_slug() ),
     3649                'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_invitations_list_invites', 'list-invites' ),
     3650            )
     3651        );
    35743652
    35753653        /**
     
    36053683        if ( 0 === $user_id ) {
    36063684            $user_id = bp_loggedin_user_id();
    3607             $domain  = bp_loggedin_user_domain();
    3608         } else {
    3609             $domain = bp_members_get_user_url( (int) $user_id );
    3610         }
    3611 
    3612         $retval = trailingslashit( $domain . bp_get_members_invitations_slug() . '/send-invites' );
     3685        }
     3686
     3687        $retval = bp_members_get_user_url(
     3688            (int) $user_id,
     3689            array(
     3690                'single_item_component' => bp_rewrites_get_slug( 'members', 'member_invitations', bp_get_members_invitations_slug() ),
     3691                'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_invitations_send_invites', 'send-invites' ),
     3692            )
     3693        );
    36133694
    36143695        /**
Note: See TracChangeset for help on using the changeset viewer.