Disable Page Restriction Leads to Critical Error
Opened this issue · 2 comments
I get a critical error when trying to disable page restrictions on one or multiple pages. Here is the code I am running to let these pages through:
add_filter( 'restricted_site_access_is_restricted', 'my_restricted_check', 10, 2 );
function my_restricted_check( $is_restricted, $wp ) {
// check query variables to see if this is the register or recovery page
if ( ! empty( $wp->query_vars['pagename'] == 'register' || 'recovery' ) ) {
$is_restricted = false;
}
return $is_restricted;
}
This is the error I get from my error_log:
PHP Warning: Undefined array key "pagename" in PATH/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()'d code on line 5
While this does still allow these pages to load as a non-logged-in user it loads a critical error page when trying to edit the page in Elementor & adds the same error to the log each time.
Hi @btsmgoffical ,
By default WordPress doesn't set the query var pagename
for non-pages.
You may want to exit early for requests that aren't for pages:
add_filter( 'restricted_site_access_is_restricted', 'my_restricted_check', 10, 2 );
function my_restricted_check( $is_restricted, $wp ) {
if ( ! is_page() ) {
return $is_restricted;
}
// check query variables to see if this is the register or recovery page
if ( ! empty( $wp->query_vars['pagename'] == 'register' || 'recovery' ) ) {
$is_restricted = false;
}
return $is_restricted;
}
For any more support related queries, I would suggest you post them to the Restricted Site support forum.
Closing as resolved. Please feel free to reopen or as suggested, open a support ticket for quicker response.