Plugin Directory

Changeset 825140


Ignore:
Timestamp:
12/18/2013 11:48:11 PM (12 years ago)
Author:
scriptrunner
Message:

replaced current_user_can function with WordPress Check User Role Function from AppThemes

Location:
wp-admin-no-show/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-admin-no-show/trunk/readme.txt

    r794104 r825140  
    44Tags: admin bar, admin menu, dashboard, disable, remove, hide
    55Requires at least: 3.1
    6 Tested up to: 3.7
    7 Stable tag: 1.4.2
     6Tested up to: 3.8
     7Stable tag: 1.4.3
    88License: MIT License
    99License URI: http://www.opensource.org/licenses/mit-license.php
     
    3939
    4040== Changelog ==
     41
     42= 1.4.3 =
     43* Removed improper use of current_user_can("role") function with WordPress Check User Role Function (AppThemes). Thanks to @massimopadovan for pointing it out.
     44* Tested for WordPress 3.8 compatibility.
    4145
    4246= 1.4.2 =
  • wp-admin-no-show/trunk/wp-admin-no-show.php

    r794104 r825140  
    44Plugin URI: http://www.dougsparling.org
    55Description: Efectively blocks admin portion of site for selected user roles. Any attempt to manually navigate to wp-admin section of site and user will be redirected to selected site page. Hides admin bar.
    6 Version: 1.4.2
     6Version: 1.4.3
    77Author: Doug Sparling
    88Author URI: http://www.dougsparling.org
     
    6868                // whitelist administrator for redirect
    6969                continue;
    70             } else if ( current_user_can( $role ) ) {
     70            } else if ( wp_admin_no_show_check_user_role( $role ) ) {
    7171                $disable = true;
    7272            }
     
    116116        }
    117117        foreach ( $blacklist_roles as $role ) {
    118             if ( current_user_can( $role ) ) {
     118            if ( wp_admin_no_show_check_user_role( $role ) ) {
    119119                $disable = true;
    120120            }
     
    129129}
    130130add_action( 'init', 'wp_admin_no_show_admin_bar_disable' );
     131
     132/**
     133 * Checks if a particular user has a role.
     134 * Returns true if a match was found.
     135 * http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/
     136 *
     137 * @param string $role Role name.
     138 * @param int $user_id (Optional) The ID of a user. Defaults to the current user.
     139 * @return bool
     140 */
     141function wp_admin_no_show_check_user_role( $role, $user_id = null ) {
     142    if ( is_numeric( $user_id ) )
     143        $user = get_userdata( $user_id );
     144    else
     145        $user = wp_get_current_user();
     146
     147    if ( empty( $user ) )
     148        return false;
     149
     150    return in_array( $role, (array) $user->roles );
     151}
    131152
    132153/**
Note: See TracChangeset for help on using the changeset viewer.