Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact
You are here: Home

BoppinCol

  • Profile
  • Topics Started
  • Replies Created
  • Engagements
  • Favorites

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 7, 2020 at 2:33 pm in reply to: Two bugs with the swpm_auto_redirect_non_members() hook provided. #19753
    BoppinCol
    Participant

    Thanks for both of your replies.

    I have quickly reproduced this error in local env with, https://localbyflywheel.com/community/t/local-lightning-public-beta/14075

    On my live site, which currently is just my personal private development environment, with no users, my solution above works well. No errors.

    I’m tried calling swpm_auto_redirect_non_members() on init and it just crashed everything!!!

    I don’t think (but don’t know 100%) that the WP main loop has been invoked. I think the is_page() function requires it to be within the loop. Sorry I am not better at WP and PHP!

    I tried adding your new code block. Not sure where you meant to place it… But the original
    Updating failed. Error message: The response is not a valid JSON response.

    persists.

    
    /***  Auto redirect a user who isn't logged into the site  ***/
    add_filter( 'pre_get_posts', 'swpm_auto_redirect_non_members' );
    function swpm_auto_redirect_non_members($query) {
    
    	if ( function_exists('wp_doing_ajax') && wp_doing_ajax()){
    	    //wp_doing_ajax() so no need to execute this code
    	    return true;
    	}
    
        $front_page_id        = get_option( 'page_on_front' );
        $current_page_id      = $query->get( 'page_id' );
        $is_static_front_page = 'page' == get_option( 'show_on_front' );
    
        if ( $is_static_front_page && $front_page_id == $current_page_id  ) {
            error_log( 'is static front page and current page is front page' );
            return;
        }
    
        if (is_admin()){
            // Inside the admin dashboard. Nothing to do.
            return;
        }
    
        if( !SwpmMemberUtils::is_member_logged_in() && !is_page( array( '', 'login', 'hello-world' ) ) ){
            wp_redirect( 'http://swpmtest.local/' );
            exit;
        }
    }
    

    In other words it still needs,

    && !current_user_can('administrator')

    At the end of that conditional before the redirect. Which is super weird as that line should never be invoked. Think you’re on to something regarding ajax though as I don’t need to refresh the backend if I add or remove that conditional. Maybe that’s to expected behaviour but I’m just trying to be helpful!

    I have mentioned it here,

    https://wordpress.stackexchange.com/questions/358022/weird-gutenberg-error-updating-failed-error-message-the-response-is-not-a-val

    I hope that you’re not annoyed by that. I can delete it if so. I’m really puzzled by this problem. Even though I have ‘fixed’ the issue I really want to know why it was breaking.

    I’m sure you could change the arg in current_user_can(‘some-string’) to something different and still get the desired effect.

    I really enjoy using this plugin so I wanted to point these things out to you guys in case you get others with a similar issue.

    February 5, 2020 at 10:18 pm in reply to: Two bugs with the swpm_auto_redirect_non_members() hook provided. #19742
    BoppinCol
    Participant

    The first issue is really weird.

    Basically if I don’t include

    && !current_user_can('administrator')

    as a condition then that breaks the Gutenberg on my theme. Which is a fairly simple child of 2016. My WP install is up-to-date and i’m using php7.3

    It’s particularly interesting because it looks to me, a non-php person that line of code should never be invoked on the backend.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
Next Page »

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy