user_can example

// Make sure that the comment post ID is valid (if specified).     if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
        if ( $wp_error ) {
            return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) );
        } else {
            return false;
        }
    }

    $filter_comment = false;
    if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
        $filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
    }

    if ( $filter_comment ) {
        add_filter( 'pre_comment_content', 'wp_filter_kses' );
    }

    // Escape data pulled from DB.     $comment = wp_slash( $comment );

    $old_status = $comment['comment_approved'];

    

function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
    $user_id = $user_id ? (int) $user_id : get_current_user_id();

    $blogs = get_blogs_of_user( $user_id );

    if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
        $url = user_admin_url( $path$scheme );
    } elseif ( ! is_multisite() ) {
        $url = admin_url( $path$scheme );
    } else {
        $current_blog = get_current_blog_id();

        if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blogarray_keys( $blogs ), true ) ) ) {
            $url = admin_url( $path$scheme );
        } else {
            $active = get_active_blog_for_user( $user_id );
            if ( $active ) {
                
// The comment was left by the author.         if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) {
            unset( $emails[ $author->user_email ] );
        }

        // The author moderated a comment on their own post.         if ( $author && ! $notify_author && get_current_user_id() == $post->post_author ) {
            unset( $emails[ $author->user_email ] );
        }

        // The post author is no longer a member of the blog.         if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
            unset( $emails[ $author->user_email ] );
        }

        // If there's no email to send the comment to, bail, otherwise flip array back around for use below.         if ( ! count( $emails ) ) {
            return false;
        } else {
            $emails = array_flip( $emails );
        }

        $switched_locale = switch_to_locale( get_locale() );

        
case 'add_users':
            $caps[] = 'promote_users';
            break;
        case 'edit_user':
        case 'edit_users':
            // Allow user to edit themselves.             if ( 'edit_user' === $cap && isset( $args[0] ) && $user_id == $args[0] ) {
                break;
            }

            // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin.             if ( is_multisite() && ( ( ! is_super_admin( $user_id ) && 'edit_user' === $cap && is_super_admin( $args[0] ) ) || ! user_can( $user_id, 'manage_network_users' ) ) ) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = 'edit_users'; // edit_user maps to edit_users.             }
            break;
        case 'delete_post':
        case 'delete_page':
            if ( ! isset( $args[0] ) ) {
                if ( 'delete_post' === $cap ) {
                    /* translators: %s: Capability name. */
                    $message = __( 'When checking for the %s capability, you must always check it against a specific post.' );
                }
if ( $id <= 0 ) {
                return $error;
            }

            $user = get_userdata( $id );
        }

        if ( empty( $user ) || ! $user->exists() ) {
            return $error;
        }

        if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) {
            return $error;
        }

        if ( ! wp_is_application_passwords_available_for_user( $user ) ) {
            return new WP_Error(
                'application_passwords_disabled_for_user',
                __( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' ),
                array( 'status' => 501 )
            );
        }

        

function get_allowed_mime_types( $user = null ) {
    $t = wp_get_mime_types();

    unset( $t['swf']$t['exe'] );
    if ( function_exists( 'current_user_can' ) ) {
        $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
    }

    if ( empty( $unfiltered ) ) {
        unset( $t['htm|html']$t['js'] );
    }

    /** * Filters the list of allowed mime types and file extensions. * * @since 2.0.0 * * @param array $t Mime types keyed by the file extension regex corresponding to those types. * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user). */
// Remove all permissions that may exist for the site.     $table_prefix = $wpdb->get_blog_prefix();
    delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true );   // Delete all.     delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // Delete all.
    // Install default site content.     wp_install_defaults( $args['user_id'] );

    // Set the site administrator.     add_user_to_blog( $site->id, $args['user_id'], 'administrator' );
    if ( ! user_can( $args['user_id'], 'manage_network' ) && ! get_user_meta( $args['user_id'], 'primary_blog', true ) ) {
        update_user_meta( $args['user_id'], 'primary_blog', $site->id );
    }

    if ( $switch ) {
        restore_current_blog();
    }

    wp_installing( $orig_installing );

    return true;
}

<?php checked( 'false', $profile_user->rich_editing ); ?> /> <?php _e( 'Disable the visual editor when writing' ); ?> </label> </td> </tr> <?php endif; ?> <?php                     $show_syntax_highlighting_preference = (
                    // For Custom HTML widget and Additional CSS in Customizer.                     user_can( $profile_user, 'edit_theme_options' )
                    ||
                    // Edit plugins.                     user_can( $profile_user, 'edit_plugins' )
                    ||
                    // Edit themes.                     user_can( $profile_user, 'edit_themes' )
                    );
                    ?> <?php if ( $show_syntax_highlighting_preference ) : ?> <tr class="user-syntax-highlighting-wrap"> <th scope="row">
Home | Imprint | This part of the site doesn't use cookies.