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


Generated: Tue Oct 19 01:00:57 2021 Cross-referenced by PHPXref 0.7.1