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

    r13409 r13436  
    6868
    6969/**
    70  * Output blog directory permalink.
    71  *
    72  * @since 1.5.0
    73  *
    74  */
    75 function bp_blogs_directory_permalink() {
    76     echo esc_url( bp_get_blogs_directory_permalink() );
    77 }
    78     /**
    79      * Return blog directory permalink.
    80      *
    81      * @since 1.5.0
    82      *
    83      *
    84      * @return string The URL of the Blogs directory.
    85      */
    86     function bp_get_blogs_directory_permalink() {
    87 
    88         /**
    89          * Filters the blog directory permalink.
    90          *
    91          * @since 1.5.0
    92          *
    93          * @param string $value Permalink URL for the blog directory.
    94          */
    95         return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
    96     }
     70 * Output Blogs directory's URL.
     71 *
     72 * @since 12.0.0
     73 */
     74function bp_blogs_directory_url() {
     75    echo esc_url( bp_get_blogs_directory_url() );
     76}
     77
     78/**
     79 * Returns the Blogs directory's URL.
     80 *
     81 * @since 12.0.0
     82 *
     83 * @param array $path_chunks {
     84 *     An array of arguments. Optional.
     85 *
     86 *     @type int $create_single_item `1` to get the Blogs create link.
     87 * }
     88 * @return string The URL built for the BP Rewrites URL parser.
     89 */
     90function bp_get_blogs_directory_url( $path_chunks = array() ) {
     91    $supported_chunks = array_fill_keys( array( 'create_single_item' ), true );
     92
     93    $path_chunks = bp_parse_args(
     94        array_intersect_key( $path_chunks, $supported_chunks ),
     95        array(
     96            'component_id' => 'blogs'
     97        )
     98    );
     99
     100    $url = bp_rewrites_get_url( $path_chunks );
     101
     102    /**
     103     * Filters the Blogs directory's URL.
     104     *
     105     * @since 12.0.0
     106     *
     107     * @param string  $url      The Blogs directory's URL.
     108     * @param array   $path_chunks {
     109     *     An array of arguments. Optional.
     110     *
     111     *     @type int $create_single_item `1` to get the Blogs create link.
     112     * }
     113     */
     114    return apply_filters( 'bp_get_blogs_directory_url', $url, $path_chunks );
     115}
    97116
    98117/**
     
    474493        global $blogs_template;
    475494
    476         if ( empty( $blogs_template->blog->domain ) )
    477             $permalink = bp_get_root_domain() . $blogs_template->blog->path;
    478         else {
     495        if ( ! empty( $blogs_template->blog->domain ) ) {
     496            $permalink = get_site_url( $blogs_template->blog->blog_id );
     497
     498        } else {
    479499            $protocol = 'http://';
    480             if ( is_ssl() )
     500            if ( is_ssl() ) {
    481501                $protocol = 'https://';
     502            }
    482503
    483504            $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
     
    13491370    }
    13501371
     1372    $url = bp_get_blogs_directory_url(
     1373        array(
     1374            'create_single_item' => 1,
     1375        )
     1376    );
     1377
    13511378    /**
    13521379     * Filters "Create a Site" links for users viewing their own profiles.
     
    13541381     * @since 1.0.0
    13551382     *
    1356      * @param string $value HTML link for creating a site.
    1357      */
    1358     echo apply_filters( 'bp_create_blog_link', '<a href="' . trailingslashit( bp_get_blogs_directory_permalink() . 'create' ) . '">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
     1383     * @param string $url HTML link for creating a site.
     1384     */
     1385    echo apply_filters( 'bp_create_blog_link', '<a href="' . $url . '">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
    13591386}
    13601387
     
    14601487        }
    14611488
     1489        $url = bp_get_blogs_directory_url(
     1490            array(
     1491                'create_single_item' => 1,
     1492            )
     1493        );
     1494
    14621495        $button_args = array(
    14631496            'id'         => 'create_blog',
     
    14651498            'link_text'  => __( 'Create a Site', 'buddypress' ),
    14661499            'link_class' => 'blog-create no-ajax',
    1467             'link_href'  => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
     1500            'link_href'  => $url,
    14681501            'wrapper'    => false,
    14691502            'block_self' => false,
Note: See TracChangeset for help on using the changeset viewer.