Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/zoninator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion zoninator.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ 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' ),
// 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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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'] ) );
?>
<div class="notice notice-warning is-dismissible">
<p><?php echo sprintf( $this->_get_message('error-zone-lock-redirect'), esc_html( $zone->name ) ); ?></p>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here if they pass a zone_id that doesn't exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sboisvert Ah, yeah, I'll need to only display the notice if $zone is not false.

Do you think there should be a different notice if $_GET['zone_lock'] isn't a valid Zone ID or ignore it? I think that should only be able to happen if:

  1. The zone is deleted as the user who was editing the zone is being redirected
  2. Someone purposefully puts an invalid Zone ID in the zone_lock url param

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nod I agree on when it should only happen. I suspect that this will throw a PHP Warning if that's the case since we're using the return of $this->get_zone() without checking if it's actually what we expect as per https://vip.wordpress.com/documentation/code-review-what-we-look-for/#not-checking-return-values :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It does throw a warning there if you pass an invalid Zone ID into $_GET['zone_lock'].

Thoughts on adding a different notice if the Zone ID is invalid?

</div>

<?php
}
}
}

function admin_enqueue_scripts() {
if( $this->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 );
Expand Down