v0.6.0
This commit is contained in:
parent
69c8e9eb97
commit
3a653a7bf3
9 changed files with 475 additions and 358 deletions
|
|
@ -76,7 +76,8 @@ class Robotstxt_Manager_Admin {
|
|||
*
|
||||
* Clears the cached catalog response, purges WordPress's update_plugins
|
||||
* transient so native update badges re-evaluate immediately, and
|
||||
* redirects back to the page.
|
||||
* redirects back to the page. Rate-limited to 6 refreshes per minute
|
||||
* per user so a stuck browser cannot hammer the store.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
@ -87,6 +88,16 @@ class Robotstxt_Manager_Admin {
|
|||
|
||||
check_admin_referer( 'robotstxt_manager_refresh_catalog' );
|
||||
|
||||
$bucket = 'robotstxt_manager_refresh_' . get_current_user_id();
|
||||
$hits_raw = get_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 );
|
||||
|
||||
$client = Robotstxt_Manager_Core_Client::from_options();
|
||||
$client->clear_catalog_cache();
|
||||
delete_site_transient( 'update_plugins' );
|
||||
|
|
@ -103,6 +114,27 @@ class Robotstxt_Manager_Admin {
|
|||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects back to the catalog page with a rate-limit error notice.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function redirect_refresh_error(): void {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
array(
|
||||
'page' => self::PAGE_SLUG,
|
||||
'robotstxt_manager_result' => 'error',
|
||||
'robotstxt_manager_message' => rawurlencode(
|
||||
__( 'Too many refreshes. Please wait a minute before refreshing again.', 'robotstxt-manager' )
|
||||
),
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a nonce-protected admin-post action URL for a plugin row.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue