Ticket #1269: 1269.03.patch
File 1269.03.patch, 133.5 KB (added by , 9 years ago) |
---|
-
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index 1ea141a..890b8b4 100644
function bp_activity_directory_permalink() { 113 113 * 114 114 * @since BuddyPress (1.0.0) 115 115 */ 116 class BP_Activity_Template { 117 var $current_activity = -1; 118 var $activity_count; 119 var $total_activity_count; 120 var $activities; 121 var $activity; 122 123 var $in_the_loop; 116 class BP_Activity_Template extends BP_Template_Loop { 124 117 125 118 /** 126 * URL parameter key for activity pagination. Default: 'acpage'.119 * Default arguments for Activity loop. 127 120 * 128 * @since BuddyPress (2.1.0) 129 * @var string 121 * @since BuddyPress (2.3.0) 122 * 123 * @access protected 124 * @var array 130 125 */ 131 var $pag_arg; 132 133 var $pag_page; 134 var $pag_num; 135 var $pag_links; 136 137 var $full_name; 126 protected $default_args = array( 127 'labels' => array( 128 'item' => 'activity', 129 'item_plural' => 'activities', 130 'item_total_count' => 'total_activity_count', 131 'item_count' => 'activity_count', 132 'current_item' => 'current_activity', 133 'hook_prefix' => 'activity', 134 ), 135 'params' => array( 136 'page_arg' => 'acpage', 137 'page' => 1, 138 'per_page' => 20, 139 'max' => 0, 140 ) 141 ); 138 142 139 143 /** 140 144 * Constructor method. … … class BP_Activity_Template { 164 168 * } 165 169 */ 166 170 function __construct( $args ) { 167 global $bp;168 171 169 172 // Backward compatibility with old method of passing arguments 170 173 if ( !is_array( $args ) || func_num_args() > 1 ) { … … class BP_Activity_Template { 211 214 'spam' => 'ham_only', 212 215 'update_meta_cache' => true, 213 216 ); 217 214 218 $r = wp_parse_args( $args, $defaults ); 215 extract( $r );216 219 217 $this->pag_arg = $r['page_arg']; 218 $this->pag_page = isset( $_REQUEST[ $this->pag_arg ] ) ? intval( $_REQUEST[ $this->pag_arg ] ) : $page; 219 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 220 $this->set_loop( array( 'params' => $r ) ); 221 } 222 223 /** 224 * Get Activities. 225 * 226 * @since BuddyPress (2.3.0) 227 * 228 * @access public 229 */ 230 public function get_items() { 231 $bp = buddypress(); 220 232 221 233 // Check if blog/forum replies are disabled 222 234 $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false; … … class BP_Activity_Template { 224 236 // Get an array of the logged in user's favorite activities 225 237 $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) ); 226 238 239 // Set Displayed user fullname 240 $this->full_name = bp_get_displayed_user_fullname(); 241 227 242 // Fetch specific activity items based on ID's 228 if ( ! empty( $include) ) {229 $ this->activities = bp_activity_get_specific( array(230 'activity_ids' => explode( ',', $ include),231 'max' => $ max,232 'count_total' => $ count_total,233 'page' => $this->pag _page,234 'per_page' => $this->p ag_num,235 'sort' => $ sort,236 'display_comments' => $ display_comments,237 'show_hidden' => $ show_hidden,238 'spam' => $ spam,239 'update_meta_cache' => $ update_meta_cache,243 if ( ! empty( $this->args['params']['include'] ) ) { 244 $activities = bp_activity_get_specific( array( 245 'activity_ids' => explode( ',', $this->args['params']['include'] ), 246 'max' => $this->args['params']['max'], 247 'count_total' => $this->args['params']['count_total'], 248 'page' => $this->page, 249 'per_page' => $this->per_page, 250 'sort' => $this->args['params']['sort'], 251 'display_comments' => $this->args['params']['display_comments'], 252 'show_hidden' => $this->args['params']['show_hidden'], 253 'spam' => $this->args['params']['spam'], 254 'update_meta_cache' => $this->args['params']['update_meta_cache'], 240 255 ) ); 241 256 242 257 // Fetch all activity items 243 258 } else { 244 $this->activities = bp_activity_get( array( 245 'display_comments' => $display_comments, 246 'max' => $max, 247 'count_total' => $count_total, 248 'per_page' => $this->pag_num, 249 'page' => $this->pag_page, 250 'sort' => $sort, 251 'search_terms' => $search_terms, 252 'meta_query' => $meta_query, 253 'date_query' => $date_query, 254 'filter_query' => $filter_query, 255 'filter' => $filter, 256 'scope' => $scope, 257 'show_hidden' => $show_hidden, 258 'exclude' => $exclude, 259 'in' => $in, 260 'spam' => $spam, 261 'update_meta_cache' => $update_meta_cache, 262 ) ); 259 $activities = bp_activity_get( $this->args['params'] ); 263 260 } 264 261 265 // The total_activity_count property will be set only if a 266 // 'count_total' query has taken place 267 if ( ! is_null( $this->activities['total'] ) ) { 268 if ( ! $max || $max >= (int) $this->activities['total'] ) { 269 $this->total_activity_count = (int) $this->activities['total']; 270 } else { 271 $this->total_activity_count = (int) $max; 272 } 273 } 274 275 $this->has_more_items = $this->activities['has_more_items']; 276 277 $this->activities = $this->activities['activities']; 278 279 if ( $max ) { 280 if ( $max >= count($this->activities) ) { 281 $this->activity_count = count( $this->activities ); 282 } else { 283 $this->activity_count = (int) $max; 284 } 285 } else { 286 $this->activity_count = count( $this->activities ); 287 } 288 289 $this->full_name = bp_get_displayed_user_fullname(); 262 $this->has_more_items = $activities['has_more_items']; 290 263 291 264 // Fetch parent content for activity comments so we do not have to query in the loop 292 foreach ( (array) $ this->activitiesas $activity ) {265 foreach ( (array) $activities['activities'] as $activity ) { 293 266 if ( 'activity_comment' != $activity->type ) 294 267 continue; 295 268 296 269 $parent_ids[] = $activity->item_id; 297 270 } 298 271 299 if ( ! empty( $parent_ids ) )272 if ( ! empty( $parent_ids ) ) { 300 273 $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) ); 301 302 if ( !empty( $activity_parents['activities'] ) ) {303 foreach( $activity_parents['activities'] as $parent )304 $this->activity_parents[$parent->id] = $parent;305 306 unset( $activity_parents );307 }308 309 if ( (int) $this->total_activity_count && (int) $this->pag_num ) {310 $this->pag_links = paginate_links( array(311 'base' => add_query_arg( $page_arg, '%#%' ),312 'format' => '',313 'total' => ceil( (int) $this->total_activity_count / (int) $this->pag_num ),314 'current' => (int) $this->pag_page,315 'prev_text' => _x( '←', 'Activity pagination previous text', 'buddypress' ),316 'next_text' => _x( '→', 'Activity pagination next text', 'buddypress' ),317 'mid_size' => 1,318 'add_args' => array(),319 ) );320 }321 }322 323 /**324 * Whether there are activity items available in the loop.325 *326 * @see bp_has_activities()327 *328 * @return bool True if there are items in the loop, otherwise false.329 */330 function has_activities() {331 if ( $this->activity_count )332 return true;333 334 return false;335 }336 337 /**338 * Set up the next activity item and iterate index.339 *340 * @return object The next activity item to iterate over.341 */342 function next_activity() {343 $this->current_activity++;344 $this->activity = $this->activities[$this->current_activity];345 346 return $this->activity;347 }348 349 /**350 * Rewind the posts and reset post index.351 */352 function rewind_activities() {353 $this->current_activity = -1;354 if ( $this->activity_count > 0 ) {355 $this->activity = $this->activities[0];356 274 } 357 }358 275 359 /** 360 * Whether there are activity items left in the loop to iterate over. 361 * 362 * This method is used by {@link bp_activities()} as part of the while loop 363 * that controls iteration inside the activities loop, eg: 364 * while ( bp_activities() ) { ... 365 * 366 * @see bp_activities() 367 * 368 * @return bool True if there are more activity items to show, 369 * otherwise false. 370 */ 371 function user_activities() { 372 if ( $this->current_activity + 1 < $this->activity_count ) { 373 return true; 374 } elseif ( $this->current_activity + 1 == $this->activity_count ) { 276 if ( ! empty( $activity_parents['activities'] ) ) { 277 foreach ( $activity_parents['activities'] as $parent ) { 278 $this->activity_parents[ $parent->id ] = $parent; 279 } 375 280 376 /** 377 * Fires right before the rewinding of activity posts. 378 * 379 * @since BuddyPress (1.1.0) 380 */ 381 do_action( 'activity_loop_end' ); 382 // Do some cleaning up after the loop 383 $this->rewind_activities(); 281 unset( $activity_parents ); 384 282 } 385 283 386 $this->in_the_loop = false; 387 return false; 388 } 389 390 /** 391 * Set up the current activity item inside the loop. 392 * 393 * Used by {@link bp_the_activity()} to set up the current activity item 394 * data while looping, so that template tags used during that iteration 395 * make reference to the current activity item. 396 * 397 * @see bp_the_activity() 398 */ 399 function the_activity() { 400 401 $this->in_the_loop = true; 402 $this->activity = $this->next_activity(); 403 404 if ( is_array( $this->activity ) ) 405 $this->activity = (object) $this->activity; 406 407 if ( $this->current_activity == 0 ) { // loop has just started 408 409 /** 410 * Fires if the current activity item is the first in the activity loop. 411 * 412 * @since BuddyPress (1.1.0) 413 */ 414 do_action('activity_loop_start'); 415 } 284 return $activities; 416 285 } 417 286 } 418 287 … … function bp_has_activities( $args = '' ) { 694 563 * @param string $activities_template Current activities template being used. 695 564 * @param array $template_args Array of arguments passed into the BP_Activity_Template class. 696 565 */ 697 return apply_filters( 'bp_has_activities', $activities_template->has_ activities(), $activities_template, $template_args );566 return apply_filters( 'bp_has_activities', $activities_template->has_items(), $activities_template, $template_args ); 698 567 } 699 568 700 569 /** … … function bp_has_activities( $args = '' ) { 703 572 * @since BuddyPress (1.0.0) 704 573 * 705 574 * @global object $activities_template {@link BP_Activity_Template} 706 * @uses BP_Activity_Template:: user_activities() {@link BP_Activity_Template::user_activities()}575 * @uses BP_Activity_Template::items() {@link BP_Activity_Template::items()} 707 576 * 708 577 * @return bool Returns true when activities are found. 709 578 */ 710 579 function bp_activities() { 711 580 global $activities_template; 712 return $activities_template-> user_activities();581 return $activities_template->items(); 713 582 } 714 583 715 584 /** … … function bp_activities() { 724 593 */ 725 594 function bp_the_activity() { 726 595 global $activities_template; 727 return $activities_template->the_ activity();596 return $activities_template->the_item(); 728 597 } 729 598 730 599 /** … … function bp_activity_load_more_link() { 739 608 global $activities_template; 740 609 741 610 $link = bp_get_requested_url(); 742 $link = add_query_arg( $activities_template->pag _arg, $activities_template->pag_page + 1, $link );611 $link = add_query_arg( $activities_template->page_arg, $activities_template->page + 1, $link ); 743 612 744 613 /** 745 614 * Filters the Load More link URL. … … function bp_activity_load_more_link() { 757 626 * @since BuddyPress (1.0.0) 758 627 * 759 628 * @global object $activities_template {@link BP_Activity_Template} 760 * @uses BP_Activity_Template::the_ activity() {@link BP_Activity_Template::the_activity()}629 * @uses BP_Activity_Template::the_item() {@link BP_Activity_Template::the_item()} 761 630 */ 762 631 function bp_activity_pagination_count() { 763 632 echo bp_get_activity_pagination_count(); … … function bp_activity_pagination_count() { 776 645 function bp_get_activity_pagination_count() { 777 646 global $activities_template; 778 647 779 $start_num = intval( ( $activities_template->pag _page - 1 ) * $activities_template->pag_num) + 1;648 $start_num = intval( ( $activities_template->page - 1 ) * $activities_template->per_page ) + 1; 780 649 $from_num = bp_core_number_format( $start_num ); 781 $to_num = bp_core_number_format( ( $start_num + ( $activities_template->p ag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num- 1 ) );650 $to_num = bp_core_number_format( ( $start_num + ( $activities_template->per_page - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->per_page - 1 ) ); 782 651 $total = bp_core_number_format( $activities_template->total_activity_count ); 783 652 784 653 return sprintf( _n( 'Viewing 1 item', 'Viewing %1$s - %2$s of %3$s items', $total, 'buddypress' ), $from_num, $to_num, $total ); … … function bp_activity_has_more_items() { 837 706 $remaining_pages = 0; 838 707 839 708 if ( ! empty( $activities_template->pag_page ) ) { 840 $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->p ag_num * $activities_template->pag_page ) );709 $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->per_page * $activities_template->page ) ); 841 710 } 842 711 843 712 $has_more_items = (int) $remaining_pages > 0; … … function bp_activity_per_page() { 916 785 * 917 786 * @since BuddyPress (1.2.0) 918 787 * 919 * @param int $p ag_numHow many post should be displayed for pagination.788 * @param int $per_page How many post should be displayed for pagination. 920 789 */ 921 return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->p ag_num);790 return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->per_page ); 922 791 } 923 792 924 793 /** -
src/bp-blogs/bp-blogs-template.php
diff --git src/bp-blogs/bp-blogs-template.php src/bp-blogs/bp-blogs-template.php index 21fdb7c..50f9f46 100644
function bp_blogs_directory_permalink() { 106 106 * 107 107 * Responsible for loading a group of blogs into a loop for display. 108 108 */ 109 class BP_Blogs_Template {109 class BP_Blogs_Template extends BP_Template_Loop { 110 110 111 111 /** 112 * The loop iterator.112 * Default arguments for Blogs loop. 113 113 * 114 * @access public 115 * @var int 116 */ 117 public $current_blog = -1; 118 119 /** 120 * The number of blogs returned by the paged query. 121 * 122 * @access public 123 * @var int 124 */ 125 public $blog_count = 0; 126 127 /** 128 * Array of blogs located by the query.. 114 * @since BuddyPress (2.3.0) 129 115 * 130 * @access p ublic116 * @access protected 131 117 * @var array 132 118 */ 133 public $blogs = array(); 134 135 /** 136 * The blog object currently being iterated on. 137 * 138 * @access public 139 * @var object 140 */ 141 public $blog; 142 143 /** 144 * A flag for whether the loop is currently being iterated. 145 * 146 * @access public 147 * @var bool 148 */ 149 public $in_the_loop = false; 150 151 /** 152 * The page number being requested. 153 * 154 * @access public 155 * @var public 156 */ 157 public $pag_page = 1; 158 159 /** 160 * The number of items being requested per page. 161 * 162 * @access public 163 * @var public 164 */ 165 public $pag_num = 20; 166 167 /** 168 * An HTML string containing pagination links. 169 * 170 * @access public 171 * @var string 172 */ 173 public $pag_links = ''; 174 175 /** 176 * The total number of blogs matching the query parameters. 177 * 178 * @access public 179 * @var int 180 */ 181 public $total_blog_count = 0; 119 protected $default_args = array( 120 'labels' => array( 121 'item' => 'blog', 122 'item_plural' => 'blogs', 123 'item_total_count' => 'total_blog_count', 124 'item_count' => 'blog_count', 125 'current_item' => 'current_blog', 126 'hook_prefix' => 'blog', 127 ), 128 'params' => array( 129 'page_arg' => 'bpage', 130 'page' => 1, 131 'per_page' => 20, 132 'max' => 0, 133 ) 134 ); 182 135 183 136 /** 184 137 * Constructor method. … … class BP_Blogs_Template { 198 151 * @param array $include_blog_ids Array of blog IDs to include. 199 152 */ 200 153 public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false ) { 154 $params = array( 'params' => array( 155 'type' => $type, 156 'page' => $page, 157 'per_page' => $per_page, 158 'max' => $max, 159 'user_id' => $user_id, 160 'search_terms' => $search_terms, 161 'page_arg' => $page_arg, 162 'update_meta_cache' => $update_meta_cache, 163 'include_blog_ids' => $include_blog_ids, 164 ) ); 201 165 202 $this->pag_page = isset( $_REQUEST[ $page_arg ] ) ? intval( $_REQUEST[ $page_arg ] ) : $page; 203 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 204 205 // Backwards compatibility support for blogs by first letter 206 if ( ! empty( $_REQUEST['letter'] ) ) { 207 $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page ); 208 209 // Typical blogs query 210 } else { 211 $this->blogs = bp_blogs_get_blogs( array( 212 'type' => $type, 213 'per_page' => $this->pag_num, 214 'page' => $this->pag_page, 215 'user_id' => $user_id, 216 'search_terms' => $search_terms, 217 'update_meta_cache' => $update_meta_cache, 218 'include_blog_ids' => $include_blog_ids, 219 ) ); 220 } 221 222 // Set the total blog count 223 if ( empty( $max ) || ( $max >= (int) $this->blogs['total'] ) ) { 224 $this->total_blog_count = (int) $this->blogs['total']; 225 } else { 226 $this->total_blog_count = (int) $max; 227 } 228 229 // Set the blogs array (to loop through later 230 $this->blogs = $this->blogs['blogs']; 231 232 // Get the current blog count to compare maximum against 233 $blog_count = count( $this->blogs ); 234 235 // Set the current blog count 236 if ( empty( $max ) || ( $max >= (int) $blog_count ) ) { 237 $this->blog_count = (int) $blog_count; 238 } else { 239 $this->blog_count = (int) $max; 240 } 241 242 // Build pagination links based on total blogs and current page number 243 if ( ! empty( $this->total_blog_count ) && ! empty( $this->pag_num ) ) { 244 $this->pag_links = paginate_links( array( 245 'base' => add_query_arg( $page_arg, '%#%' ), 246 'format' => '', 247 'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ), 248 'current' => (int) $this->pag_page, 249 'prev_text' => _x( '←', 'Blog pagination previous text', 'buddypress' ), 250 'next_text' => _x( '→', 'Blog pagination next text', 'buddypress' ), 251 'mid_size' => 1, 252 'add_args' => array(), 253 ) ); 254 } 255 } 256 257 /** 258 * Whether there are blogs available in the loop. 259 * 260 * @see bp_has_blogs() 261 * 262 * @return bool True if there are items in the loop, otherwise false. 263 */ 264 public function has_blogs() { 265 return (bool) ! empty( $this->blog_count ); 266 } 267 268 /** 269 * Set up the next blog and iterate index. 270 * 271 * @return object The next blog to iterate over. 272 */ 273 public function next_blog() { 274 $this->current_blog++; 275 $this->blog = $this->blogs[ $this->current_blog ]; 276 277 return $this->blog; 278 } 279 280 /** 281 * Rewind the blogs and reset blog index. 282 */ 283 public function rewind_blogs() { 284 $this->current_blog = -1; 285 if ( $this->blog_count > 0 ) { 286 $this->blog = $this->blogs[0]; 287 } 166 $this->set_loop( $params ); 288 167 } 289 168 290 169 /** 291 * Whether there are blogs left in the loop to iterate over. 292 * 293 * This method is used by {@link bp_blogs()} as part of the while loop 294 * that controls iteration inside the blogs loop, eg: 295 * while ( bp_blogs() ) { ... 170 * Get Blogs. 296 171 * 297 * @s ee bp_blogs()172 * @since BuddyPress (2.3.0) 298 173 * 299 * @ return bool True if there are more blogs to show, otherwise false.174 * @access public 300 175 */ 301 public function blogs() {302 if ( ( $this->current_blog + 1 ) < $this->blog_count ) {303 return true;304 } elseif ( ( $this->current_blog + 1 ) === $this->blog_count ) {176 public function get_items() { 177 // Backwards compatibility support for blogs by first letter 178 if ( ! empty( $_REQUEST['letter'] ) ) { 179 $blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->per_page, $this->page ); 305 180 306 /** 307 * Fires right before the rewinding of blogs listing after all are shown. 308 * 309 * @since BuddyPress (1.5.0) 310 */ 311 do_action( 'blog_loop_end' ); 312 // Do some cleaning up after the loop 313 $this->rewind_blogs(); 181 // Typical blogs query 182 } else { 183 $blogs = bp_blogs_get_blogs( $this->args['params'] ); 314 184 } 315 185 316 $this->in_the_loop = false; 317 return false; 186 return $blogs; 318 187 } 319 188 320 189 /** 321 * Set up the current blog inside the loop. 322 * 323 * Used by {@link bp_the_blog()} to set up the current blog data while 324 * looping, so that template tags used during that iteration make 325 * reference to the current blog. 190 * Rewind Blogs is an alias of rewind_items() 326 191 * 327 * @ see bp_the_blog()192 * @access public 328 193 */ 329 public function the_blog() { 330 331 $this->in_the_loop = true; 332 $this->blog = $this->next_blog(); 333 334 // loop has just started 335 if ( 0 === $this->current_blog ) { 336 337 /** 338 * Fires if on the first blog in the loop. 339 * 340 * @since BuddyPress (1.5.0) 341 */ 342 do_action( 'blog_loop_start' ); 343 } 194 public function rewind_blogs() { 195 _doing_it_wrong( __FUNCTION__, __( 'BP_Blogs_Template->rewind_blogs() should not be used directly, please use bp_rewind_blogs()', 'buddypress' ), '2.3.0' ); 196 $this->rewind_items(); 344 197 } 345 198 } 346 199 … … class BP_Blogs_Template { 350 203 function bp_rewind_blogs() { 351 204 global $blogs_template; 352 205 353 $blogs_template->rewind_ blogs();206 $blogs_template->rewind_items(); 354 207 } 355 208 356 209 /** … … function bp_has_blogs( $args = '' ) { 429 282 * @param BP_Blogs_Template $blogs_template Current blogs template object. 430 283 * @param array $r Parsed arguments used in blogs template query. 431 284 */ 432 return apply_filters( 'bp_has_blogs', $blogs_template->has_ blogs(), $blogs_template, $r );285 return apply_filters( 'bp_has_blogs', $blogs_template->has_items(), $blogs_template, $r ); 433 286 } 434 287 435 288 /** … … function bp_has_blogs( $args = '' ) { 442 295 function bp_blogs() { 443 296 global $blogs_template; 444 297 445 return $blogs_template-> blogs();298 return $blogs_template->items(); 446 299 } 447 300 448 301 /** … … function bp_blogs() { 455 308 function bp_the_blog() { 456 309 global $blogs_template; 457 310 458 return $blogs_template->the_ blog();311 return $blogs_template->the_item(); 459 312 } 460 313 461 314 /** … … function bp_the_blog() { 466 319 function bp_blogs_pagination_count() { 467 320 global $blogs_template; 468 321 469 $start_num = intval( ( $blogs_template->pag _page - 1 ) * $blogs_template->pag_num) + 1;322 $start_num = intval( ( $blogs_template->page - 1 ) * $blogs_template->per_page ) + 1; 470 323 $from_num = bp_core_number_format( $start_num ); 471 $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->p ag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num- 1 ) );324 $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->per_page - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->per_page - 1 ) ); 472 325 $total = bp_core_number_format( $blogs_template->total_blog_count ); 473 326 474 327 echo sprintf( _n( 'Viewing 1 site', 'Viewing %1$s - %2$s of %3$s sites', $total, 'buddypress' ), $from_num, $to_num, $total ); -
src/bp-core/bp-core-classes.php
diff --git src/bp-core/bp-core-classes.php src/bp-core/bp-core-classes.php index f47f0b8..0babf2b 100644
abstract class BP_Recursive_Query { 2978 2978 * @return bool 2979 2979 */ 2980 2980 abstract protected function is_first_order_clause( $query ); 2981 } 2982 No newline at end of file 2981 } 2982 2983 /** 2984 * Base class for components template loops. 2985 * 2986 * Each public method can be overriden from a custom template class 2987 * For instance, you can customize the default paginate links within 2988 * your class. 2989 * @see BP_Groups_Template->set_pag_links() for an example of use 2990 * 2991 * the abstract method get_items() is required. This is where you define 2992 * an associative array having your custom 'item_plural' and 'total' keys 2993 * 2994 * @since 2.3.0 2995 */ 2996 abstract class BP_Template_Loop { 2997 2998 /** 2999 * Default arguments common to all components loop. 3000 * 3001 * You can add the custom item default args within the custom template loop class 3002 * @see BP_Groups_Template->default_args for an example of use. 3003 * 3004 * @since BuddyPress (2.3.0) 3005 * 3006 * @access protected 3007 * @var array $default_args { 3008 * Array describing the default argument for the item loop. 3009 * @type array $labels list of custom var names for the loop 3010 * - @type string $item the singular item var name 3011 * for instance 'group' for the groups loop 3012 * - @type string $item_plural the plural item var name 3013 * for instance 'groups' for the groups loop 3014 * - @type string $item_total_count the total count var name 3015 * for instance 'total_group_count' for the groups loop 3016 * - @type string $item_count the current items count var name 3017 * for instance 'group_count' for the groups loop 3018 * - @type string $current_item the current item var name 3019 * for instance 'current_group' for the groups loop 3020 * - @type string $hook_prefix the hook prefix to use in loop start 3021 * and loop end actions for instance 'activity' for the activity loop 3022 * @type array $params list of default arguments for the loop 3023 * - @type string $page_arg the var name to get the page value. 3024 * for instance 'grpage' for the groups loop 3025 * - @type int $page default value for the page argument 3026 * - @type int $per_page default value for the per page argument 3027 * - @type int $max default value for the max argument 3028 * } 3029 */ 3030 protected $default_args = array( 3031 'labels' => array( 3032 'item' => 'item', 3033 'item_plural' => 'items', 3034 'item_total_count' => 'total_item_count', 3035 'item_count' => 'item_count', 3036 'current_item' => 'current_item', 3037 'hook_prefix' => 'item', 3038 ), 3039 'params' => array( 3040 'page_arg' => 'page', 3041 'page' => 1, 3042 'per_page' => 20, 3043 'max' => 0, 3044 ) 3045 ); 3046 3047 /** 3048 * Holds the arguments to customize the loop labels and the component's items query. 3049 * 3050 * This includes `$default_args`, as well as the user-supplied values. 3051 * 3052 * @since BuddyPress (2.3.0) 3053 * 3054 * @access protected 3055 * @var array 3056 */ 3057 protected $args = array(); 3058 3059 /** 3060 * A flag for whether the loop is currently being iterated. 3061 * 3062 * @since BuddyPress (2.3.0) 3063 * 3064 * @access public 3065 * @var bool 3066 */ 3067 public $in_the_loop; 3068 3069 /** 3070 * An HTML string containing pagination links. 3071 * 3072 * @since BuddyPress (2.3.0) 3073 * 3074 * @access public 3075 * @var string 3076 */ 3077 public $pag_links; 3078 3079 /** 3080 * Set the loop 3081 * 3082 * @since BuddyPress (2.3.0) 3083 * 3084 * @access public 3085 * @param array $args component's loop arguments 3086 */ 3087 public function set_loop( $args = array() ) { 3088 $this->args = wp_parse_args( $args, $this->default_args ); 3089 3090 // If not set the hook prefix defaults to the singular item name 3091 if ( empty( $this->args['labels']['hook_prefix'] ) ) { 3092 $this->args['labels']['hook_prefix'] = $this->args['labels']['item']; 3093 } 3094 3095 $this->{$this->args['labels']['current_item']} = -1; 3096 3097 // Setting loop parameters 3098 if ( ! empty( $this->args['params'] ) ) { 3099 foreach ( (array) $this->args['params'] as $key => $value ) { 3100 $this->{$key} = $value; 3101 } 3102 3103 if ( isset( $this->page_arg ) && ! empty( $_REQUEST[ $this->page_arg ] ) ) { 3104 $this->page = intval( $_REQUEST[ $this->page_arg ] ); 3105 } 3106 3107 if ( ! empty( $_REQUEST['num'] ) ) { 3108 $this->per_page = intval( $_REQUEST['num'] ); 3109 } 3110 } 3111 3112 // Setup the Items to loop through 3113 $items = $this->get_items(); 3114 3115 if ( ! isset( $items[ $this->args['labels']['item_plural'] ] ) ) { 3116 return false; 3117 } 3118 3119 // Set items 3120 $this->{$this->args['labels']['item_plural']} = $items[ $this->args['labels']['item_plural'] ]; 3121 3122 if ( empty( $this->{$this->args['labels']['item_plural']} ) ) { 3123 $this->{$this->args['labels']['item_count']} = 0; 3124 $this->{$this->args['labels']['item_total_count']} = 0; 3125 3126 } else { 3127 // Set the total items count 3128 $this->{$this->args['labels']['item_total_count']} = (int) $items['total']; 3129 3130 if ( ! empty( $this->max ) && ( $this->max < (int) $items['total'] ) ) { 3131 $this->{$this->args['labels']['item_total_count']} = (int) $this->max; 3132 } 3133 3134 // Set current items count 3135 $this->{$this->args['labels']['item_count']} = count( $this->{$this->args['labels']['item_plural']} ); 3136 3137 if ( ! empty( $this->max ) && ( $this->max < (int) $this->{$this->args['labels']['item_count']} ) ) { 3138 $this->{$this->args['labels']['item_count']} = (int) $this->max; 3139 } 3140 } 3141 3142 if ( ! empty( $this->{$this->args['labels']['item_total_count']} ) && ! empty( $this->per_page ) && ! empty( $this->page ) ) { 3143 $this->set_pag_links(); 3144 } 3145 } 3146 3147 /** 3148 * Get the component's items 3149 * 3150 * This method needs to be set within the custom Template class 3151 * @see BP_Blogs_Template->get_items() for an example of use 3152 * 3153 * @since BuddyPress (2.3.0) 3154 * 3155 * @access public 3156 */ 3157 abstract public function get_items(); 3158 3159 /** 3160 * Set the pagination links 3161 * 3162 * Each item loop can override this and sets its own pagination links 3163 * within its custom template class. 3164 * @see BP_Groups_Template->set_pag_links() for an example of use 3165 * 3166 * @since BuddyPress (2.3.0) 3167 * 3168 * @access public 3169 */ 3170 public function set_pag_links() { 3171 $this->pag_links = paginate_links( array( 3172 'base' => add_query_arg( $this->page_arg, '%#%' ), 3173 'format' => '', 3174 'total' => ceil( (int) $this->{$this->args['labels']['item_total_count']} / (int) $this->per_page ), 3175 'current' => (int) $this->page, 3176 'prev_text' => _x( '←', 'pagination previous text', 'buddypress' ), 3177 'next_text' => _x( '→', 'pagination next text', 'buddypress' ), 3178 'mid_size' => 1, 3179 'add_args' => array(), 3180 ) ); 3181 } 3182 3183 /** 3184 * Whether there are Items available in the loop. 3185 * 3186 * @since BuddyPress (2.3.0) 3187 * 3188 * @return bool True if there are items in the loop, otherwise false. 3189 */ 3190 public function has_items() { 3191 if ( ! empty( $this->{$this->args['labels']['item_count']} ) ) { 3192 return true; 3193 } 3194 3195 return false; 3196 } 3197 3198 /** 3199 * Set up the next item and iterate index. 3200 * 3201 * @since BuddyPress (2.3.0) 3202 * 3203 * @return object The next item to iterate over. 3204 */ 3205 public function next_item() { 3206 3207 $this->{$this->args['labels']['current_item']}++; 3208 3209 $this->{$this->args['labels']['item']} = $this->{$this->args['labels']['item_plural']}[ $this->{$this->args['labels']['current_item']} ]; 3210 3211 return $this->{$this->args['labels']['item']}; 3212 } 3213 3214 /** 3215 * Rewind the items and reset items index. 3216 * 3217 * @since BuddyPress (2.3.0) 3218 */ 3219 public function rewind_items() { 3220 3221 $this->{$this->args['labels']['current_item']} = -1; 3222 3223 if ( $this->{$this->args['labels']['item_count']} > 0 ) { 3224 $this->{$this->args['labels']['item']} = $this->{$this->args['labels']['item_plural']}[0]; 3225 } 3226 } 3227 3228 /** 3229 * Whether there are items left in the loop to iterate over. 3230 * 3231 * @since BuddyPress (2.3.0) 3232 * 3233 * @return bool True if there are more items to show, 3234 * otherwise false. 3235 */ 3236 public function items() { 3237 3238 if ( $this->{$this->args['labels']['current_item']} + 1 < $this->{$this->args['labels']['item_count']} ) { 3239 return true; 3240 3241 } elseif ( $this->{$this->args['labels']['current_item']} + 1 == $this->{$this->args['labels']['item_count']} ) { 3242 /** 3243 * Inform when the item loop ends. Dynamically built using the hook_prefix label 3244 * For instance the messages box loop is using 'messages_box' as its item hook_prefix, 3245 * as a result the action will be 'messages_box_loop_end' 3246 */ 3247 do_action( $this->args['labels']['hook_prefix'] . '_loop_end' ); 3248 3249 $this->rewind_items(); 3250 } 3251 3252 $this->in_the_loop = false; 3253 return false; 3254 } 3255 3256 /** 3257 * Set up the current item inside the loop. 3258 * 3259 * Each item loop can override this to append custom vars to the item 3260 * within its custom template class. 3261 * @see BP_Groups_Invite_Template->the_item() for an example of use 3262 * 3263 * @since BuddyPress (2.3.0) 3264 */ 3265 public function the_item() { 3266 $this->in_the_loop = true; 3267 $this->{$this->args['labels']['item']} = $this->next_item(); 3268 3269 // loop has just started 3270 if ( 0 === $this->{$this->args['labels']['current_item']} ) { 3271 /** 3272 * Inform when the item loop starts. Dynamically built using the hook_prefix label 3273 * For instance the groups loop is using 'group' as its hook_prefix, as a result 3274 * the action will be 'group_loop_start' 3275 */ 3276 do_action( $this->args['labels']['hook_prefix'] . '_loop_start' ); 3277 } 3278 } 3279 } -
src/bp-groups/bp-groups-template.php
diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php index 4684804..88a6561 100644
function bp_groups_directory_permalink() { 63 63 function bp_get_groups_directory_permalink() { 64 64 return apply_filters( 'bp_get_groups_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) ); 65 65 } 66 67 66 /** 68 67 * The main Groups template loop class. 69 68 * 70 69 * Responsible for loading a group of groups into a loop for display. 71 70 */ 72 class BP_Groups_Template {71 class BP_Groups_Template extends BP_Template_Loop { 73 72 74 73 /** 75 * The loop iterator.74 * Default arguments for Groups loop. 76 75 * 77 * @access public 78 * @var int 79 */ 80 var $current_group = -1; 81 82 /** 83 * The number of groups returned by the paged query. 84 * 85 * @access public 86 * @var int 87 */ 88 var $group_count; 89 90 /** 91 * Array of groups located by the query. 76 * @since BuddyPress (2.3.0) 92 77 * 93 * @access p ublic78 * @access protected 94 79 * @var array 95 80 */ 96 var $groups; 97 98 /** 99 * The group object currently being iterated on. 100 * 101 * @access public 102 * @var object 103 */ 104 var $group; 105 106 /** 107 * A flag for whether the loop is currently being iterated. 108 * 109 * @access public 110 * @var bool 111 */ 112 var $in_the_loop; 113 114 /** 115 * The page number being requested. 116 * 117 * @access public 118 * @var public 119 */ 120 var $pag_page; 121 122 /** 123 * The number of items being requested per page. 124 * 125 * @access public 126 * @var public 127 */ 128 var $pag_num; 129 130 /** 131 * An HTML string containing pagination links. 132 * 133 * @access public 134 * @var string 135 */ 136 var $pag_links; 137 138 /** 139 * The total number of groups matching the query parameters. 140 * 141 * @access public 142 * @var int 143 */ 144 var $total_group_count; 145 146 /** 147 * Whether the template loop is for a single group page. 148 * 149 * @access public 150 * @var bool 151 */ 152 var $single_group = false; 153 154 /** 155 * Field to sort by. 156 * 157 * @access public 158 * @var string 159 */ 160 var $sort_by; 161 162 /** 163 * Sort order. 164 * 165 * @access public 166 * @var string 167 */ 168 var $order; 81 protected $default_args = array( 82 'labels' => array( 83 'item' => 'group', 84 'item_plural' => 'groups', 85 'item_total_count' => 'total_group_count', 86 'item_count' => 'group_count', 87 'current_item' => 'current_group', 88 'hook_prefix' => 'group', 89 ), 90 'params' => array( 91 'page_arg' => 'grpage', 92 'page' => 1, 93 'per_page' => 20, 94 'max' => 0, 95 ) 96 ); 169 97 170 98 /** 171 99 * Constructor method. … … class BP_Groups_Template { 180 108 * @type int $page Default: 1. 181 109 * } 182 110 */ 183 function __construct( $args = array() ){ 184 111 public function __construct( $args = array() ) { 185 112 // Backward compatibility with old method of passing arguments 186 113 if ( ! is_array( $args ) || func_num_args() > 1 ) { 187 114 _deprecated_argument( __METHOD__, '1.7', 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__ ) ); … … class BP_Groups_Template { 206 133 } 207 134 208 135 $defaults = array( 209 'type' => 'active',210 'page' => 1,211 'per_page' => 20,212 'max' => false,213 'show_hidden' => false,214 'page_arg' => 'grpage',215 'user_id' => 0,216 'slug' => false,217 'include' => false,218 'exclude' => false,219 'search_terms' => '',220 'meta_query' => false,221 'populate_extras' => true,136 'type' => 'active', 137 'page' => 1, 138 'per_page' => 20, 139 'max' => false, 140 'show_hidden' => false, 141 'page_arg' => 'grpage', 142 'user_id' => 0, 143 'slug' => false, 144 'include' => false, 145 'exclude' => false, 146 'search_terms' => '', 147 'meta_query' => false, 148 'populate_extras' => true, 222 149 'update_meta_cache' => true, 223 150 ); 224 151 225 152 $r = wp_parse_args( $args, $defaults ); 226 extract( $r );227 153 228 $this-> pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;229 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;154 $this->set_loop( array( 'params' => $r ) ); 155 } 230 156 231 if ( bp_current_user_can( 'bp_moderate' ) || ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) ) 232 $show_hidden = true; 157 /** 158 * Get Groups. 159 * 160 * @since BuddyPress (2.3.0) 161 * 162 * @access public 163 */ 164 public function get_items() { 165 if ( bp_current_user_can( 'bp_moderate' ) || ( is_user_logged_in() && $this->user_id == bp_loggedin_user_id() ) ) { 166 $this->args['params']['show_hidden'] = true; 167 } 168 169 if ( 'invites' == $this->type ) { 170 return groups_get_invites_for_user( $this->user_id, $this->per_page, $this->page, $this->exclude ); 233 171 234 if ( 'invites' == $type ) { 235 $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page, $exclude ); 236 } else if ( 'single-group' == $type ) { 172 } else if ( 'single-group' == $this->type ) { 237 173 $this->single_group = true; 238 174 239 175 if ( groups_get_current_group() ) { … … class BP_Groups_Template { 241 177 242 178 } else { 243 179 $group = groups_get_group( array( 244 'group_id' => BP_Groups_Group::get_id_from_slug( $ r['slug']),245 'populate_extras' => $ r['populate_extras'],180 'group_id' => BP_Groups_Group::get_id_from_slug( $this->slug ), 181 'populate_extras' => $this->populate_extras, 246 182 ) ); 247 183 } 248 184 249 // backwards compatibility - the 'group_id' variable is not part of the250 // BP_Groups_Group object, but we add it here for devs doing checks against it251 //252 // @see https://buddypress.trac.wordpress.org/changeset/3540253 //254 // this is subject to removal in a future release; devs should check against255 // $group->id instead256 $group->group_id = $group->id;257 258 $this->groups = array( $group );259 260 } else {261 $this->groups = groups_get_groups( array(262 'type' => $type,263 'order' => $order,264 'orderby' => $orderby,265 'per_page' => $this->pag_num,266 'page' => $this->pag_page,267 'user_id' => $user_id,268 'search_terms' => $search_terms,269 'meta_query' => $meta_query,270 'include' => $include,271 'exclude' => $exclude,272 'populate_extras' => $populate_extras,273 'update_meta_cache' => $update_meta_cache,274 'show_hidden' => $show_hidden275 ) );276 }277 278 if ( 'invites' == $type ) {279 $this->total_group_count = (int) $this->groups['total'];280 $this->group_count = (int) $this->groups['total'];281 $this->groups = $this->groups['groups'];282 } else if ( 'single-group' == $type ) {283 185 if ( empty( $group->id ) ) { 284 $this->total_group_count = 0; 285 $this->group_count = 0; 286 } else { 287 $this->total_group_count = 1; 288 $this->group_count = 1; 289 } 290 } else { 291 if ( empty( $max ) || $max >= (int) $this->groups['total'] ) { 292 $this->total_group_count = (int) $this->groups['total']; 293 } else { 294 $this->total_group_count = (int) $max; 295 } 296 297 $this->groups = $this->groups['groups']; 298 299 if ( !empty( $max ) ) { 300 if ( $max >= count( $this->groups ) ) { 301 $this->group_count = count( $this->groups ); 302 } else { 303 $this->group_count = (int) $max; 304 } 186 return array( 'groups' => array(), 'total' => 0 ); 305 187 } else { 306 $this->group_count = count( $this->groups);188 return array( 'groups' => array( $group ), 'total' => 1 ); 307 189 } 308 }309 310 // Build pagination links311 if ( (int) $this->total_group_count && (int) $this->pag_num ) {312 $pag_args = array(313 $page_arg => '%#%'314 );315 190 316 if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) { 317 $base = remove_query_arg( 's', wp_get_referer() ); 318 } else { 319 $base = ''; 320 } 321 322 $add_args = array( 323 'num' => $this->pag_num, 324 'sortby' => $this->sort_by, 325 'order' => $this->order, 326 ); 327 328 if ( ! empty( $search_terms ) ) { 329 $add_args['s'] = urlencode( $search_terms ); 330 } 331 332 $this->pag_links = paginate_links( array( 333 'base' => add_query_arg( $pag_args, $base ), 334 'format' => '', 335 'total' => ceil( (int) $this->total_group_count / (int) $this->pag_num ), 336 'current' => $this->pag_page, 337 'prev_text' => _x( '←', 'Group pagination previous text', 'buddypress' ), 338 'next_text' => _x( '→', 'Group pagination next text', 'buddypress' ), 339 'mid_size' => 1, 340 'add_args' => $add_args, 341 ) ); 191 } else { 192 return groups_get_groups( $this->args['params'] ); 342 193 } 343 194 } 344 195 345 196 /** 346 * Whether there are groups available in the loop.197 * Set Groups pagination. 347 198 * 348 * @s ee bp_has_groups()199 * @since BuddyPress (2.3.0) 349 200 * 350 * @return bool True if there are items in the loop, otherwise false. 351 */ 352 function has_groups() { 353 if ( $this->group_count ) 354 return true; 355 356 return false; 357 } 358 359 /** 360 * Set up the next group and iterate index. 361 * 362 * @return object The next group to iterate over. 363 */ 364 function next_group() { 365 $this->current_group++; 366 $this->group = $this->groups[$this->current_group]; 367 368 return $this->group; 369 } 370 371 /** 372 * Rewind the groups and reset member index. 201 * @access public 373 202 */ 374 function rewind_groups() { 375 $this->current_group = -1; 376 if ( $this->group_count > 0 ) { 377 $this->group = $this->groups[0]; 378 } 379 } 203 public function set_pag_links() { 204 $pag_args = array( 205 $this->page_arg => '%#%' 206 ); 380 207 381 /** 382 * Whether there are groups left in the loop to iterate over. 383 * 384 * This method is used by {@link bp_groups()} as part of the while loop 385 * that controls iteration inside the groups loop, eg: 386 * while ( bp_groups() ) { ... 387 * 388 * @see bp_groups() 389 * 390 * @return bool True if there are more groups to show, otherwise false. 391 */ 392 function groups() { 393 if ( $this->current_group + 1 < $this->group_count ) { 394 return true; 395 } elseif ( $this->current_group + 1 == $this->group_count ) { 396 do_action('group_loop_end'); 397 // Do some cleaning up after the loop 398 $this->rewind_groups(); 208 if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) { 209 $base = remove_query_arg( 's', wp_get_referer() ); 210 } else { 211 $base = ''; 399 212 } 400 213 401 $this->in_the_loop = false; 402 return false; 403 } 214 $add_args = array( 215 'num' => $this->per_page, 216 'sortby' => $this->orderby, 217 'order' => $this->order, 218 ); 404 219 405 /** 406 * Set up the current group inside the loop. 407 * 408 * Used by {@link bp_the_group()} to set up the current group data 409 * while looping, so that template tags used during that iteration make 410 * reference to the current member. 411 * 412 * @see bp_the_group() 413 */ 414 function the_group() { 415 $this->in_the_loop = true; 416 $this->group = $this->next_group(); 220 if ( ! empty( $this->search_terms ) ) { 221 $add_args['s'] = urlencode( $this->search_terms ); 222 } 417 223 418 if ( 0 == $this->current_group ) // loop has just started 419 do_action('group_loop_start'); 224 $this->pag_links = paginate_links( array( 225 'base' => add_query_arg( $pag_args, $base ), 226 'format' => '', 227 'total' => ceil( (int) $this->{$this->args['labels']['item_total_count']} / (int) $this->per_page ), 228 'current' => (int) $this->page, 229 'prev_text' => _x( '←', 'Group pagination previous text', 'buddypress' ), 230 'next_text' => _x( '→', 'Group pagination next text', 'buddypress' ), 231 'mid_size' => 1, 232 'add_args' => $add_args, 233 ) ); 420 234 } 421 235 } 422 236 … … function bp_has_groups( $args = '' ) { 539 353 ) ); 540 354 541 355 // Filter and return whether or not the groups loop has groups in it 542 return apply_filters( 'bp_has_groups', $groups_template->has_ groups(), $groups_template, $r );356 return apply_filters( 'bp_has_groups', $groups_template->has_items(), $groups_template, $r ); 543 357 } 544 358 545 359 /** … … function bp_has_groups( $args = '' ) { 549 363 */ 550 364 function bp_groups() { 551 365 global $groups_template; 552 return $groups_template-> groups();366 return $groups_template->items(); 553 367 } 554 368 555 369 /** … … function bp_groups() { 559 373 */ 560 374 function bp_the_group() { 561 375 global $groups_template; 562 return $groups_template->the_ group();376 return $groups_template->the_item(); 563 377 } 564 378 565 379 /** … … function bp_groups_pagination_count() { 1575 1389 function bp_get_groups_pagination_count() { 1576 1390 global $groups_template; 1577 1391 1578 $start_num = intval( ( $groups_template->pag _page - 1 ) * $groups_template->pag_num) + 1;1392 $start_num = intval( ( $groups_template->page - 1 ) * $groups_template->per_page ) + 1; 1579 1393 $from_num = bp_core_number_format( $start_num ); 1580 $to_num = bp_core_number_format( ( $start_num + ( $groups_template->p ag_num - 1 ) > $groups_template->total_group_count ) ? $groups_template->total_group_count : $start_num + ( $groups_template->pag_num- 1 ) );1394 $to_num = bp_core_number_format( ( $start_num + ( $groups_template->per_page - 1 ) > $groups_template->total_group_count ) ? $groups_template->total_group_count : $start_num + ( $groups_template->per_page - 1 ) ); 1581 1395 $total = bp_core_number_format( $groups_template->total_group_count ); 1582 1396 1583 1397 return apply_filters( 'bp_get_groups_pagination_count', sprintf( _n( 'Viewing 1 group', 'Viewing %1$s - %2$s of %3$s groups', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total ); … … function bp_total_group_count_for_user( $user_id = 0 ) { 2931 2745 * Group Members Template Tags 2932 2746 **/ 2933 2747 2934 class BP_Groups_Group_Members_Template { 2935 var $current_member = -1; 2936 var $member_count; 2937 var $members; 2938 var $member; 2939 2940 var $in_the_loop; 2748 class BP_Groups_Group_Members_Template extends BP_Template_Loop { 2941 2749 2942 var $pag_page; 2943 var $pag_num; 2944 var $pag_links; 2945 var $total_group_count; 2750 /** 2751 * Default arguments for Group Members loop. 2752 * 2753 * @since BuddyPress (2.3.0) 2754 * 2755 * @access protected 2756 * @var array 2757 */ 2758 protected $default_args = array( 2759 'labels' => array( 2760 'item' => 'member', 2761 'item_plural' => 'members', 2762 'item_total_count' => 'total_member_count', 2763 'item_count' => 'member_count', 2764 'current_item' => 'current_member', 2765 'hook_prefix' => 'group_member', 2766 ), 2767 'params' => array( 2768 'page_arg' => 'mlpage', 2769 'page' => 1, 2770 'per_page' => 20, 2771 'max' => 0, 2772 ) 2773 ); 2946 2774 2947 2775 /** 2948 2776 * Constructor. … … class BP_Groups_Group_Members_Template { 2988 2816 'group_id' => bp_get_current_group_id(), 2989 2817 'page' => 1, 2990 2818 'per_page' => 20, 2819 'page_arg' => 'mlpage', 2991 2820 'max' => false, 2992 2821 'exclude' => false, 2993 2822 'exclude_admins_mods' => 1, … … class BP_Groups_Group_Members_Template { 2997 2826 'type' => 'last_joined', 2998 2827 ) ); 2999 2828 3000 // @todo No 3001 extract( $r ); 3002 3003 $this->pag_page = isset( $_REQUEST['mlpage'] ) ? intval( $_REQUEST['mlpage'] ) : $r['page']; 3004 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 2829 $this->set_loop( array( 'params' => $r ) ); 2830 } 3005 2831 2832 /** 2833 * Get Group members. 2834 * 2835 * @since BuddyPress (2.3.0) 2836 * 2837 * @access public 2838 */ 2839 public function get_items() { 3006 2840 /** 3007 2841 * Check the current group is the same as the supplied group ID. 3008 2842 * It can differ when using {@link bp_group_has_members()} outside the Groups screens. 3009 2843 */ 3010 2844 $current_group = groups_get_current_group(); 3011 2845 if ( ! $current_group || $current_group && $current_group->id !== bp_get_current_group_id() ) { 3012 $current_group = groups_get_group( array( 'group_id' => $ r['group_id'] ) );2846 $current_group = groups_get_group( array( 'group_id' => $this->args['params']['group_id'] ) ); 3013 2847 } 3014 2848 3015 // Assemble the base URL for pagination 3016 $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() ); 3017 if ( bp_action_variable() ) { 3018 $base_url = trailingslashit( $base_url . bp_action_variable() ); 3019 } 3020 3021 $members_args = $r; 3022 3023 $members_args['page'] = $this->pag_page; 3024 $members_args['per_page'] = $this->pag_num; 2849 $this->current_group = $current_group; 3025 2850 3026 $ this->members = groups_get_group_members( $members_args);2851 $group_members = groups_get_group_members( $this->args['params'] ); 3027 2852 3028 if ( !$max || $max >= (int) $this->members['count'] ) 3029 $this->total_member_count = (int) $this->members['count']; 3030 else 3031 $this->total_member_count = (int) $max; 3032 3033 $this->members = $this->members['members']; 2853 // Make sure to return an array using the keys the abastract class is waiting for 2854 return array( 'members' => $group_members['members'], 'total' => $group_members['count'] ); 2855 } 3034 2856 3035 if ( $max ) { 3036 if ( $max >= count($this->members) ) 3037 $this->member_count = count($this->members); 3038 else 3039 $this->member_count = (int) $max; 3040 } else { 3041 $this->member_count = count($this->members); 2857 /** 2858 * Set Group members pagination. 2859 * 2860 * @since BuddyPress (2.3.0) 2861 * 2862 * @access public 2863 */ 2864 public function set_pag_links() { 2865 // Assemble the base URL for pagination 2866 $base_url = trailingslashit( bp_get_group_permalink( $this->current_group ) . bp_current_action() ); 2867 if ( bp_action_variable() ) { 2868 $base_url = trailingslashit( $base_url . bp_action_variable() ); 3042 2869 } 3043 2870 3044 2871 $this->pag_links = paginate_links( array( 3045 2872 'base' => add_query_arg( array( 'mlpage' => '%#%' ), $base_url ), 3046 2873 'format' => '', 3047 'total' => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count,3048 'current' => $this->pag_page,2874 'total' => ceil( (int) $this->{$this->args['labels']['item_total_count']} / (int) $this->per_page ), 2875 'current' => (int) $this->page, 3049 2876 'prev_text' => '←', 3050 2877 'next_text' => '→', 3051 2878 'mid_size' => 1, 3052 2879 'add_args' => array(), 3053 )); 3054 } 3055 3056 function has_members() { 3057 if ( $this->member_count ) 3058 return true; 3059 3060 return false; 3061 } 3062 3063 function next_member() { 3064 $this->current_member++; 3065 $this->member = $this->members[$this->current_member]; 3066 3067 return $this->member; 3068 } 3069 3070 function rewind_members() { 3071 $this->current_member = -1; 3072 if ( $this->member_count > 0 ) { 3073 $this->member = $this->members[0]; 3074 } 3075 } 3076 3077 function members() { 3078 if ( $this->current_member + 1 < $this->member_count ) { 3079 return true; 3080 } elseif ( $this->current_member + 1 == $this->member_count ) { 3081 do_action('loop_end'); 3082 // Do some cleaning up after the loop 3083 $this->rewind_members(); 3084 } 3085 3086 $this->in_the_loop = false; 3087 return false; 3088 } 3089 3090 function the_member() { 3091 3092 $this->in_the_loop = true; 3093 $this->member = $this->next_member(); 3094 3095 if ( 0 == $this->current_member ) // loop has just started 3096 do_action('loop_start'); 2880 ) ); 3097 2881 } 3098 2882 } 3099 2883 … … function bp_group_has_members( $args = '' ) { 3149 2933 } 3150 2934 3151 2935 $members_template = new BP_Groups_Group_Members_Template( $r ); 3152 return apply_filters( 'bp_group_has_members', $members_template->has_ members(), $members_template );2936 return apply_filters( 'bp_group_has_members', $members_template->has_items(), $members_template ); 3153 2937 } 3154 2938 3155 2939 function bp_group_members() { 3156 2940 global $members_template; 3157 2941 3158 return $members_template-> members();2942 return $members_template->items(); 3159 2943 } 3160 2944 3161 2945 function bp_group_the_member() { 3162 2946 global $members_template; 3163 2947 3164 return $members_template->the_ member();2948 return $members_template->the_item(); 3165 2949 } 3166 2950 3167 2951 /** … … function bp_group_member_id() { 3344 3128 function bp_group_member_needs_pagination() { 3345 3129 global $members_template; 3346 3130 3347 if ( $members_template->total_member_count > $members_template->p ag_num)3131 if ( $members_template->total_member_count > $members_template->per_page ) 3348 3132 return true; 3349 3133 3350 3134 return false; … … function bp_group_member_pagination_count() { 3372 3156 function bp_get_group_member_pagination_count() { 3373 3157 global $members_template; 3374 3158 3375 $start_num = intval( ( $members_template->pag _page - 1 ) * $members_template->pag_num) + 1;3159 $start_num = intval( ( $members_template->page - 1 ) * $members_template->per_page ) + 1; 3376 3160 $from_num = bp_core_number_format( $start_num ); 3377 $to_num = bp_core_number_format( ( $start_num + ( $members_template->p ag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num- 1 ) );3161 $to_num = bp_core_number_format( ( $start_num + ( $members_template->per_page - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->per_page - 1 ) ); 3378 3162 $total = bp_core_number_format( $members_template->total_member_count ); 3379 3163 3380 3164 return apply_filters( 'bp_get_group_member_pagination_count', sprintf( _n( 'Viewing 1 member', 'Viewing %1$s - %2$s of %3$s members', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total ); … … function bp_custom_group_fields() { 3981 3765 * Membership Requests Template Tags 3982 3766 **/ 3983 3767 3984 class BP_Groups_Membership_Requests_Template { 3985 var $current_request = -1; 3986 var $request_count; 3987 var $requests; 3988 var $request; 3768 class BP_Groups_Membership_Requests_Template extends BP_Template_Loop { 3989 3769 3990 var $in_the_loop; 3991 3992 var $pag_page; 3993 var $pag_num; 3994 var $pag_links; 3995 var $total_request_count; 3770 /** 3771 * Default arguments for Group Membership requests loop. 3772 * 3773 * @since BuddyPress (2.3.0) 3774 * 3775 * @access protected 3776 * @var array 3777 */ 3778 protected $default_args = array( 3779 'labels' => array( 3780 'item' => 'request', 3781 'item_plural' => 'requests', 3782 'item_total_count' => 'total_request_count', 3783 'item_count' => 'request_count', 3784 'current_item' => 'current_request', 3785 'hook_prefix' => 'group_request', 3786 ), 3787 'params' => array( 3788 'page_arg' => 'mrpage', 3789 'page' => 1, 3790 'per_page' => 20, 3791 'max' => 0, 3792 ) 3793 ); 3996 3794 3997 3795 /** 3998 3796 * Constructor method. … … class BP_Groups_Membership_Requests_Template { 4028 3826 'page' => 1, 4029 3827 'max' => false, 4030 3828 'type' => 'first_joined', 3829 'page_arg' => 'mrpage', 4031 3830 ) ); 4032 3831 4033 $this-> pag_page = isset( $_REQUEST['mrpage'] ) ? intval( $_REQUEST['mrpage'] ) : $r['page'];4034 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $r['per_page'];3832 $this->set_loop( array( 'params' => $r ) ); 3833 } 4035 3834 3835 /** 3836 * Get Group Membership requests. 3837 * 3838 * @since BuddyPress (2.3.0) 3839 * 3840 * @access public 3841 */ 3842 public function get_items() { 4036 3843 $mquery = new BP_Group_Member_Query( array( 4037 'group_id' => $ r['group_id'],4038 'type' => $ r['type'],4039 'per_page' => $this->p ag_num,4040 'page' => $this->pag _page,3844 'group_id' => $this->args['params']['group_id'], 3845 'type' => $this->args['params']['type'], 3846 'per_page' => $this->per_page, 3847 'page' => $this->page, 4041 3848 4042 3849 // These filters ensure we only get pending requests 4043 3850 'is_confirmed' => false, 4044 3851 'inviter_id' => 0, 4045 3852 ) ); 4046 3853 4047 $this->requests = array_values( $mquery->results );4048 $ this->request_count = count( $this->requests );3854 // Make sure to return an array using the keys the abastract class is waiting for 3855 $requests = array( 'requests' => array_values( $mquery->results ), 'total' => $mquery->total_users ); 4049 3856 4050 3857 // Compatibility with legacy format of request data objects 4051 foreach ( $ this->requestsas $rk => $rv ) {3858 foreach ( $requests['requests'] as $rk => $rv ) { 4052 3859 // For legacy reasons, the 'id' property of each 4053 3860 // request must match the membership id, not the ID of 4054 3861 // the user (as it's returned by BP_Group_Member_Query) 4055 $ this->requests[ $rk ]->user_id = $rv->ID;4056 $ this->requests[ $rk ]->id = $rv->membership_id;3862 $requests['requests'][ $rk ]->user_id = $rv->ID; 3863 $requests['requests'][ $rk ]->id = $rv->membership_id; 4057 3864 4058 3865 // Miscellaneous values 4059 $this->requests[ $rk ]->group_id = $r['group_id']; 4060 } 4061 4062 if ( !$r['max'] || $r['max'] >= (int) $mquery->total_users ) 4063 $this->total_request_count = (int) $mquery->total_users; 4064 else 4065 $this->total_request_count = (int) $r['max']; 4066 4067 if ( $r['max'] ) { 4068 if ( $r['max'] >= count($this->requests) ) 4069 $this->request_count = count($this->requests); 4070 else 4071 $this->request_count = (int) $r['max']; 4072 } else { 4073 $this->request_count = count($this->requests); 4074 } 4075 4076 $this->pag_links = paginate_links( array( 4077 'base' => add_query_arg( 'mrpage', '%#%' ), 4078 'format' => '', 4079 'total' => ceil( $this->total_request_count / $this->pag_num ), 4080 'current' => $this->pag_page, 4081 'prev_text' => '←', 4082 'next_text' => '→', 4083 'mid_size' => 1, 4084 'add_args' => array(), 4085 ) ); 4086 } 4087 4088 function has_requests() { 4089 if ( $this->request_count ) 4090 return true; 4091 4092 return false; 4093 } 4094 4095 function next_request() { 4096 $this->current_request++; 4097 $this->request = $this->requests[$this->current_request]; 4098 4099 return $this->request; 4100 } 4101 4102 function rewind_requests() { 4103 $this->current_request = -1; 4104 4105 if ( $this->request_count > 0 ) 4106 $this->request = $this->requests[0]; 4107 } 4108 4109 function requests() { 4110 if ( $this->current_request + 1 < $this->request_count ) { 4111 return true; 4112 } elseif ( $this->current_request + 1 == $this->request_count ) { 4113 do_action('group_request_loop_end'); 4114 // Do some cleaning up after the loop 4115 $this->rewind_requests(); 3866 $requests['requests'][ $rk ]->group_id = $this->args['params']['group_id']; 4116 3867 } 4117 3868 4118 $this->in_the_loop = false; 4119 return false; 4120 } 4121 4122 function the_request() { 4123 $this->in_the_loop = true; 4124 $this->request = $this->next_request(); 4125 4126 if ( 0 == $this->current_request ) // loop has just started 4127 do_action('group_request_loop_start'); 3869 return $requests; 4128 3870 } 4129 3871 } 4130 3872 … … function bp_group_has_membership_requests( $args = '' ) { 4152 3894 $r = wp_parse_args( $args, $defaults ); 4153 3895 4154 3896 $requests_template = new BP_Groups_Membership_Requests_Template( $r ); 4155 return apply_filters( 'bp_group_has_membership_requests', $requests_template->has_ requests(), $requests_template );3897 return apply_filters( 'bp_group_has_membership_requests', $requests_template->has_items(), $requests_template ); 4156 3898 } 4157 3899 4158 3900 function bp_group_membership_requests() { 4159 3901 global $requests_template; 4160 3902 4161 return $requests_template-> requests();3903 return $requests_template->items(); 4162 3904 } 4163 3905 4164 3906 function bp_group_the_membership_request() { 4165 3907 global $requests_template; 4166 3908 4167 return $requests_template->the_ request();3909 return $requests_template->the_item(); 4168 3910 } 4169 3911 4170 3912 function bp_group_request_user_avatar_thumb() { … … function bp_group_requests_pagination_count() { 4250 3992 function bp_get_group_requests_pagination_count() { 4251 3993 global $requests_template; 4252 3994 4253 $start_num = intval( ( $requests_template->pag _page - 1 ) * $requests_template->pag_num) + 1;3995 $start_num = intval( ( $requests_template->page - 1 ) * $requests_template->per_page ) + 1; 4254 3996 $from_num = bp_core_number_format( $start_num ); 4255 $to_num = bp_core_number_format( ( $start_num + ( $requests_template->p ag_num - 1 ) > $requests_template->total_request_count ) ? $requests_template->total_request_count : $start_num + ( $requests_template->pag_num- 1 ) );3997 $to_num = bp_core_number_format( ( $start_num + ( $requests_template->per_page - 1 ) > $requests_template->total_request_count ) ? $requests_template->total_request_count : $start_num + ( $requests_template->per_page - 1 ) ); 4256 3998 $total = bp_core_number_format( $requests_template->total_request_count ); 4257 3999 4258 4000 return apply_filters( 'bp_get_group_requests_pagination_count', sprintf( _n( 'Viewing 1 request', 'Viewing %1$s - %2$s of %3$s requests', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total ); … … function bp_group_requests_pagination_count() { 4262 4004 * Invite Friends Template Tags 4263 4005 **/ 4264 4006 4265 class BP_Groups_Invite_Template { 4266 var $current_invite = -1; 4267 var $invite_count; 4268 var $invites; 4269 var $invite; 4007 class BP_Groups_Invite_Template extends BP_Template_Loop { 4270 4008 4271 var $in_the_loop; 4272 4273 var $pag_page; 4274 var $pag_num; 4275 var $pag_links; 4276 var $total_invite_count; 4009 /** 4010 * Default arguments for Groups Invite loop. 4011 * 4012 * @since BuddyPress (2.3.0) 4013 * 4014 * @access protected 4015 * @var array 4016 */ 4017 protected $default_args = array( 4018 'labels' => array( 4019 'item' => 'invite', 4020 'item_plural' => 'invites', 4021 'item_total_count' => 'total_invite_count', 4022 'item_count' => 'invite_count', 4023 'current_item' => 'current_invite', 4024 'hook_prefix' => 'group_invite', 4025 ), 4026 'params' => array( 4027 'page_arg' => 'invitepage', 4028 'page' => 1, 4029 'per_page' => 10, 4030 'max' => 0, 4031 ) 4032 ); 4277 4033 4034 /** 4035 * Constructor. 4036 * 4037 * @param array $args { 4038 * An array of optional arguments. 4039 * @type int $user_id ID of the user 4040 * @type int $group_id ID of the group 4041 * @type int $page Page of results to be queried. Default: 1. 4042 * @type int $per_page Number of items to return per page of 4043 * results. Default: 10. 4044 * @type string page_arg Optional. 4045 * } 4046 */ 4278 4047 public function __construct( $args = array() ) { 4279 4048 4280 4049 // Backward compatibility with old method of passing arguments … … class BP_Groups_Invite_Template { 4295 4064 'group_id' => bp_get_current_group_id(), 4296 4065 'page' => 1, 4297 4066 'per_page' => 10, 4067 'page_arg' => 'invitepage', 4298 4068 ) ); 4299 4069 4300 $this-> pag_num = intval( $r['per_page']);4301 $this->pag_page = isset( $_REQUEST['invitepage'] ) ? intval( $_REQUEST['invitepage'] ) : $r['page'];4070 $this->set_loop( array( 'params' => $r ) ); 4071 } 4302 4072 4073 /** 4074 * Get Groups Invite. 4075 * 4076 * @since BuddyPress (2.3.0) 4077 * 4078 * @access public 4079 */ 4080 public function get_items() { 4303 4081 $iquery = new BP_Group_Member_Query( array( 4304 'group_id' => $ r['group_id'],4082 'group_id' => $this->args['params']['group_id'], 4305 4083 'type' => 'first_joined', 4306 'per_page' => $this->p ag_num,4307 'page' => $this->pag _page,4084 'per_page' => $this->per_page, 4085 'page' => $this->page, 4308 4086 4309 4087 // These filters ensure we get only pending invites 4310 4088 'is_confirmed' => false, 4311 'inviter_id' => $ r['user_id'],4089 'inviter_id' => $this->args['params']['user_id'], 4312 4090 ) ); 4313 $this->invite_data = $iquery->results;4314 4315 $this->total_invite_count = $iquery->total_users;4316 $this->invites = array_values( wp_list_pluck( $this->invite_data, 'ID' ) );4317 $this->invite_count = count( $this->invites );4318 4319 // If per_page is set to 0 (show all results), don't generate4320 // pag_links4321 if ( ! empty( $this->pag_num ) ) {4322 $this->pag_links = paginate_links( array(4323 'base' => add_query_arg( 'invitepage', '%#%' ),4324 'format' => '',4325 'total' => ceil( $this->total_invite_count / $this->pag_num ),4326 'current' => $this->pag_page,4327 'prev_text' => '←',4328 'next_text' => '→',4329 'mid_size' => 1,4330 'add_args' => array(),4331 ) );4332 } else {4333 $this->pag_links = '';4334 }4335 }4336 4337 function has_invites() {4338 if ( $this->invite_count )4339 return true;4340 4341 return false;4342 }4343 4344 function next_invite() {4345 $this->current_invite++;4346 $this->invite = $this->invites[$this->current_invite];4347 4091 4348 return $this->invite;4349 }4092 // This will be use in BP_Groups_Invite_Template->the_invite() 4093 $this->invite_data = $iquery->results; 4350 4094 4351 function rewind_invites() { 4352 $this->current_invite = -1; 4353 if ( $this->invite_count > 0 ) 4354 $this->invite = $this->invites[0]; 4095 return array( 'invites' => array_values( wp_list_pluck( $this->invite_data, 'ID' ) ), 'total' => $iquery->total_users ); 4355 4096 } 4356 4097 4357 function invites() { 4358 if ( $this->current_invite + 1 < $this->invite_count ) { 4359 return true; 4360 } elseif ( $this->current_invite + 1 == $this->invite_count ) { 4361 do_action('loop_end'); 4362 // Do some cleaning up after the loop 4363 $this->rewind_invites(); 4364 } 4365 4366 $this->in_the_loop = false; 4367 return false; 4098 /** 4099 * Override parent method as we need to do custom work. 4100 * 4101 * @since BuddyPress (2.3.0) 4102 * 4103 * @uses BP_Groups_Invite_Template->the_invite() 4104 */ 4105 public function the_item() { 4106 $this->the_invite(); 4368 4107 } 4369 4108 4370 function the_invite() { 4109 /** 4110 * Set up the current invite inside the loop. 4111 */ 4112 public function the_invite() { 4371 4113 global $group_id; 4372 4114 $this->in_the_loop = true; 4373 $user_id = $this->next_i nvite();4115 $user_id = $this->next_item(); 4374 4116 4375 4117 $this->invite = new stdClass; 4376 4118 $this->invite->user = $this->invite_data[ $user_id ]; … … class BP_Groups_Invite_Template { 4395 4137 $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups ); 4396 4138 } 4397 4139 4398 if ( bp_is_active( 'friends' ) ) {4399 $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );4400 }4401 4402 4140 $this->invite->user->total_blogs = null; 4403 4141 4404 4142 $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites() 4405 4143 4406 if ( 0 == $this->current_invite ) // loop has just started 4407 do_action('loop_start'); 4144 if ( 0 == $this->current_invite ) { 4145 do_action( 'group_invite_loop_start' ); 4146 } 4408 4147 } 4409 4148 } 4410 4149 … … function bp_group_has_invites( $args = '' ) { 4436 4175 } 4437 4176 4438 4177 $invites_template = new BP_Groups_Invite_Template( $r ); 4439 return apply_filters( 'bp_group_has_invites', $invites_template->has_i nvites(), $invites_template );4178 return apply_filters( 'bp_group_has_invites', $invites_template->has_items(), $invites_template ); 4440 4179 } 4441 4180 4442 4181 function bp_group_invites() { 4443 4182 global $invites_template; 4444 4183 4445 return $invites_template->i nvites();4184 return $invites_template->items(); 4446 4185 } 4447 4186 4448 4187 function bp_group_the_invite() { 4449 4188 global $invites_template; 4450 4189 4451 return $invites_template->the_i nvite();4190 return $invites_template->the_item(); 4452 4191 } 4453 4192 4454 4193 function bp_group_invite_item_id() { … … function bp_group_invite_pagination_count() { 4542 4281 function bp_get_group_invite_pagination_count() { 4543 4282 global $invites_template; 4544 4283 4545 $start_num = intval( ( $invites_template->pag _page - 1 ) * $invites_template->pag_num) + 1;4284 $start_num = intval( ( $invites_template->page - 1 ) * $invites_template->per_page ) + 1; 4546 4285 $from_num = bp_core_number_format( $start_num ); 4547 $to_num = bp_core_number_format( ( $start_num + ( $invites_template->p ag_num - 1 ) > $invites_template->total_invite_count ) ? $invites_template->total_invite_count : $start_num + ( $invites_template->pag_num- 1 ) );4286 $to_num = bp_core_number_format( ( $start_num + ( $invites_template->per_page - 1 ) > $invites_template->total_invite_count ) ? $invites_template->total_invite_count : $start_num + ( $invites_template->per_page - 1 ) ); 4548 4287 $total = bp_core_number_format( $invites_template->total_invite_count ); 4549 4288 4550 4289 return apply_filters( 'bp_get_groups_pagination_count', sprintf( _n( 'Viewing 1 invitation', 'Viewing %1$s - %2$s of %3$s invitations', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total ); -
src/bp-members/bp-members-template.php
diff --git src/bp-members/bp-members-template.php src/bp-members/bp-members-template.php index feb679f..c95d85f 100644
function bp_activate_slug() { 180 180 * 181 181 * Responsible for loading a group of members into a loop for display. 182 182 */ 183 class BP_Core_Members_Template {183 class BP_Core_Members_Template extends BP_Template_Loop { 184 184 185 185 /** 186 * The loop iterator.186 * Default arguments for Members loop. 187 187 * 188 * @access public 189 * @var int 190 */ 191 var $current_member = -1; 192 193 /** 194 * The number of members returned by the paged query. 188 * @since BuddyPress (2.3.0) 195 189 * 196 * @access public 197 * @var int 198 */ 199 var $member_count; 200 201 /** 202 * Array of members located by the query. 203 * 204 * @access public 190 * @access protected 205 191 * @var array 206 192 */ 207 var $members; 208 209 /** 210 * The member object currently being iterated on. 211 * 212 * @access public 213 * @var object 214 */ 215 var $member; 216 217 /** 218 * A flag for whether the loop is currently being iterated. 219 * 220 * @access public 221 * @var bool 222 */ 223 var $in_the_loop; 224 225 /** 226 * The page number being requested. 227 * 228 * @access public 229 * @var public 230 */ 231 var $pag_page; 232 233 /** 234 * The number of items being requested per page. 235 * 236 * @access public 237 * @var public 238 */ 239 var $pag_num; 240 241 /** 242 * An HTML string containing pagination links. 243 * 244 * @access public 245 * @var string 246 */ 247 var $pag_links; 248 249 /** 250 * The total number of members matching the query parameters. 251 * 252 * @access public 253 * @var int 254 */ 255 var $total_member_count; 193 protected $default_args = array( 194 'labels' => array( 195 'item' => 'member', 196 'item_plural' => 'members', 197 'item_total_count' => 'total_member_count', 198 'item_count' => 'member_count', 199 'current_item' => 'current_member', 200 'hook_prefix' => 'member', 201 ), 202 'params' => array( 203 'page_arg' => 'upage', 204 'page' => 1, 205 'per_page' => 20, 206 'max' => 0, 207 ) 208 ); 256 209 257 210 /** 258 211 * Constructor method. … … class BP_Core_Members_Template { 275 228 * @param array|string $member_type Array or comma-separated string of member types to limit results to. 276 229 */ 277 230 function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '' ) { 231 $params = array( 'params' => array( 232 'type' => $type, 233 'per_page' => $per_page, 234 'page' => $page_number, 235 'user_id' => $user_id, 236 'include' => $include, 237 'search_terms' => $search_terms, 238 'populate_extras' => $populate_extras, 239 'exclude' => $exclude, 240 'meta_key' => $meta_key, 241 'meta_value' => $meta_value, 242 'member_type' => $member_type, 243 'page_arg' => $page_arg, 244 'max' => $max, 245 ) ); 278 246 279 $this->pag_page = !empty( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : (int) $page_number; 280 $this->pag_num = !empty( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : (int) $per_page; 281 $this->type = $type; 282 283 if ( !empty( $_REQUEST['letter'] ) ) 284 $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude ); 285 else 286 $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type ) ); 287 288 if ( !$max || $max >= (int) $this->members['total'] ) 289 $this->total_member_count = (int) $this->members['total']; 290 else 291 $this->total_member_count = (int) $max; 292 293 $this->members = $this->members['users']; 294 295 if ( $max ) { 296 if ( $max >= count( $this->members ) ) { 297 $this->member_count = count( $this->members ); 298 } else { 299 $this->member_count = (int) $max; 300 } 301 } else { 302 $this->member_count = count( $this->members ); 303 } 304 305 if ( (int) $this->total_member_count && (int) $this->pag_num ) { 306 $pag_args = array( 307 $page_arg => '%#%', 308 ); 309 310 if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) { 311 $base = remove_query_arg( 's', wp_get_referer() ); 312 } else { 313 $base = ''; 314 } 315 316 /** 317 * Defaults to an empty array to make sure paginate_links() 318 * won't add the $page_arg to the links which would break 319 * pagination in case javascript is disabled. 320 */ 321 $add_args = array(); 322 323 if ( ! empty( $search_terms ) ) { 324 $add_args['s'] = urlencode( $search_terms ); 325 } 326 327 $this->pag_links = paginate_links( array( 328 'base' => add_query_arg( $pag_args, $base ), 329 'format' => '', 330 'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ), 331 'current' => (int) $this->pag_page, 332 'prev_text' => _x( '←', 'Member pagination previous text', 'buddypress' ), 333 'next_text' => _x( '→', 'Member pagination next text', 'buddypress' ), 334 'mid_size' => 1, 335 'add_args' => $add_args, 336 ) ); 337 } 247 $this->set_loop( $params ); 338 248 } 339 249 340 250 /** 341 * Whether there are members available in the loop.251 * Get Members. 342 252 * 343 * @s ee bp_has_members()253 * @since BuddyPress (2.3.0) 344 254 * 345 * @ return bool True if there are items in the loop, otherwise false.255 * @access public 346 256 */ 347 function has_members() { 348 if ( $this->member_count ) 349 return true; 257 public function get_items() { 258 if ( ! empty( $_REQUEST['letter'] ) ) { 259 $members = BP_Core_User::get_users_by_letter( 260 $_REQUEST['letter'], 261 $this->args['params']['per_page'], 262 $this->args['params']['page'], 263 $this->args['params']['populate_extras'], 264 $this->args['params']['exclude'] 265 ); 266 267 } else { 268 $members = bp_core_get_users( $this->args['params'] ); 269 } 350 270 351 return false;271 return array( 'members' => $members['users'] , 'total' => $members['total'] ); 352 272 } 353 273 354 274 /** 355 * Set up the next member and iterate index.275 * Set Members pagination. 356 276 * 357 * @return object The next member to iterate over. 277 * @since BuddyPress (2.3.0) 278 * 279 * @access public 358 280 */ 359 function next_member() { 360 $this->current_member++; 361 $this->member = $this->members[$this->current_member]; 362 363 return $this->member; 364 } 281 public function set_pag_links() { 282 $pag_args = array( 283 $this->page_arg => '%#%' 284 ); 365 285 366 /** 367 * Rewind the members and reset member index. 368 */ 369 function rewind_members() { 370 $this->current_member = -1; 371 if ( $this->member_count > 0 ) { 372 $this->member = $this->members[0]; 286 if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) { 287 $base = remove_query_arg( 's', wp_get_referer() ); 288 } else { 289 $base = ''; 373 290 } 374 }375 291 376 /** 377 * Whether there are members left in the loop to iterate over. 378 * 379 * This method is used by {@link bp_members()} as part of the while loop 380 * that controls iteration inside the members loop, eg: 381 * while ( bp_members() ) { ... 382 * 383 * @see bp_members() 384 * 385 * @return bool True if there are more members to show, otherwise false. 386 */ 387 function members() { 388 if ( $this->current_member + 1 < $this->member_count ) { 389 return true; 390 } elseif ( $this->current_member + 1 == $this->member_count ) { 292 /** 293 * Defaults to an empty array to make sure paginate_links() 294 * won't add the $page_arg to the links which would break 295 * pagination in case javascript is disabled. 296 */ 297 $add_args = array(); 391 298 392 /** 393 * Fires right before the rewinding of members listing. 394 * 395 * @since BuddyPress (1.5.0) 396 */ 397 do_action('member_loop_end'); 398 // Do some cleaning up after the loop 399 $this->rewind_members(); 299 if ( ! empty( $this->search_terms ) ) { 300 $add_args['s'] = urlencode( $this->search_terms ); 400 301 } 401 302 402 $this->in_the_loop = false; 403 return false; 303 $this->pag_links = paginate_links( array( 304 'base' => add_query_arg( $pag_args, $base ), 305 'format' => '', 306 'total' => ceil( (int) $this->{$this->args['labels']['item_total_count']} / (int) $this->per_page ), 307 'current' => (int) $this->page, 308 'prev_text' => _x( '←', 'Member pagination previous text', 'buddypress' ), 309 'next_text' => _x( '→', 'Member pagination next text', 'buddypress' ), 310 'mid_size' => 1, 311 'add_args' => $add_args, 312 ) ); 404 313 } 405 314 406 315 /** 407 * Set up the current member inside the loop. 408 * 409 * Used by {@link bp_the_member()} to set up the current member data 410 * while looping, so that template tags used during that iteration make 411 * reference to the current member. 316 * Rewind Members is an alias of rewind_items() 412 317 * 413 * @ see bp_the_member()318 * @access public 414 319 */ 415 function the_member() { 416 417 $this->in_the_loop = true; 418 $this->member = $this->next_member(); 419 420 // loop has just started 421 if ( 0 == $this->current_member ) { 422 423 /** 424 * Fires if the current member is the first in the loop. 425 * 426 * @since BuddyPress (1.5.0) 427 */ 428 do_action( 'member_loop_start' ); 429 } 430 320 public function rewind_members() { 321 _doing_it_wrong( __FUNCTION__, __( 'BP_Core_Members_Template->rewind_members() should not be used directly, please use bp_rewind_members()', 'buddypress' ), '2.3.0' ); 322 $this->rewind_items(); 431 323 } 432 324 } 433 325 … … class BP_Core_Members_Template { 437 329 function bp_rewind_members() { 438 330 global $members_template; 439 331 440 return $members_template->rewind_ members();332 return $members_template->rewind_items(); 441 333 } 442 334 443 335 /** … … function bp_has_members( $args = '' ) { 559 451 * @param bool $value Whether or not there are members to iterate over. 560 452 * @param array $members_template Populated $members_template global. 561 453 */ 562 return apply_filters( 'bp_has_members', $members_template->has_ members(), $members_template );454 return apply_filters( 'bp_has_members', $members_template->has_items(), $members_template ); 563 455 } 564 456 565 457 /** … … function bp_has_members( $args = '' ) { 569 461 */ 570 462 function bp_the_member() { 571 463 global $members_template; 572 return $members_template->the_ member();464 return $members_template->the_item(); 573 465 } 574 466 575 467 /** … … function bp_the_member() { 579 471 */ 580 472 function bp_members() { 581 473 global $members_template; 582 return $members_template-> members();474 return $members_template->items(); 583 475 } 584 476 585 477 /** … … function bp_members_pagination_count() { 596 488 function bp_get_members_pagination_count() { 597 489 global $members_template; 598 490 599 if ( empty( $members_template->type ) ) 491 if ( empty( $members_template->type ) ) { 600 492 $members_template->type = ''; 493 } 601 494 602 $start_num = intval( ( $members_template->pag _page - 1 ) * $members_template->pag_num) + 1;495 $start_num = intval( ( $members_template->page - 1 ) * $members_template->per_page ) + 1; 603 496 $from_num = bp_core_number_format( $start_num ); 604 $to_num = bp_core_number_format( ( $start_num + ( $members_template->p ag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num- 1 ) );497 $to_num = bp_core_number_format( ( $start_num + ( $members_template->per_page - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->per_page - 1 ) ); 605 498 $total = bp_core_number_format( $members_template->total_member_count ); 606 499 607 if ( 'active' == $members_template->type ) 500 if ( 'active' == $members_template->type ){ 608 501 $pag = sprintf( _n( 'Viewing 1 active member', 'Viewing %1$s - %2$s of %3$s active members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 609 else if ( 'popular' == $members_template->type )502 } else if ( 'popular' == $members_template->type ) { 610 503 $pag = sprintf( _n( 'Viewing 1 member with friends', 'Viewing %1$s - %2$s of %3$s members with friends', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 611 else if ( 'online' == $members_template->type )504 } else if ( 'online' == $members_template->type ) { 612 505 $pag = sprintf( _n( 'Viewing 1 online member', 'Viewing %1$s - %2$s of %3$s online members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 613 else506 } else { 614 507 $pag = sprintf( _n( 'Viewing 1 member', 'Viewing %1$s - %2$s of %3$s members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 508 } 615 509 616 510 /** 617 511 * Filters the members pagination count. -
src/bp-messages/bp-messages-template.php
diff --git src/bp-messages/bp-messages-template.php src/bp-messages/bp-messages-template.php index fe9e1bd..4ab9c7d 100644
if ( !defined( 'ABSPATH' ) ) exit; 13 13 /** 14 14 * Message Box Template Class 15 15 */ 16 class BP_Messages_Box_Template {16 class BP_Messages_Box_Template extends BP_Template_Loop { 17 17 18 18 /** 19 * The loop iterator.19 * Default arguments for Messages Box loop. 20 20 * 21 * @access public 22 * @var int 23 */ 24 public $current_thread = -1; 25 26 /** 27 * The number of threads returned by the paged query. 21 * @since BuddyPress (2.3.0) 28 22 * 29 * @access public 30 * @var int 31 */ 32 public $current_thread_count = 0; 33 34 /** 35 * Total number of threads matching the query params. 36 * 37 * @access public 38 * @var int 39 */ 40 public $total_thread_count = 0; 41 42 /** 43 * Array of threads located by the query. 44 * 45 * @access public 23 * @access protected 46 24 * @var array 47 25 */ 48 public $threads = array(); 49 50 /** 51 * The thread object currently being iterated on. 52 * 53 * @access public 54 * @var object 55 */ 56 public $thread = false; 57 58 /** 59 * A flag for whether the loop is currently being iterated. 60 * 61 * @access public 62 * @var bool 63 */ 64 public $in_the_loop = false; 65 66 /** 67 * User ID of the current inbox. 68 * 69 * @access public 70 * @var int 71 */ 72 public $user_id = 0; 73 74 /** 75 * The current "box" view ('notices', 'sentbox', 'inbox') 76 * 77 * @access public 78 * @var string 79 */ 80 public $box = 'inbox'; 81 82 /** 83 * The page number being requested. 84 * 85 * @access public 86 * @var int 87 */ 88 public $pag_page = 1; 89 90 /** 91 * The number of items being requested per page. 92 * 93 * @access public 94 * @var int 95 */ 96 public $pag_num = 10; 97 98 /** 99 * An HTML string containing pagination links. 100 * 101 * @access public 102 * @var string 103 */ 104 public $pag_links = ''; 105 106 /** 107 * Search terms for limiting the thread query. 108 * 109 * @access public 110 * @var string 111 */ 112 public $search_terms = ''; 26 protected $default_args = array( 27 'labels' => array( 28 'item' => 'thread', 29 'item_plural' => 'threads', 30 'item_total_count' => 'total_thread_count', 31 'item_count' => 'thread_count', 32 'current_item' => 'current_thread', 33 'hook_prefix' => 'messages_box', 34 ), 35 'params' => array( 36 'page_arg' => 'mpage', 37 'page' => 1, 38 'per_page' => 20, 39 'max' => 0, 40 ) 41 ); 113 42 114 43 /** 115 44 * Constructor method. … … class BP_Messages_Box_Template { 127 56 * parameter. Default: 'mpage'. 128 57 */ 129 58 public function __construct( $user_id, $box, $per_page, $max, $type, $search_terms, $page_arg = 'mpage' ) { 130 $this->pag_page = isset( $_GET[$page_arg] ) ? intval( $_GET[$page_arg] ) : 1; 131 $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; 132 133 $this->user_id = $user_id; 134 $this->box = $box; 135 $this->type = $type; 136 $this->search_terms = $search_terms; 137 138 if ( 'notices' == $this->box ) { 139 $this->threads = BP_Messages_Notice::get_notices( array( 140 'pag_num' => $this->pag_num, 141 'pag_page' => $this->pag_page 142 ) ); 143 } else { 144 $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page, $this->search_terms ); 145 146 $this->threads = $threads['threads']; 147 $this->total_thread_count = $threads['total']; 148 } 149 150 if ( !$this->threads ) { 151 $this->thread_count = 0; 152 $this->total_thread_count = 0; 153 } else { 154 $total_notice_count = BP_Messages_Notice::get_total_notice_count(); 59 $page = 1; 155 60 156 if ( !$max || $max >= (int) $total_notice_count ) { 157 if ( 'notices' == $this->box ) { 158 $this->total_thread_count = (int) $total_notice_count; 159 } 160 } else { 161 $this->total_thread_count = (int) $max; 162 } 163 164 if ( $max ) { 165 if ( $max >= count( $this->threads ) ) { 166 $this->thread_count = count( $this->threads ); 167 } else { 168 $this->thread_count = (int) $max; 169 } 170 } else { 171 $this->thread_count = count( $this->threads ); 172 } 61 if ( ! empty( $_GET[ $page_arg ] ) ) { 62 $page = $_GET[ $page_arg ]; 173 63 } 174 64 175 if ( (int) $this->total_thread_count && (int) $this->pag_num ) { 176 $pag_args = array( 177 $page_arg => '%#%', 178 ); 179 180 if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) { 181 $base = remove_query_arg( 's', wp_get_referer() ); 182 } else { 183 $base = ''; 184 } 185 186 $add_args = array(); 187 188 if ( ! empty( $this->search_terms ) ) { 189 $add_args['s'] = $this->search_terms; 190 } 65 $params = array( 'params' => array( 66 'user_id' => $user_id, 67 'box' => $box, 68 'per_page' => $per_page, 69 'max' => $max, 70 'type' => $type, 71 'search_terms' => $search_terms, 72 'page_arg' => $page_arg, 73 'page' => $page, 74 ) ); 191 75 192 $this->pag_links = paginate_links( array( 193 'base' => add_query_arg( $pag_args, $base ), 194 'format' => '', 195 'total' => ceil( (int) $this->total_thread_count / (int) $this->pag_num ), 196 'current' => $this->pag_page, 197 'prev_text' => _x( '←', 'Message pagination previous text', 'buddypress' ), 198 'next_text' => _x( '→', 'Message pagination next text', 'buddypress' ), 199 'mid_size' => 1, 200 'add_args' => $add_args, 201 ) ); 202 } 76 $this->set_loop( $params ); 203 77 } 204 78 205 79 /** 206 * Whether there are threads available in the loop.80 * Get Threads. 207 81 * 208 * @s ee bp_has_message_threads()82 * @since BuddyPress (2.3.0) 209 83 * 210 * @ return bool True if there are items in the loop, otherwise false.84 * @access public 211 85 */ 212 public function has_threads() { 213 if ( $this->thread_count ) { 214 return true; 86 public function get_items() { 87 if ( 'notices' == $this->args['params']['box'] ) { 88 $threads = array( 89 'threads' => BP_Messages_Notice::get_notices( array( 90 'pag_num' => $this->per_page, 91 'pag_page' => $this->page 92 ) ), 93 'total' => BP_Messages_Notice::get_total_notice_count(), 94 ); 95 96 } else { 97 $threads = BP_Messages_Thread::get_current_threads_for_user( 98 $this->args['params']['user_id'], 99 $this->args['params']['box'], 100 $this->args['params']['type'], 101 $this->per_page, 102 $this->page, 103 $this->args['params']['search_terms'] 104 ); 215 105 } 216 106 217 return false;107 return $threads; 218 108 } 219 109 220 110 /** 221 * Set up the next member and iterate index. 111 * Set Threads pagination. 112 * 113 * @since BuddyPress (2.3.0) 222 114 * 223 * @ return object The next member to iterate over.115 * @access public 224 116 */ 225 public function next_thread() { 226 $this->current_thread++; 227 $this->thread = $this->threads[$this->current_thread]; 117 public function set_pag_links() { 118 $pag_args = array( 119 $this->page_arg => '%#%' 120 ); 228 121 229 return $this->thread; 230 } 122 if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) { 123 $base = remove_query_arg( 's', wp_get_referer() ); 124 } else { 125 $base = ''; 126 } 231 127 232 /** 233 * Rewind the threads and reset thread index. 234 */ 235 public function rewind_threads() { 236 $this->current_thread = -1; 237 if ( $this->thread_count > 0 ) { 238 $this->thread = $this->threads[0]; 128 /** 129 * Defaults to an empty array to make sure paginate_links() 130 * won't add the $page_arg to the links which would break 131 * pagination in case javascript is disabled. 132 */ 133 $add_args = array(); 134 135 if ( ! empty( $this->search_terms ) ) { 136 $add_args['s'] = urlencode( $this->search_terms ); 239 137 } 138 139 $this->pag_links = paginate_links( array( 140 'base' => add_query_arg( $pag_args, $base ), 141 'format' => '', 142 'total' => ceil( (int) $this->{$this->args['labels']['item_total_count']} / (int) $this->per_page ), 143 'current' => (int) $this->page, 144 'prev_text' => _x( '←', 'Message pagination previous text', 'buddypress' ), 145 'next_text' => _x( '→', 'Message pagination next text', 'buddypress' ), 146 'mid_size' => 1, 147 'add_args' => $add_args, 148 ) ); 240 149 } 241 150 242 151 /** 243 * Whether there are threads left in the loop to iterate over. 244 * 245 * This method is used by {@link bp_message_threads()} as part of the 246 * while loop that controls iteration inside the threads loop, eg: 247 * while ( bp_message_threads() ) { ... 152 * Override parent method as we need to do custom work. 248 153 * 249 * @s ee bp_message_threads()154 * @since BuddyPress (2.3.0) 250 155 * 251 * @ return bool True if there are more threads to show, otherwise false.156 * @uses BP_Messages_Box_Template->the_message_thread() 252 157 */ 253 function message_threads() { 254 if ( $this->current_thread + 1 < $this->thread_count ) { 255 return true; 256 } elseif ( $this->current_thread + 1 == $this->thread_count ) { 257 258 /** 259 * Fires when at the end of threads to iterate over. 260 * 261 * @since BuddyPress (1.5.0) 262 */ 263 do_action( 'messages_box_loop_end' ); 264 // Do some cleaning up after the loop 265 $this->rewind_threads(); 266 } 267 268 $this->in_the_loop = false; 269 return false; 158 public function the_item() { 159 $this->the_message_thread(); 270 160 } 271 161 272 162 /** … … class BP_Messages_Box_Template { 281 171 public function the_message_thread() { 282 172 283 173 $this->in_the_loop = true; 284 $this->thread = $this->next_ thread();174 $this->thread = $this->next_item(); 285 175 286 176 if ( ! bp_is_current_action( 'notices' ) ) { 287 177 $last_message_index = count( $this->thread->messages ) - 1; 288 178 $this->thread->messages = array_reverse( (array) $this->thread->messages ); 289 179 290 180 // Set up the last message data 291 if ( count( $this->thread->messages) > 1 ) {181 if ( count( $this->thread->messages ) > 1 ) { 292 182 if ( 'inbox' == $this->box ) { 293 183 foreach ( (array) $this->thread->messages as $key => $message ) { 294 184 if ( bp_loggedin_user_id() != $message->sender_id ) { … … function bp_has_message_threads( $args = '' ) { 401 291 * @param BP_Messages_Box_Template $messages_template Current message box template object. 402 292 * @param array $r Array of parsed arguments passed into function. 403 293 */ 404 return apply_filters( 'bp_has_message_threads', $messages_template->has_ threads(), $messages_template, $r );294 return apply_filters( 'bp_has_message_threads', $messages_template->has_items(), $messages_template, $r ); 405 295 } 406 296 407 297 /** … … function bp_has_message_threads( $args = '' ) { 411 301 */ 412 302 function bp_message_threads() { 413 303 global $messages_template; 414 return $messages_template-> message_threads();304 return $messages_template->items(); 415 305 } 416 306 417 307 /** … … function bp_message_threads() { 421 311 */ 422 312 function bp_message_thread() { 423 313 global $messages_template; 424 return $messages_template->the_ message_thread();314 return $messages_template->the_item(); 425 315 } 426 316 427 317 /** … … function bp_messages_pagination() { 1055 945 function bp_messages_pagination_count() { 1056 946 global $messages_template; 1057 947 1058 $start_num = intval( ( $messages_template->pag _page - 1 ) * $messages_template->pag_num) + 1;948 $start_num = intval( ( $messages_template->page - 1 ) * $messages_template->per_page ) + 1; 1059 949 $from_num = bp_core_number_format( $start_num ); 1060 $to_num = bp_core_number_format( ( $start_num + ( $messages_template->p ag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num- 1 ) );950 $to_num = bp_core_number_format( ( $start_num + ( $messages_template->per_page - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->per_page - 1 ) ); 1061 951 $total = bp_core_number_format( $messages_template->total_thread_count ); 1062 952 1063 953 echo sprintf( _n( 'Viewing 1 message', 'Viewing %1$s - %2$s of %3$s messages', $total, 'buddypress' ), $from_num, $to_num, number_format_i18n( $total ) ); … … function bp_message_get_recipient_usernames() { 1685 1575 return apply_filters( 'bp_get_message_get_recipient_usernames', $recipients ); 1686 1576 } 1687 1577 1688 1689 1578 /** 1690 1579 * Message Thread Template Class 1691 1580 */ 1692 class BP_Messages_Thread_Template {1581 class BP_Messages_Thread_Template extends BP_Template_Loop { 1693 1582 1694 1583 /** 1695 * The loop iterator.1584 * Default arguments for Messages loop. 1696 1585 * 1697 * @access public 1698 * @var int 1699 */ 1700 public $current_message = -1; 1701 1702 /** 1703 * Number of messages returned by the paged query. 1704 * 1705 * @access public 1706 * @var int 1707 */ 1708 public $message_count = 0; 1709 1710 /** 1711 * The message object currently being iterated on. 1712 * 1713 * @access public 1714 * @var object 1715 */ 1716 public $message; 1717 1718 /** 1719 * Thread that the current messages belong to. 1720 * 1721 * @access public 1722 * @var BP_Messages_Thread 1723 */ 1724 public $thread; 1725 1726 /** 1727 * A flag for whether the loop is currently being iterated. 1586 * @since BuddyPress (2.3.0) 1728 1587 * 1729 * @access p ublic1730 * @var bool1588 * @access protected 1589 * @var array 1731 1590 */ 1732 public $in_the_loop = false; 1591 protected $default_args = array( 1592 'labels' => array( 1593 'item' => 'message', 1594 'item_plural' => 'messages', 1595 'item_total_count' => 'total_message_count', 1596 'item_count' => 'message_count', 1597 'current_item' => 'current_message', 1598 'hook_prefix' => 'thread', 1599 ), 1600 'params' => array( 1601 'order' => 'ASC', 1602 ) 1603 ); 1733 1604 1734 1605 /** 1735 * The page number being requested.1606 * Constructor method. 1736 1607 * 1737 * @access public 1738 * @var int 1608 * @see BP_Messages_Thread::populate() for full parameter info 1739 1609 */ 1740 public $pag_page = 1; 1610 public function __construct( $thread_id = 0, $order = 'ASC', $args = array() ) { 1611 $params = array( 'params' => array( 1612 'thread_id' => $thread_id, 1613 'order' => $order, 1614 'thread_args' => $args, 1615 ) ); 1741 1616 1742 /** 1743 * The number of items being requested per page. 1744 * 1745 * @access public 1746 * @var int 1747 */ 1748 public $pag_num = 10; 1617 $this->set_loop( $params ); 1618 } 1749 1619 1750 1620 /** 1751 * An HTML string containing pagination links.1621 * Get Messages. 1752 1622 * 1753 * @access public 1754 * @var string 1755 */ 1756 public $pag_links = ''; 1757 1758 /** 1759 * The total number of messages matching the query. 1623 * @since BuddyPress (2.3.0) 1760 1624 * 1761 1625 * @access public 1762 * @var int1763 */1764 public $total_message_count = 0;1765 1766 /**1767 * Constructor method.1768 *1769 * @see BP_Messages_Thread::populate() for full parameter info1770 1626 */ 1771 public function __construct( $thread_id = 0, $order = 'ASC', $args = array() ) { 1772 $this->thread = new BP_Messages_Thread( $thread_id, $order, $args ); 1773 $this->message_count = count( $this->thread->messages ); 1627 public function get_items() { 1628 $this->thread = new BP_Messages_Thread( 1629 $this->args['params']['thread_id'], 1630 $this->args['params']['order'], 1631 $this->args['params']['thread_args'] 1632 ); 1774 1633 1775 $last_message_index = $this->message_count- 1;1634 $last_message_index = count( $this->thread->messages ) - 1; 1776 1635 $this->thread->last_message_id = $this->thread->messages[ $last_message_index ]->id; 1777 1636 $this->thread->last_message_date = $this->thread->messages[ $last_message_index ]->date_sent; 1778 1637 $this->thread->last_sender_id = $this->thread->messages[ $last_message_index ]->sender_id; 1779 1638 $this->thread->last_message_subject = $this->thread->messages[ $last_message_index ]->subject; 1780 1639 $this->thread->last_message_content = $this->thread->messages[ $last_message_index ]->message; 1781 }1782 1783 /**1784 * Whether there are messages available in the loop.1785 *1786 * @see bp_thread_has_messages()1787 *1788 * @return bool True if there are items in the loop, otherwise false.1789 */1790 public function has_messages() {1791 if ( ! empty( $this->message_count ) ) {1792 return true;1793 }1794 1795 return false;1796 }1797 1798 /**1799 * Set up the next member and iterate index.1800 *1801 * @return object The next member to iterate over.1802 */1803 public function next_message() {1804 $this->current_message++;1805 $this->message = $this->thread->messages[ $this->current_message ];1806 1807 return $this->message;1808 }1809 1810 /**1811 * Rewind the messages and reset message index.1812 */1813 public function rewind_messages() {1814 $this->current_message = -1;1815 if ( $this->message_count > 0 ) {1816 $this->message = $this->thread->messages[0];1817 }1818 }1819 1820 /**1821 * Whether there are messages left in the loop to iterate over.1822 *1823 * This method is used by {@link bp_thread_messages()} as part of the1824 * while loop that controls iteration inside the messages loop, eg:1825 * while ( bp_thread_messages() ) { ...1826 *1827 * @see bp_thread_messages()1828 *1829 * @return bool True if there are more messages to show, otherwise false.1830 */1831 public function messages() {1832 if ( ( $this->current_message + 1 ) < $this->message_count ) {1833 return true;1834 } elseif ( ( $this->current_message + 1 ) === $this->message_count ) {1835 1836 /**1837 * Fires when at the end of messages to iterate over.1838 *1839 * @since BuddyPress (1.1.0)1840 */1841 do_action( 'thread_loop_end' );1842 // Do some cleaning up after the loop1843 $this->rewind_messages();1844 }1845 1846 $this->in_the_loop = false;1847 return false;1848 }1849 1640 1850 /** 1851 * Set up the current message inside the loop. 1852 * 1853 * Used by {@link bp_thread_the_message()} to set up the current 1854 * message data while looping, so that template tags used during 1855 * that iteration make reference to the current message. 1856 * 1857 * @see bp_thread_the_message() 1858 */ 1859 public function the_message() { 1860 $this->in_the_loop = true; 1861 $this->message = $this->next_message(); 1862 1863 // loop has just started 1864 if ( 0 === $this->current_message ) { 1865 1866 /** 1867 * Fires if at the start of the message loop. 1868 * 1869 * @since BuddyPress (1.1.0) 1870 */ 1871 do_action( 'thread_loop_start' ); 1872 } 1641 return array( 'messages' => $this->thread->messages, 'total' => 0 ); 1873 1642 } 1874 1643 } 1875 1644 … … function bp_thread_has_messages( $args = '' ) { 1906 1675 1907 1676 $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'], $extra_args ); 1908 1677 1909 return $thread_template->has_ messages();1678 return $thread_template->has_items(); 1910 1679 } 1911 1680 1912 1681 /** … … function bp_thread_messages_order() { 1933 1702 function bp_thread_messages() { 1934 1703 global $thread_template; 1935 1704 1936 return $thread_template-> messages();1705 return $thread_template->items(); 1937 1706 } 1938 1707 1939 1708 /** … … function bp_thread_messages() { 1944 1713 function bp_thread_the_message() { 1945 1714 global $thread_template; 1946 1715 1947 return $thread_template->the_ message();1716 return $thread_template->the_item(); 1948 1717 } 1949 1718 1950 1719 /** -
src/bp-notifications/bp-notifications-template.php
diff --git src/bp-notifications/bp-notifications-template.php src/bp-notifications/bp-notifications-template.php index 8ff04ac..f2e76ac 100644
function bp_notifications_read_permalink() { 98 98 * 99 99 * @since BuddyPress (1.9.0) 100 100 */ 101 class BP_Notifications_Template {101 class BP_Notifications_Template extends BP_Template_Loop { 102 102 103 103 /** 104 * The loop iterator.104 * Default arguments for Notifications loop. 105 105 * 106 * @since BuddyPress (1.9.0) 107 * @access public 108 * @var int 109 */ 110 public $current_notification = -1; 111 112 /** 113 * The number of notifications returned by the paged query. 114 * 115 * @since BuddyPress (1.9.0) 116 * @access public 117 * @var int 118 */ 119 public $current_notification_count; 120 121 /** 122 * Total number of notifications matching the query. 123 * 124 * @since BuddyPress (1.9.0) 125 * @access public 126 * @var int 127 */ 128 public $total_notification_count; 129 130 /** 131 * Array of notifications located by the query. 106 * @since BuddyPress (2.3.0) 132 107 * 133 * @since BuddyPress (1.9.0) 134 * @access public 108 * @access protected 135 109 * @var array 136 110 */ 137 public $notifications; 138 139 /** 140 * The notification object currently being iterated on. 141 * 142 * @since BuddyPress (1.9.0) 143 * @access public 144 * @var object 145 */ 146 public $notification; 147 148 /** 149 * A flag for whether the loop is currently being iterated. 150 * 151 * @since BuddyPress (1.9.0) 152 * @access public 153 * @var bool 154 */ 155 public $in_the_loop; 156 157 /** 158 * The ID of the user to whom the displayed notifications belong. 159 * 160 * @since BuddyPress (1.9.0) 161 * @access public 162 * @var int 163 */ 164 public $user_id; 165 166 /** 167 * The page number being requested. 168 * 169 * @since BuddyPress (1.9.0) 170 * @access public 171 * @var int 172 */ 173 public $pag_page; 174 175 /** 176 * The number of items to display per page of results. 177 * 178 * @since BuddyPress (1.9.0) 179 * @access public 180 * @var int 181 */ 182 public $pag_num; 183 184 /** 185 * An HTML string containing pagination links. 186 * 187 * @since BuddyPress (1.9.0) 188 * @access public 189 * @var string 190 */ 191 public $pag_links; 192 193 /** 194 * A string to match against. 195 * 196 * @since BuddyPress (1.9.0) 197 * @access public 198 * @var string 199 */ 200 public $search_terms; 201 202 /** 203 * A database column to order the results by. 204 * 205 * @since BuddyPress (1.9.0) 206 * @access public 207 * @var string 208 */ 209 public $order_by; 210 211 /** 212 * The direction to sort the results (ASC or DESC) 213 * 214 * @since BuddyPress (1.9.0) 215 * @access public 216 * @var string 217 */ 218 public $sort_order; 111 protected $default_args = array( 112 'labels' => array( 113 'item' => 'notification', 114 'item_plural' => 'notifications', 115 'item_total_count' => 'total_notification_count', 116 'item_count' => 'notification_count', 117 'current_item' => 'current_notification', 118 'hook_prefix' => 'notifications', 119 ), 120 'params' => array( 121 'page_arg' => 'npage', 122 'page' => 1, 123 'per_page' => 20, 124 'max' => 0, 125 ) 126 ); 219 127 220 128 /** 221 129 * Constructor method. … … class BP_Notifications_Template { 248 156 'page_arg' => 'npage', 249 157 ) ); 250 158 251 // Overrides252 253 // Set which pagination page254 if ( isset( $_GET[ $r['page_arg'] ] ) ) {255 $r['page'] = intval( $_GET[ $r['page_arg'] ] );256 }257 258 // Set the number to show per page259 if ( isset( $_GET['num'] ) ) {260 $r['per_page'] = intval( $_GET['num'] );261 } else {262 $r['per_page'] = intval( $r['per_page'] );263 }264 265 159 // Sort order direction 266 160 $orders = array( 'ASC', 'DESC' ); 267 161 if ( ! empty( $_GET['sort_order'] ) && in_array( $_GET['sort_order'], $orders ) ) { … … class BP_Notifications_Template { 270 164 $r['sort_order'] = in_array( $r['sort_order'], $orders ) ? $r['sort_order'] : 'DESC'; 271 165 } 272 166 273 // Setup variables 274 $this->pag_page = $r['page']; 275 $this->pag_num = $r['per_page']; 276 $this->user_id = $r['user_id']; 277 $this->is_new = $r['is_new']; 278 $this->search_terms = $r['search_terms']; 279 $this->page_arg = $r['page_arg']; 280 $this->order_by = $r['order_by']; 281 $this->sort_order = $r['sort_order']; 282 283 // Setup the notifications to loop through 284 $this->notifications = BP_Notifications_Notification::get( $r ); 285 $this->total_notification_count = BP_Notifications_Notification::get_total_count( $r ); 286 287 if ( empty( $this->notifications ) ) { 288 $this->notification_count = 0; 289 $this->total_notification_count = 0; 290 291 } else { 292 if ( ! empty( $r['max'] ) ) { 293 if ( $r['max'] >= count( $this->notifications ) ) { 294 $this->notification_count = count( $this->notifications ); 295 } else { 296 $this->notification_count = (int) $r['max']; 297 } 298 } else { 299 $this->notification_count = count( $this->notifications ); 300 } 301 } 302 303 if ( (int) $this->total_notification_count && (int) $this->pag_num ) { 304 $add_args = array( 305 'sort_order' => $this->sort_order, 306 ); 307 308 $this->pag_links = paginate_links( array( 309 'base' => add_query_arg( $this->page_arg, '%#%' ), 310 'format' => '', 311 'total' => ceil( (int) $this->total_notification_count / (int) $this->pag_num ), 312 'current' => $this->pag_page, 313 'prev_text' => _x( '←', 'Notifications pagination previous text', 'buddypress' ), 314 'next_text' => _x( '→', 'Notifications pagination next text', 'buddypress' ), 315 'mid_size' => 1, 316 'add_args' => $add_args, 317 ) ); 318 319 // Remove first page from pagination 320 $this->pag_links = str_replace( '?' . $r['page_arg'] . '=1', '', $this->pag_links ); 321 $this->pag_links = str_replace( '&' . $r['page_arg'] . '=1', '', $this->pag_links ); 322 } 323 } 324 325 /** 326 * Whether there are notifications available in the loop. 327 * 328 * @since BuddyPress (1.9.0) 329 * 330 * @see bp_has_notifications() 331 * 332 * @return bool True if there are items in the loop, otherwise false. 333 */ 334 public function has_notifications() { 335 if ( $this->notification_count ) { 336 return true; 337 } 338 339 return false; 167 $this->set_loop( array( 'params' => $r ) ); 340 168 } 341 169 342 170 /** 343 * Set up the next notification and iterate index. 344 * 345 * @since BuddyPress (1.9.0) 171 * Get Notifications. 346 172 * 347 * @return object The next notification to iterate over. 348 */ 349 public function next_notification() { 350 351 $this->current_notification++; 352 353 $this->notification = $this->notifications[ $this->current_notification ]; 354 355 return $this->notification; 356 } 357 358 /** 359 * Rewind the blogs and reset blog index. 173 * @since BuddyPress (2.3.0) 360 174 * 361 * @ since BuddyPress (1.9.0)175 * @access public 362 176 */ 363 public function rewind_notifications() { 364 365 $this->current_notification = -1; 366 367 if ( $this->notification_count > 0 ) { 368 $this->notification = $this->notifications[0]; 369 } 177 public function get_items() { 178 return array( 179 'notifications' => BP_Notifications_Notification::get( $this->args['params'] ), 180 'total' => BP_Notifications_Notification::get_total_count( $this->args['params'] ) 181 ); 370 182 } 371 183 372 184 /** 373 * Whether there are notifications left in the loop to iterate over. 374 * 375 * This method is used by {@link bp_notifications()} as part of the 376 * while loop that controls iteration inside the notifications loop, eg: 377 * while ( bp_notifications() ) { ... 378 * 379 * @since BuddyPress (1.9.0) 185 * Set Notifications pagination. 380 186 * 381 * @s ee bp_notifications()187 * @since BuddyPress (2.3.0) 382 188 * 383 * @return bool True if there are more notifications to show, 384 * otherwise false. 189 * @access public 385 190 */ 386 public function notifications() { 387 388 if ( $this->current_notification + 1 < $this->notification_count ) { 389 return true; 390 391 } elseif ( $this->current_notification + 1 == $this->notification_count ) { 392 do_action( 'notifications_loop_end'); 393 394 $this->rewind_notifications(); 395 } 396 397 $this->in_the_loop = false; 398 return false; 399 } 191 public function set_pag_links() { 192 $add_args = array( 193 'sort_order' => $this->sort_order, 194 ); 400 195 401 /** 402 * Set up the current notification inside the loop. 403 * 404 * Used by {@link bp_the_notification()} to set up the current 405 * notification data while looping, so that template tags used during 406 * that iteration make reference to the current notification. 407 * 408 * @since BuddyPress (1.9.0) 409 * 410 * @see bp_the_notification() 411 */ 412 public function the_notification() { 413 $this->in_the_loop = true; 414 $this->notification = $this->next_notification(); 196 $this->pag_links = paginate_links( array( 197 'base' => add_query_arg( $this->page_arg, '%#%' ), 198 'format' => '', 199 'total' => ceil( (int) $this->{$this->args['labels']['item_total_count']} / (int) $this->per_page ), 200 'current' => (int) $this->page, 201 'prev_text' => _x( '←', 'Notifications pagination previous text', 'buddypress' ), 202 'next_text' => _x( '→', 'Notifications pagination next text', 'buddypress' ), 203 'mid_size' => 1, 204 'add_args' => $add_args, 205 ) ); 415 206 416 // loop has just started 417 if ( 0 === $this->current_notification ) { 418 do_action( 'notifications_loop_start' ); 419 } 207 // Remove first page from pagination 208 $this->pag_links = str_replace( '?' . $this->page_arg . '=1', '', $this->pag_links ); 209 $this->pag_links = str_replace( '&' . $this->page_arg . '=1', '', $this->pag_links ); 420 210 } 421 211 } 422 212 … … function bp_has_notifications( $args = '' ) { 489 279 // Setup the global query loop 490 280 buddypress()->notifications->query_loop = $query_loop; 491 281 492 return apply_filters( 'bp_has_notifications', $query_loop->has_ notifications(), $query_loop );282 return apply_filters( 'bp_has_notifications', $query_loop->has_items(), $query_loop ); 493 283 } 494 284 495 285 /** … … function bp_has_notifications( $args = '' ) { 500 290 * @return array List of notifications. 501 291 */ 502 292 function bp_the_notifications() { 503 return buddypress()->notifications->query_loop-> notifications();293 return buddypress()->notifications->query_loop->items(); 504 294 } 505 295 506 296 /** … … function bp_the_notifications() { 511 301 * @return object The current notification within the loop. 512 302 */ 513 303 function bp_the_notification() { 514 return buddypress()->notifications->query_loop->the_ notification();304 return buddypress()->notifications->query_loop->the_item(); 515 305 } 516 306 517 307 /** Loop Output ***************************************************************/ … … function bp_notifications_pagination_count() { 991 781 */ 992 782 function bp_get_notifications_pagination_count() { 993 783 $query_loop = buddypress()->notifications->query_loop; 994 $start_num = intval( ( $query_loop->pag _page - 1 ) * $query_loop->pag_num) + 1;784 $start_num = intval( ( $query_loop->page - 1 ) * $query_loop->per_page ) + 1; 995 785 $from_num = bp_core_number_format( $start_num ); 996 $to_num = bp_core_number_format( ( $start_num + ( $query_loop->p ag_num - 1 ) > $query_loop->total_notification_count ) ? $query_loop->total_notification_count : $start_num + ( $query_loop->pag_num- 1 ) );786 $to_num = bp_core_number_format( ( $start_num + ( $query_loop->per_page - 1 ) > $query_loop->total_notification_count ) ? $query_loop->total_notification_count : $start_num + ( $query_loop->per_page - 1 ) ); 997 787 $total = bp_core_number_format( $query_loop->total_notification_count ); 998 788 $pag = sprintf( _n( 'Viewing 1 notification', 'Viewing %1$s - %2$s of %3$s notifications', $total, 'buddypress' ), $from_num, $to_num, $total ); 999 789 -
src/bp-templates/bp-legacy/buddypress/members/register.php
diff --git src/bp-templates/bp-legacy/buddypress/members/register.php src/bp-templates/bp-legacy/buddypress/members/register.php index e0f8f5b..8c84606 100644
65 65 <?php /* Use the profile field loop to render input fields for the 'base' profile field group */ ?> 66 66 <?php if ( bp_is_active( 'xprofile' ) ) : if ( bp_has_profile( array( 'profile_group_id' => 1, 'fetch_field_data' => false ) ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?> 67 67 68 <?php while ( bp_profile_fields() ) : bp_the_profile_field();?>68 <?php if ( bp_profile_group_has_fields() ) : ?> 69 69 70 <div<?php bp_field_css_class( 'editfield' ); ?>>70 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 71 71 72 <?php 73 $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); 74 $field_type->edit_field_html(); 72 <div<?php bp_field_css_class( 'editfield' ); ?>> 75 73 76 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 74 <?php 75 $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); 76 $field_type->edit_field_html(); 77 77 78 if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 79 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 80 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <a href="#" class="visibility-toggle-link"><?php _ex( 'Change', 'Change profile field visibility level', 'buddypress' ); ?></a> 81 </p> 78 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 82 79 83 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 84 <fieldset> 85 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend> 80 if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 81 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 82 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <a href="#" class="visibility-toggle-link"><?php _ex( 'Change', 'Change profile field visibility level', 'buddypress' ); ?></a> 83 </p> 86 84 87 <?php bp_profile_visibility_radio_buttons() ?> 85 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 86 <fieldset> 87 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend> 88 88 89 </fieldset> 90 <a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a> 89 <?php bp_profile_visibility_radio_buttons() ?> 91 90 92 </div> 93 <?php else : ?> 94 <p class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 95 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> 96 </p> 97 <?php endif ?> 91 </fieldset> 92 <a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a> 93 94 </div> 95 <?php else : ?> 96 <p class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 97 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> 98 </p> 99 <?php endif ?> 98 100 99 <?php do_action( 'bp_custom_profile_edit_fields' ); ?>101 <?php do_action( 'bp_custom_profile_edit_fields' ); ?> 100 102 101 <p class="description"><?php bp_the_profile_field_description(); ?></p> 103 <p class="description"><?php bp_the_profile_field_description(); ?></p> 104 105 </div> 102 106 103 </div>107 <?php endwhile; ?> 104 108 105 <?php endwhile;?>109 <?php endif ;?> 106 110 107 111 <input type="hidden" name="signup_profile_field_ids" id="signup_profile_field_ids" value="<?php bp_the_profile_field_ids(); ?>" /> 108 112 -
src/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php src/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php index 7fe800f..ae2b58c 100644
if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) 19 19 20 20 <div class="clear"></div> 21 21 22 <?php while ( bp_profile_fields() ) : bp_the_profile_field();?>22 <?php if ( bp_profile_group_has_fields() ) : ?> 23 23 24 < div<?php bp_field_css_class( 'editfield' ); ?>>24 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 25 25 26 <?php 27 $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); 28 $field_type->edit_field_html(); 26 <div<?php bp_field_css_class( 'editfield' ); ?>> 29 27 30 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 31 ?> 28 <?php 29 $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); 30 $field_type->edit_field_html(); 32 31 33 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 34 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 35 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <a href="#" class="visibility-toggle-link"><?php _e( 'Change', 'buddypress' ); ?></a> 36 </p> 32 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 33 ?> 37 34 38 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 39 <fieldset> 40 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend> 35 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 36 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 37 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <a href="#" class="visibility-toggle-link"><?php _e( 'Change', 'buddypress' ); ?></a> 38 </p> 41 39 42 <?php bp_profile_visibility_radio_buttons() ?> 40 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 41 <fieldset> 42 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend> 43 43 44 </fieldset> 45 <a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a> 46 </div> 47 <?php else : ?> 48 <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 49 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> 50 </div> 51 <?php endif ?> 44 <?php bp_profile_visibility_radio_buttons() ?> 52 45 53 <?php do_action( 'bp_custom_profile_edit_fields' ); ?> 46 </fieldset> 47 <a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a> 48 </div> 49 <?php else : ?> 50 <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 51 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> 52 </div> 53 <?php endif ?> 54 54 55 <p class="description"><?php bp_the_profile_field_description(); ?></p> 56 </div> 55 <?php do_action( 'bp_custom_profile_edit_fields' ); ?> 57 56 58 <?php endwhile; ?> 57 <p class="description"><?php bp_the_profile_field_description(); ?></p> 58 </div> 59 60 <?php endwhile; ?> 61 62 <?php endif ;?> 59 63 60 64 <?php do_action( 'bp_after_profile_field_content' ); ?> 61 65 -
src/bp-templates/bp-legacy/buddypress/members/single/settings/profile.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/settings/profile.php src/bp-templates/bp-legacy/buddypress/members/single/settings/profile.php index 0fdae6f..cd4d040 100644
6 6 7 7 <?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?> 8 8 9 <?php if ( bp_profile_ fields() ) : ?>9 <?php if ( bp_profile_group_has_fields() ) : ?> 10 10 11 11 <table class="profile-settings" id="xprofile-settings-<?php bp_the_profile_group_slug(); ?>"> 12 12 <thead> -
src/bp-xprofile/bp-xprofile-admin.php
diff --git src/bp-xprofile/bp-xprofile-admin.php src/bp-xprofile/bp-xprofile-admin.php index 24d36e1..c9fb625 100644
class BP_XProfile_User_Admin { 756 756 757 757 <?php endif; ?> 758 758 759 <?php if ( ! bp_profile_group_has_fields() ) { continue ; } ?> 760 759 761 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 760 762 761 763 <div<?php bp_field_css_class( 'bp-profile-field' ); ?>> -
src/bp-xprofile/bp-xprofile-template.php
diff --git src/bp-xprofile/bp-xprofile-template.php src/bp-xprofile/bp-xprofile-template.php index 5c9e53f..7381f57 100644
10 10 // Exit if accessed directly 11 11 if ( !defined( 'ABSPATH' ) ) exit; 12 12 13 class BP_XProfile_Data_Template { 14 var $current_group = -1; 15 var $group_count; 16 var $groups; 17 var $group; 13 /** 14 * The main xProfile Groups template loop class. 15 * 16 * Responsible for loading a group of fields into a loop for display. 17 */ 18 class BP_XProfile_Data_Template extends BP_Template_Loop { 19 20 /** 21 * Default arguments for xProfile Groups loop. 22 * 23 * @since BuddyPress (2.3.0) 24 * 25 * @access protected 26 * @var array 27 */ 28 protected $default_args = array( 29 'labels' => array( 30 'item' => 'group', 31 'item_plural' => 'groups', 32 'item_total_count' => 'total_group_count', 33 'item_count' => 'group_count', 34 'current_item' => 'current_group', 35 'hook_prefix' => 'xprofile_template', 36 ), 37 'params' => array() 38 ); 18 39 19 var $current_field = -1; 20 var $field_count; 21 var $field_has_data; 22 var $field; 40 /** 41 * @deprecated BuddyPress (2.3.0). 42 * 43 * @access public 44 * @var int 45 */ 46 public $current_field = -1; 23 47 24 var $in_the_loop; 25 var $user_id; 48 /** 49 * @deprecated BuddyPress (2.3.0). 50 * 51 * @access public 52 * @var object 53 */ 54 public $field; 26 55 56 /** 57 * Constructor method. 58 * 59 * @see BP_XProfile_Group::get() for an in-depth description of arguments. 60 * 61 * @param int $user_id 62 * @param int $profile_group_id 63 * @param bool $hide_empty_groups 64 * @param bool $fetch_fields 65 * @param bool $fetch_field_data 66 * @param bool|string $exclude_groups Comma-separated list of profile field group IDs to exclude 67 * @param bool|string $exclude_fields Comma-separated list of profile field IDs to exclude 68 * @param bool $hide_empty_fields 69 * @param bool $fetch_visibility_level 70 * @param bool $update_meta_cache 71 */ 27 72 function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_visibility_level = false, $update_meta_cache = true ) { 28 $ this->groups = bp_xprofile_get_groups(array(29 'profile_group_id' => $profile_group_id,30 'user_id' => $user_id,31 'hide_empty_groups' => $hide_empty_groups,32 'hide_empty_fields' => $hide_empty_fields,33 'fetch_fields' => $fetch_fields,34 'fetch_field_data' => $fetch_field_data,73 $params = array( 'params' => array( 74 'profile_group_id' => $profile_group_id, 75 'user_id' => $user_id, 76 'hide_empty_groups' => $hide_empty_groups, 77 'hide_empty_fields' => $hide_empty_fields, 78 'fetch_fields' => $fetch_fields, 79 'fetch_field_data' => $fetch_field_data, 35 80 'fetch_visibility_level' => $fetch_visibility_level, 36 'exclude_groups' => $exclude_groups,37 'exclude_fields' => $exclude_fields,38 'update_meta_cache' => $update_meta_cache,81 'exclude_groups' => $exclude_groups, 82 'exclude_fields' => $exclude_fields, 83 'update_meta_cache' => $update_meta_cache, 39 84 ) ); 40 85 41 $this->group_count = count($this->groups); 42 $this->user_id = $user_id; 86 $this->set_loop( $params ); 43 87 } 44 88 45 function has_groups() { 46 if ( $this->group_count ) 47 return true; 89 /** 90 * Get xProfile Groups. 91 * 92 * @since BuddyPress (2.3.0) 93 * 94 * @access public 95 */ 96 public function get_items() { 97 $groups = bp_xprofile_get_groups( $this->args['params'] ); 48 98 49 return false;99 return array( 'groups' => $groups, 'total' => count( $groups ) ); 50 100 } 51 101 52 function next_group() { 102 /** 103 * Alias of BP_XProfile_Data_Template->next_item(). 104 */ 105 public function next_group() { 106 $this->next_item(); 107 } 108 109 /** 110 * Override parent method as we need to do custom work. 111 * 112 * @since BuddyPress (2.3.0) 113 */ 114 function next_item() { 53 115 $this->current_group++; 54 116 55 117 $this->group = $this->groups[$this->current_group]; … … class BP_XProfile_Data_Template { 63 125 return $this->group; 64 126 } 65 127 66 function rewind_groups() { 67 $this->current_group = -1; 68 if ( $this->group_count > 0 ) { 69 $this->group = $this->groups[0]; 70 } 71 } 72 73 function profile_groups() { 74 if ( $this->current_group + 1 < $this->group_count ) { 75 return true; 76 } elseif ( $this->current_group + 1 == $this->group_count ) { 77 do_action('xprofile_template_loop_end'); 78 // Do some cleaning up after the loop 79 $this->rewind_groups(); 80 } 81 82 $this->in_the_loop = false; 83 return false; 84 } 85 86 function the_profile_group() { 128 /** 129 * Override parent method as we need to do custom work. 130 * Set up the current xProfile Group inside the loop. 131 * 132 * @since BuddyPress (2.3.0) 133 * 134 * @global $group 135 */ 136 public function the_item() { 87 137 global $group; 88 138 89 $this->in_the_loop = true; 90 $group = $this->next_group(); 139 parent::the_item(); 91 140 92 if ( 0 == $this->current_group ) // loop has just started 93 do_action('xprofile_template_loop_start'); 141 if ( ! empty( $this->group ) ) { 142 $group = $this->group; 143 } 94 144 } 95 145 96 /**** FIELDS ****/146 /**** FIELDS : backcompat methods *********************************************/ 97 147 98 function next_field() { 148 /** 149 * These methods are used to ensure back compatibility for themes using 150 * bp_profile_fields() without first initiating the loop thanks to bp_profile_group_has_fields() 151 */ 152 153 /** 154 * @deprecated BuddyPress (2.3.0). 155 * 156 * @access public 157 */ 158 public function next_field() { 99 159 $this->current_field++; 100 160 101 161 $this->field = $this->group->fields[$this->current_field]; 102 162 return $this->field; 103 163 } 104 164 105 function rewind_fields() { 165 /** 166 * @deprecated BuddyPress (2.3.0). 167 * 168 * @access public 169 */ 170 public function rewind_fields() { 106 171 $this->current_field = -1; 107 172 if ( $this->field_count > 0 ) { 108 173 $this->field = $this->group->fields[0]; 109 174 } 110 175 } 111 176 112 function has_fields() { 113 $has_data = false; 114 115 for ( $i = 0, $count = count( $this->group->fields ); $i < $count; ++$i ) { 116 $field = &$this->group->fields[$i]; 117 118 if ( !empty( $field->data ) && $field->data->value != null ) { 119 $has_data = true; 120 } 177 /** 178 * @deprecated BuddyPress (2.3.0). 179 * 180 * @access public 181 */ 182 public function profile_fields() { 183 if ( empty( $this->doing_it_wrong ) ) { 184 _doing_it_wrong( __FUNCTION__, __( 'bp_profile_group_has_fields() should always be used before bp_profile_fields(), please update your templates.', 'buddypress' ), '2.3.0' ); 121 185 } 186 // Display the doing it wrong message once only 187 $this->doing_it_wrong = true; 122 188 123 if ( $has_data )124 return true;125 126 return false;127 }128 129 function profile_fields() {130 189 if ( $this->current_field + 1 < $this->field_count ) { 131 190 return true; 132 191 } elseif ( $this->current_field + 1 == $this->field_count ) { … … class BP_XProfile_Data_Template { 137 196 return false; 138 197 } 139 198 140 function the_profile_field() { 199 /** 200 * @deprecated BuddyPress (2.3.0). 201 * 202 * @access public 203 */ 204 public function the_profile_field() { 141 205 global $field; 142 206 143 207 $field = $this->next_field(); 144 145 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731146 if ( ! empty( $field->data ) && ( ! empty( $field->data->value ) || '0' == $field->data->value ) ) {147 $value = maybe_unserialize( $field->data->value );148 } else {149 $value = false;150 }151 152 if ( ! empty( $value ) || '0' == $value ) {153 $this->field_has_data = true;154 } else {155 $this->field_has_data = false;156 }157 208 } 158 209 } 159 210 … … function bp_has_profile( $args = '' ) { 185 236 ); 186 237 187 238 $r = bp_parse_args( $args, $defaults, 'has_profile' ); 188 extract( $r, EXTR_SKIP );189 239 190 $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_visibility_level, $update_meta_cache ); 191 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template ); 240 $profile_template = new BP_XProfile_Data_Template( 241 $r['user_id'], 242 $r['profile_group_id'], 243 $r['hide_empty_groups'], 244 $r['fetch_fields'], 245 $r['fetch_field_data'], 246 $r['exclude_groups'], 247 $r['exclude_fields'], 248 $r['hide_empty_fields'], 249 $r['fetch_visibility_level'], 250 $r['update_meta_cache'] 251 ); 252 253 return apply_filters( 'bp_has_profile', $profile_template->has_items(), $profile_template ); 192 254 } 193 255 194 256 function bp_profile_groups() { 195 257 global $profile_template; 196 return $profile_template-> profile_groups();258 return $profile_template->items(); 197 259 } 198 260 199 261 function bp_the_profile_group() { 200 262 global $profile_template; 201 return $profile_template->the_ profile_group();263 return $profile_template->the_item(); 202 264 } 203 265 204 function bp_profile_group_has_fields() { 266 /** 267 * xProfile Fields template loop class. 268 * 269 * Responsible for loading fields into a loop for display. 270 * 271 * @since BuddyPress (2.3.0) 272 */ 273 class BP_XProfile_Fields_Template extends BP_Template_Loop { 274 275 /** 276 * Default arguments for xProfile Fields loop. 277 * 278 * @since BuddyPress (2.3.0) 279 * 280 * @access protected 281 * @var array 282 */ 283 protected $default_args = array( 284 'labels' => array( 285 'item' => 'field', 286 'item_plural' => 'fields', 287 'item_total_count' => 'total_field_count', 288 'item_count' => 'field_count', 289 'current_item' => 'current_field', 290 'hook_prefix' => 'xprofile_field', 291 ) ); 292 293 /** 294 * Constructor method. 295 * 296 * @since BuddyPress (2.3.0) 297 * 298 * @param array $fields a list of all field objects 299 * @param int $group_id the profile group id to loop the fields on. 300 * @uses wp_list_filter() 301 */ 302 public function __construct( $fields = null, $group_id = 0 ) { 303 if ( empty( $fields ) || empty( $group_id ) ) { 304 return false; 305 } 306 307 $fields = wp_list_filter( $fields, array( 'group_id' => $group_id ) ); 308 309 $this->set_loop( array( 'fields' => $fields ) ); 310 } 311 312 /** 313 * Get xProfile Fields. 314 * 315 * @since BuddyPress (2.3.0) 316 * 317 * @access public 318 */ 319 public function get_items() { 320 return array( 321 'fields' => $this->args['fields'], 322 'total' => count( $this->args['fields'] ), 323 ); 324 } 325 326 /** 327 * Override parent method as we need to do custom work. 328 * 329 * @since BuddyPress (2.3.0) 330 * 331 * @global $field 332 */ 333 public function the_item() { 334 global $field; 335 336 parent::the_item(); 337 338 if ( empty( $this->field ) ) { 339 return; 340 } 341 342 $field = $this->field; 343 } 344 } 345 346 /** 347 * Initialize the Fields loop for a given xProfile Group 348 * 349 * @global $profile_template 350 * @param array $fields a list of all field objects 351 * @param int $group_id the profile group id to loop the fields on. 352 * @uses BP_XProfile_Fields_Template 353 * @return bool true if fields were found, false otherwise 354 */ 355 function bp_profile_group_has_fields( $fields = array(), $group_id = 0 ) { 205 356 global $profile_template; 206 return $profile_template->has_fields(); 357 358 if ( empty( $fields ) ) { 359 if ( ! empty( $profile_template->group->fields ) ) { 360 $fields =& $profile_template->group->fields; 361 362 // We really need the group fields to init the loop 363 } else { 364 return false; 365 } 366 } 367 368 if ( empty( $group_id ) && ! empty( $profile_template->group->id ) ) { 369 $group_id =& $profile_template->group->id; 370 } 371 372 if ( empty( $profile_template ) ) { 373 $profile_template = new stdClass(); 374 } 375 376 $profile_template->group_fields = new BP_XProfile_Fields_Template( $fields, $group_id ); 377 378 return apply_filters( 'bp_profile_group_has_fields', $profile_template->group_fields->has_items(), $profile_template->group_fields ); 207 379 } 208 380 209 381 function bp_field_css_class( $class = false ) { … … function bp_field_css_class( $class = false ) { 214 386 215 387 $css_classes = array(); 216 388 389 /** 390 * Backcompat check in case bp_profile_group_has_fields() 391 * wasn't used before bp_profile_fields() 392 */ 393 if ( empty( $profile_template->group_fields ) ) { 394 $group_field = $profile_template; 395 } else { 396 $group_field = $profile_template->group_fields; 397 } 398 217 399 if ( $class ) 218 400 $css_classes[] = sanitize_title( esc_attr( $class ) ); 219 401 220 402 // Set a class with the field ID 221 $css_classes[] = 'field_' . $ profile_template->field->id;403 $css_classes[] = 'field_' . $group_field->field->id; 222 404 223 405 // Set a class with the field name (sanitized) 224 $css_classes[] = 'field_' . sanitize_title( $ profile_template->field->name );406 $css_classes[] = 'field_' . sanitize_title( $group_field->field->name ); 225 407 226 408 // Set a class indicating whether the field is required or optional 227 if ( ! empty( $ profile_template->field->is_required ) ) {409 if ( ! empty( $group_field->field->is_required ) ) { 228 410 $css_classes[] = 'required-field'; 229 411 } else { 230 412 $css_classes[] = 'optional-field'; … … function bp_field_css_class( $class = false ) { 233 415 // Add the field visibility level 234 416 $css_classes[] = 'visibility-' . esc_attr( bp_get_the_profile_field_visibility_level() ); 235 417 236 if ( $ profile_template->current_field % 2 == 1 )418 if ( $group_field->current_field % 2 == 1 ) { 237 419 $css_classes[] = 'alt'; 420 } 238 421 239 $css_classes[] = 'field_type_' . sanitize_title( $ profile_template->field->type );422 $css_classes[] = 'field_type_' . sanitize_title( $group_field->field->type ); 240 423 $css_classes = apply_filters_ref_array( 'bp_field_css_classes', array( &$css_classes ) ); 241 424 242 425 return apply_filters( 'bp_get_field_css_class', ' class="' . implode( ' ', $css_classes ) . '"' ); … … function bp_the_profile_field_ids() { 346 529 347 530 function bp_profile_fields() { 348 531 global $profile_template; 349 return $profile_template->profile_fields(); 532 533 /** 534 * Backcompat check in case bp_profile_group_has_fields() 535 * wasn't used before bp_profile_fields() 536 */ 537 if ( empty( $profile_template->group_fields ) ) { 538 return $profile_template->profile_fields(); 539 } 540 541 return $profile_template->group_fields->items(); 350 542 } 351 543 352 544 function bp_the_profile_field() { 353 545 global $profile_template; 354 return $profile_template->the_profile_field(); 546 547 /** 548 * Backcompat check in case bp_profile_group_has_fields() 549 * wasn't used before bp_profile_fields() 550 */ 551 if ( empty( $profile_template->group_fields ) ) { 552 $field = $profile_template->the_profile_field(); 553 } else { 554 $field = $profile_template->group_fields->the_item(); 555 } 556 557 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731 558 if ( ! empty( $field->data ) && ( ! empty( $field->data->value ) || '0' == $field->data->value ) ) { 559 $value = maybe_unserialize( $field->data->value ); 560 } else { 561 $value = false; 562 } 563 564 if ( ! empty( $value ) || '0' == $value ) { 565 $profile_template->field_has_data = true; 566 } else { 567 $profile_template->field_has_data = false; 568 } 569 570 return $field; 355 571 } 356 572 357 573 function bp_the_profile_field_id() {