Ejemplo n.º 1
0
 public function testIndex()
 {
     $client = Core\Utils::client(Core\Registry::instance()->getAccessKeyId(), Core\Registry::instance()->getAccessKeySecret(), Core\Registry::instance()->getAccessHost());
     $index = new SDK\CloudsearchIndex('wp', $client);
     $this->assertInstanceOf('CloudsearchIndex', get_class($index));
 }
Ejemplo n.º 2
0
 /**
  * Save settings modified by the user
  */
 public function updateOptions()
 {
     if (!current_user_can('manage_options') || !isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], Settings::updateAction)) {
         return;
     }
     // Get all the settings
     $options = Registry::instance()->getOptions();
     foreach ($options as $option => $value) {
         if (!isset($_POST[self::settingsField]) || !isset($_POST[self::settingsField][$option])) {
             continue;
         }
         if (is_array($_POST[self::settingsField][$option])) {
             $options[$option] = array_map('sanitize_text_field', $_POST[self::settingsField][$option]);
         } else {
             $options[$option] = sanitize_text_field($_POST[self::settingsField][$option]);
         }
     }
     if (!empty($options['accessKeyId']) && !empty($options['accessKeySecret']) && !empty($options['accessHost'])) {
         static::$client = Core\Utils::client($options['accessKeyId'], $options['accessKeySecret'], $options['accessHost']);
     }
     // If there is a CloudsearchClient instance validate it
     $options['accessValid'] = 0;
     if (!empty(static::$client)) {
         $validAccess = Core\Utils::validAccess(static::$client);
         if (!is_wp_error($validAccess)) {
             $options['accessValid'] = 1;
         } else {
             $options['accessValid'] = 0;
         }
     }
     // If there is an appName and a cloudsearchClient instance validate them
     $options['accessIndexValid'] = 0;
     if (!empty($options['appName']) && !empty(static::$client)) {
         $validIndex = Core\Utils::validAccessIndex($options['appName'], static::$client);
         if (!is_wp_error($validIndex)) {
             $options['accessIndexValid'] = 1;
         } else {
             $options['accessIndexValid'] = 0;
         }
     }
     // pre($options);
     // exit;
     Registry::instance()->saveOptions($options);
     $referer = add_query_arg(array('opSouMessage' => 'settingsUpdated'), wp_get_referer());
     //Redirect back to the settings page that was submitted
     wp_safe_redirect($referer);
     die('Failed redirect saving settings');
 }