encrypt(base64_encode(maybe_serialize($options)))); maybe_unserialize($options); } if (substr($options, 0, strlen('as__')) == 'as__') { $options = maybe_unserialize(base64_decode($decrypt->decrypt(substr($options, strlen('as__'))))); } if (!is_array($options) or empty($options)) { $options = array( 'adscout_api_endpoint' => 'https://scoutefy.com/', 'adscout_api_token' => false, 'adscout_partner_domain_hex' => false, 'as_feed_last_updated' => false, 'as_feed_last_updated_timestamp' => false, 'as_feed_url' => false, 'as_feed_file_path' => false, 'adscout_hash' => false, 'adscout_order_statuses_to_sync' => ['wc-completed', 'wc-processing'], 'order_status_synced_to_adscout' => null, 'order_status_synced_to_adscout_timestamp' => null, 'sync_user_data' => false ); } foreach ($required_options as $option) { if (is_array($options) and !array_key_exists($option, $options)) { $options[$option] = false; } } if (!$options['adscout_hash']) { $options['adscout_hash'] = md5(get_home_url()); } return $options; } /** * Get an option value by name. * If the option does not exist, will return false. * If the option exists, will return the decrypted value. * * @param $name * @return string|bool The option value or false if option does not exist. * * @since 2.0.0 */ public static function get_option($name) { $options = self::all_options(); return array_key_exists($name, $options) ? $options[$name] : false; } /** * Set an option value by name. * * @param $name * @param $value * @return bool * * @since 2.0.0 * @updated 2.0.1 */ public static function set_option($name, $value): bool { $return = false; $options = self::all_options(); $options[$name] = $value; $encrypt = new AdScout_Encrypt_Decrypt(); $options = 'as__' . $encrypt->encrypt(base64_encode(maybe_serialize($options))); $options = update_option('adscout_integration_options', $options); if (!is_wp_error($options)) { $return = true; } return $return; } /** * Update multiple options at once. * * @param $options: array * @return bool * @access private * @static * * @since 2.0.0 */ public static function update_options(array $options): bool { foreach ($options as $key => $value) { $update = self::set_option($key, $value); if (is_wp_error($update)) { return false; } } return true; } public static function delete_options(): void { delete_option('adscout_integration_options'); } }