[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-blogs/ -> bp-blogs-template.php (source)

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


Generated: Sun Oct 25 01:01:40 2020 Cross-referenced by PHPXref 0.7.1