I have wrote a small plugin that check user permissions and send corresponding JSON to ExtJS client.
<?php
/*
Plugin Name: Check gallery user
Description: Check gallery user
Version: 1.0
*/
if (strpos(__FILE__, 'check_manage_options.php') !== false) {
require('../../../wp-load.php');
$manage_options = 'no';
if (is_user_logged_in() && current_user_can('manage_options')) {
$manage_options = 'yes';
}
$perms = array("perms" => array("perm" => $manage_options));
echo json_encode($perms);
}
?>
With ExtJS it works correctly. But when I try to come on “/wordpress/wp-admin/” URL, I’ve get error:
Warning: require(../../../wp-load.php) [function.require]: failed to
open stream: No such file or directory in
Z:homelocalhostwwwwordpresswp-contentpluginsCheckGalleryUsercheck_manage_options.php
on line 9Fatal error: require() [function.require]: Failed opening required
‘../../../wp-load.php’ (include_path=’.;/usr/local/php5/PEAR’) in
Z:homelocalhostwwwwordpresswp-contentpluginsCheckGalleryUsercheck_manage_options.php
on line 9
Also I tried another approach:
<?php
/*
Plugin Name: Check gallery user
Description: Check gallery user
Version: 1.0
*/
add_action('init', 'check_gallery_user');
function check_gallery_user() {
$manage_options = 'no';
if (is_user_logged_in() && current_user_can('manage_options')) {
$manage_options = 'yes';
}
}
$perms = array("perms" => array("perm" => $manage_options));
echo json_encode($perms);
?>
Then I get such error:
Fatal error: Call to undefined function add_action() in
Z:homelocalhostwwwwordpresswp-contentpluginsCheckGalleryUsercheck_manage_options.php
on line 7
please try below approach
And then when you send request just send it to
http://your-site/?cgu_check=check
Problem solved!
In addition I have set output_buffering = On in php.ini because this code caused an “Warning: Cannot modify header information – headers already sent” warning on “/wordpress/wp-admin/” URL.
Thank you!