/bp-blogs/bp-blogs-template.php

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