Created
September 3, 2014 23:41
-
-
Save afragen/97ac1e349316f51fd40c to your computer and use it in GitHub Desktop.
A plugin to show that an admin user really can do anything.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Admin User Can | |
Plugin URI: https://gist.github.com/afragen/97ac1e349316f51fd40c | |
Author: Andy Fragen | |
Author URI: http://thefragens.com/ | |
Description: A plugin to show that an admin user really can do anything. | |
Version: 0.0.1 | |
License: GNU General Public License v2 | |
License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
*/ | |
add_action( 'admin_notices', 'fragen_auc_msg' ); | |
function fragen_auc_msg() { | |
$cap = 'fladort'; | |
$current_user = wp_get_current_user(); | |
$current_user_caps = $current_user->allcaps; | |
$if_strpos = false; | |
if ( array_key_exists( $cap, $current_user_caps ) ) { | |
$msg_arraykey = '`array_key_exists` says you have the capability "' . $cap . '"<br />'; | |
} else { | |
$msg_arraykey = '`array_key_exists` says you don\'t have the capability "' . $cap . '".<br />'; | |
} | |
foreach ( $current_user_caps as $key => $value ) { | |
if ( ! $if_strpos ) { | |
if ( strpos( $key, $cap ) ) { | |
$msg_strpos = '`strpos` says you have the capability "' . $cap . '".<br />'; | |
$if_strpos = true; | |
} else { | |
$msg_strpos = '`strpos` says you don\'t have the capability "' . $cap . '".<br />'; | |
} | |
} | |
} | |
if ( is_admin() ) { | |
if ( current_user_can( $cap ) ) { | |
$msg = 'The current user is ' . key( $current_user->caps ) . ' and can "' . $cap . '"<br />'; | |
} else { | |
$msg = 'The current user is ' . key( $current_user->caps ) . ' and cannot "' . $cap . '"<br />'; | |
} | |
$user_switch = '<p>You need to use <a href="http://wordpress.org/plugins/user-switching/">User Switching plugin</a> to test completely.</p>'; | |
echo '<div class="error"><p>' . $user_switch . $msg . $msg_arraykey . $msg_strpos . '</p></div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment