Changeset 8942 for trunk/src/bp-blogs/bp-blogs-functions.php
- Timestamp:
- 08/18/2014 01:15:40 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-blogs/bp-blogs-functions.php
r8935 r8942 768 768 * parses the changes, and records them as necessary in the BP blog tracker. 769 769 * 770 * BuddyPress does not track blogs for Subscribers. 771 * 772 * @param int $user_id The ID of the user. 773 * @param string|bool $role The WP role being assigned to the user 774 * ('subscriber', 'contributor', 'author', 'editor', 'administrator', or 775 * a custom role). Defaults to false. 776 * @param int $blog_id Default: the current blog ID. 770 * BuddyPress does not track blogs for users with the 'subscriber' role by 771 * default, though as of 2.1.0 you can filter 'bp_blogs_get_allowed_roles' to 772 * modify this behavior. 773 * 774 * @param int $user_id The ID of the user 775 * @param string|bool $role User's WordPress role for this blog ID 776 * @param int $blog_id Blog ID user is being added to 777 * 777 778 * @return bool|null False on failure. 778 779 */ 779 780 function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) { 780 781 global $wpdb; 781 782 require_once( ABSPATH . '/wp-admin/includes/user.php' );783 782 784 783 // If no blog ID was passed, use the root blog ID … … 792 791 // Get user capabilities 793 792 $key = $wpdb->get_blog_prefix( $blog_id ). 'capabilities'; 794 $user_roles = bp_get_user_meta( $user_id, $key, true);793 $user_roles = array_keys( bp_get_user_meta( $user_id, $key, true ) ); 795 794 796 795 // User has roles so lets 797 796 if ( ! empty( $user_roles ) ) { 798 797 799 // Look for blog onlyroles800 $blog_roles = array_intersect(801 array_keys( $user_roles ), 802 array_keys( get_editable_roles() )803 );798 // Get blog roles 799 $blog_roles = array_keys( bp_get_current_blog_roles() ); 800 801 // Look for blog only roles of the user 802 $intersect_roles = array_intersect( $user_roles, $blog_roles ); 804 803 805 804 // If there's a role in the array, use the first one. This isn't … … 807 806 // WordPress does not yet have a UI for multiple user roles, it's 808 807 // fine for now. 809 if ( ! empty( $ blog_roles ) ) {810 $role = array_shift( $ blog_roles );808 if ( ! empty( $intersect_roles ) ) { 809 $role = array_shift( $intersect_roles ); 811 810 } 812 811 } 813 812 } 814 813 815 // Bail if no role was found or user is a subscriber816 if ( empty( $role ) || ( $role === 'subscriber') ) {814 // Bail if no role was found or role is not in the allowed roles array 815 if ( empty( $role ) || ! in_array( $role, bp_blogs_get_allowed_roles() ) ) { 817 816 return false; 818 817 } … … 824 823 add_action( 'profile_update', 'bp_blogs_add_user_to_blog' ); 825 824 add_action( 'user_register', 'bp_blogs_add_user_to_blog' ); 825 826 /** 827 * The allowed blog roles a member must have to be recorded into the 828 * `bp_user_blogs` pointer table. 829 * 830 * This added and was made filterable in BuddyPress 2.1.0 to make it easier 831 * to extend the functionality of the Blogs component. 832 * 833 * @since BuddyPress (2.1.0) 834 * 835 * @return string 836 */ 837 function bp_blogs_get_allowed_roles() { 838 return apply_filters( 'bp_blogs_get_allowed_roles', array( 'contributor', 'author', 'editor', 'administrator' ) ); 839 } 826 840 827 841 /**
Note: See TracChangeset
for help on using the changeset viewer.