strangerstudios / paid-memberships-pro

WordPress membership plugin to restrict access to content and charge recurring subscriptions using Stripe, PayPal, and more. Fully open source. 100% GPL.
https://www.paidmembershipspro.com
Other
460 stars 357 forks source link

for some reason pmpro_set_current_user() not being called by set_current_user action #33

Closed shimondoodkin closed 10 years ago

shimondoodkin commented 11 years ago

the function wp_set_current_user is executed before this plugin has been loaded. so it has no chance to add the hook

shimondoodkin commented 11 years ago

solved it this way


function pmpro_init()
{
     global $current_user;
     $id = intval($current_user->ID);
     if($id)
     {
      if(!isset($current_user->membership_level))   
      pmpro_set_current_user();
     }
 ...
strangerstudios commented 11 years ago

Shimon, do you have more info on when this doesn't run? It's running for me. Perhaps another plugin is doing a remove_action("set_current_user") or something like that?

shimondoodkin commented 11 years ago

my wordpress i latest and bbpress is the latest.

the issue noticed when i set in a pmpro level that some category is required and added content even the authenticated user coulod not see the content and got level required message

From below the only other plugin that I have that has anything related to is bbpress

shared:/home/public_html/site# grep set_current_user ./* -R
./wp-admin/includes/class-wp-importer.php:              if ( !$user_id || !wp_set_current_user( $user_id ) ) {
./wp-content/plugins/bbpress/includes/core/actions.php:add_action( 'set_current_user',         'bbp_setup_current_user',       10    );
./wp-content/plugins/bbpress/includes/core/actions.php:add_action( 'switch_blog',            'bbp_set_current_user_default_role' );
./wp-content/plugins/bbpress/includes/core/actions.php:add_action( 'bbp_setup_current_user', 'bbp_set_current_user_default_role' );
./wp-content/plugins/bbpress/includes/users/capabilities.php:function bbp_set_current_user_default_role() {
./wp-content/plugins/bbpress/includes/users/capabilities.php:   if ( ! did_action( 'set_current_user' ) )
./wp-content/plugins/paid-memberships-pro/includes/functions.php:               pmpro_set_current_user();
./wp-content/plugins/paid-memberships-pro/paid-memberships-pro.php:function pmpro_set_current_user()
./wp-content/plugins/paid-memberships-pro/paid-memberships-pro.php:     do_action("pmpro_after_set_current_user");
./wp-content/plugins/paid-memberships-pro/paid-memberships-pro.php:add_action('set_current_user', 'pmpro_set_current_user');
./wp-content/plugins/paid-memberships-pro/paid-memberships-pro.php:     pmpro_set_current_user();
./wp-content/plugins/paid-memberships-pro/preheaders/checkout.php:                              pmpro_set_current_user();
./wp-includes/class-wp-xmlrpc-server.php:               wp_set_current_user( $user->ID );
./wp-includes/user.php: * Used by wp_set_current_user() for back compat. Might be deprecated in the future.
./wp-includes/pluggable.php:if ( !function_exists('wp_set_current_user') ) :
./wp-includes/pluggable.php: * @uses do_action() Calls 'set_current_user' hook after setting the current user.
./wp-includes/pluggable.php:function wp_set_current_user($id, $name = '') {
./wp-includes/pluggable.php:    do_action('set_current_user');
./wp-includes/pluggable.php:                    wp_set_current_user( $cur_id );
./wp-includes/pluggable.php:            wp_set_current_user( 0 );
./wp-includes/pluggable.php:            wp_set_current_user( 0 );
./wp-includes/pluggable.php:                    wp_set_current_user( 0 );
./wp-includes/pluggable.php:    wp_set_current_user( $user );
./wp-includes/pluggable-deprecated.php:if ( !function_exists('set_current_user') ) :
./wp-includes/pluggable-deprecated.php: * @see wp_set_current_user() An alias of wp_set_current_user()
./wp-includes/pluggable-deprecated.php: * @deprecated Use wp_set_current_user()
./wp-includes/pluggable-deprecated.php: * @return object returns wp_set_current_user()
./wp-includes/pluggable-deprecated.php:function set_current_user($id, $name = '') {
./wp-includes/pluggable-deprecated.php: _deprecated_function( __FUNCTION__, '3.0', 'wp_set_current_user()' );
./wp-includes/pluggable-deprecated.php: return wp_set_current_user($id, $name);
./wp-includes/kses.php: * default). Also does not remove kses_init() function from 'set_current_user'
./wp-includes/kses.php: * 'set_current_user' (priority is default), then none of the Kses filter hooks
./wp-includes/kses.php:add_action('set_current_user', 'kses_init');

if you like to debug it i can give you the code of the website

the wordpress is latest and the bbpress-wordpress-plugin is also latest

solhuebner commented 10 years ago

Hi shimondoodkin, is it solved?

shimondoodkin commented 10 years ago

Sorry It was too long ago. I don't remember what is going in that website.

strangerstudios commented 10 years ago

Not yet, but I like the solution offered earlier. We've actually been running into issues from this and offering other fixes (like checking for ->membership_level specifically when we want to use it). We'll have something like this in the next update.

Going to experiment with just adding

add_action('init', 'pmpro_set_current_user');

solhuebner commented 10 years ago

Thank you for the updated information :+1: