/** * Grab instance of object. * @return SolrPower_WP_Query */ public static function get_instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Grab instance of object. * @return SolrPower_WP_Query */ public static function get_instance() { if (!self::$instance) { self::$instance = new self(); add_action('init', array(self::$instance, 'setup')); } return self::$instance; }
/** * Fetches and displays returned facets. */ function fetch_facets() { $solr_options = solr_options(); if (!$solr_options['s4wp_output_facets']) { return; } $facets = SolrPower_WP_Query::get_instance()->facets; foreach ($facets as $facet_name => $data) { if (false === $this->show_facet($facet_name)) { continue; } /** * Filter facet HTML * * Filter the HTML output of a facet. * * @param string $facet_name the facet name. * * @param object $data the Solarium facet data object. */ $html = apply_filters('solr_facet_items', false, $facet_name, $data); if ($html) { echo $html; continue; } /** * Filter facet title * * Filter the facet title displayed in the widget. * * @param boolean|string the custom facet title, defaults to false. * * @param string $facet_name the facet name. * */ $facet_nice_name = apply_filters('solr_facet_title', false, $facet_name); if (false === $facet_nice_name) { $replace = array('/\\_taxonomy/', '/\\_str/', '/\\_/'); $facet_nice_name = ucwords(preg_replace($replace, ' ', $facet_name)); } $values = $data->getValues(); if (0 === count($values)) { continue; } echo '<h2>' . esc_html($facet_nice_name) . '</h2>'; echo '<ul>'; foreach ($values as $name => $count) { $nice_name = str_replace('^^', '', $name); $checked = ''; if (isset($this->facets[$facet_name]) && in_array(htmlspecialchars_decode($name), $this->facets[$facet_name])) { $checked = checked(true, true, false); } echo '<li>'; echo '<input type="checkbox" name="facet[' . esc_attr($facet_name) . '][]" value="' . esc_attr($name) . '" ' . $checked . '> '; echo esc_html($nice_name); echo ' (' . esc_html($count) . ')'; echo '</li>'; } echo '</ul>'; echo '<a href="' . $this->reset_url($facet_name) . '">Reset</a>'; } }
/** * Test to make custom field a facet. * @group 37 */ function test_custom_field_facet() { // Set 'my_field' as a custom field facet. $this->__change_option('s4wp_facet_on_custom_fields', array('my_field')); $this->__change_option('s4wp_index_custom_fields', array('my_field')); $this->__setup_custom_fields(); $this->__facet_query(); $facets = SolrPower_WP_Query::get_instance()->facets; $this->assertNotEmpty($facets); $this->assertArrayHasKey('my_field_str', $facets); $this->assertArrayNotHasKey('other_field_str', $facets); $data = $facets['my_field_str']->getValues(); $this->assertArrayHasKey('my_value', $data); $this->assertArrayHasKey('my_value2', $data); $this->assertArrayHasKey('my_value3', $data); }
if (version_compare(PHP_VERSION, '5.4', '<')) { add_action('admin_notices', 'solr_power_PHP_admin_notice'); add_action('admin_init', 'solr_power__deactivate'); } elseif (false === getenv('PANTHEON_INDEX_HOST') || false === getenv('PANTHEON_INDEX_PORT')) { add_action('admin_notices', 'solr_power_env_variables_admin_notice'); add_action('admin_init', 'solr_power__deactivate'); } else { define('SOLR_POWER_PATH', untrailingslashit(plugin_dir_path(__FILE__))); define('SOLR_POWER_URL', plugin_dir_url(__FILE__)); require_once SOLR_POWER_PATH . '/vendor/autoload.php'; require_once SOLR_POWER_PATH . '/includes/legacy-functions.php'; SolrPower::get_instance(); SolrPower_Api::get_instance(); SolrPower_Options::get_instance(); SolrPower_Sync::get_instance(); SolrPower_WP_Query::get_instance(); function solr_options() { return SolrPower_Options::get_instance()->get_option(); } /** * Helper function to return Solr object. */ function get_solr() { return SolrPower_Api::get_instance()->get_solr(); } if (defined('WP_CLI') && true === WP_CLI) { WP_CLI::add_command('solr', 'SolrPower_CLI'); } register_activation_hook(__FILE__, array(SolrPower::get_instance(), 'activate'));