88 public static function update( $user_id, $post_data )
92 $value = isset( $post_data[self::LAST_TIME_SUCCESS_LOGIN] ) ? $post_data[self::LAST_TIME_SUCCESS_LOGIN] :
'';
93 if ( !empty( $value ) ) {
94 $value = strtotime( $value );
95 update_user_meta( $user_id, self::LAST_TIME_SUCCESS_LOGIN, $value );
99 $value = isset( $post_data[self::COUNT_SUCCESS_LOGIN] ) ? $post_data[self::COUNT_SUCCESS_LOGIN] :
'';
100 update_user_meta( $user_id, self::COUNT_SUCCESS_LOGIN, $value );
103 $value = isset( $post_data[self::LAST_TIME_WRONG_LOGIN] ) ? $post_data[self::LAST_TIME_WRONG_LOGIN] :
'';
104 if ( !empty( $value ) ) {
105 $value = strtotime( $value );
106 update_user_meta( $user_id, self::LAST_TIME_WRONG_LOGIN, $value );
110 $value = isset( $post_data[self::COUNT_WRONG_LOGIN] ) ? $post_data[self::COUNT_WRONG_LOGIN] :
'';
111 update_user_meta( $user_id, self::COUNT_WRONG_LOGIN, $value );
114 $value = isset( $post_data[self::LAST_TIME_LOGOUT] ) ? $post_data[self::LAST_TIME_LOGOUT] :
'';
115 if ( !empty( $value ) ) {
116 $value = strtotime( $value );
117 update_user_meta( $user_id, self::LAST_TIME_LOGOUT, $value );
121 $value = isset( $post_data[self::STATUS] ) ? $post_data[self::STATUS] :
'';
122 update_user_meta( $user_id, self::STATUS, $value );
125 $value = isset( $post_data[self::STATUS_DESCRIPTION] ) ? $post_data[self::STATUS_DESCRIPTION] :
'';
126 update_user_meta( $user_id, self::STATUS_DESCRIPTION, $value );
162 '' => __(
'Not set' ),
163 self::DISABLED => __(
'Disabled' ),
165 return apply_filters(
'wpdk_user_status_statuses', $statuses );
269 if( !is_user_logged_in() ) {
287 public function __construct( $user = 0, $name =
'', $blog_id =
'' )
293 if ( is_numeric( $user ) ) {
297 if ( empty( $id_user ) ) {
298 $id_user = get_current_user_id();
301 elseif ( is_object( $user ) && isset( $user->ID ) ) {
302 $id_user = absint( $user->ID );
304 elseif ( is_array( $user ) && isset( $user[
'ID'] ) ) {
305 $id_user = absint( $user[
'ID'] );
309 elseif ( is_string( $user ) && is_email( $user ) ) {
310 $user = get_user_by(
'email', $user );
311 $id_user = $user->ID;
314 parent::__construct( $id_user, $name, $blog_id );
317 if ( !empty( $id_user ) ) {
318 $this->first_name = $this->
get(
'first_name' );
319 $this->last_name = $this->
get(
'last_name' );
320 $this->
nice_name = $this->data->user_nicename;
322 $this->display_name = $this->data->display_name;
323 $this->email = sanitize_email( $this->data->user_email );
328 $this->data->ID = absint( $id_user );
342 public static function nice_name( $firstName, $lastName )
344 $result = sprintf(
'%s.%s', strtoupper( substr( $firstName, 0, 1 ) ), ucfirst( $lastName ) );
359 public static function full_name( $firstName, $lastName, $nameFirst =
true )
362 $result = sprintf(
'%s %s', $firstName, $lastName );
365 $result = sprintf(
'%s %s', $lastName, $firstName );
411 $user_id = is_null( $user_id ) ? get_current_user_id() : $user_id;
413 $pre = apply_filters(
'pre_user_transient_' . $transient,
false, $user_id );
414 if (
false !== $pre ) {
418 $transient_timeout =
'_transient_timeout_' . $transient;
419 $transient =
'_transient_' . $transient;
420 if ( get_user_meta( $user_id, $transient_timeout,
true ) < time() ) {
421 delete_user_meta( $user_id, $transient );
422 delete_user_meta( $user_id, $transient_timeout );
426 $value = get_user_meta( $user_id, $transient,
true );
428 return apply_filters(
'user_transient_' . $transient, $value, $user_id );
448 if( !empty( $this->ID ) ) {
449 return self::getTransientWithUser( $transient, $this->ID );
466 $user_id = is_null( $user_id ) ? get_current_user_id() : $user_id;
467 $transient_timeout =
'_transient_timeout_' . $transient;
468 return get_user_meta( $user_id, $transient_timeout,
true );
483 if ( !empty( $this->ID ) ) {
484 return self::getTransientTimeWithUser( $transient, $this->ID );
510 $user_id = is_null( $user_id ) ? get_current_user_id() : $user_id;
512 $value = apply_filters(
'pre_set_user_transient_' . $transient, $value, $user_id );
514 $transient_timeout =
'_transient_timeout_' . $transient;
515 $transient =
'_transient_' . $transient;
516 if (
false === get_user_meta( $user_id, $transient,
true ) ) {
518 update_user_meta( $user_id, $transient_timeout, time() + $expiration );
520 $result = update_user_meta( $user_id, $transient, $value );
524 update_user_meta( $user_id, $transient_timeout, time() + $expiration );
526 $result = update_user_meta( $user_id, $transient, $value );
530 do_action(
'set_user_transient_' . $transient );
531 do_action(
'setted_user_transient', $transient, $user_id );
554 if ( !empty( $this->ID ) ) {
555 self::setTransientWithUser( $transient, $value, $expiration, $this->ID );
575 public function gravatar( $size = 40, $alt =
'', $default =
"wavatar" )
577 return WPDKUsers::init()->gravatar( $this->ID, $size, $alt, $default );
608 public function age( $birthday )
612 if ( !empty( $birthday ) ) {
613 if (
false !== strpos( $birthday,
'-' ) ) {
614 list( $year, $month, $day ) = explode(
'-', $birthday );
617 list( $day, $month, $year ) = explode(
'/', $birthday );
619 $year_diff = date(
'Y' ) - $year;
620 $month_diff = date(
'm' ) - $month;
621 $day_diff = date(
'd' ) - $day;
622 if ( $month_diff < 0 || ( $month_diff == 0 && $day_diff < 0 ) ) {
626 return intval( $year_diff );
646 if ( !isset( $wp_roles ) ) {
647 $wp_roles =
new WP_Roles();
650 $current_roles = $this->roles;
651 if ( is_array( $roles ) ) {
652 foreach ( $roles as $role ) {
653 if ( in_array( $role, $current_roles ) ) {
660 return in_array( $roles, $current_roles );
675 $id_user = absint( $id_user );
676 $user =
new WP_User( $id_user );
677 if ( !empty( $user ) ) {
678 $role_key = $user->roles[key( $user->roles )];
679 if ( !empty( $role_key ) ) {
680 return $wp_roles->roles[$role_key][
'name'];
697 public static function hasCap( $cap, $id_user = null )
699 if ( is_null( $id_user ) ) {
700 $id_user = get_current_user_id();
702 $user =
new WP_User( $id_user );
704 return $user->has_cap( $cap );
721 $all_caps = $this->allcaps;
722 if ( is_array( $caps ) ) {
723 foreach ( $caps as $cap ) {
724 if ( isset( $all_caps[$cap] ) ) {
730 return in_array( $all_caps, $caps );
748 $roles = $wp_roles->get_names();
749 foreach ( $roles as $key => $rolename ) {
750 $role = get_role( $key );
751 $merge = array_merge( $merge, $role->capabilities );
753 $result = array_keys( $merge );
755 $result = array_combine( $result, $result );
773 if ( $id_user && is_array( $selected_caps ) ) {
774 $user =
new WP_User( $id_user );
775 foreach ( $capabilities as $key => $cap ) {
776 if ( in_array( $key, $selected_caps ) ) {
778 $user->add_cap( $key );
782 $user->remove_cap( $key );
820 static $instance = null;
821 if ( is_null( $instance ) ) {
835 private function __construct()
841 add_action(
'init', array( $this,
'logout' ) );
848 add_action(
'wp_login', array( $this,
'wp_login' ) );
849 add_action(
'wp_logout', array( $this,
'wp_logout' ) );
850 add_action(
'wp_login_failed', array( $this,
'wp_login_failed' ) );
856 add_action(
'delete_user', array( $this,
'delete_user' ) );
857 add_action(
'deleted_user', array( $this,
'deleted_user' ) );
860 add_action(
'show_user_profile', array( $this,
'show_user_profile' ) );
861 add_action(
'personal_options_update', array( $this,
'personal_options_update' ) );
862 add_action(
'personal_options', array( $this,
'personal_options' ) );
863 add_action(
'profile_personal_options', array( $this,
'profile_personal_options' ) );
866 add_action(
'edit_user_profile', array( $this,
'edit_user_profile' ) );
867 add_action(
'edit_user_profile_update', array( $this,
'edit_user_profile_update' ) );
872 add_filter(
'wp_authenticate_user', array( $this,
'wp_authenticate_user' ), 1 );
874 add_filter(
'user_contactmethods', array( $this,
'user_contactmethods' ) );
885 if ( is_user_logged_in() ) {
886 $user_id = get_current_user_id();
896 if ( isset( $_REQUEST[
'wpdk_logout'] ) ) {
900 if (
true === $logout ) {
904 wp_safe_redirect( wp_login_url( wp_get_referer() ) );
907 wp_safe_redirect( stripslashes( $_SERVER[
'REQUEST_URI'] ) );
930 if ( is_wp_error( $user ) ) {
939 $continue = apply_filters(
'wpdk_users_should_denied_signin',
true, $user->ID, $status );
942 $message = apply_filters(
'wpdk_users_access_denied_status_description', $message, $user->ID, $status );
943 return new WP_Error(
'wpdk_users_access_denied', $message, array(
961 public function wp_login( $user_login, $user = null )
965 if ( is_null( $user ) ) {
966 $user = get_user_by(
'login', $user_login );
971 if ( empty( $count ) ) {
991 if ( empty( $user_login ) ) {
995 $user = get_user_by(
'login', $user_login );
998 if (
false === $user ) {
1003 if ( empty( $count ) ) {
1012 do_action(
'wpdk_user_wrong_login_count', $user->ID, $count );
1033 public function signIn( $user, $password, $remember =
false )
1040 if ( is_numeric( $user ) ) {
1044 elseif ( is_email( $user ) ) {
1046 $email = sanitize_email( $user );
1048 $user_id = email_exists( $email );
1052 $user = get_user_by(
'login', $user );
1054 $user_id = $user->ID;
1058 if (
false !== $user_id ) {
1061 $result = wp_authenticate( $user->user_login, $password );
1062 if ( !is_wp_error( $result ) ) {
1064 wp_set_auth_cookie( $user->ID, $remember );
1065 do_action(
'wp_login', $user->user_login, $user );
1068 $this->
wp_login( $user->user_login, $user );
1071 wp_set_current_user( $user->ID );
1077 do_action(
'wpdk_singin_wrong', empty( $email ) ? $user_id : $email, $password );
1095 if ( empty( $email ) || empty( $password ) ) {
1099 $id_user = email_exists( $email );
1100 if ( !empty( $id_user ) ) {
1102 $access = wp_authenticate( $user->data->user_login, $password );
1103 if ( !is_wp_error( $access ) ) {
1121 $user_id = get_current_user_id();
1122 if ( !empty( $user_id ) ) {
1143 $blog_url = get_bloginfo(
'url' );
1144 wp_safe_redirect( $blog_url );
1164 public function create( $first_name, $last_name, $email, $password =
false, $enabled =
false, $role =
'subscriber' )
1168 if (
false === $password ) {
1171 do_action(
'wpdk_users_random_password', $password );
1178 'user_login' => $email,
1179 'user_pass' => $password,
1180 'user_email' => $email,
1181 'user_nicename' => $nice_name,
1182 'nickname' => $nice_name,
1183 'display_name' => $display_name,
1184 'first_name' => $first_name,
1185 'last_name' => $last_name,
1189 $user_id = wp_insert_user( $user_data );
1191 if ( is_wp_error( $user_id ) ) {
1196 if ( isset( $_SERVER[
'REMOTE_ADDR'] ) && !empty( $_SERVER[
'REMOTE_ADDR'] ) ) {
1201 if (
false === $enabled ) {
1205 $status_description = apply_filters(
'wpdk_users_status_description',
'', $user_id );
1228 echo
'<br clear="all" /><a name="wpdk"></a>';
1230 $message = __(
'This view <strong>is enhanced</strong> by wpXtreme and WPDK framework. Please, have a look below for additional information.', WPDK_TEXTDOMAIN );
1231 $alert =
new WPDKTwitterBootstrapAlert(
'wpdk-alert-show_user_profile', $message, WPDKTwitterBootstrapAlertType::INFORMATION );
1232 $alert->permanent_dismiss =
true;
1236 $disabled = !current_user_can(
'manage_options' );
1245 __(
'Login information', WPDK_TEXTDOMAIN ) => array(
1250 'label' => __(
'Last success login', WPDK_TEXTDOMAIN ),
1251 'value' => empty( $last_time_success_login ) ?
'' : date( __(
'm/d/Y H:i', WPDK_TEXTDOMAIN ), $last_time_success_login ),
1252 'disabled' => $disabled
1257 'label' => __(
'# success login', WPDK_TEXTDOMAIN ),
1266 'label' => __(
'Last wrong login', WPDK_TEXTDOMAIN ),
1267 'value' => empty( $last_time_wrong_login ) ?
'' : date( __(
'm/d/Y H:i', WPDK_TEXTDOMAIN ), $last_time_wrong_login ),
1268 'disabled' => $disabled
1273 'label' => __(
'# wrong login', WPDK_TEXTDOMAIN ),
1275 'disabled' => $disabled
1280 __(
'Logout information', WPDK_TEXTDOMAIN ) => array(
1285 'label' => __(
'Last logout', WPDK_TEXTDOMAIN ),
1286 'value' => empty( $last_time_logout ) ?
'' : date( __(
'm/d/Y H:i', WPDK_TEXTDOMAIN ), $last_time_logout ),
1287 'disabled' => $disabled
1292 __(
'Status', WPDK_TEXTDOMAIN ) => array(
1297 'label' => __(
'Status', WPDK_TEXTDOMAIN ),
1300 'disabled' => $disabled
1309 'label' => __(
'Description', WPDK_TEXTDOMAIN ),
1310 'placeholder' => __(
'eg: this user is disabled because...', WPDK_TEXTDOMAIN ),
1311 'value' => $status_description,
1312 'disabled' => $disabled,
1318 $fields = apply_filters(
'wpdk_users_fields_profile', $fields, $user );
1323 do_action(
'wpdk_users_show_user_profile', $user );
1351 $message = __(
'This view <strong>is enhanced</strong> by wpXtreme and WPDK framework. Please, <strong><a href="#wpdk">have a look below</a></strong> for additional information.', WPDK_TEXTDOMAIN );
1352 $alert =
new WPDKTwitterBootstrapAlert(
'wpdk-alert-personal_options', $message, WPDKTwitterBootstrapAlertType::INFORMATION );
1353 $alert->permanent_dismiss =
true;
1404 if ( !current_user_can(
'edit_user' ) ) {
1409 if ( current_user_can(
'manage_options' ) ) {
1496 FROM {$wpdb->usermeta}
1497 WHERE meta_key =
'{$meta_key}'
1498 AND meta_value =
'{$meta_value}'
1500 $result = $wpdb->get_var( $sql );
1517 foreach ( $users_caps as $user_id => $caps ) {
1518 $keys = array_keys( $caps );
1519 if ( in_array( $find_caps, $keys ) ) {
1520 $users[] = $user_id;
1542 public function gravatar( $id_user = null, $size = 40, $alt =
'', $default =
'wavatar' )
1544 if ( is_null( $id_user ) ) {
1549 $alt = empty( $alt ) ? $user->display_name : $alt;
1552 $gravatar = is_ssl() ?
'https://secure.gravatar.com/avatar/' :
'http://0.gravatar.com/avatar/';
1554 $src = sprintf(
'%s%s?s=%s&d=%s', $gravatar, md5( $user->email ), $size, $default );
1555 $html = sprintf(
'<img src="%s" alt="%s" title="%s" />', $src, $alt, $alt );
1573 public function avatar( $id_user = null, $size = 40 )
1575 if ( is_null( $id_user ) ) {
1580 $alt = empty( $alt ) ? $user->display_name : $alt;
1582 $default = apply_filters(
'wpdk_default_avatar',
'wavatar' );
1585 $gravatar = is_ssl() ?
'https://secure.gravatar.com/avatar/' :
'http://0.gravatar.com/avatar/';
1587 $src = sprintf(
'%s%s?s=%s&d=%s', $gravatar, md5( $user->email ), $size, $default );
1612 $users_list = get_users();
1613 if ( $users_list ) {
1614 foreach ( $users_list as $user ) {
1615 $user_id =
'' . $user->ID;
1616 $users[$user_id] = sprintf(
'%s (%s)', $user->display_name, $user->user_email );
1640 if ( !isset( $wp_roles ) ) {
1641 $wp_roles =
new WP_Roles();
1646 $roles = $wp_roles->get_names();
1647 foreach ( $roles as $key => $role ) {
1648 $result[$key] = $role;
1719 $role_id = sanitize_title( strtolower( $role ) );
1723 $role_object = $wpdk_roles->get_role( $role_id );
1726 if ( is_null( $role_object ) ) {
1728 if ( empty( $display_name ) ) {
1729 $display_name = ucfirst( $role );
1731 $role_object = $wpdk_roles->add_role( $role_id, $display_name, $capabilities,
$description,
$owner );
1732 $this->displayName = $display_name;
1733 $this->capabilities = $role_object->capabilities;
1734 $this->name = $role_id;
1741 $this->name = $role;
1742 $this->displayName = $wpdk_roles->role_names[$role_id];
1743 $this->capabilities = $role_object->capabilities;
1748 if ( !empty( $extra ) && isset( $extra[$role_id] ) ) {
1749 $this->description = $extra[$role][1];
1750 $this->owner = $extra[$role][2];
1765 if ( !empty( $extra ) ) {
1766 $extra[$this->name] = array(
1870 private $_extendedData;
1879 private static $instance = null;
1889 public static function init()
1891 return self::getInstance();
1903 if ( is_null( self::$instance ) ) {
1906 return self::$instance;
1918 self::$instance = null;
1919 return self::getInstance();
1935 parent::__construct();
1938 $this->_extendedData = get_option( self::OPTION_KEY );
1940 if ( !empty( $this->role_names ) ) {
1941 $this->count = count( $this->role_names );
1953 if ( empty( $this->_extendedData ) ) {
1955 update_option( self::OPTION_KEY, $this->_extendedData );
1978 foreach ( $this->role_names as $role => $name ) {
1980 if ( !empty(
$count ) ) {
1981 $this->
activeRoles[$role] = isset( $this->_extendedData[$role] ) ? $this->_extendedData[$role] : array( $name,
'',
'' );
2003 foreach ( $this->role_names as $role => $name ) {
2006 $this->
inactiveRoles[$role] = isset( $this->_extendedData[$role] ) ? $this->_extendedData[$role] : array( $name,
'',
'' );
2030 if ( !isset( $this->arrayCountUsersByRole ) ) {
2032 $this->arrayCountUsersByRole = array();
2047 $user_count = count_users();
2050 foreach ( $user_count[
'avail_roles'] as $role =>
$count ) {
2051 $this->arrayCountUsersByRole[$role] =
$count;
2056 if ( empty( $user_role ) ) {
2061 if ( !isset( $this->arrayCountUsersByRole[$user_role] ) ) {
2062 $this->arrayCountUsersByRole[$user_role] = 0;
2066 return $this->arrayCountUsersByRole[$user_role];
2082 foreach ( $this->get_names() as $role => $name ) {
2085 $wp_role = $this->get_role( $role );
2086 ksort( $wp_role->capabilities );
2104 return ( array_key_exists( $role, $this->role_names ) );
2117 'administrator' => array(
'Administrator', __(
'Somebody who has access to all the administration features', WPDK_TEXTDOMAIN ),
'WordPress' ),
2118 'editor' => array(
'Editor', __(
'Somebody who can publish and manage posts and pages as well as manage other users posts, etc.', WPDK_TEXTDOMAIN ),
'WordPress' ),
2119 'author' => array(
'Author', __(
'Somebody who can publish and manage their own posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2120 'contributor' => array(
'Contributor', __(
'Somebody who can write and manage their posts but not publish them', WPDK_TEXTDOMAIN ),
'WordPress' ),
2121 'subscriber' => array(
'Subscriber', __(
'Somebody who can only manage their profile', WPDK_TEXTDOMAIN ),
'WordPress' ),
2153 public function add_role( $role, $display_name, $capabilities = array(), $description =
'', $owner =
'' )
2157 foreach ( $capabilities as $cap ) {
2161 $role_object = parent::add_role( $role, $display_name, $caps );
2162 if ( !is_null( $role_object ) ) {
2163 if ( !isset( $this->_extendedData[$role] ) ) {
2164 $this->_extendedData[$role] = array(
2170 update_option( self::OPTION_KEY, $this->_extendedData );
2172 return $role_object;
2184 parent::remove_role( $role );
2185 unset( $this->_extendedData[$role] );
2186 update_option( self::OPTION_KEY, $this->_extendedData );
2204 if ( is_object( $role ) && is_a( $role,
'WPDKRole' ) ) {
2205 $role = $role->name;
2212 <option><?php echo $cap ?></option>
2217 $content = ob_get_contents();
2250 const OPTION_KEY =
'_wpdk_capabilities_extends';
2305 private $_extendedData;
2316 static $instance = null;
2317 if ( is_null( $instance ) ) {
2330 private function __construct()
2334 $this->_extendedData = get_option( self::OPTION_KEY );
2347 sort( $this->capabilities );
2363 public function get_cap( $cap_id )
2369 if ( isset( $this->_extendedData[$cap_id] ) ) {
2370 list( $cap_id, $description, $owner ) = $this->_extendedData[$cap_id];
2402 'activate_plugins' => array(
'activate_plugins', __(
'Allows access to Administration Panel options: Plugins', WPDK_TEXTDOMAIN ),
'WordPress' ),
2403 'add_users' => array(
'add_users', __(
'add_users', WPDK_TEXTDOMAIN ),
'WordPress' ),
2404 'create_users' => array(
'create_users', __(
'create_users', WPDK_TEXTDOMAIN ),
'WordPress' ),
2405 'delete_others_pages' => array(
'delete_others_pages', __(
'delete_others_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2406 'delete_others_posts' => array(
'delete_others_posts', __(
'delete_others_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2407 'delete_pages' => array(
'delete_pages', __(
'delete_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2408 'delete_plugins' => array(
'delete_plugins', __(
'delete_plugins', WPDK_TEXTDOMAIN ),
'WordPress' ),
2409 'delete_posts' => array(
'delete_posts', __(
'delete_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2410 'delete_private_pages' => array(
'delete_private_pages', __(
'delete_private_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2411 'delete_private_posts' => array(
'delete_private_posts', __(
'delete_private_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2412 'delete_published_pages' => array(
'delete_published_pages', __(
'delete_published_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2413 'delete_published_posts' => array(
'delete_published_posts', __(
'delete_published_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2414 'delete_users' => array(
'delete_users', __(
'delete_users', WPDK_TEXTDOMAIN ),
'WordPress' ),
2415 'edit_dashboard' => array(
'edit_dashboard', __(
'edit_dashboard', WPDK_TEXTDOMAIN ),
'WordPress' ),
2416 'edit_files' => array(
'edit_files', __(
'No longer used.', WPDK_TEXTDOMAIN ),
'WordPress' ),
2417 'edit_others_pages' => array(
'edit_others_pages', __(
'edit_others_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2418 'edit_others_posts' => array(
'edit_others_posts', __(
'edit_others_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2419 'edit_pages' => array(
'edit_pages', __(
'edit_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2420 'edit_plugins' => array(
'edit_plugins', __(
'edit_plugins', WPDK_TEXTDOMAIN ),
'WordPress' ),
2421 'edit_posts' => array(
'edit_posts', __(
'edit_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2422 'edit_private_pages' => array(
'edit_private_pages', __(
'edit_private_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2423 'edit_private_posts' => array(
'edit_private_posts', __(
'edit_private_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2424 'edit_published_pages' => array(
'edit_published_pages', __(
'edit_published_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2425 'edit_published_posts' => array(
'edit_published_posts', __(
'edit_published_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2426 'edit_theme_options' => array(
'edit_theme_options', __(
'Allows access to Administration Panel options: Appearance > Widgets, Appearance > Menus, Appearance > Theme Options if they are supported by the current theme, Appearance > Background, Appearance > Header ', WPDK_TEXTDOMAIN ),
'WordPress' ),
2427 'edit_themes' => array(
'edit_themes', __(
'edit_themes', WPDK_TEXTDOMAIN ),
'WordPress' ),
2428 'edit_users' => array(
'edit_users', __(
'Allows access to Administration Panel options: Users', WPDK_TEXTDOMAIN ),
'WordPress' ),
2429 'import' => array(
'import', __(
'import', WPDK_TEXTDOMAIN ),
'WordPress' ),
2430 'install_plugins' => array(
'install_plugins', __(
'Allows access to Administration Panel options: Plugins > Add New ', WPDK_TEXTDOMAIN ),
'WordPress' ),
2431 'install_themes' => array(
'install_themes', __(
'Allows access to Administration Panel options: Appearance > Add New Themes', WPDK_TEXTDOMAIN ),
'WordPress' ),
2432 'list_users' => array(
'list_users', __(
'list_users', WPDK_TEXTDOMAIN ),
'WordPress' ),
2433 'manage_categories' => array(
'manage_categories', __(
'Allows access to Administration Panel options: Posts > Categories, Links > Categories', WPDK_TEXTDOMAIN ),
'WordPress' ),
2434 'manage_links' => array(
'manage_links', __(
'Allows access to Administration Panel options: Links Links > Add New', WPDK_TEXTDOMAIN ),
'WordPress' ),
2435 'manage_options' => array(
'manage_options', __(
'Allows access to Administration Panel options: Settings > General, Settings > Writing, Settings > Reading, Settings > Discussion, Settings > Permalinks, Settings > Miscellaneous', WPDK_TEXTDOMAIN ),
'WordPress' ),
2436 'moderate_comments' => array(
'moderate_comments', __(
'Allows users to moderate comments from the Comments SubPanel (although a user needs the edit_posts Capability in order to access this)', WPDK_TEXTDOMAIN ),
'WordPress' ),
2437 'promote_users' => array(
'promote_users', __(
'promote_users', WPDK_TEXTDOMAIN ),
'WordPress' ),
2438 'publish_pages' => array(
'publish_pages', __(
'publish_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2439 'publish_posts' => array(
'publish_posts', __(
'See and use the "publish" button when editing their post (otherwise they can only save drafts). Can use XML-RPC to publish (otherwise they get a "Sorry, you can not post on this weblog or category.")', WPDK_TEXTDOMAIN ),
'WordPress' ),
2440 'read' => array(
'read', __(
'Allows access to Administration Panel options: Dashboard, Users > Your Profile. Used nowhere in the core code except the menu.php', WPDK_TEXTDOMAIN ),
'WordPress' ),
2441 'read_private_pages' => array(
'read_private_pages', __(
'read_private_pages', WPDK_TEXTDOMAIN ),
'WordPress' ),
2442 'read_private_posts' => array(
'read_private_posts', __(
'read_private_posts', WPDK_TEXTDOMAIN ),
'WordPress' ),
2443 'remove_users' => array(
'remove_users', __(
'remove_users', WPDK_TEXTDOMAIN ),
'WordPress' ),
2444 'switch_themes' => array(
'switch_themes', __(
'Allows access to Administration Panel options: Appearance, Appearance > Themes ', WPDK_TEXTDOMAIN ),
'WordPress' ),
2445 'unfiltered_html' => array(
'unfiltered_html', __(
'Allows user to post HTML markup or even JavaScript code in pages, posts, and comments. Note: Enabling this option for untrusted users may result in their posting malicious or poorly formatted code. ', WPDK_TEXTDOMAIN ),
'WordPress' ),
2446 'unfiltered_upload' => array(
'unfiltered_upload', __(
'unfiltered_upload', WPDK_TEXTDOMAIN ),
'WordPress' ),
2447 'update_core' => array(
'update_core', __(
'update_core', WPDK_TEXTDOMAIN ),
'WordPress' ),
2448 'update_plugins' => array(
'update_plugins', __(
'update_plugins', WPDK_TEXTDOMAIN ),
'WordPress' ),
2449 'update_themes' => array(
'update_themes', __(
'update_themes', WPDK_TEXTDOMAIN ),
'WordPress' ),
2450 'upload_files' => array(
'upload_files', __(
'Allows access to Administration Panel options: Media, Media > Add New ', WPDK_TEXTDOMAIN ),
'WordPress' ),
2454 return apply_filters(
'wpdk_capabilities_defaults', $defaults );
2467 private static function oldLevels()
2469 $old_levels = array(
2470 'level_0' => array(
'level_0',
'',
'WordPress' ),
2471 'level_1' => array(
'level_1',
'',
'WordPress' ),
2472 'level_2' => array(
'level_2',
'',
'WordPress' ),
2473 'level_3' => array(
'level_3',
'',
'WordPress' ),
2474 'level_4' => array(
'level_4',
'',
'WordPress' ),
2475 'level_5' => array(
'level_5',
'',
'WordPress' ),
2476 'level_6' => array(
'level_6',
'',
'WordPress' ),
2477 'level_7' => array(
'level_7',
'',
'WordPress' ),
2478 'level_8' => array(
'level_8',
'',
'WordPress' ),
2479 'level_9' => array(
'level_9',
'',
'WordPress' ),
2480 'level_10' => array(
'level_10',
'',
'WordPress' )
2482 return apply_filters(
'wpdk_capabilities_old_levels', $old_levels );
2510 foreach ( $wpdk_roles->role_objects as $key => $role ) {
2513 if ( is_array( $role->capabilities ) ) {
2516 $exclude = self::oldLevels();
2517 foreach ( $role->capabilities as $cap => $grant ) {
2518 if ( !isset( $exclude[$cap] ) ) {
2519 $capabilities[$cap] = isset( $this->_extendedData[$cap] ) ? $this->_extendedData[$cap] : array(
2553 $sql =
"SELECT user_id, meta_value FROM `{$wpdb->usermeta}` WHERE meta_key = 'wp_capabilities'";
2554 $result = $wpdb->get_results( $sql, ARRAY_A );
2556 foreach ( $result as $user_cap ) {
2558 $temp = array_keys( unserialize( $user_cap[
'meta_value'] ) );
2559 foreach ( $temp as $key ) {
2560 $capabilities[$key] = isset( $this->_extendedData[$key] ) ? $this->_extendedData[$key] : array(
2620 if ( empty( $user_caps ) ) {
2621 $sql =
"SELECT user_id, meta_value FROM `{$wpdb->usermeta}` WHERE meta_key = 'wp_capabilities'";
2622 $result = $wpdb->get_results( $sql, ARRAY_A );
2624 foreach ( $result as $user_cap ) {
2625 $user_caps[$user_cap[
'user_id']] = get_userdata( $user_cap[
'user_id'] )->allcaps;
2703 if ( !empty( $extra ) ) {