It you want to restrict some code in your plugin within WP Admin only for “administrator”, you can’t just use “current_user_can()” as this function is defined after running plugin code. You need to execute your code only when “current_user_can()” is available:


/**
* Admin Functionality
*/
add_action( 'plugins_loaded', 'admin_functionality' );
function admin_functionality()
{
if ( is_admin() )
{
$current_user = wp_get_current_user();
if ( current_user_can('administrator') )
{
require ( plugin_dir_path( __FILE__ ) . 'admin/functions.php');
}
}
}
Dnia napisał: Adgraf.
 

Your email address will not be published. Required fields are marked *

Treść *
Podpis *