WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
[resolved] Multisite Issues (16 posts)

  1. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    Heya Matty,

    I believe this used to be an error, was resolved for a while, and came back at some point.

    Let's assume 2 users with their own sites on a multisite network, Adam has /adamsite and Bob has /bobsite.

    If Adam enables Subscribe2, enables the widget, and then Bob visits the site, he'll see the message "You can manage your subscription options from your [profile]", where profile links to /adamsite/wp-admin/admin.php?page=s2

    However, when he tries to go there, he gets this message:
    You attempted to access the "Adam's Site" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "Adam's Site" dashboard, please contact your network administrator.

    This is on 3.3.2 with 7.2, and 3.4.1 with both 7.2 and 8.4 (unsure of what other combinations)

    I believe the fix likely involves adding the user as a subscriber to the blog they're trying to visit the backend of before taking them to their settings page.

    (You should have my email from previous issues I've helped test, so feel free to send me any possible updates to test!)

    Thanks!

    http://wordpress.org/extend/plugins/subscribe2/

  2. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    Here's my first go at a fix. When I add the following code, I get added as a subscriber, but it's just a hair too late, as the link in the widget takes me to a less verbose error page: "You do not have sufficient permissions to access this page.", and if I refresh, then I can control my settings, so it's at least a start!

    <?php
    function maybe_add_to_blog() {
    
    	if (is_user_logged_in()) {
    		global $current_user, $blog_id;
    		get_currentuserinfo();
    
    		if (isset($_GET['page']) && $_GET['page'] == 's2') {
    
    			if (!is_user_member_of_blog($current_user->ID, $blog_id)) {
    
    				add_user_to_blog($blog_id, $current_user->ID, 'subscriber');
    			}
    		}
    	}
    }
    add_action('init', 'maybe_add_to_blog');
  3. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    More debugging fodder for you... It looks like you're actually trying to address this with line 17 of class-s2-core.php, but the check on line 13 is coming up false (at least for me) on all my installs.

    Is there a reason you aren't just using the conditional tag "is_multisite()" to determine if it's part of a network? It correctly identifies for me, at least.

    However, if I just replace your multisite check with "if(is_multisite())", then I white screen when it tries to call is_blog_user, with the error "call to undefined function wp_get_current_user()" which must happen somewhere inside of is_blog_user

  4. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @MadtownLems,

    Thanks once again for your reports and details of your own investigations and findings.

    I think the issue has, hopefully, an easy fix.

    Line 17 in the class-s2-core.php file starts with $this->use_profile_admin. Try changing that to just $this->profile and see if that helps.

  5. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    Matty,

    Tried it just to confirm, but nope - no change. If you read my follow up comments, you'll see that this code never actually gets run.

    Line 13 in there is always returning false, skipping this whole block. When I manually enter that 'if' by using either if (true) or even if (is_multisite), then line 15 causes a whitescreen error somewhere down in the code by saying that wp_get_current_user is not defined.

  6. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @MadtownLems,

    Hmm, okay well that line needed fixed anyway.

    I'm using a more global approach to multisites. On line 1642 (or thereabouts) of the same file I do some checking for multisite using the is_multisite() function. That then sets a global for use throughout the Subscribe2 code so I don't have to keep re-checking.

    If that line in your code is coming back as false then I'm wondering if the multisite file is being included on your install as that code is added using the exact same check.

    Ah - something extra - just BEFORE my checks on line 1642 there is a line $this->load_strings();. That is being called too early and $this->s2_mu isn't set yet, move that line to AFTER those checks. Doe sit work now?

  7. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    For debugging, I did the following:

    line 1646..
    if ( function_exists('is_multisite') && is_multisite() ) {
    die('its multisite');

    and sure enough - it's multisite at that point of the check.

    However, back up at the code in question, I tried var_dump()'ing $this and at that point, s2_mu is in fact false.

    I did a little MORE debugging, putting die(...) statements both in the area of line 1646 (s2init) and in the area of load_strings, and it turns out that load_strings is actually getting called BEFORE s2init, therefore it hasn't had time to even see if it's multisite or not yet

  8. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    If I call load_strings AFTER that multisite checking code, then s2 properly determines that we're multisite! yay!

    Unfortunately, I do still get the error then of 'wp_get_current_user' is undefined, which again I'm guessing is called somewhere down the chain of is_blog_user

    Progress, baby! :D

  9. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    More general "trying to be helpful" debuggery:

    I tried modifying subscribe2.php to be this at the very bottom:

    function ok_really_init() {
    	if ( is_admin() ) {
    		require_once(S2PATH . 'classes/class-s2-admin.php');
    		global $mysubscribe2;
    		$mysubscribe2 = new s2_admin;
    		$mysubscribe2->s2init();
    	} else {
    		require_once(S2PATH . 'classes/class-s2-frontend.php');
    		global $mysubscribe2;
    		$mysubscribe2 = new s2_frontend;
    		$mysubscribe2->s2init();
    	}
    }
    add_action('plugins_loaded', 'ok_really_init');

    which gets around my undefined function problem, and thus modifies the widget's subscribe text and link (MOAR PROGRESS!), but it still isn't right. It generates this link for the text subscribe:
    'www.example.com/sub-site-slug/wp-admin/?s2mu_subscribe={blog-id}', which looks better, but following the link still gives the error screen of:
    You attempted to access the "Sub Site" dashboard, but you do not currently have priveleges on this site...

  10. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @MadtownLems,

    That might be because the loader changes you made are now running some code too late so the multisite code is not getting added.

    Try reverting that change and change the $this->load_strings(); to:

    add_action('init', array(&$this, 'load_strings') );

  11. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @MadtownLems,

    Those changes look good to me on non-multisite installs and in theory they should work fine on multisite too. Can you confirm?

  12. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    Delaying load_strings until init gets me the proper text in the widget, and wants to send me to this url:

    example.com/sub-site/wp-admin/?s2mu_subscribe=5 ... but I get the error page text again of:
    You attempted to access "Sub Site" dashboard, but you do not currently have privileges on this site. If you believe...

    So it's now correctly recognizing me as MS, correctly trying to give me a link that will get me added as a subscriber... unfortunately that link doesn't seem to be processed correctly yet. hrm....

  13. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    Line 1659ish says:
    add_action('init', array(&$this, 'wpmu_subscribe'));

    However, the function wpmu_subscribe is actually part of the class s2class_multisite, not "$this" - so this function is not being called properly.

    Update:
    Changing that line to this:
    add_action('init', array($s2class_multisite, 'wpmu_subscribe'));

    is working so far.. moving on to more elaborate testing!

  14. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @MadtownLems,

    Okay, we are getting closer, step by step.

    Change that line 1659 to this:
    add_action('init', array(&$s2class_multisite, 'wpmu_subscribe'));

    How does that look?

  15. Jason Lemahieu (MadtownLems)
    Member
    Posted 1 year ago #

    You may have missed my 'Update' in the previous post, but yup - when I use that modified line, it's working great! :D

  16. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @MadtownLems,

    I think you posted that update around the time of my reply. Great news that it's working I'll get those changes all merged into the code for the next version release. Thanks for your help. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.