I am writing a small php file that is called via ajax from a plugin’s js file to update a user’s role. The file looks like this…
include "../../../../wp-includes/pluggable.php";
global $current_user;
get_currentuserinfo();
$u = new WP_User( $current_user->ID );
$u->add_role( 'trainer3' );
pluggable is the module that contains the get_currentuser() function. But I am getting additional errors (is_ssl() not found). What other WordPress modules do I need to include to gain access to the current user object? The plugin I am using is not one that I wrote. It appears as though they did not include any WordPress hooks. This code works fine in other plugins such as woocommerce.
Thanks!
Include
wp-load.phpinstead or, preferably, use the WordPress ajax actionshttp://codex.wordpress.org/AJAX_in_Plugins