Forum Replies Created
-
AuthorPosts
-
February 7, 2020 at 2:33 pm in reply to: Two bugs with the swpm_auto_redirect_non_members() hook provided. #19753
BoppinCol
ParticipantThanks 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,
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. #19742BoppinCol
ParticipantThe 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.
-
AuthorPosts