Skip to content

Instantly share code, notes, and snippets.

@afragen
Created September 3, 2014 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afragen/97ac1e349316f51fd40c to your computer and use it in GitHub Desktop.
Save afragen/97ac1e349316f51fd40c to your computer and use it in GitHub Desktop.
A plugin to show that an admin user really can do anything.
<?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