admin管理员组文章数量:1291320
I would like to open up certain parts of my website where the remaining pages should only be accessible as an administrator on the website.
I have made a maintaince plugin and it all works as it should. However, I have trouble filtering users by which page they are visiting.
I would like to open up a specific product category, as well as all products that belong to this category.
If I am not logged in as an administrator, I can not access the product category and products belonging to it.
My code is below - anyone can see what I'm doing wrong?
Thanks.
<?php
@return void
function ng_maintenance_mode() {
global $pagenow;
if ( ! current_user_can('administrator') ) {
if ( $pagenow !== 'wp-login.php' && ! is_product_category( 232 ) && ! has_term( 232, 'product_cat' ) {
header( $_SERVER["SERVER_PROTOCOL"] . ' 503 Service Temporarily Unavailable', true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
if ( file_exists( plugin_dir_path( __FILE__ ) . 'views/maintenance.php' ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'views/maintenance.php' );
}
die();
}
}
}
add_action( 'wp_loaded', 'ng_maintenance_mode' );
?>
I would like to open up certain parts of my website where the remaining pages should only be accessible as an administrator on the website.
I have made a maintaince plugin and it all works as it should. However, I have trouble filtering users by which page they are visiting.
I would like to open up a specific product category, as well as all products that belong to this category.
If I am not logged in as an administrator, I can not access the product category and products belonging to it.
My code is below - anyone can see what I'm doing wrong?
Thanks.
<?php
@return void
function ng_maintenance_mode() {
global $pagenow;
if ( ! current_user_can('administrator') ) {
if ( $pagenow !== 'wp-login.php' && ! is_product_category( 232 ) && ! has_term( 232, 'product_cat' ) {
header( $_SERVER["SERVER_PROTOCOL"] . ' 503 Service Temporarily Unavailable', true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
if ( file_exists( plugin_dir_path( __FILE__ ) . 'views/maintenance.php' ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'views/maintenance.php' );
}
die();
}
}
}
add_action( 'wp_loaded', 'ng_maintenance_mode' );
?>
Share
Improve this question
asked Jun 9, 2021 at 2:09
Oscar S.Oscar S.
191 gold badge1 silver badge3 bronze badges
1 Answer
Reset to default 0You need to replace the following:
if ( ! current_user_can('administrator') ) {
with
if ( ! current_user_can('manage_options') ) {
This is because there's no such capability as administrator
. There are a couple of administrator-only capabilities, and manage_options
is a reliable one to use.
本文标签: plugin developmentWooCommerce maintaince mode by using php
版权声明:本文标题:plugin development - WooCommerce maintaince mode by using php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741515468a2382859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论