Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed Mar 31, 2020
2 parents bfc51f5 + 589bb19 commit 84bb692
Show file tree
Hide file tree
Showing 18 changed files with 673 additions and 94 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file, per [the Keep a Changelog standard](http://keepachangelog.com/).

## [3.4.1] - 2020-3-31

* Make weighting dashboard flex containers to prevent the slider from changing size. Props [@mlaroy](https://github.com/mlaroy).
* Fix issue where weightings wouldn't save properly for certain post types. Props [mustafauysal](https://github.com/mustafauysal).
* Fix bug where terms wouldn't finish syncing in certain scenarios.
* Properly order WooCommerce products using double to account for decimals. Props [@oscarsanchez](https://github.com/oscarsanchez).
* Show current indices in index health dashboard. Props [moraleida](https://github.com/moraleida).

## [3.4]

* Addition of Terms Indexable and Feature. ElasticPress can now integrate with `WP_Term_Query`. Props [dkotter](https://github.com/dkotter).
Expand Down
16 changes: 14 additions & 2 deletions assets/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,11 @@ h2.ep-list-features {

.weighting-settings .postbox {
max-width: 650px;
box-sizing: border-box;

* {
box-sizing: border-box;
}
}

.weighting-settings .postbox h2.hndle {
Expand All @@ -648,6 +653,7 @@ h2.ep-list-features {

.weighting-settings fieldset p {
display: inline-block;
float: left;
margin: 0;
}

Expand All @@ -669,8 +675,14 @@ h2.ep-list-features {
width: 120px;
}

.weighting-settings .weighting {
display: flex;
align-items: center;
}

.weighting-settings .weighting label {
width: 60px; /* not localization friendly */
min-width: 80px;
margin-right: 10px;
}

.weighting-settings input[type=range] {
Expand Down Expand Up @@ -1056,4 +1068,4 @@ p.ep-totals-data {
.ep-qchart-container {
width: 90%;
}
}
}
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/css/dashboard-styles.min.css

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: ElasticPress
* Description: A fast and flexible search and query engine for WordPress.
* Version: 3.4
* Version: 3.4.1
* Author: 10up
* Author URI: http://10up.com
* License: GPLv2 or later
Expand All @@ -27,7 +27,8 @@

define( 'EP_URL', plugin_dir_url( __FILE__ ) );
define( 'EP_PATH', plugin_dir_path( __FILE__ ) );
define( 'EP_VERSION', '3.4' );
define( 'EP_FILE', plugin_basename( __FILE__ ) );
define( 'EP_VERSION', '3.4.1' );

/**
* PSR-4-ish autoloading
Expand Down Expand Up @@ -76,7 +77,7 @@ function( $class ) {
require_once __DIR__ . '/includes/utils.php';

// Define a constant if we're network activated to allow plugin to respond accordingly.
$network_activated = Utils\is_network_activated( plugin_basename( __FILE__ ) );
$network_activated = Utils\is_network_activated( EP_FILE );

if ( $network_activated ) {
define( 'EP_IS_NETWORK', true );
Expand Down
66 changes: 42 additions & 24 deletions includes/classes/Feature/Search/Weighting.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,33 @@ public function handle_save() {
return;
}

$this->save_weighting_configuration( $_POST );

$redirect_url = admin_url( 'admin.php?page=elasticpress-weighting' );
$redirect_url = add_query_arg( 'settings-updated', true, $redirect_url );

// Do a non-blocking search query to force the autosuggest hash to update
$url = add_query_arg( [ 's' => 'search test' ], home_url( '/' ) );
wp_remote_get(
$url,
[
'blocking' => false,
]
);

wp_safe_redirect( $redirect_url );
exit();
}

/**
* Save weighting configuration for each searchable post_type
*
* @param array $settings weighting settings
*
* @return array final settings
* @since 3.4.1
*/
public function save_weighting_configuration( $settings ) {
$new_config = array();
$previous_config_formatted = array();
$current_config = $this->get_weighting_configuration();
Expand All @@ -326,22 +353,26 @@ public function handle_save() {
// We need a way to know if fields have been explicitly set before, let's compare a previous state against $_POST['weighting']
foreach ( $post_type_weighting as $weighting_field => $weighting_values ) {
$previous_config_formatted[ $post_type ][ sanitize_text_field( $weighting_field ) ] = [
'weight' => isset( $_POST['weighting'][ $post_type ][ $weighting_field ]['weight'] ) ? intval( $_POST['weighting'][ $post_type ][ $weighting_field ]['weight'] ) : 0,
'enabled' => isset( $_POST['weighting'][ $post_type ][ $weighting_field ]['enabled'] ) && 'on' === $_POST['weighting'][ $post_type ][ $weighting_field ]['enabled'] ? true : false,
'weight' => isset( $settings['weighting'][ $post_type ][ $weighting_field ]['weight'] ) ? intval( $settings['weighting'][ $post_type ][ $weighting_field ]['weight'] ) : 0,
'enabled' => isset( $settings['weighting'][ $post_type ][ $weighting_field ]['enabled'] ) && 'on' === $settings['weighting'][ $post_type ][ $weighting_field ]['enabled'] ? true : false,
];
}
}

if ( ! empty( $_POST['weighting'] ) ) {
foreach ( $_POST['weighting'] as $post_type => $post_type_weighting ) {
// This also ensures the string is safe, since this would return false otherwise
if ( ! post_type_exists( $post_type ) ) {
continue;
}
$search = Features::factory()->get_registered_feature( 'search' );
$post_types = $search->get_searchable_post_types();

$new_config[ $post_type ] = array();
foreach ( $post_types as $post_type ) {
// This also ensures the string is safe, since this would return false otherwise
if ( ! post_type_exists( $post_type ) ) {
continue;
}

foreach ( $post_type_weighting as $weighting_field => $weighting_values ) {
/** override default post_type settings while saving */
$new_config[ $post_type ] = array();

if ( isset( $settings['weighting'][ $post_type ] ) ) {
foreach ( $settings['weighting'][ $post_type ] as $weighting_field => $weighting_values ) {
$new_config[ $post_type ][ sanitize_text_field( $weighting_field ) ] = [
'weight' => isset( $weighting_values['weight'] ) ? intval( $weighting_values['weight'] ) : 0,
'enabled' => isset( $weighting_values['enabled'] ) && 'on' === $weighting_values['enabled'] ? true : false,
Expand All @@ -354,20 +385,7 @@ public function handle_save() {

update_option( 'elasticpress_weighting', $final_config );

$redirect_url = admin_url( 'admin.php?page=elasticpress-weighting' );
$redirect_url = add_query_arg( 'settings-updated', true, $redirect_url );

// Do a non-blocking search query to force the autosuggest hash to update
$url = add_query_arg( [ 's' => 'search test' ], home_url( '/' ) );
wp_remote_get(
$url,
[
'blocking' => false,
]
);

wp_safe_redirect( $redirect_url );
exit();
return $final_config;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/classes/Feature/WooCommerce/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@ public function get_orderby_meta_mapping( $meta_key ) {
'ID' => 'ID',
'menu_order' => 'menu_order title date',
'menu_order title' => 'menu_order title date',
'total_sales' => 'meta.total_sales.long date',
'total_sales' => 'meta.total_sales.double date',
'_wc_average_rating' => 'meta._wc_average_rating.double date',
'_price' => 'meta._price.long date',
'_price' => 'meta._price.double date',
)
);

Expand Down
6 changes: 3 additions & 3 deletions includes/classes/Indexable/Post/DateQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use \WP_Date_Query as WP_Date_Query;

if ( ! defined( 'ABSPATH' ) ) {
// @codeCoverageIgnoreStart
exit; // Exit if accessed directly.
// @codeCoverageIgnoreEnd
}

/**
Expand Down Expand Up @@ -70,9 +72,7 @@ protected function get_es_filter_for_query( $query, $depth = 0 ) {
$clause_filter = $this->get_es_filter_for_clause( $clause, $query );

$filter_count = count( $clause_filter );
if ( ! $filter_count ) {
$filter_chunks['filters'][] = '';
} else {
if ( $filter_count ) {
$filter_chunks['filters'][] = $clause_filter;
}

Expand Down
Loading

0 comments on commit 84bb692

Please sign in to comment.