Skip to:
Content

BuddyPress.org

Changeset 7942


Ignore:
Timestamp:
02/20/2014 09:02:33 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce blog- and group-create button functions, and use to build directory headers in bp-legacy

The new functions bp_get_blog_create_button() and bp_get_group_create_button()
standardize the treatment of these buttons by using bp_get_button(). They also
make life easier for themers, who will not need to build the buttons from
scratch.

In this changeset we modify the way that bp-legacy loads these buttons into the
titles of the directory pages. Previously, it was done directly in BP's theme
compat layer, with the result that all template packs had to follow the
questionable practice of embedding a button inside of a header element. Now,
the directory title is a string, but is filtered; bp-legacy then chooses to
add a button by using the new create-button functions + the new filters.

Fixes #5144

Props hnla, r-a-y

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-screens.php

    r7926 r7942  
    142142    public function directory_dummy_post() {
    143143
    144         // Title based on ability to create blogs
    145         if ( is_user_logged_in() && bp_blog_signup_enabled() ) {
    146             $title = __( 'Sites', 'buddypress' ) . '&nbsp;<a class="button" href="' . trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create' ) . '">' . __( 'Create a Sites', 'buddypress' ) . '</a>';
    147         } else {
    148             $title = __( 'Sites', 'buddypress' );
    149         }
     144        $title = apply_filters( 'bp_blogs_directory_title', __( 'Sites', 'buddypress' ) );
    150145
    151146        bp_theme_compat_reset_post( array(
  • trunk/bp-blogs/bp-blogs-template.php

    r7919 r7942  
    11501150
    11511151/**
     1152 * Output the Create a Site button.
     1153 *
     1154 * @since BuddyPress (2.0.0)
     1155 */
     1156function bp_blog_create_button() {
     1157    echo bp_get_blog_create_button();
     1158}
     1159    /**
     1160     * Get the Create a Site button.
     1161     *
     1162     * @since BuddyPress (2.0.0)
     1163     *
     1164     * @return string
     1165     */
     1166    function bp_get_blog_create_button() {
     1167        if ( ! is_user_logged_in() ) {
     1168            return false;
     1169        }
     1170
     1171        if ( ! bp_blog_signup_enabled() ) {
     1172            return false;
     1173        }
     1174
     1175        $button_args = array(
     1176            'id'         => 'create_blog',
     1177            'component'  => 'blogs',
     1178            'link_text'  => __( 'Create a Site', 'buddypress' ),
     1179            'link_title' => __( 'Create a Site', 'buddypress' ),
     1180            'link_class' => 'button blog-create bp-title-button',
     1181            'link_href'  => trailingslashit( bp_get_root_domain() ) . trailingslashit( bp_get_blogs_root_slug() ) . trailingslashit( 'create' ),
     1182            'wrapper'    => false,
     1183        );
     1184
     1185        return bp_get_button( $button_args );
     1186    }
     1187
     1188/**
    11521189 * Output button for visiting a blog in a loop.
    11531190 *
  • trunk/bp-groups/bp-groups-screens.php

    r7926 r7942  
    10221022    public function directory_dummy_post() {
    10231023
    1024         // Title based on ability to create groups
    1025         if ( is_user_logged_in() && bp_user_can_create_groups() ) {
    1026             $title = __( 'Groups', 'buddypress' ) . '&nbsp;<a class="button bp-title-button" href="' . trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create' ) . '">' . __( 'Create a Group', 'buddypress' ) . '</a>';
    1027         } else {
    1028             $title = __( 'Groups', 'buddypress' );
    1029         }
     1024        $title = apply_filters( 'bp_groups_directory_title', __( 'Groups', 'buddypress' ) );
    10301025
    10311026        bp_theme_compat_reset_post( array(
  • trunk/bp-groups/bp-groups-template.php

    r7931 r7942  
    18551855
    18561856/**
     1857 * Output the Create a Group button.
     1858 *
     1859 * @since BuddyPress (2.0.0)
     1860 */
     1861function bp_group_create_button() {
     1862    echo bp_get_group_create_button();
     1863}
     1864    /**
     1865     * Get the Create a Group button.
     1866     *
     1867     * @since BuddyPress (2.0.0)
     1868     *
     1869     * @return string
     1870     */
     1871    function bp_get_group_create_button() {
     1872        if ( ! is_user_logged_in() ) {
     1873            return false;
     1874        }
     1875
     1876        if ( ! bp_user_can_create_groups() ) {
     1877            return false;
     1878        }
     1879
     1880        $button_args = array(
     1881            'id'         => 'create_group',
     1882            'component'  => 'groups',
     1883            'link_text'  => __( 'Create a Group', 'buddypress' ),
     1884            'link_title' => __( 'Create a Group', 'buddypress' ),
     1885            'link_class' => 'button group-create bp-title-button',
     1886            'link_href'  => trailingslashit( bp_get_root_domain() ) . trailingslashit( bp_get_groups_root_slug() ) . trailingslashit( 'create' ),
     1887            'wrapper'    => false,
     1888        );
     1889
     1890        return bp_get_button( $button_args );
     1891    }
     1892
     1893/**
    18571894 * Prints a message if the group is not visible to the current user (it is a
    18581895 * hidden or private group, and the user does not have access).
  • trunk/bp-templates/bp-legacy/buddypress-functions.php

    r7570 r7942  
    112112                add_action( 'bp_group_header_actions',     'bp_group_new_topic_button',      20 );
    113113                add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
     114                add_filter( 'bp_groups_directory_title',   'bp_legacy_theme_group_create_button' );
     115                add_filter( 'bp_blogs_directory_title',    'bp_legacy_theme_blog_create_button' );
    114116            }
    115117
     
    421423
    422424/**
     425 * Add the Create a Group button to the Groups directory title.
     426 *
     427 * bp-legacy puts the Create a Group button into the page title, to mimic
     428 * the behavior of bp-default.
     429 *
     430 * @since BuddyPress (2.0.0)
     431 *
     432 * @param string $title Groups directory title.
     433 * @return string
     434 */
     435function bp_legacy_theme_group_create_button( $title ) {
     436    return $title . ' ' . bp_get_group_create_button();
     437}
     438
     439/**
     440 * Add the Create a Site button to the Sites directory title.
     441 *
     442 * bp-legacy puts the Create a Site button into the page title, to mimic
     443 * the behavior of bp-default.
     444 *
     445 * @since BuddyPress (2.0.0)
     446 *
     447 * @param string $title Sites directory title.
     448 * @return string
     449 */
     450function bp_legacy_theme_blog_create_button( $title ) {
     451    return $title . ' ' . bp_get_blog_create_button();
     452}
     453/**
    423454 * This function looks scarier than it actually is. :)
    424455 * Each object loop (activity/members/groups/blogs/forums) contains default
Note: See TracChangeset for help on using the changeset viewer.