Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings screen improvements #2976

Merged
merged 7 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion images/logo-elasticpress-io.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/logo-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion includes/classes/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ElasticPress;

use ElasticPress\Utils as Utils;
use ElasticPress\Utils;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand Down Expand Up @@ -46,6 +46,7 @@ public function setup() {
'3.5.3' => [ 'upgrade_3_5_3', 'init' ],
'3.6.6' => [ 'upgrade_3_6_6', 'init' ],
'4.2.2' => [ 'upgrade_4_2_2', 'init' ],
'4.4.0' => [ 'upgrade_4_4_0', 'init' ],
];

array_walk( $routines, [ $this, 'run_upgrade_routine' ] );
Expand Down Expand Up @@ -179,6 +180,17 @@ public function upgrade_4_2_2() {
}
}

/**
* Upgrade routine of v4.4.0.
*
* Delete the ep_prefix option, as that is now obtained via ep_credentials
*
* @see https://github.com/10up/ElasticPress/issues/2739
*/
public function upgrade_4_4_0() {
Utils\delete_option( 'ep_prefix' );
}

/**
* Adjust the upgrade sync notice to warn users about Instant Results.
*
Expand Down
6 changes: 0 additions & 6 deletions includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,6 @@ function action_admin_init() {
Utils\update_option( 'ep_host', $host );
}

if ( isset( $_POST['ep_prefix'] ) ) {
$prefix = ( isset( $_POST['ep_prefix'] ) ) ? sanitize_text_field( wp_unslash( $_POST['ep_prefix'] ) ) : '';
Utils\update_option( 'ep_prefix', $prefix );
}

if ( isset( $_POST['ep_credentials'] ) ) {
$credentials = ( isset( $_POST['ep_credentials'] ) ) ? Utils\sanitize_credentials( $_POST['ep_credentials'] ) : [
'username' => '',
Expand All @@ -625,7 +620,6 @@ function action_admin_init() {
}
} else {
register_setting( 'elasticpress', 'ep_host', 'esc_url_raw' );
register_setting( 'elasticpress', 'ep_prefix', 'sanitize_text_field' );
register_setting( 'elasticpress', 'ep_credentials', 'ep_sanitize_credentials' );
register_setting( 'elasticpress', 'ep_language', 'sanitize_text_field' );
register_setting(
Expand Down
37 changes: 7 additions & 30 deletions includes/partials/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,42 +90,18 @@
<?php if ( $wpconfig ) : ?>
<p class="description ep-host-legend"><?php esc_html_e( 'Host already defined in wp-config.php.', 'elasticpress' ); ?></p>
<?php elseif ( $is_epio ) : ?>
<p class="description ep-host-legend"><?php esc_html_e( 'Plug in your ElasticPress.io server here!', 'elasticpress' ); ?></p>
<p class="description ep-host-legend"><?php esc_html_e( 'Plug in your ElasticPress.io server here.', 'elasticpress' ); ?></p>
<?php else : ?>
<p class="description ep-host-legend"><?php esc_html_e( 'Plug in your Elasticsearch server here!', 'elasticpress' ); ?></p>
<p class="description ep-host-legend"><?php esc_html_e( 'Plug in your Elasticsearch server here.', 'elasticpress' ); ?></p>
<?php endif; ?>
<?php endif; ?>
</td>
</tr>
<?php if ( $is_epio || ! $wpconfig ) : ?>
<tr class="ep-additional-fields <?php if ( $host && ! $is_epio ) { ?>hidden<?php } ?>">
<th scope="row">
<label for="ep_prefix"><?php esc_html_e( 'Subscription ID', 'elasticpress' ); ?></label>
</th>
<td>
<?php
/**
* Filter whether to show index prefix field in admin UI or not
*
* @hook ep_admin_index_prefix
* @param {boolean} $show True to show
* @return {boolean} New value
*/
if ( apply_filters( 'ep_admin_show_index_prefix', true ) ) :
?>
<input <?php if ( defined( 'EP_INDEX_PREFIX' ) && EP_INDEX_PREFIX ) : ?>disabled<?php endif; ?> type="text" value="<?php echo esc_attr( rtrim( Utils\get_index_prefix(), '-' ) ); ?>" name="ep_prefix" id="ep_prefix">
<?php endif ?>
<?php if ( defined( 'EP_INDEX_PREFIX' ) && EP_INDEX_PREFIX ) : ?>
<p class="description"><?php esc_html_e( 'Your Subscription ID is set in wp-config.php', 'elasticpress' ); ?></p>
<?php else : ?>
<p class="description"><?php esc_html_e( 'Plug in your Subscription ID here.', 'elasticpress' ); ?></p>
<?php endif; ?>
</td>
</tr>

<tr class="ep-additional-fields <?php if ( $host && ! $is_epio ) { ?>hidden<?php } ?>" aria-hidden="<?php if ( $host && ! $is_epio ) { ?>true<?php } else { ?>false<?php } ?>">
<th scope="row">
<label for="ep_username"><?php esc_html_e( 'Subscription Username', 'elasticpress' ); ?></label>
<label for="ep_username"><?php esc_html_e( 'Subscription ID', 'elasticpress' ); ?></label>
</th>
<td>
<?php
Expand All @@ -141,16 +117,17 @@
<input <?php if ( defined( 'EP_CREDENTIALS' ) && EP_CREDENTIALS ) : ?>disabled<?php endif; ?> type="text" value="<?php echo esc_attr( $credentials['username'] ); ?>" name="ep_credentials[username]" id="ep_username">
<?php endif ?>
<?php if ( defined( 'EP_CREDENTIALS' ) && EP_CREDENTIALS ) : ?>
<p class="description"><?php esc_html_e( 'Your Subscription Username is set in wp-config.php', 'elasticpress' ); ?></p>
<p class="description"><?php esc_html_e( 'Your Subscription ID is set in wp-config.php', 'elasticpress' ); ?></p>
<?php else : ?>
<p class="description"><?php esc_html_e( 'Plug in your subscription username here.', 'elasticpress' ); ?></p>
<p class="description"><?php esc_html_e( 'Plug in your subscription ID (or subscription name) here.', 'elasticpress' ); ?></p>
<?php endif; ?>
</td>
</tr>

<tr class="ep-additional-fields <?php if ( $host && ! $is_epio ) { ?>hidden<?php } ?>" aria-hidden="<?php if ( $host && ! $is_epio ) { ?>true<?php } else { ?>false<?php } ?>">
<th scope="row">
<label for="ep_token"><?php esc_html_e( 'Subscription Token', 'elasticpress' ); ?></label></th>
<label for="ep_token"><?php esc_html_e( 'Subscription Token', 'elasticpress' ); ?></label>
</th>
<td>
<?php
/**
Expand Down
15 changes: 8 additions & 7 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ function get_shield_credentials() {
* @return string|bool
*/
function get_index_prefix() {
if ( defined( 'EP_INDEX_PREFIX' ) && EP_INDEX_PREFIX ) {
$prefix = EP_INDEX_PREFIX;
} elseif ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK && is_epio() ) {
$prefix = get_site_option( 'ep_prefix', false );
if ( defined( 'EP_INDEX_PREFIX' ) && \EP_INDEX_PREFIX ) {
$prefix = \EP_INDEX_PREFIX;
} elseif ( is_epio() ) {
$prefix = get_option( 'ep_prefix', false );

if ( '-' !== substr( $prefix, - 1 ) ) {
$credentials = get_epio_credentials();
$prefix = $credentials['username'];
if (
( ! defined( 'EP_IS_NETWORK' ) || ! EP_IS_NETWORK ) &&
( '-' !== substr( $prefix, - 1 ) )
) {
$prefix .= '-';
}
} else {
Expand Down