/** * Check if away mode is active * * @since 4.4 * @static * * @param bool $get_details Optional, defaults to false. True to receive details rather than a boolean response. * * @return mixed If $get_details is true, an array of status details. Otherwise, true if away and false otherwise. */ public static function is_active($get_details = false) { require_once dirname(__FILE__) . '/utilities.php'; $settings = ITSEC_Modules::get_settings('away-mode'); if ('daily' === $settings['type']) { $details = ITSEC_Away_Mode_Utilities::is_current_time_active($settings['start_time'], $settings['end_time'], true); } else { $details = ITSEC_Away_Mode_Utilities::is_current_timestamp_active($settings['start'], $settings['end'], true); } $details['has_active_file'] = ITSEC_Away_Mode_Utilities::has_active_file(); $details['override_type'] = $settings['override_type']; $details['override_end'] = $settings['override_end']; if (empty($settings['override_type']) || ITSEC_Core::get_current_time() > $settings['override_end']) { $details['override_active'] = false; } else { $details['override_active'] = true; if ('activate' === $details['override_type']) { $details['active'] = true; } else { $details['active'] = false; } } if (!$details['has_active_file']) { $details['active'] = false; $details['remaining'] = false; $details['next'] = false; $details['length'] = false; } if (!isset($details['error'])) { $details['error'] = false; } if ($get_details) { return $details; } return $details['active']; }
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); } } } }
protected function after_save() { require_once dirname(__FILE__) . '/utilities.php'; ITSEC_Away_Mode_Utilities::create_active_file(); }
<?php require_once dirname(__FILE__) . '/utilities.php'; ITSEC_Away_Mode_Utilities::delete_active_file();