~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/capabilities.php

  • Committer: Jacek Nykis
  • Date: 2013-08-22 11:13:48 UTC
  • Revision ID: jacek.nykis@canonical.com-20130822111348-c4rttn5cynk5tl3o
Import wordpress 3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
         * @param string $role Role name.
159
159
         * @param string $display_name Role display name.
160
160
         * @param array $capabilities List of role capabilities in the above format.
161
 
         * @return null|WP_Role WP_Role object if role is added, null if already exists.
 
161
         * @return WP_Role|null WP_Role object if role is added, null if already exists.
162
162
         */
163
163
        function add_role( $role, $display_name, $capabilities = array() ) {
164
164
                if ( isset( $this->roles[$role] ) )
239
239
         * @access public
240
240
         *
241
241
         * @param string $role Role name.
242
 
         * @return object|null Null, if role does not exist. WP_Role object, if found.
 
242
         * @return WP_Role|null WP_Role object if found, null if the role does not exist.
243
243
         */
244
244
        function get_role( $role ) {
245
245
                if ( isset( $this->role_objects[$role] ) )
535
535
                        // to int 1.
536
536
                        if ( ! is_numeric( $value ) )
537
537
                                return false;
538
 
                        $value = absint( $value );
 
538
                        $value = intval( $value );
 
539
                        if ( $value < 1 )
 
540
                                return false;
539
541
                } else {
540
542
                        $value = trim( $value );
541
543
                }
803
805
                foreach ( (array) $this->roles as $oldrole )
804
806
                        unset( $this->caps[$oldrole] );
805
807
 
 
808
                $old_roles = $this->roles;
806
809
                if ( !empty( $role ) ) {
807
810
                        $this->caps[$role] = true;
808
811
                        $this->roles = array( $role => true );
812
815
                update_user_meta( $this->ID, $this->cap_key, $this->caps );
813
816
                $this->get_role_caps();
814
817
                $this->update_user_level_from_caps();
815
 
                do_action( 'set_user_role', $this->ID, $role );
 
818
                do_action( 'set_user_role', $this->ID, $role, $old_roles );
816
819
        }
817
820
 
818
821
        /**
1159
1162
        case 'delete_post_meta':
1160
1163
        case 'add_post_meta':
1161
1164
                $post = get_post( $args[0] );
1162
 
                $post_type_object = get_post_type_object( $post->post_type );
1163
 
                $caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
 
1165
                $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
1164
1166
 
1165
1167
                $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false;
1166
1168
 
1175
1177
        case 'edit_comment':
1176
1178
                $comment = get_comment( $args[0] );
1177
1179
                $post = get_post( $comment->comment_post_ID );
1178
 
                $post_type_object = get_post_type_object( $post->post_type );
1179
 
 
1180
 
                $caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );
 
1180
                $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
1181
1181
                break;
1182
1182
        case 'unfiltered_upload':
1183
1183
                if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) )  )
1371
1371
 * @since 2.0.0
1372
1372
 *
1373
1373
 * @param string $role Role name.
1374
 
 * @return object
 
1374
 * @return WP_Role|null WP_Role object if found, null if the role does not exist.
1375
1375
 */
1376
1376
function get_role( $role ) {
1377
1377
        global $wp_roles;
1391
1391
 * @param string $role Role name.
1392
1392
 * @param string $display_name Display name for role.
1393
1393
 * @param array $capabilities List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false );
1394
 
 * @return null|WP_Role WP_Role object if role is added, null if already exists.
 
1394
 * @return WP_Role|null WP_Role object if role is added, null if already exists.
1395
1395
 */
1396
1396
function add_role( $role, $display_name, $capabilities = array() ) {
1397
1397
        global $wp_roles;