build(); self::$rendering = false; return $output; } // End render() /** * Build the shortcode output. * * @return string */ private function build() : string { $page_id = (int) Settings::get( 'no_access_page' ); $current_id = (int) get_the_ID(); $is_admin = current_user_can( 'manage_options' ); $generic = '
' . esc_html__( 'Sorry, you do not have access to view this page.', 'deadbolt' ) . '
'; if ( ! $page_id && $current_id && is_singular() && 'publish' === get_post_status( $current_id ) ) { Settings::update( 'no_access_page', $current_id ); return $is_admin ? '' . esc_html__( 'This page has automatically been set as your No Access Page. You can change it under Deadbolt > Settings. From now on, visitors will be sent here when they cannot view a page.', 'deadbolt' ) . '
' : $generic; } $post_id = isset( $_GET[ 'no_access' ] ) ? absint( $_GET[ 'no_access' ] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only, identifies which template to display. if ( ! $post_id || $post_id === $page_id || ! get_post( $post_id ) ) { if ( ! $is_admin ) { return $generic; } if ( $page_id !== $current_id ) { return '' . esc_html__( 'Hello, Admin! This page is not set as your No Access Page, so visitors will not be sent here. You can set it under Deadbolt > Settings.', 'deadbolt' ) . '
'; } $example = add_query_arg( 'no_access', '{post_id}', get_permalink( $page_id ) ); /* translators: %s: Example URL of the No Access Page. */ return '' . sprintf( esc_html__( 'Hello, Admin! This is your No Access Page. Visitors see the matching template here when they are redirected from a page they cannot view, for example: %s', 'deadbolt' ), '' . esc_html( $example ) . '' ) . '
' . sprintf( esc_html__( 'Oops! It looks like there was a mistake giving you access. Please %s.', 'deadbolt' ), $retry ) . '
'; } $rule = Access::get_rule( $post_id ); $allowed_html = (array) apply_filters( 'deadbolt_template_allowed_html', wp_kses_allowed_html( 'post' ) ); $content = wp_kses( Templates::render( $post_id, $reason, $redirect_to ), $allowed_html ); return ''; } // End build() } // End class Shortcode Shortcode::instance();