public function testGetCount() { global $wp_query; register_post_type('post'); $this->assertEquals(100, Indexer::get_count()); $this->assertEquals(array('post'), $wp_query->args['post_type']); $this->assertEquals('publish', $wp_query->args['post_status']); }
<?php namespace elasticsearch; add_action('admin_head-toplevel_page_elastic_search', function () { wp_enqueue_script('es-indexing', plugins_url('/manage-index.js', __FILE__), array('jquery')); wp_localize_script('es-indexing', 'indexing', array('ajaxurl' => admin_url('admin-ajax.php'), 'total' => Indexer::get_count(), 'perpage' => Indexer::per_page())); }); add_filter('nhp-opts-saved-text-elasticsearch', function ($default) { if (get_transient('es-wiped') == 1) { return '<strong>The index has been wiped.</strong>'; delete_transient('es-wiped'); } if (get_transient('es-indexed') == 1) { return '<strong>The index has been populated.</strong>'; delete_transient('es-indexed'); } return $default; }); add_action('nhp-opts-options-validate-elasticsearch', function () { if (isset($_POST['wipe']) && $_POST['wipe']) { try { Indexer::clear(); set_transient('es-wiped', 1, 30); } catch (\Exception $ex) { $errors = get_transient('nhp-opts-errors-elasticsearch'); $errors[] = array('section_id' => 'index'); set_transient('nhp-opts-errors-elasticsearch', $errors, 1000); set_transient('es-wiped-error', $ex->getMessage(), 30); } }