From fd8b4d3a4d746fb630375d8a17b8f2a3b55b3973 Mon Sep 17 00:00:00 2001 From: Brett Shumaker Date: Thu, 3 May 2018 13:24:36 -0500 Subject: [PATCH 1/5] Updated redirect url for expired zone lock Zoninator#44 Updated the redirect url to use when the zone lock expires. --- js/zoninator.js | 2 +- zoninator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/zoninator.js b/js/zoninator.js index ba6ce87..5611ef6 100644 --- a/js/zoninator.js +++ b/js/zoninator.js @@ -280,7 +280,7 @@ var zoninator = {}; setTimeout(zoninator.updateLock, zoninator.heartbeatInterval); } else { alert(zoninatorOptions.errorZoneLockMax); - location.href = zoninatorOptions.adminUrl; + location.href = zoninatorOptions.baseUrl + '&zone_lock=' + zoninator.getZoneId(); } }, function(returnData, originalData) { // Show alert and reload page to update lock diff --git a/zoninator.php b/zoninator.php index 368d705..4d2a71d 100644 --- a/zoninator.php +++ b/zoninator.php @@ -48,7 +48,7 @@ class Zoninator var $zone_nonce_prefix = 'zone-nonce'; var $zone_ajax_nonce_action = 'ajax-action'; var $zone_lock_period = 30; // number of seconds a lock is valid for - var $zone_max_lock_period = 600; // max number of seconds for all locks in a session + var $zone_max_lock_period = 60; // max number of seconds for all locks in a session var $post_types = null; var $zone_detail_defaults = array( 'description' => '' From 54f4f915d3eb2a0afc2029b96641fd1680bf1909 Mon Sep 17 00:00:00 2001 From: Brett Shumaker Date: Thu, 3 May 2018 13:26:11 -0500 Subject: [PATCH 2/5] Update max idle message Zoninator #44 Changed the `error-zone-lock-max` message to reflect the updated redirect url. --- zoninator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zoninator.php b/zoninator.php index 4d2a71d..2f346f2 100644 --- a/zoninator.php +++ b/zoninator.php @@ -101,7 +101,7 @@ function init() { 'delete-success' => __( 'The zone was successfully deleted.', 'zoninator' ), 'error-general' => __( 'Sorry, something went wrong! Please try again?', 'zoninator' ), 'error-zone-lock' => __( 'Sorry, this zone is in use by %s and is currently locked. Please try again later.', 'zoninator' ), - 'error-zone-lock-max' => __( 'Sorry, you have reached the maximum idle limit and will now be redirected to the Dashboard.', 'zoninator' ), + 'error-zone-lock-max' => __( 'Sorry, you have reached the maximum idle limit and will now be redirected to the Zones page.', 'zoninator' ), ); $this->zone_lock_period = apply_filters( 'zoninator_zone_lock_period', $this->zone_lock_period ); From 6cc019490d87274194dfc6c4683affd706102a83 Mon Sep 17 00:00:00 2001 From: Brett Shumaker Date: Thu, 3 May 2018 14:05:13 -0500 Subject: [PATCH 3/5] Added an admin notice when a user's zone lock expires. Zoninator #44 Added an admin notice when a user's zone lock expires and they get redirected to the top level zones page. --- zoninator.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/zoninator.php b/zoninator.php index 2f346f2..b93e21e 100644 --- a/zoninator.php +++ b/zoninator.php @@ -48,7 +48,7 @@ class Zoninator var $zone_nonce_prefix = 'zone-nonce'; var $zone_ajax_nonce_action = 'ajax-action'; var $zone_lock_period = 30; // number of seconds a lock is valid for - var $zone_max_lock_period = 60; // max number of seconds for all locks in a session + var $zone_max_lock_period = 600; // max number of seconds for all locks in a session var $post_types = null; var $zone_detail_defaults = array( 'description' => '' @@ -102,6 +102,8 @@ function init() { 'error-general' => __( 'Sorry, something went wrong! Please try again?', 'zoninator' ), 'error-zone-lock' => __( 'Sorry, this zone is in use by %s and is currently locked. Please try again later.', 'zoninator' ), 'error-zone-lock-max' => __( 'Sorry, you have reached the maximum idle limit and will now be redirected to the Zones page.', 'zoninator' ), + // Translators: %s below refers to the zone title + 'error-zone-lock-redirect' => __( 'Sorry, you had reached the maximum idle limit while editing zone "%s" and were redirected to the Zones page.', 'zoninator' ), ); $this->zone_lock_period = apply_filters( 'zoninator_zone_lock_period', $this->zone_lock_period ); @@ -131,6 +133,8 @@ function init() { add_action( 'admin_menu', array( $this, 'admin_page_init' ) ); + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); + # Add default advanced search fields add_action( 'zoninator_advanced_search_fields', array( $this, 'zone_advanced_search_cat_filter' ) ); add_action( 'zoninator_advanced_search_fields', array( $this, 'zone_advanced_search_date_filter' ), 20 ); @@ -171,6 +175,27 @@ function admin_page_init() { add_menu_page( __( 'Zoninator', 'zoninator' ), __( 'Zones', 'zoninator' ), $this->_get_manage_zones_cap(), $this->key, array( $this, 'admin_page' ), '', 11 ); } + /** + * Loads any admin notices on the top level zones screen. + */ + public function admin_notices() { + + $screen = get_current_screen(); + + if ( 'toplevel_page_zoninator' === $screen->base ) { + + if ( isset( $_GET['zone_lock'] ) ) { + $zone = $this->get_zone( intval( $_GET['zone_lock'] ) ); + ?> +
+

_get_message('error-zone-lock-redirect'), esc_html( $zone->name ) ); ?>

+
+ + is_zoninator_page() ) { wp_enqueue_script( 'zoninator-js', ZONINATOR_URL . 'js/zoninator.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-position', 'jquery-ui-sortable', 'jquery-ui-autocomplete' ), ZONINATOR_VERSION, true ); From a6732584f9dc8f12fbe55c443dd0333c9bf3cbd0 Mon Sep 17 00:00:00 2001 From: Brett Shumaker Date: Wed, 9 May 2018 16:30:05 -0500 Subject: [PATCH 4/5] Check our returned $zone to make sure it's not false Zoninator #44 We needed to check and make sure that `$zone` is not `false` coming back from `$this->get_zone()` otherwise a PHP Warning is thrown. --- zoninator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zoninator.php b/zoninator.php index b93e21e..d3eaeb7 100644 --- a/zoninator.php +++ b/zoninator.php @@ -186,12 +186,16 @@ public function admin_notices() { if ( isset( $_GET['zone_lock'] ) ) { $zone = $this->get_zone( intval( $_GET['zone_lock'] ) ); - ?> + + // Make sure we actually have a good $zone before showing a notice + if ( false !== $zone ) { + ?>

_get_message('error-zone-lock-redirect'), esc_html( $zone->name ) ); ?>

- Date: Wed, 9 May 2018 16:32:20 -0500 Subject: [PATCH 5/5] Whitespace issue Zoninator #44 Fixed a whitespace issue in new code. --- zoninator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zoninator.php b/zoninator.php index d3eaeb7..c8cd76e 100644 --- a/zoninator.php +++ b/zoninator.php @@ -191,7 +191,7 @@ public function admin_notices() { if ( false !== $zone ) { ?>
-

_get_message('error-zone-lock-redirect'), esc_html( $zone->name ) ); ?>

+

_get_message( 'error-zone-lock-redirect' ), esc_html( $zone->name ) ); ?>