'is_string', 'logtivity_disable_default_logging' => 'is_bool', 'logtivity_should_store_user_id' => 'is_bool', 'logtivity_should_store_ip' => 'is_bool', 'logtivity_should_log_profile_link' => 'is_bool', 'logtivity_should_log_username' => 'is_bool', 'logtivity_enable_debug_mode' => 'is_bool', 'logtivity_latest_response' => 'is_array', ]; /** * Get the admin settings or the plugin * * @return array */ public function getOptions() { $options = []; foreach ($this->settings as $setting) { $options[$setting] = get_option($setting); } return $options; } /** * Get an option from the database * * @param string $key * @return mixed */ public function getOption($key) { if (!in_array($key, $this->settings)) { return false; } return get_option($key); } /** * Should we store the user id? * * @return bool */ public function shouldStoreUserId() { return $this->getOption('logtivity_should_store_user_id'); } /** * Should we store the users IP? * * @return bool */ public function shouldStoreIp() { return $this->getOption('logtivity_should_store_ip'); } /** * Should we store the users profile link? * * @return bool */ public function shouldStoreProfileLink() { return $this->getOption('logtivity_should_log_profile_link'); } /** * Should we store the users username? * * @return bool */ public function shouldStoreUsername() { return $this->getOption('logtivity_should_log_username'); } /** * Should we be logging the response from the API * * @return bool */ public function shouldLogLatestResponse() { return $this->getOption('logtivity_enable_debug_mode'); } /** * Update the options for this plugin * * @param array $data * @return void */ public function update($data = null) { if ($data) { foreach ($this->settings as $setting) { if (array_key_exists($setting, $data) && $this->validateSetting($setting, $data[$setting])) { update_option($setting, $data[$setting]); } } return; } foreach ($this->settings as $setting) { if (isset($_POST[$setting]) && $this->validateSetting($setting, $_POST[$setting])) { update_option($setting, $_POST[$setting]); } } } /** * Validate that the passed parameters are in the correct format * * @param string $setting * @param string $value * @return bool */ protected function validateSetting($setting, $value) { $method = $this->rules[$setting]; if ($method == 'is_bool') { return $method((bool) $value); } return $method($value); } }