map_meta_cap example


    public function grant_edit_post_capability_for_changeset( $caps$cap$user_id$args ) {
        if ( 'edit_post' === $cap && ! empty( $args[0] ) && 'customize_changeset' === get_post_type( $args[0] ) ) {
            $post_type_obj = get_post_type_object( 'customize_changeset' );
            $caps          = map_meta_cap( $post_type_obj->cap->$cap$user_id );
        }
        return $caps;
    }

    /** * Marks the changeset post as being currently edited by the current user. * * @since 4.9.0 * * @param int $changeset_post_id Changeset post ID. * @param bool $take_over Whether to take over the changeset. Default false. */
$caps[] = $post_type->cap->delete_published_posts;
                } elseif ( 'private' === $post->post_status ) {
                    $caps[] = $post_type->cap->delete_private_posts;
                }
            }

            /* * Setting the privacy policy page requires `manage_privacy_options`, * so deleting it should require that too. */
            if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) {
                $caps = array_merge( $capsmap_meta_cap( 'manage_privacy_options', $user_id ) );
            }

            break;
        /* * edit_post breaks down to edit_posts, edit_published_posts, or * edit_others_posts. */
        case 'edit_post':
        case 'edit_page':
            if ( ! isset( $args[0] ) ) {
                if ( 'edit_post' === $cap ) {
                    

    public function has_cap( $cap, ...$args ) {
        if ( is_numeric( $cap ) ) {
            _deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) );
            $cap = $this->translate_level_to_cap( $cap );
        }

        $caps = map_meta_cap( $cap$this->ID, ...$args );

        // Multisite super admin has all caps by definition, Unless specifically denied.         if ( is_multisite() && is_super_admin( $this->ID ) ) {
            if ( in_array( 'do_not_allow', $caps, true ) ) {
                return false;
            }
            return true;
        }

        // Maintain BC for the argument passed to the "user_has_cap" filter.         $args = array_merge( array( $cap$this->ID )$args );

        
Home | Imprint | This part of the site doesn't use cookies.