[英]With Wordpress in Maintenance Mode, how do we exclude the wp-login.php page?
So we added a custom maintenance page to our custom wordpress theme using ACF - but we somehow have to exclude the wp-login.php page or we won't be able to login to our website if Maintenance is on, any suggestions on how we would do this?因此,我们使用 ACF 在我们的自定义 wordpress 主题中添加了一个自定义维护页面 - 但我们必须以某种方式排除wp-login.php页面,否则如果维护开启,我们将无法登录我们的网站,关于我们如何提供任何建议会这样做吗? Here is the code we have so far:这是我们到目前为止的代码:
///////////// Wordpress Maintenance Mode ///////////
function maintenance_mode() {
$context = Timber::get_context();
Timber::render('maintenance.twig', $context);
die();
}
$config = get_field('website', 'option');
if($config["status"]) {
add_filter( 'wp_die_handler', '_custom_wp_die_handler' );
}else {
if(!is_user_logged_in() && !is_admin()) {
maintenance_mode();
}
}
function _custom_wp_die_handler( $message, $title = '', $args = array() ) {
maintenance_mode();
}
Using $wp->request you should be able to add an exclusion for the wp-login page to your if(!is_user_logged_in() && !is_admin()) {
statement to prevent the code from loading there.使用$wp->request您应该能够将wp-login页面的排除添加到if(!is_user_logged_in() && !is_admin()) {
语句以防止代码加载到那里。
You also need to use home_url( $wp-request ) inside a function call.您还需要在函数调用中使用 home_url( $wp-request )。 The code for this would be something like:代码如下:
add_action('pre_get_posts', 'maintenance_mode_logic');
function maintenance_mode_logic() {
global $wp;
$config = get_field('website', 'option');
if($config["status"] == 1) {
echo 'hello';
exit();
add_filter( 'wp_die_handler', '_custom_wp_die_handler' );
}else {
if(!is_user_logged_in() && !is_admin() && home_url( $wp->request ) != wp_login_url()) {
maintenance_mode();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.