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