public function search($query)
 {
     if (function_exists('is_main_query') && !$query->is_main_query()) {
         return $query;
     }
     if (is_search() && !is_admin() && $this->algolia_registry->validCredential && isset($_GET['instant']) === false) {
         if ($this->algolia_registry->instant) {
             $url = get_site_url() . '/?instant=1&s=' . $query->query['s'] . '#q=' . $query->query['s'] . '&page=0&refinements=%5B%5D&numerics_refinements=%7B%7D&index_name=%22' . $this->algolia_registry->index_name . 'all%22';
             header('Location: ' . $url);
             die;
         }
         $algolia_query = get_search_query(false);
         $options = array('hitsPerPage' => $this->algolia_registry->number_by_page, 'page' => get_query_var('paged') ? get_query_var('paged') - 1 : 0);
         $algolia_helper = new \Algolia\Core\AlgoliaHelper($this->algolia_registry->app_id, $this->algolia_registry->search_key, $this->algolia_registry->admin_key);
         $results = $algolia_helper->search($algolia_query, $options, $this->algolia_registry->index_name . 'all');
         foreach ($results['hits'] as $result) {
             $this->ids[] = $result['objectID'];
         }
         $this->num_pages = $results['nbPages'];
         $this->total_result_count = $results['nbHits'];
         $this->page = $results['page'];
         $query->query = array();
         set_query_var('post__in', $this->ids);
         set_query_var('post_type', null);
         set_query_var('s', null);
         set_query_var('paged', null);
         return $query;
     }
     return $query;
 }
 public function admin_post_update_account_info()
 {
     if (isset($_POST['submit']) && $_POST['submit'] == 'Import' && isset($_FILES['import']) && isset($_FILES['import']['tmp_name']) && is_file($_FILES['import']['tmp_name'])) {
         $content = file_get_contents($_FILES['import']['tmp_name']);
         try {
             $this->algolia_registry->import(json_decode($content, true));
             wp_redirect('admin.php?page=algolia-settings#credentials');
             return;
         } catch (\Exception $e) {
             echo $e->getMessage();
             echo '<pre>';
             echo $e->getTraceAsString();
             die;
         }
     }
     $app_id = !empty($_POST['APP_ID']) ? sanitize_text_field($_POST['APP_ID']) : '';
     $search_key = !empty($_POST['SEARCH_KEY']) ? sanitize_text_field($_POST['SEARCH_KEY']) : '';
     $admin_key = !empty($_POST['ADMIN_KEY']) ? sanitize_text_field($_POST['ADMIN_KEY']) : '';
     $index_name = !empty($_POST['INDEX_NAME']) ? sanitize_text_field($_POST['INDEX_NAME']) : '';
     $algolia_helper = new \Algolia\Core\AlgoliaHelper($app_id, $search_key, $admin_key);
     $this->algolia_registry->app_id = $app_id;
     $this->algolia_registry->search_key = $search_key;
     $this->algolia_registry->admin_key = $admin_key;
     $this->algolia_registry->index_name = $index_name;
     $algolia_helper->checkRights();
     wp_redirect('admin.php?page=algolia-settings#credentials');
 }