开发者 |
helderk
jfinch3 petervandoorn |
---|---|
更新时间 | 2024年6月6日 20:32 |
PHP版本: | 7.4 及以上 |
WordPress版本: | 6.4.1 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
hkdev-maintenance-mode
folder to your plugins directory (usually /wp-content/plugins/
).Plugins
menu in WordPress.Maintenance Mode
Settings panel.There is a filter which allow you to programatically bypass the redirection block:
hkdev_matches
This allows you to run pretty much any test you like, although be aware that the whole redirection thing runs before the $post
global is set up, so WordPress conditionals such as is_post()
and is_tax()
are not available.
This example looks in the $_SERVER
global to see if any part of the URL contains "demo"
function my_hkdev_matches( $hkdev_matches ) {
if ( stristr( $_SERVER['REQUEST_URI'], 'demo' ) )
$hkdev_matches[] = "";
return $hkdev_matches;
}
add_filter( "hkdev_matches", "my_hkdev_matches" );`
Props to @brianhenryie for this!
By default, Maintenance Mode uses the manage_options
cap, but that is normally only applied to administrators. As it stands, a user with a lesser permissions level, such as editor, is able to view the admin side of the site, but not the front end. You can change this using this filter:
hkdev_user_can
This filter is used to pass a different WordPress capability to check if the logged-in user has permission to view the site and thus bypass the redirection, such as edit_posts
. Note that this is run before $post
is set up, so WordPress conditionals such as is_post()
and is_tax()
are not available. However, it's not really meant for programatically determining whether a user should have access, but rather just changing the default capability to be tested, so you don't really need to do anything other than the example below.
function my_hkdev_user_can( $capability ) {
return "edit_posts";
}
add_filter( "hkdev_user_can", "my_hkdev_user_can" );