Ticket #5272: bp-blogs-template.php.patch
File bp-blogs-template.php.patch, 6.0 KB (added by , 11 years ago) |
---|
-
bp-blogs-template.php
161 161 * 162 162 * @see BP_Blogs_Blog::get() for a description of parameters. 163 163 * 164 * @param string $type See {@link BP_Blogs_Blog::get()}. 164 * @param array $args { 165 * An array of arguments. All items are optional. 166 * @param string $type See {@link BP_Blogs_Blog::get()}. 165 167 * @param string $page See {@link BP_Blogs_Blog::get()}. 166 168 * @param string $per_page See {@link BP_Blogs_Blog::get()}. 167 169 * @param string $max See {@link BP_Blogs_Blog::get()}. … … 169 171 * @param string $search_terms See {@link BP_Blogs_Blog::get()}. 170 172 * @param string $page_arg The string used as a query parameter in 171 173 * pagination links. Default: 'bpage'. 174 * @param bool $show_hidden Get also the private blogs of user 175 * 176 * } 172 177 */ 173 function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage' ) { 178 function __construct($args) { 179 // Backward compatibility with old method of passing arguments 180 if (!is_array($args) || func_num_args() > 1) { 181 _deprecated_argument(__METHOD__, '2.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__)); 174 182 175 $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page; 176 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 183 $old_args_keys = array( 184 0 => 'type', 185 1 => 'page', 186 2 => 'per_page', 187 3 => 'max', 188 4 => 'user_id', 189 5 => 'search_terms', 190 6 => 'page_arg', 191 7 => 'show_hidden' 192 ); 177 193 194 $func_args = func_get_args(); 195 $args = bp_core_parse_args_array($old_args_keys, $func_args); 196 } 197 198 $defaults = array( 199 'type' => 'active', 200 'page' => 1, 201 'per_page' => 20, 202 'max' => false, 203 'user_id' => '0', 204 'search_terms' => false, // Pass search terms to filter on the blog title or description. 205 'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679 206 'show_hidden' => false 207 ); 208 $r = wp_parse_args($args, $defaults); 209 extract($r); 210 211 $this->pag_page = isset($_REQUEST[$page_arg]) ? intval($_REQUEST[$page_arg]) : $page; 212 $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page; 213 178 214 if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) 179 $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page);215 $this->blogs = BP_Blogs_Blog::get_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page, $show_hidden); 180 216 else 181 $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ));217 $this->blogs = bp_blogs_get_blogs(array('type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'show_hidden' => $show_hidden)); 182 218 183 219 if ( !$max || $max >= (int) $this->blogs['total'] ) 184 220 $this->total_blog_count = (int) $this->blogs['total']; … … 331 367 * @type int $user_id The ID of the user whose blogs should be retrieved. 332 368 * When viewing a user profile page, 'user_id' defaults to the ID of 333 369 * the displayed user. Otherwise the default is false. 370 * @type bool $show_hidden. Whether to show private blogs or not 334 371 * } 335 372 * @return bool Returns true when blogs are found, otherwise false. 336 373 */ … … 359 396 'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679 360 397 361 398 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to 362 'search_terms' => $search_terms // Pass search terms to filter on the blog title or description. 399 'search_terms' => $search_terms, // Pass search terms to filter on the blog title or description. 400 'show_hidden' => false 363 401 ); 364 402 365 403 $r = wp_parse_args( $args, $defaults ); … … 378 416 } 379 417 } 380 418 381 $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg ); 419 $args = array('type' => $type, 'page' => $page, 'per_page' => $per_page, 'max' => $max, 'user_id' => $user_id, 'search_terms' => $search_terms, 'page_arg' => $page_arg, 'show_hidden' => $show_hidden); 420 $blogs_template = new BP_Blogs_Template($args); 382 421 return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template ); 383 422 } 384 423 … … 833 872 * Output the total number of blogs for a given user. 834 873 * 835 874 * @param int $user_id ID of the user. 875 * @param bool $show_hidden Whether to count also hidden blogs. 836 876 */ 837 function bp_total_blog_count_for_user( $user_id = 0) {838 echo bp_get_total_blog_count_for_user( $user_id);877 function bp_total_blog_count_for_user($user_id = 0, $show_hidden = false) { 878 echo bp_get_total_blog_count_for_user($user_id, $show_hidden); 839 879 } 840 880 /** 841 881 * Return the total number of blogs for a given user. 842 882 * 843 883 * @param int $user_id ID of the user. 884 * @param bool $show_hidden whether to count also private blogs of user 844 885 * @return int Total number of blogs for the user. 845 886 */ 846 function bp_get_total_blog_count_for_user( $user_id = 0) {847 return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ));848 887 function bp_get_total_blog_count_for_user($user_id = 0, $show_hidden = false) { 888 return apply_filters('bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user($user_id, $show_hidden)); 889 } 849 890 add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' ); 850 891 851 892