v1.6.0
This commit is contained in:
parent
b2849880ec
commit
5589c54b9b
13 changed files with 138 additions and 58 deletions
|
|
@ -33,7 +33,8 @@ class Robotstxt_Manager_Admin {
|
|||
* @return void
|
||||
*/
|
||||
public function register( Robotstxt_Manager_Loader $loader ): void {
|
||||
$loader->add_action( 'admin_menu', $this, 'add_menu' );
|
||||
$menu_hook = is_multisite() ? 'network_admin_menu' : 'admin_menu';
|
||||
$loader->add_action( $menu_hook, $this, 'add_menu' );
|
||||
$loader->add_action( 'admin_post_robotstxt_manager_refresh_catalog', $this, 'handle_refresh' );
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +44,11 @@ class Robotstxt_Manager_Admin {
|
|||
* @return void
|
||||
*/
|
||||
public function add_menu(): void {
|
||||
$cap = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
add_menu_page(
|
||||
esc_html__( 'Manager (by ROBOTSTXT) — Plugins', 'robotstxt-manager' ),
|
||||
esc_html__( 'ROBOTSTXT', 'robotstxt-manager' ),
|
||||
'manage_options',
|
||||
$cap,
|
||||
self::PAGE_SLUG,
|
||||
array( $this, 'render_page' ),
|
||||
'dashicons-screenoptions',
|
||||
|
|
@ -60,7 +62,7 @@ class Robotstxt_Manager_Admin {
|
|||
* @return void
|
||||
*/
|
||||
public function render_page(): void {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( is_multisite() ? 'manage_network_options' : 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-manager' ) );
|
||||
}
|
||||
|
||||
|
|
@ -149,21 +151,21 @@ class Robotstxt_Manager_Admin {
|
|||
* @return void
|
||||
*/
|
||||
public function handle_refresh(): void {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! current_user_can( is_multisite() ? 'manage_network_options' : 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'Insufficient permissions.', 'robotstxt-manager' ) );
|
||||
}
|
||||
|
||||
check_admin_referer( 'robotstxt_manager_refresh_catalog' );
|
||||
|
||||
$bucket = 'robotstxt_manager_refresh_' . get_current_user_id();
|
||||
$hits_raw = get_transient( $bucket );
|
||||
$hits_raw = get_site_transient( $bucket );
|
||||
$hits = is_numeric( $hits_raw ) ? (int) $hits_raw : 0;
|
||||
|
||||
if ( $hits >= 6 ) {
|
||||
$this->redirect_refresh_error();
|
||||
}
|
||||
|
||||
set_transient( $bucket, $hits + 1, MINUTE_IN_SECONDS );
|
||||
set_site_transient( $bucket, $hits + 1, MINUTE_IN_SECONDS );
|
||||
|
||||
$client = Robotstxt_Manager_Core_Client::from_options();
|
||||
$client->clear_catalog_cache();
|
||||
|
|
@ -175,7 +177,7 @@ class Robotstxt_Manager_Admin {
|
|||
'page' => self::PAGE_SLUG,
|
||||
'refreshed' => '1',
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
( is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) )
|
||||
);
|
||||
|
||||
wp_safe_redirect( $redirect );
|
||||
|
|
@ -197,7 +199,7 @@ class Robotstxt_Manager_Admin {
|
|||
__( 'Too many refreshes. Please wait a minute before refreshing again.', 'robotstxt-manager' )
|
||||
),
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
( is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) )
|
||||
)
|
||||
);
|
||||
exit;
|
||||
|
|
|
|||
Loading…
Reference in a new issue