protected function validate_settings() { // Only validate settings if the data was successfully sanitized. if (!$this->can_save()) { return; } require_once dirname(__FILE__) . '/utilities.php'; $id = $this->get_id(); if ('one-time' === $this->settings['type']) { if ($this->settings['start'] >= $this->settings['end']) { /* translators: 1: "Start Date", 2: "Start Time", 3: "End Date", 4: "End Time" */ $this->add_error(new WP_Error("itsec-validator-{$id}-start-after-end", sprintf(__('The %1$s and %2$s must be before the %3$s and %4$s.', 'better-wp-security'), __('Start Date', 'better-wp-security'), __('Start Time', 'better-wp-security'), __('End Date', 'better-wp-security'), __('End Time', 'better-wp-security')))); $this->set_can_save(false); } else { if (false === ITSEC_Away_Mode_Utilities::is_current_timestamp_active($this->settings['start'], $this->settings['end'], true)) { /* translators: 1: "End Date", 2: "End Time" */ $this->add_error(new WP_Error("itsec-validator-{$id}-end-already-ended", sprintf(__('The selected restriction date and time has already ended. Please select an %1$s and %2$s that has not already ended.', 'better-wp-security'), __('End Date', 'better-wp-security'), __('End Time', 'better-wp-security')))); $this->set_can_save(false); } else { if (ITSEC_Core::is_interactive() && ITSEC_Away_Mode_Utilities::is_current_timestamp_active($this->settings['start'], $this->settings['end'])) { /* translators: 1: "Start Date", 2: "Start Time" */ $this->add_error(new WP_Error("itsec-validator-{$id}-start-already-started", sprintf(__('The selected restriction date and time has already started and would result in locking you out immediately. Please select a %1$s and %2$s that has not already started.', 'better-wp-security'), __('Start Date', 'better-wp-security'), __('Start Time', 'better-wp-security')))); $this->set_can_save(false); } } } } else { if ($this->settings['start_time'] === $this->settings['end_time']) { /* translators: 1: "Start Time", 2: "End Time" */ $this->add_error(new WP_Error("itsec-validator-{$id}-start-equals-end", sprintf(__('The %1$s and %2$s cannot be the same.', 'better-wp-security'), __('Start Time', 'better-wp-security'), __('End Time', 'better-wp-security')))); $this->set_can_save(false); } else { if (ITSEC_Core::is_interactive() && ITSEC_Away_Mode_Utilities::is_current_time_active($this->settings['start_time'], $this->settings['end_time'])) { /* translators: 1: "Start Time", 2: "End Time" */ $this->add_error(new WP_Error("itsec-validator-{$id}-settings-result-in-current-lockout", sprintf(__('The %1$s and %2$s settings restrict the current time and would result in locking you out immediately. Please select a %1$s and %2$s that does not restrict the current time.', 'better-wp-security'), __('Start Time', 'better-wp-security'), __('End Time', 'better-wp-security')))); $this->set_can_save(false); } } } }