Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:08:04 AM (10 years ago)
Author:
boonebgorges
Message:

Move bp-blogs classes to their own files.

See #6870.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/classes/class-bp-blogs-template.php

    r10515 r10517  
    11<?php
    22/**
    3  * BuddyPress Blogs Template Tags.
     3 * BuddyPress Blogs Template Class.
    44 *
    55 * @package BuddyPress
     
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Output the blogs component slug.
    15  *
    16  * @since 1.5.0
    17  *
    18  * @uses bp_get_blogs_slug()
    19  */
    20 function bp_blogs_slug() {
    21     echo bp_get_blogs_slug();
    22 }
    23     /**
    24      * Return the blogs component slug.
    25      *
    26      * @since 1.5.0
    27      *
    28      * @return string The 'blogs' slug.
    29      */
    30     function bp_get_blogs_slug() {
    31 
    32         /**
    33          * Filters the blogs component slug.
    34          *
    35          * @since 1.5.0
    36          *
    37          * @param string $slug Slug for the blogs component.
    38          */
    39         return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug );
    40     }
    41 
    42 /**
    43  * Output the blogs component root slug.
    44  *
    45  * @since 1.5.0
    46  *
    47  * @uses bp_get_blogs_root_slug()
    48  */
    49 function bp_blogs_root_slug() {
    50     echo bp_get_blogs_root_slug();
    51 }
    52     /**
    53      * Return the blogs component root slug.
    54      *
    55      * @since 1.5.0
    56      *
    57      * @return string The 'blogs' root slug.
    58      */
    59     function bp_get_blogs_root_slug() {
    60 
    61         /**
    62          * Filters the blogs component root slug.
    63          *
    64          * @since 1.5.0
    65          *
    66          * @param string $root_slug Root slug for the blogs component.
    67          */
    68         return apply_filters( 'bp_get_blogs_root_slug', buddypress()->blogs->root_slug );
    69     }
    70 
    71 /**
    72  * Output blog directory permalink.
    73  *
    74  * @since 1.5.0
    75  *
    76  * @uses bp_get_blogs_directory_permalink()
    77  */
    78 function bp_blogs_directory_permalink() {
    79     echo esc_url( bp_get_blogs_directory_permalink() );
    80 }
    81     /**
    82      * Return blog directory permalink.
    83      *
    84      * @since 1.5.0
    85      *
    86      * @uses apply_filters()
    87      * @uses trailingslashit()
    88      * @uses bp_get_root_domain()
    89      * @uses bp_get_blogs_root_slug()
    90      *
    91      * @return string The URL of the Blogs directory.
    92      */
    93     function bp_get_blogs_directory_permalink() {
    94 
    95         /**
    96          * Filters the blog directory permalink.
    97          *
    98          * @since 1.5.0
    99          *
    100          * @param string $value Permalink URL for the blog directory.
    101          */
    102         return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
    103     }
    10412
    10513/**
     
    337245    }
    338246}
    339 
    340 /**
    341  * Rewind the blogs and reset blog index.
    342  */
    343 function bp_rewind_blogs() {
    344     global $blogs_template;
    345 
    346     $blogs_template->rewind_blogs();
    347 }
    348 
    349 /**
    350  * Initialize the blogs loop.
    351  *
    352  * Based on the $args passed, bp_has_blogs() populates the $blogs_template
    353  * global, enabling the use of BuddyPress templates and template functions to
    354  * display a list of activity items.
    355  *
    356  * @global object $blogs_template {@link BP_Blogs_Template}
    357  *
    358  * @param array|string $args {
    359  *     Arguments for limiting the contents of the blogs loop. Most arguments
    360  *     are in the same format as {@link BP_Blogs_Blog::get()}. However, because
    361  *     the format of the arguments accepted here differs in a number of ways,
    362  *     and because bp_has_blogs() determines some default arguments in a
    363  *     dynamic fashion, we list all accepted arguments here as well.
    364  *
    365  *     Arguments can be passed as an associative array, or as a URL query
    366  *     string (eg, 'user_id=4&per_page=3').
    367  *
    368  *     @type int      $page             Which page of results to fetch. Using page=1 without
    369  *                                      per_page will result in no pagination. Default: 1.
    370  *     @type int|bool $per_page         Number of results per page. Default: 20.
    371  *     @type string   $page_arg         The string used as a query parameter in
    372  *                                      pagination links. Default: 'bpage'.
    373  *     @type int|bool $max              Maximum number of results to return.
    374  *                                      Default: false (unlimited).
    375  *     @type string   $type             The order in which results should be fetched.
    376  *                                      'active', 'alphabetical', 'newest', or 'random'.
    377  *     @type array    $include_blog_ids Array of blog IDs to limit results to.
    378  *     @type string   $sort             'ASC' or 'DESC'. Default: 'DESC'.
    379  *     @type string   $search_terms     Limit results by a search term. Default: the value of `$_REQUEST['s']` or
    380  *                                      `$_REQUEST['sites_search']`, if present.
    381  *     @type int      $user_id          The ID of the user whose blogs should be retrieved.
    382  *                                      When viewing a user profile page, 'user_id' defaults to the
    383  *                                      ID of the displayed user. Otherwise the default is false.
    384  * }
    385  * @return bool Returns true when blogs are found, otherwise false.
    386  */
    387 function bp_has_blogs( $args = '' ) {
    388     global $blogs_template;
    389 
    390     // Check for and use search terms.
    391     $search_terms_default = false;
    392     $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' );
    393     if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
    394         $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
    395     } elseif ( ! empty( $_REQUEST['s'] ) ) {
    396         $search_terms_default = stripslashes( $_REQUEST['s'] );
    397     }
    398 
    399     // Parse arguments.
    400     $r = bp_parse_args( $args, array(
    401         'type'              => 'active',
    402         'page_arg'          => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679.
    403         'page'              => 1,
    404         'per_page'          => 20,
    405         'max'               => false,
    406         'user_id'           => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user is a member of.
    407         'include_blog_ids'  => false,
    408         'search_terms'      => $search_terms_default,
    409         'update_meta_cache' => true
    410     ), 'has_blogs' );
    411 
    412     // Set per_page to maximum if max is enforced.
    413     if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) {
    414         $r['per_page'] = (int) $r['max'];
    415     }
    416 
    417     // Get the blogs.
    418     $blogs_template = new BP_Blogs_Template( $r['type'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['search_terms'], $r['page_arg'], $r['update_meta_cache'], $r['include_blog_ids'] );
    419 
    420     /**
    421      * Filters whether or not there are blogs to list.
    422      *
    423      * @since 1.1.0
    424      *
    425      * @param bool              $value          Whether or not there are blogs to list.
    426      * @param BP_Blogs_Template $blogs_template Current blogs template object.
    427      * @param array             $r              Parsed arguments used in blogs template query.
    428      */
    429     return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template, $r );
    430 }
    431 
    432 /**
    433  * Determine if there are still blogs left in the loop.
    434  *
    435  * @global object $blogs_template {@link BP_Blogs_Template}
    436  *
    437  * @return bool Returns true when blogs are found.
    438  */
    439 function bp_blogs() {
    440     global $blogs_template;
    441 
    442     return $blogs_template->blogs();
    443 }
    444 
    445 /**
    446  * Get the current blog object in the loop.
    447  *
    448  * @global object $blogs_template {@link BP_Blogs_Template}
    449  *
    450  * @return object The current blog within the loop.
    451  */
    452 function bp_the_blog() {
    453     global $blogs_template;
    454 
    455     return $blogs_template->the_blog();
    456 }
    457 
    458 /**
    459  * Output the blogs pagination count.
    460  *
    461  * @global object $blogs_template {@link BP_Blogs_Template}
    462  */
    463 function bp_blogs_pagination_count() {
    464     global $blogs_template;
    465 
    466     $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
    467     $from_num  = bp_core_number_format( $start_num );
    468     $to_num    = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
    469     $total     = bp_core_number_format( $blogs_template->total_blog_count );
    470 
    471     if ( 1 == $blogs_template->total_blog_count ) {
    472         $message = __( 'Viewing 1 site', 'buddypress' );
    473     } else {
    474         $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s site', 'Viewing %1$s - %2$s of %3$s sites', $blogs_template->total_blog_count, 'buddypress' ), $from_num, $to_num, $total );
    475     }
    476 
    477     echo $message;
    478 }
    479 
    480 /**
    481  * Output the blogs pagination links.
    482  */
    483 function bp_blogs_pagination_links() {
    484     echo bp_get_blogs_pagination_links();
    485 }
    486     /**
    487      * Return the blogs pagination links.
    488      *
    489      * @global object $blogs_template {@link BP_Blogs_Template}
    490      *
    491      * @return string HTML pagination links.
    492      */
    493     function bp_get_blogs_pagination_links() {
    494         global $blogs_template;
    495 
    496         /**
    497          * Filters the blogs pagination links.
    498          *
    499          * @since 1.0.0
    500          *
    501          * @param string $pag_links HTML pagination links.
    502          */
    503         return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
    504     }
    505 
    506 /**
    507  * Output a blog's avatar.
    508  *
    509  * @see bp_get_blog_avatar() for description of arguments.
    510  *
    511  * @param array|string $args See {@link bp_get_blog_avatar()}.
    512  */
    513 function bp_blog_avatar( $args = '' ) {
    514     echo bp_get_blog_avatar( $args );
    515 }
    516     /**
    517      * Get a blog's avatar.
    518      *
    519      * At the moment, blog avatars are simply the user avatars of the blog
    520      * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize.
    521      *
    522      * @since 2.4.0 Introduced `$title` argument.
    523      *
    524      * @see bp_core_fetch_avatar() For a description of arguments and
    525      *      return values.
    526      *
    527      * @param array|string $args  {
    528      *     Arguments are listed here with an explanation of their defaults.
    529      *     For more information about the arguments, see
    530      *     {@link bp_core_fetch_avatar()}.
    531      *     @type string   $alt     Default: 'Profile picture of site author [user name]'.
    532      *     @type string   $class   Default: 'avatar'.
    533      *     @type string   $title   Default: 'Profile picture of site author [user name]'.
    534      *     @type string   $type    Default: 'full'.
    535      *     @type int|bool $width   Default: false.
    536      *     @type int|bool $height  Default: false.
    537      *     @type bool     $id      Currently unused.
    538      *     @type bool     $no_grav Default: true.
    539      * }
    540      * @return string User avatar string.
    541      */
    542     function bp_get_blog_avatar( $args = '' ) {
    543         global $blogs_template;
    544 
    545         // Bail if avatars are turned off
    546         // @todo Should we maybe still filter this?
    547         if ( ! buddypress()->avatar->show_avatars ) {
    548             return false;
    549         }
    550 
    551         $author_displayname = bp_core_get_user_displayname( $blogs_template->blog->admin_user_id );
    552 
    553         // Parse the arguments.
    554         $r = bp_parse_args( $args, array(
    555             'type'    => 'full',
    556             'width'   => false,
    557             'height'  => false,
    558             'class'   => 'avatar',
    559             'title'   => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
    560             'id'      => false,
    561             'alt'     => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
    562             'no_grav' => true,
    563         ) );
    564 
    565         // Fetch the avatar.
    566         $avatar = bp_core_fetch_avatar( array(
    567             'item_id'    => $blogs_template->blog->admin_user_id,
    568             'title'      => $r['title'],
    569             // 'avatar_dir' => 'blog-avatars',
    570             // 'object'     => 'blog',
    571             'type'       => $r['type'],
    572             'alt'        => $r['alt'],
    573             'css_id'     => $r['id'],
    574             'class'      => $r['class'],
    575             'width'      => $r['width'],
    576             'height'     => $r['height']
    577         ) );
    578 
    579         /**
    580          * In future BuddyPress versions you will be able to set the avatar for a blog.
    581          * Right now you can use a filter with the ID of the blog to change it if you wish.
    582          * By default it will return the avatar for the primary blog admin.
    583          *
    584          * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.
    585          * Use the 'bp_get_blog_avatar' filter instead.
    586          */
    587         $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar );
    588 
    589         /**
    590          * Filters a blog's avatar.
    591          *
    592          * @since 1.5.0
    593          *
    594          * @param string $avatar  Formatted HTML <img> element, or raw avatar
    595          *                        URL based on $html arg.
    596          * @param int    $blog_id ID of the blog whose avatar is being displayed.
    597          * @param array  $r       Array of arguments used when fetching avatar.
    598          */
    599         return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, $r );
    600     }
    601 
    602 function bp_blog_permalink() {
    603     echo bp_get_blog_permalink();
    604 }
    605     function bp_get_blog_permalink() {
    606         global $blogs_template;
    607 
    608         if ( empty( $blogs_template->blog->domain ) )
    609             $permalink = bp_get_root_domain() . $blogs_template->blog->path;
    610         else {
    611             $protocol = 'http://';
    612             if ( is_ssl() )
    613                 $protocol = 'https://';
    614 
    615             $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
    616         }
    617 
    618         /**
    619          * Filters the blog permalink.
    620          *
    621          * @since 1.0.0
    622          *
    623          * @param string $permalink Permalink URL for the blog.
    624          */
    625         return apply_filters( 'bp_get_blog_permalink', $permalink );
    626     }
    627 
    628 /**
    629  * Output the name of the current blog in the loop.
    630  */
    631 function bp_blog_name() {
    632     echo bp_get_blog_name();
    633 }
    634     /**
    635      * Return the name of the current blog in the loop.
    636      *
    637      * @return string The name of the current blog in the loop.
    638      */
    639     function bp_get_blog_name() {
    640         global $blogs_template;
    641 
    642         /**
    643          * Filters the name of the current blog in the loop.
    644          *
    645          * @since 1.2.0
    646          *
    647          * @param string $name Name of the current blog in the loop.
    648          */
    649         return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
    650     }
    651 
    652 /**
    653  * Output the ID of the current blog in the loop.
    654  *
    655  * @since 1.7.0
    656  */
    657 function bp_blog_id() {
    658     echo bp_get_blog_id();
    659 }
    660     /**
    661      * Return the ID of the current blog in the loop.
    662      *
    663      * @since 1.7.0
    664      *
    665      * @return int ID of the current blog in the loop.
    666      */
    667     function bp_get_blog_id() {
    668         global $blogs_template;
    669 
    670         /**
    671          * Filters the ID of the current blog in the loop.
    672          *
    673          * @since 1.7.0
    674          *
    675          * @param int $blog_id ID of the current blog in the loop.
    676          */
    677         return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id );
    678     }
    679 
    680 /**
    681  * Output the description of the current blog in the loop.
    682  */
    683 function bp_blog_description() {
    684 
    685     /**
    686      * Filters the description of the current blog in the loop.
    687      *
    688      * @since 1.2.0
    689      *
    690      * @param string $value Description of the current blog in the loop.
    691      */
    692     echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
    693 }
    694     /**
    695      * Return the description of the current blog in the loop.
    696      *
    697      * @return string Description of the current blog in the loop.
    698      */
    699     function bp_get_blog_description() {
    700         global $blogs_template;
    701 
    702         /**
    703          * Filters the description of the current blog in the loop.
    704          *
    705          * @since 1.0.0
    706          *
    707          * @param string $value Description of the current blog in the loop.
    708          */
    709         return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
    710     }
    711 
    712 /**
    713  * Output the row class of the current blog in the loop.
    714  *
    715  * @since 1.7.0
    716  *
    717  * @param array $classes Array of custom classes.
    718  */
    719 function bp_blog_class( $classes = array() ) {
    720     echo bp_get_blog_class( $classes );
    721 }
    722     /**
    723      * Return the row class of the current blog in the loop.
    724      *
    725      * @since 1.7.0
    726      *
    727      * @global BP_Blogs_Template $blogs_template
    728      *
    729      * @param array $classes Array of custom classes.
    730      * @return string Row class of the site.
    731      */
    732     function bp_get_blog_class( $classes = array() ) {
    733         global $blogs_template;
    734 
    735         // Add even/odd classes, but only if there's more than 1 group.
    736         if ( $blogs_template->blog_count > 1 ) {
    737             $pos_in_loop = (int) $blogs_template->current_blog;
    738             $classes[]   = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
    739 
    740         // If we've only one site in the loop, don't bother with odd and even.
    741         } else {
    742             $classes[] = 'bp-single-blog';
    743         }
    744 
    745         /**
    746          * Filters the row class of the current blog in the loop.
    747          *
    748          * @since 1.7.0
    749          *
    750          * @param array $classes Array of classes to be applied to row.
    751          */
    752         $classes = apply_filters( 'bp_get_blog_class', $classes );
    753         $classes = array_merge( $classes, array() );
    754         $retval  = 'class="' . join( ' ', $classes ) . '"';
    755 
    756         return $retval;
    757     }
    758 
    759 /**
    760  * Output the last active date of the current blog in the loop.
    761  *
    762  * @param array $args See {@link bp_get_blog_last_active()}.
    763  */
    764 function bp_blog_last_active( $args = array() ) {
    765     echo bp_get_blog_last_active( $args );
    766 }
    767     /**
    768      * Return the last active date of the current blog in the loop.
    769      *
    770      * @param array $args {
    771      *     Array of optional arguments.
    772      *     @type bool $active_format If true, formatted "Active 5 minutes ago".
    773      *                               If false, formatted "5 minutes ago".
    774      *                               Default: true.
    775      * }
    776      * @return string Last active date.
    777      */
    778     function bp_get_blog_last_active( $args = array() ) {
    779         global $blogs_template;
    780 
    781         // Parse the activity format.
    782         $r = bp_parse_args( $args, array(
    783             'active_format' => true
    784         ) );
    785 
    786         // Backwards compatibility for anyone forcing a 'true' active_format.
    787         if ( true === $r['active_format'] ) {
    788             $r['active_format'] = __( 'active %s', 'buddypress' );
    789         }
    790 
    791         // Blog has been posted to at least once.
    792         if ( isset( $blogs_template->blog->last_activity ) ) {
    793 
    794             // Backwards compatibility for pre 1.5 'ago' strings.
    795             $last_activity = ! empty( $r['active_format'] )
    796                 ? bp_core_get_last_activity( $blogs_template->blog->last_activity, $r['active_format'] )
    797                 : bp_core_time_since( $blogs_template->blog->last_activity );
    798 
    799         // Blog has never been posted to.
    800         } else {
    801             $last_activity = __( 'Never active', 'buddypress' );
    802         }
    803 
    804         /**
    805          * Filters the last active date of the current blog in the loop.
    806          *
    807          * @since
    808          *
    809          * @param string $last_activity Last active date.
    810          * @param array  $r             Array of parsed args used to determine formatting.
    811          */
    812         return apply_filters( 'bp_blog_last_active', $last_activity, $r );
    813     }
    814 
    815 /**
    816  * Output the latest post from the current blog in the loop.
    817  *
    818  * @param array $args See {@link bp_get_blog_latest_post()}.
    819  */
    820 function bp_blog_latest_post( $args = array() ) {
    821     echo bp_get_blog_latest_post( $args );
    822 }
    823     /**
    824      * Return the latest post from the current blog in the loop.
    825      *
    826      * @param array $args {
    827      *     Array of optional arguments.
    828      *     @type bool $latest_format If true, formatted "Latest post: [link to post]".
    829      *                               If false, formatted "[link to post]".
    830      *                               Default: true.
    831      * }
    832      * @return string $retval String of the form 'Latest Post: [link to post]'.
    833      */
    834     function bp_get_blog_latest_post( $args = array() ) {
    835         global $blogs_template;
    836 
    837         $r = wp_parse_args( $args, array(
    838             'latest_format' => true,
    839         ) );
    840 
    841         $retval = bp_get_blog_latest_post_title();
    842 
    843         if ( ! empty( $retval ) ) {
    844             if ( ! empty( $r['latest_format'] ) ) {
    845 
    846                 /**
    847                  * Filters the title text of the latest post for the current blog in loop.
    848                  *
    849                  * @since 1.0.0
    850                  *
    851                  * @param string $retval Title of the latest post.
    852                  */
    853                 $retval = sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' );
    854             } else {
    855 
    856                 /** This filter is documented in bp-blogs/bp-blogs-template.php */
    857                 $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>';
    858             }
    859         }
    860 
    861         /**
    862          * Filters the HTML markup result for the latest blog post in loop.
    863          *
    864          * @since 1.2.0
    865          *
    866          * @param string $retval HTML markup for the latest post.
    867          */
    868         return apply_filters( 'bp_get_blog_latest_post', $retval );
    869     }
    870 
    871 /**
    872  * Output the title of the latest post on the current blog in the loop.
    873  *
    874  * @since 1.7.0
    875  *
    876  * @see bp_get_blog_latest_post_title()
    877  */
    878 function bp_blog_latest_post_title() {
    879     echo bp_get_blog_latest_post_title();
    880 }
    881     /**
    882      * Return the title of the latest post on the current blog in the loop.
    883      *
    884      * @since 1.7.0
    885      *
    886      * @global BP_Blogs_Template
    887      *
    888      * @return string Post title.
    889      */
    890     function bp_get_blog_latest_post_title() {
    891         global $blogs_template;
    892 
    893         $retval = '';
    894 
    895         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) )
    896             $retval = $blogs_template->blog->latest_post->post_title;
    897 
    898         /**
    899          * Filters the title text of the latest post on the current blog in the loop.
    900          *
    901          * @since 1.7.0
    902          *
    903          * @param string $retval Title text for the latest post.
    904          */
    905         return apply_filters( 'bp_get_blog_latest_post_title', $retval );
    906     }
    907 
    908 /**
    909  * Output the permalink of the latest post on the current blog in the loop.
    910  *
    911  * @since 1.7.0
    912  *
    913  * @see bp_get_blog_latest_post_title()
    914  */
    915 function bp_blog_latest_post_permalink() {
    916     echo esc_url( bp_get_blog_latest_post_permalink() );
    917 }
    918     /**
    919      * Return the permalink of the latest post on the current blog in the loop.
    920      *
    921      * @since 1.7.0
    922      *
    923      * @global BP_Blogs_Template
    924      *
    925      * @return string URL of the blog's latest post.
    926      */
    927     function bp_get_blog_latest_post_permalink() {
    928         global $blogs_template;
    929 
    930         $retval = '';
    931 
    932         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) )
    933             $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() );
    934 
    935         /**
    936          * Filters the permalink of the latest post on the current blog in the loop.
    937          *
    938          * @since 1.7.0
    939          *
    940          * @param string $retval Permalink URL of the latest post.
    941          */
    942         return apply_filters( 'bp_get_blog_latest_post_permalink', $retval );
    943     }
    944 
    945 /**
    946  * Output the content of the latest post on the current blog in the loop.
    947  *
    948  * @since 1.7.0
    949  *
    950  * @uses bp_get_blog_latest_post_content()
    951  */
    952 function bp_blog_latest_post_content() {
    953     echo bp_get_blog_latest_post_content();
    954 }
    955     /**
    956      * Return the content of the latest post on the current blog in the loop.
    957      *
    958      * @since 1.7.0
    959      *
    960      * @global BP_Blogs_Template
    961      *
    962      * @return string Content of the blog's latest post.
    963      */
    964     function bp_get_blog_latest_post_content() {
    965         global $blogs_template;
    966 
    967         $retval = '';
    968 
    969         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) )
    970             $retval = $blogs_template->blog->latest_post->post_content;
    971 
    972         /**
    973          * Filters the content of the latest post on the current blog in the loop.
    974          *
    975          * @since 1.7.0
    976          *
    977          * @param string $retval Content of the latest post on the current blog in the loop.
    978          */
    979         return apply_filters( 'bp_get_blog_latest_post_content', $retval );
    980     }
    981 
    982 /**
    983  * Output the featured image of the latest post on the current blog in the loop.
    984  *
    985  * @since 1.7.0
    986  *
    987  * @see bp_get_blog_latest_post_content() For description of parameters.
    988  *
    989  * @param string $size See {@link bp_get_blog_latest_post_featured_image()}.
    990  */
    991 function bp_blog_latest_post_featured_image( $size = 'thumbnail' ) {
    992     echo bp_get_blog_latest_post_featured_image( $size );
    993 }
    994     /**
    995      * Return the featured image of the latest post on the current blog in the loop.
    996      *
    997      * @since 1.7.0
    998      *
    999      * @global BP_Blogs_Template
    1000      *
    1001      * @param string $size Image version to return. 'thumbnail', 'medium',
    1002      *                     'large', or 'post-thumbnail'. Default: 'thumbnail'.
    1003      * @return string URL of the image.
    1004      */
    1005     function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) {
    1006         global $blogs_template;
    1007 
    1008         $retval = '';
    1009 
    1010         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[$size] ) )
    1011             $retval = $blogs_template->blog->latest_post->images[$size];
    1012 
    1013         /**
    1014          * Filters the featured image of the latest post on the current blog in the loop.
    1015          *
    1016          * @since 1.7.0
    1017          *
    1018          * @param string $retval The featured image of the latest post on the current blog in the loop.
    1019          */
    1020         return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval );
    1021     }
    1022 
    1023 /**
    1024  * Does the latest blog post have a featured image?
    1025  *
    1026  * @since 1.7.0
    1027  *
    1028  * @param string $thumbnail Image version to return. 'thumbnail', 'medium', 'large',
    1029  *                          or 'post-thumbnail'. Default: 'thumbnail'.
    1030  * @return bool True if the latest blog post from the current blog has a
    1031  *              featured image of the given size.
    1032  */
    1033 function bp_blog_latest_post_has_featured_image( $thumbnail = 'thumbnail' ) {
    1034     $image  = bp_get_blog_latest_post_featured_image( $thumbnail );
    1035 
    1036     /**
    1037      * Filters whether or not the latest blog post has a featured image.
    1038      *
    1039      * @since 1.7.0
    1040      *
    1041      * @param bool   $value     Whether or not the latest blog post has a featured image.
    1042      * @param string $thumbnail Image version to return.
    1043      * @param string $image     Returned value from bp_get_blog_latest_post_featured_image.
    1044      */
    1045     return apply_filters( 'bp_blog_latest_post_has_featured_image', ! empty( $image ), $thumbnail, $image );
    1046 }
    1047 
    1048 /**
    1049  * Output hidden fields to help with form submissions in Sites directory.
    1050  *
    1051  * This function detects whether 's', 'letter', or 'blogs_search' requests are
    1052  * currently being made (as in a URL parameter), and creates corresponding
    1053  * hidden fields.
    1054  */
    1055 function bp_blog_hidden_fields() {
    1056     if ( isset( $_REQUEST['s'] ) )
    1057         echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />';
    1058 
    1059     if ( isset( $_REQUEST['letter'] ) )
    1060         echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    1061 
    1062     if ( isset( $_REQUEST['blogs_search'] ) )
    1063         echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
    1064 }
    1065 
    1066 /**
    1067  * Output the total number of blogs on the site.
    1068  */
    1069 function bp_total_blog_count() {
    1070     echo bp_get_total_blog_count();
    1071 }
    1072     /**
    1073      * Return the total number of blogs on the site.
    1074      *
    1075      * @return int Total number of blogs.
    1076      */
    1077     function bp_get_total_blog_count() {
    1078 
    1079         /**
    1080          * Filters the total number of blogs on the site.
    1081          *
    1082          * @since 1.2.0
    1083          *
    1084          * @param int $value Total number of blogs on the site.
    1085          */
    1086         return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
    1087     }
    1088     add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
    1089 
    1090 /**
    1091  * Output the total number of blogs for a given user.
    1092  *
    1093  * @param int $user_id ID of the user.
    1094  */
    1095 function bp_total_blog_count_for_user( $user_id = 0 ) {
    1096     echo bp_get_total_blog_count_for_user( $user_id );
    1097 }
    1098     /**
    1099      * Return the total number of blogs for a given user.
    1100      *
    1101      * @param int $user_id ID of the user.
    1102      * @return int Total number of blogs for the user.
    1103      */
    1104     function bp_get_total_blog_count_for_user( $user_id = 0 ) {
    1105 
    1106         /**
    1107          * Filters the total number of blogs for a given user.
    1108          *
    1109          * @since 1.2.0
    1110          *
    1111          * @param int $value Total number of blogs for a given user.
    1112          */
    1113         return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
    1114     }
    1115     add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
    1116 
    1117 
    1118 /** Blog Registration ********************************************************/
    1119 
    1120 /**
    1121  * Checks whether blog creation is enabled.
    1122  *
    1123  * Returns true when blog creation is enabled for logged-in users only, or
    1124  * when it's enabled for new registrations.
    1125  *
    1126  * @return bool True if blog registration is enabled.
    1127  */
    1128 function bp_blog_signup_enabled() {
    1129     $bp = buddypress();
    1130 
    1131     $active_signup = isset( $bp->site_options['registration'] )
    1132         ? $bp->site_options['registration']
    1133         : 'all';
    1134 
    1135     /**
    1136      * Filters whether or not blog creation is enabled.
    1137      *
    1138      * Return "all", "none", "blog" or "user".
    1139      *
    1140      * @since 1.0.0
    1141      *
    1142      * @param string $active_signup Value of the registration site option creation status.
    1143      */
    1144     $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
    1145 
    1146     if ( 'none' == $active_signup || 'user' == $active_signup )
    1147         return false;
    1148 
    1149     return true;
    1150 }
    1151 
    1152 /**
    1153  * Output the wrapper markup for the blog signup form.
    1154  *
    1155  * @param string          $blogname   Optional. The default blog name (path or domain).
    1156  * @param string          $blog_title Optional. The default blog title.
    1157  * @param string|WP_Error $errors     Optional. The WP_Error object returned by a previous
    1158  *                                    submission attempt.
    1159  */
    1160 function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
    1161     global $current_user;
    1162 
    1163     if ( isset($_POST['submit']) ) {
    1164         bp_blogs_validate_blog_signup();
    1165     } else {
    1166         if ( ! is_wp_error($errors) ) {
    1167             $errors = new WP_Error();
    1168         }
    1169 
    1170         /**
    1171          * Filters the default values for Blog name, title, and any current errors.
    1172          *
    1173          * @since 1.0.0
    1174          *
    1175          * @param array $value {
    1176          *      string   $blogname   Default blog name provided.
    1177          *      string   $blog_title Default blog title provided.
    1178          *      WP_Error $errors     WP_Error object.
    1179          * }
    1180          */
    1181         $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
    1182         $blogname = $filtered_results['blogname'];
    1183         $blog_title = $filtered_results['blog_title'];
    1184         $errors = $filtered_results['errors'];
    1185 
    1186         if ( $errors->get_error_code() ) {
    1187             echo "<p>" . __('There was a problem; please correct the form below and try again.', 'buddypress') . "</p>";
    1188         }
    1189         ?>
    1190         <p><?php printf(__("By filling out the form below, you can <strong>add a site to your account</strong>. There is no limit to the number of sites that you can have, so create to your heart's content, but blog responsibly!", 'buddypress'), $current_user->display_name) ?></p>
    1191 
    1192         <p><?php _e("If you&#8217;re not going to use a great domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>
    1193 
    1194         <form class="standard-form" id="setupform" method="post" action="">
    1195 
    1196             <input type="hidden" name="stage" value="gimmeanotherblog" />
    1197             <?php
    1198 
    1199             /**
    1200              * Fires after the default hidden fields in blog signup form markup.
    1201              *
    1202              * @since 1.0.0
    1203              */
    1204             do_action( 'signup_hidden_fields' ); ?>
    1205 
    1206             <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
    1207             <p>
    1208                 <input id="submit" type="submit" name="submit" class="submit" value="<?php esc_attr_e('Create Site', 'buddypress') ?>" />
    1209             </p>
    1210 
    1211             <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
    1212         </form>
    1213         <?php
    1214     }
    1215 }
    1216 
    1217 /**
    1218  * Output the input fields for the blog creation form.
    1219  *
    1220  * @param string          $blogname   Optional. The default blog name (path or domain).
    1221  * @param string          $blog_title Optional. The default blog title.
    1222  * @param string|WP_Error $errors     Optional. The WP_Error object returned by a previous
    1223  *                                    submission attempt.
    1224  */
    1225 function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
    1226     global $current_site;
    1227 
    1228     // Blog name.
    1229     if( !is_subdomain_install() )
    1230         echo '<label for="blogname">' . __('Site Name:', 'buddypress') . '</label>';
    1231     else
    1232         echo '<label for="blogname">' . __('Site Domain:', 'buddypress') . '</label>';
    1233 
    1234     if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
    1235 
    1236         <p class="error"><?php echo $errmsg ?></p>
    1237 
    1238     <?php }
    1239 
    1240     if ( !is_subdomain_install() )
    1241         echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" /><br />';
    1242     else
    1243         echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" ' . bp_get_form_field_attributes( 'blogname' ) . '/> <span class="suffix_address">.' . bp_blogs_get_subdomain_base() . '</span><br />';
    1244 
    1245     if ( !is_user_logged_in() ) {
    1246         print '(<strong>' . __( 'Your address will be ' , 'buddypress');
    1247 
    1248         if ( !is_subdomain_install() ) {
    1249             print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
    1250         } else {
    1251             print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
    1252         }
    1253 
    1254         echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
    1255     }
    1256 
    1257     // Blog Title.
    1258     ?>
    1259 
    1260     <label for="blog_title"><?php _e('Site Title:', 'buddypress') ?></label>
    1261 
    1262     <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
    1263 
    1264         <p class="error"><?php echo $errmsg ?></p>
    1265 
    1266     <?php }
    1267     echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_html($blog_title, 1).'" /></p>';
    1268     ?>
    1269 
    1270     <p>
    1271         <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
    1272         <?php _e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?>
    1273 
    1274         <label class="checkbox" for="blog_public_on">
    1275             <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
    1276             <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
    1277         </label>
    1278         <label class="checkbox" for="blog_public_off">
    1279             <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
    1280             <strong><?php _e( 'No' , 'buddypress'); ?></strong>
    1281         </label>
    1282     </p>
    1283 
    1284     <?php
    1285 
    1286     /**
    1287      * Fires at the end of all of the default input fields for blog creation form.
    1288      *
    1289      * @since 1.0.0
    1290      *
    1291      * @param WP_Error $errors WP_Error object if any present.
    1292      */
    1293     do_action('signup_blogform', $errors);
    1294 }
    1295 
    1296 /**
    1297  * Process a blog registration submission.
    1298  *
    1299  * Passes submitted values to {@link wpmu_create_blog()}.
    1300  *
    1301  * @return bool True on success, false on failure.
    1302  */
    1303 function bp_blogs_validate_blog_signup() {
    1304     global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path, $current_site;
    1305 
    1306     if ( !check_admin_referer( 'bp_blog_signup_form' ) )
    1307         return false;
    1308 
    1309     $current_user = wp_get_current_user();
    1310 
    1311     if( !is_user_logged_in() )
    1312         die();
    1313 
    1314     $result = bp_blogs_validate_blog_form();
    1315     extract($result);
    1316 
    1317     if ( $errors->get_error_code() ) {
    1318         unset($_POST['submit']);
    1319         bp_show_blog_signup_form( $blogname, $blog_title, $errors );
    1320         return false;
    1321     }
    1322 
    1323     $public = (int) $_POST['blog_public'];
    1324 
    1325     // Depreciated.
    1326     $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) );
    1327 
    1328     /**
    1329      * Filters the default values for Blog meta.
    1330      *
    1331      * @since 1.0.0
    1332      *
    1333      * @param array $meta {
    1334      *      string $value  Default blog language ID.
    1335      *      string $public Default public status.
    1336      * }
    1337      */
    1338     $meta = apply_filters( 'add_signup_meta', $meta );
    1339 
    1340     // If this is a subdomain install, set up the site inside the root domain.
    1341     if ( is_subdomain_install() )
    1342         $domain = $blogname . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
    1343 
    1344     wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
    1345     bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
    1346     return true;
    1347 }
    1348 
    1349 /**
    1350  * Validate a blog creation submission.
    1351  *
    1352  * Essentially, a wrapper for {@link wpmu_validate_blog_signup()}.
    1353  *
    1354  * @return array Contains the new site data and error messages.
    1355  */
    1356 function bp_blogs_validate_blog_form() {
    1357     $user = '';
    1358     if ( is_user_logged_in() )
    1359         $user = wp_get_current_user();
    1360 
    1361     return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
    1362 }
    1363 
    1364 /**
    1365  * Display a message after successful blog registration.
    1366  *
    1367  * @param string       $domain     The new blog's domain.
    1368  * @param string       $path       The new blog's path.
    1369  * @param string       $blog_title The new blog's title.
    1370  * @param string       $user_name  The user name of the user who created the blog. Unused.
    1371  * @param string       $user_email The email of the user who created the blog. Unused.
    1372  * @param string|array $meta       Meta values associated with the new blog. Unused.
    1373  */
    1374 function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
    1375     $protocol = is_ssl() ? 'https://' : 'http://';
    1376     $blog_url = $protocol . $domain . $path; ?>
    1377 
    1378     <p><?php _e( 'Congratulations! You have successfully registered a new site.', 'buddypress' ) ?></p>
    1379     <p>
    1380         <?php printf(__( '<a href="%1$s">%2$s</a> is your new site.  <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress' ), $blog_url, $blog_url, $blog_url . "wp-login.php", $user_name ); ?>
    1381     </p>
    1382 
    1383 <?php
    1384 
    1385     /**
    1386      * Fires after the default successful blog registration message markup.
    1387      *
    1388      * @since 1.0.0
    1389      */
    1390     do_action('signup_finished');
    1391 }
    1392 
    1393 /**
    1394  * Output a "Create a Site" link for users viewing their own profiles.
    1395  *
    1396  * This function is not used by BuddyPress as of 1.2, but is kept here for older
    1397  * themes that may still be using it.
    1398  */
    1399 function bp_create_blog_link() {
    1400 
    1401     // Don't show this link when not on your own profile.
    1402     if ( ! bp_is_my_profile() ) {
    1403         return;
    1404     }
    1405 
    1406     /**
    1407      * Filters "Create a Site" links for users viewing their own profiles.
    1408      *
    1409      * @since 1.0.0
    1410      *
    1411      * @param string $value HTML link for creating a site.
    1412      */
    1413     echo apply_filters( 'bp_create_blog_link', '<a href="' . trailingslashit( bp_get_blogs_directory_permalink() . 'create' ) . '">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
    1414 }
    1415 
    1416 /**
    1417  * Output navigation tabs for a user Blogs page.
    1418  *
    1419  * Currently unused by BuddyPress.
    1420  */
    1421 function bp_blogs_blog_tabs() {
    1422 
    1423     // Don't show these tabs on a user's own profile.
    1424     if ( bp_is_my_profile() ) {
    1425         return false;
    1426     } ?>
    1427 
    1428     <ul class="content-header-nav">
    1429         <li<?php if ( bp_is_current_action( 'my-blogs'        ) || !bp_current_action() ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs'        ); ?>"><?php printf( __( "%s's Sites", 'buddypress' ),           bp_get_displayed_user_fullname() ); ?></a></li>
    1430         <li<?php if ( bp_is_current_action( 'recent-posts'    )                         ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-posts'    ); ?>"><?php printf( __( "%s's Recent Posts", 'buddypress' ),    bp_get_displayed_user_fullname() ); ?></a></li>
    1431         <li<?php if ( bp_is_current_action( 'recent-comments' )                         ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-comments' ); ?>"><?php printf( __( "%s's Recent Comments", 'buddypress' ), bp_get_displayed_user_fullname() ); ?></a></li>
    1432     </ul>
    1433 
    1434 <?php
    1435 
    1436     /**
    1437      * Fires after the markup for the navigation tabs for a user Blogs page.
    1438      *
    1439      * @since 1.0.0
    1440      */
    1441     do_action( 'bp_blogs_blog_tabs' );
    1442 }
    1443 
    1444 /**
    1445  * Output the blog directory search form.
    1446  */
    1447 function bp_directory_blogs_search_form() {
    1448 
    1449     $query_arg = bp_core_get_component_search_query_arg( 'blogs' );
    1450 
    1451     if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
    1452         $search_value = stripslashes( $_REQUEST[ $query_arg ] );
    1453     } else {
    1454         $search_value = bp_get_search_default_text( 'blogs' );
    1455     }
    1456 
    1457     $search_form_html = '<form action="" method="get" id="search-blogs-form">
    1458         <label for="blogs_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="blogs_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
    1459         <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
    1460     </form>';
    1461 
    1462     /**
    1463      * Filters the output for the blog directory search form.
    1464      *
    1465      * @since 1.9.0
    1466      *
    1467      * @param string $search_form_html HTML markup for blog directory search form.
    1468      */
    1469     echo apply_filters( 'bp_directory_blogs_search_form', $search_form_html );
    1470 }
    1471 
    1472 /**
    1473  * Output the Create a Site button.
    1474  *
    1475  * @since 2.0.0
    1476  */
    1477 function bp_blog_create_button() {
    1478     echo bp_get_blog_create_button();
    1479 }
    1480     /**
    1481      * Get the Create a Site button.
    1482      *
    1483      * @since 2.0.0
    1484      *
    1485      * @return string
    1486      */
    1487     function bp_get_blog_create_button() {
    1488         if ( ! is_user_logged_in() ) {
    1489             return false;
    1490         }
    1491 
    1492         if ( ! bp_blog_signup_enabled() ) {
    1493             return false;
    1494         }
    1495 
    1496         $button_args = array(
    1497             'id'         => 'create_blog',
    1498             'component'  => 'blogs',
    1499             'link_text'  => __( 'Create a Site', 'buddypress' ),
    1500             'link_title' => __( 'Create a Site', 'buddypress' ),
    1501             'link_class' => 'blog-create no-ajax',
    1502             'link_href'  => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
    1503             'wrapper'    => false,
    1504             'block_self' => false,
    1505         );
    1506 
    1507         /**
    1508          * Filters the Create a Site button.
    1509          *
    1510          * @since 2.0.0
    1511          *
    1512          * @param array $button_args Array of arguments to be used for the Create a Site button.
    1513          */
    1514         return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) );
    1515     }
    1516 
    1517 /**
    1518  * Output the Create a Site nav item.
    1519  *
    1520  * @since 2.2.0
    1521  */
    1522 function bp_blog_create_nav_item() {
    1523     echo bp_get_blog_create_nav_item();
    1524 }
    1525 
    1526     /**
    1527      * Get the Create a Site nav item.
    1528      *
    1529      * @since 2.2.0
    1530      *
    1531      * @return string
    1532      */
    1533     function bp_get_blog_create_nav_item() {
    1534         // Get the create a site button.
    1535         $create_blog_button = bp_get_blog_create_button();
    1536 
    1537         // Make sure the button is available.
    1538         if ( empty( $create_blog_button ) ) {
    1539             return;
    1540         }
    1541 
    1542         $output = '<li id="blog-create-nav">' . $create_blog_button . '</li>';
    1543 
    1544         return apply_filters( 'bp_get_blog_create_nav_item', $output );
    1545     }
    1546 
    1547 /**
    1548  * Checks if a specific theme is still filtering the Blogs directory title
    1549  * if so, transform the title button into a Blogs directory nav item.
    1550  *
    1551  * @since 2.2.0
    1552  *
    1553  * @uses bp_blog_create_nav_item() to output the Create a Site nav item.
    1554  *
    1555  * @return string HTML Output
    1556  */
    1557 function bp_blog_backcompat_create_nav_item() {
    1558     // Bail if Blogs nav item is already used by bp-legacy.
    1559     if ( has_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 ) ) {
    1560         return;
    1561     }
    1562 
    1563     // Bail if the theme is not filtering the Blogs directory title.
    1564     if ( ! has_filter( 'bp_blogs_directory_header' ) ) {
    1565         return;
    1566     }
    1567 
    1568     bp_blog_create_nav_item();
    1569 }
    1570 add_action( 'bp_blogs_directory_blog_types', 'bp_blog_backcompat_create_nav_item', 1000 );
    1571 
    1572 /**
    1573  * Output button for visiting a blog in a loop.
    1574  *
    1575  * @see bp_get_blogs_visit_blog_button() for description of arguments.
    1576  *
    1577  * @param array|string $args See {@link bp_get_blogs_visit_blog_button()}.
    1578  */
    1579 function bp_blogs_visit_blog_button( $args = '' ) {
    1580     echo bp_get_blogs_visit_blog_button( $args );
    1581 }
    1582     /**
    1583      * Return button for visiting a blog in a loop.
    1584      *
    1585      * @see BP_Button for a complete description of arguments and return
    1586      *      value.
    1587      *
    1588      * @param array|string $args {
    1589      *     Arguments are listed below, with their default values. For a
    1590      *     complete description of arguments, see {@link BP_Button}.
    1591      *     @type string $id                Default: 'visit_blog'.
    1592      *     @type string $component         Default: 'blogs'.
    1593      *     @type bool   $must_be_logged_in Default: false.
    1594      *     @type bool   $block_self        Default: false.
    1595      *     @type string $wrapper_class     Default: 'blog-button visit'.
    1596      *     @type string $link_href         Permalink of the current blog in the loop.
    1597      *     @type string $link_class        Default: 'blog-button visit'.
    1598      *     @type string $link_text         Default: 'Visit Site'.
    1599      *     @type string $link_title        Default: 'Visit Site'.
    1600      * }
    1601      * @return string The HTML for the Visit button.
    1602      */
    1603     function bp_get_blogs_visit_blog_button( $args = '' ) {
    1604         $defaults = array(
    1605             'id'                => 'visit_blog',
    1606             'component'         => 'blogs',
    1607             'must_be_logged_in' => false,
    1608             'block_self'        => false,
    1609             'wrapper_class'     => 'blog-button visit',
    1610             'link_href'         => bp_get_blog_permalink(),
    1611             'link_class'        => 'blog-button visit',
    1612             'link_text'         => __( 'Visit Site', 'buddypress' ),
    1613             'link_title'        => __( 'Visit Site', 'buddypress' ),
    1614         );
    1615 
    1616         $button = wp_parse_args( $args, $defaults );
    1617 
    1618         /**
    1619          * Filters the button for visiting a blog in a loop.
    1620          *
    1621          * @since 1.2.10
    1622          *
    1623          * @param array $button Array of arguments to be used for the button to visit a blog.
    1624          */
    1625         return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
    1626     }
    1627 
    1628 /** Stats **********************************************************************/
    1629 
    1630 /**
    1631  * Display the number of blogs in user's profile.
    1632  *
    1633  * @since 2.0.0
    1634  *
    1635  * @uses bp_blogs_admin_get_profile_stats() to get the stats.
    1636  *
    1637  * @param array|string $args Before|after|user_id.
    1638  */
    1639 function bp_blogs_profile_stats( $args = '' ) {
    1640     echo bp_blogs_get_profile_stats( $args );
    1641 }
    1642 add_action( 'bp_members_admin_user_stats', 'bp_blogs_profile_stats', 9, 1 );
    1643 
    1644 /**
    1645  * Return the number of blogs in user's profile.
    1646  *
    1647  * @since 2.0.0
    1648  *
    1649  * @param array|string $args Before|after|user_id.
    1650  * @return string HTML for stats output.
    1651  */
    1652 function bp_blogs_get_profile_stats( $args = '' ) {
    1653 
    1654     // Parse the args.
    1655     $r = bp_parse_args( $args, array(
    1656         'before'  => '<li class="bp-blogs-profile-stats">',
    1657         'after'   => '</li>',
    1658         'user_id' => bp_displayed_user_id(),
    1659         'blogs'   => 0,
    1660         'output'  => ''
    1661     ), 'blogs_get_profile_stats' );
    1662 
    1663     // Allow completely overloaded output.
    1664     if ( is_multisite() && empty( $r['output'] ) ) {
    1665 
    1666         // Only proceed if a user ID was passed.
    1667         if ( ! empty( $r['user_id'] ) ) {
    1668 
    1669             // Get the user's blogs.
    1670             if ( empty( $r['blogs'] ) ) {
    1671                 $r['blogs'] = absint( bp_blogs_total_blogs_for_user( $r['user_id'] ) );
    1672             }
    1673 
    1674             // If blogs exist, show some formatted output.
    1675             $r['output'] = $r['before'] . sprintf( _n( '%s site', '%s sites', $r['blogs'], 'buddypress' ), '<strong>' . $r['blogs'] . '</strong>' ) . $r['after'];
    1676         }
    1677     }
    1678 
    1679     /**
    1680      * Filters the number of blogs in user's profile.
    1681      *
    1682      * @since 2.0.0
    1683      *
    1684      * @param string $value Output determined for the profile stats.
    1685      * @param array  $r     Array of arguments used for default output if none provided.
    1686      */
    1687     return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r );
    1688 }
Note: See TracChangeset for help on using the changeset viewer.