Ticket #4728: 4728.02.patch
File 4728.02.patch, 7.4 KB (added by , 9 years ago) |
---|
-
src/bp-core/bp-core-functions.php
2542 2542 2543 2543 return $bp->upload_dir; 2544 2544 } 2545 2546 /** Visibility ***************************************************************/ 2547 2548 /** 2549 * Registers a visiblity level with BuddyPress. 2550 * 2551 * Run this on the 'bp_setup_globals' action. 2552 * 2553 * @since BuddyPress (2.4.0) 2554 * 2555 * @param array $args { 2556 * Array of arguments. 2557 * @type string $id The ID for the visibility level. Required. 2558 * @type string $label Label for the visibility level. Required. 2559 * @type int $position Position to order the visibility level. Optional. Default: 99. 2560 * } 2561 * @return bool 2562 */ 2563 function bp_register_visibility_level( $args = array() ) { 2564 $r = bp_parse_args( $args, array( 2565 'id' => '', 2566 'label' => '', 2567 'position' => 99 2568 ), 'register_visibility_level' ); 2569 2570 if ( empty( $r['id'] ) || empty( $r['label'] ) ) { 2571 return false; 2572 } 2573 2574 $bp = buddypress(); 2575 2576 $id = sanitize_key( $r['id'] ); 2577 unset( $r['id'] ); 2578 if ( ! empty( $bp->core->visibility_levels[ $id ] ) ) { 2579 return false; 2580 } 2581 2582 // register the level 2583 $bp->core->visibility_levels[ $id ]['id'] = $id; 2584 2585 // left open so plugins can add parameters if needed (callbacks, etc.) 2586 $bp->core->visibility_levels[ $id ] = array_merge( $bp->core->visibility_levels[ $id ], $r ); 2587 2588 return true; 2589 } 2590 2591 /** 2592 * Deregisters a BuddyPress visiblity level. 2593 * 2594 * Run this on the 'bp_setup_globals' if needed. 2595 * 2596 * @since BuddyPress (2.4.0) 2597 * 2598 * @param string $id The ID of the visibility level to deregister. 2599 * @return bool 2600 */ 2601 function bp_deregister_visibility_level( $id = '' ) { 2602 if ( empty( $id ) ) { 2603 return false; 2604 } 2605 2606 $bp = buddypress(); 2607 2608 if ( empty( $bp->core->visibility_levels[$id] ) ) { 2609 return false; 2610 } 2611 2612 unset( $bp->core->visibility_levels[$id] ); 2613 return true; 2614 } 2615 2616 /** 2617 * Get available visibility levels for BuddyPress. 2618 * 2619 * @since BuddyPress (2.4.0) 2620 * 2621 * @return array 2622 */ 2623 function bp_core_get_visibility_levels() { 2624 2625 /** 2626 * Filters the visibility levels. 2627 * 2628 * @since BuddyPress (2.4.0) 2629 * 2630 * @param array Array of visibility levels. 2631 */ 2632 return apply_filters( 'bp_core_get_visibility_levels', buddypress()->core->visibility_levels ); 2633 } 2634 2635 /** 2636 * Sorts visibility levels by the 'position' subkey. 2637 * 2638 * Used only once. 2639 * 2640 * @since BuddyPress (2.4.0) 2641 * 2642 * @access private 2643 */ 2644 function _bp_core_sort_visibility_levels() { 2645 $bp = buddypress(); 2646 $temp = bp_sort_by_key( $bp->core->visibility_levels, 'position', 'num' ); 2647 2648 $bp->core->visibility_levels = array(); 2649 foreach( $temp as $level ) { 2650 $bp->core->visibility_levels[ $level['id'] ] = $level; 2651 } 2652 unset( $temp ); 2653 } 2654 add_action( 'bp_setup_globals', '_bp_core_sort_visibility_levels', 999 ); 2655 No newline at end of file -
src/bp-core/bp-core-loader.php
15 15 class BP_Core extends BP_Component { 16 16 17 17 /** 18 * Visibility levels. 19 * 20 * @since BuddyPress (2.4.0) 21 * 22 * @var array 23 */ 24 public $visibility_levels = array(); 25 26 /** 18 27 * Start the members component creation process. 19 28 * 20 29 * @since BuddyPress (1.5.0) -
src/bp-friends/bp-friends-loader.php
95 95 ); 96 96 97 97 parent::setup_globals( $args ); 98 99 // Register visibility level 100 bp_register_visibility_level( array( 101 'id' => 'friends', 102 'label' => _x( 'My Friends', 'Visibility level setting', 'buddypress' ) 103 ) ); 98 104 } 99 105 100 106 /** -
src/bp-members/bp-members-loader.php
146 146 $bp->profile->slug = 'profile'; 147 147 $bp->profile->id = 'profile'; 148 148 } 149 150 /** Visibility ********************************************************/ 151 152 bp_register_visibility_level( array( 153 'id' => 'public', 154 'label' => _x( 'Everyone', 'Visibility level setting', 'buddypress' ), 155 'position' => 10 156 ) ); 157 bp_register_visibility_level( array( 158 'id' => 'adminsonly', 159 'label' => _x( 'Only Me', 'Visibility level setting', 'buddypress' ), 160 'position' => 20 161 ) ); 162 bp_register_visibility_level( array( 163 'id' => 'loggedin', 164 'label' => _x( 'All Members', 'Visibility level setting', 'buddypress' ), 165 'position' => 30 166 ) ); 149 167 } 150 168 151 169 /** -
src/bp-xprofile/bp-xprofile-functions.php
997 997 * 998 998 * @param array $visibility_levels Array of visibility levels. 999 999 */ 1000 return apply_filters( 'bp_xprofile_get_visibility_levels', b uddypress()->profile->visibility_levels);1000 return apply_filters( 'bp_xprofile_get_visibility_levels', bp_core_get_visibility_levels() ); 1001 1001 } 1002 1002 1003 1003 /** -
src/bp-xprofile/bp-xprofile-loader.php
116 116 // but it must be whitelisted 117 117 $this->field_types[] = 'option'; 118 118 119 // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter 120 $this->visibility_levels = array( 121 'public' => array( 122 'id' => 'public', 123 'label' => _x( 'Everyone', 'Visibility level setting', 'buddypress' ) 124 ), 125 'adminsonly' => array( 126 'id' => 'adminsonly', 127 'label' => _x( 'Only Me', 'Visibility level setting', 'buddypress' ) 128 ), 129 'loggedin' => array( 130 'id' => 'loggedin', 131 'label' => _x( 'All Members', 'Visibility level setting', 'buddypress' ) 132 ) 133 ); 134 135 if ( bp_is_active( 'friends' ) ) { 136 $this->visibility_levels['friends'] = array( 137 'id' => 'friends', 138 'label' => _x( 'My Friends', 'Visibility level setting', 'buddypress' ) 139 ); 140 } 119 /** 120 * Visibility levels. 121 * 122 * @since BuddyPress (2.4.0) Core now handles visibility levels. For backpat, we byref core's visibility 123 * levels. See bp_core_get_visibility_levels(). 124 */ 125 $this->visibility_levels = & buddypress()->core->visibility_levels; 141 126 142 127 // Tables 143 128 $global_tables = array( -
tests/phpunit/testcases/core/functions.php
685 685 // Reset buddypress() vars 686 686 $bp->active_components = $reset_active_components; 687 687 } 688 689 /** 690 * @group bp_register_visibility_level 691 * @group bp_deregister_visibility_level 692 */ 693 public function test_bp_register_visibility_level_and_bp_deregister_visibility_level() { 694 // register a visibility level 695 bp_register_visibility_level( array( 696 'id' => 'nohomers', 697 'label' => 'No Homers', 698 ) ); 699 $this->assertTrue( isset( buddypress()->core->visibility_levels['nohomers'] ) ); 700 701 // deregister the level 702 bp_deregister_visibility_level( 'nohomers' ); 703 $this->assertFalse( isset( buddypress()->core->visibility_levels['nohomers'] ) ); 704 } 688 705 }