| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template for ElasticPress settings page |
| 4 |
* |
| 5 |
* @since 2.1 |
| 6 |
* @package elasticpress |
| 7 |
*/ |
| 8 |
|
| 9 |
use ElasticPress\Dashboard; |
| 10 |
use ElasticPress\Elasticsearch; |
| 11 |
use ElasticPress\IndexHelper; |
| 12 |
use ElasticPress\Utils; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
$index_meta = IndexHelper::factory()->get_index_meta(); |
| 19 |
|
| 20 |
$version = Elasticsearch::factory()->get_elasticsearch_version(); |
| 21 |
|
| 22 |
$host = Utils\get_host(); |
| 23 |
$is_epio = Utils\is_epio(); |
| 24 |
$credentials = Utils\get_epio_credentials(); |
| 25 |
$wpconfig = defined( 'EP_HOST' ) && EP_HOST; |
| 26 |
|
| 27 |
$bulk_setting = Utils\get_option( 'ep_bulk_setting', 350 ); |
| 28 |
?> |
| 29 |
|
| 30 |
<?php require_once __DIR__ . '/header.php'; ?> |
| 31 |
|
| 32 |
<div class="error-overlay <?php if ( ! empty( $index_meta ) ) : ?>syncing<?php endif; ?>"></div> |
| 33 |
<div class="wrap"> |
| 34 |
<h1><?php esc_html_e( 'Settings', 'elasticpress' ); ?></h1> |
| 35 |
|
| 36 |
<form action="" method="post" class="ep-settings"> |
| 37 |
<?php wp_nonce_field( 'elasticpress_settings', 'ep_settings_nonce' ); ?> |
| 38 |
|
| 39 |
<div class="ep-credentials"> |
| 40 |
<?php if ( ! $wpconfig ) : ?> |
| 41 |
<h2 class="nav-tab-wrapper ep-credentials-tabs"> |
| 42 |
<button class="nav-tab ep-credentials-tab <?php if ( ! $host || $is_epio ) { ?>nav-tab-active initial<?php } ?>" data-epio type="button"> |
| 43 |
<img src="<?php echo esc_url( plugins_url( '/images/logo-icon.svg', dirname( __DIR__ ) ) ); ?>" width="16" height="16" alt="ElasticPress.io" /> |
| 44 |
<span>ElasticPress.io</span> |
| 45 |
</button> |
| 46 |
<button class="nav-tab ep-credentials-tab <?php if ( $host && ! $is_epio ) { ?>nav-tab-active initial<?php } ?>" type="button"> |
| 47 |
<span>Third-Party/Self-Hosted</span> |
| 48 |
</button> |
| 49 |
</h2> |
| 50 |
<?php endif; ?> |
| 51 |
|
| 52 |
<fieldset class="<?php if ( $wpconfig ) { ?>predefined<?php } ?>"> |
| 53 |
<?php if ( $is_epio || ! $wpconfig ) : ?> |
| 54 |
<p class="ep-legend ep-additional-fields <?php if ( $host && ! $is_epio ) { ?>hidden<?php } ?>" aria-hidden="<?php if ( $host && ! $is_epio ) { ?>true<?php } else { ?>false<?php } ?>"> |
| 55 |
<a href="https://elasticpress.io/" target="_blank" rel="noreferrer noopener">ElasticPress.io</a> is a hosted Elasticsearch service built for ElasticPress, powered by <a href="https://10up.com/" target="_blank" rel="noreferrer noopener">10up</a>. |
| 56 |
</p> |
| 57 |
<?php endif; ?> |
| 58 |
<table class="form-table"> |
| 59 |
<tbody> |
| 60 |
<tr class="ep-host-row"> |
| 61 |
<th scope="row"> |
| 62 |
<label for="ep_host"> |
| 63 |
<?php if ( $is_epio ) : ?> |
| 64 |
<?php esc_html_e( 'ElasticPress.io Host URL', 'elasticpress' ); ?> |
| 65 |
<?php else : ?> |
| 66 |
<?php esc_html_e( 'Elasticsearch Host URL', 'elasticpress' ); ?> |
| 67 |
<?php endif; ?> |
| 68 |
</label> |
| 69 |
</th> |
| 70 |
<td> |
| 71 |
<?php |
| 72 |
/** |
| 73 |
* Filter whether to show host field in admin UI or not |
| 74 |
* |
| 75 |
* @hook ep_admin_show_host |
| 76 |
* @param {boolean} $show True to show |
| 77 |
* @return {boolean} New value |
| 78 |
*/ |
| 79 |
$show_host = apply_filters( 'ep_admin_show_host', true ); |
| 80 |
$disabled = $wpconfig || ! $show_host; |
| 81 |
$value = $show_host ? esc_url( $host ) : __( '••••••••••••••••', 'elasticpress' ); |
| 82 |
?> |
| 83 |
<input <?php disabled( $disabled, true, true ); ?> placeholder="https://" type="text" value="<?php echo esc_attr( $value ); ?>" name="ep_host" id="ep_host"> |
| 84 |
<?php if ( $show_host ) : ?> |
| 85 |
<?php if ( $wpconfig ) : ?> |
| 86 |
<p class="description ep-host-legend"><?php esc_html_e( 'Host already defined in wp-config.php.', 'elasticpress' ); ?></p> |
| 87 |
<?php elseif ( $is_epio ) : ?> |
| 88 |
<p class="description ep-host-legend"><?php esc_html_e( 'Plug in your ElasticPress.io server here.', 'elasticpress' ); ?></p> |
| 89 |
<?php else : ?> |
| 90 |
<p class="description ep-host-legend"><?php esc_html_e( 'Plug in your Elasticsearch server here.', 'elasticpress' ); ?></p> |
| 91 |
<?php endif; ?> |
| 92 |
<?php endif; ?> |
| 93 |
</td> |
| 94 |
</tr> |
| 95 |
<?php if ( $is_epio || ! $wpconfig ) : ?> |
| 96 |
|
| 97 |
<tr class="ep-additional-fields <?php if ( $host && ! $is_epio ) { ?>hidden<?php } ?>" aria-hidden="<?php if ( $host && ! $is_epio ) { ?>true<?php } else { ?>false<?php } ?>"> |
| 98 |
<th scope="row"> |
| 99 |
<label for="ep_username"><?php esc_html_e( 'Subscription ID', 'elasticpress' ); ?></label> |
| 100 |
</th> |
| 101 |
<td> |
| 102 |
<?php |
| 103 |
/** |
| 104 |
* Filter whether to show epio credentials fields in admin UI or not |
| 105 |
* |
| 106 |
* @hook ep_admin_show_credentials |
| 107 |
* @param {boolean} $show True to show |
| 108 |
* @return {boolean} New value |
| 109 |
*/ |
| 110 |
if ( apply_filters( 'ep_admin_show_credentials', true ) ) : |
| 111 |
?> |
| 112 |
<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"> |
| 113 |
<?php endif ?> |
| 114 |
<?php if ( defined( 'EP_CREDENTIALS' ) && EP_CREDENTIALS ) : ?> |
| 115 |
<p class="description"><?php esc_html_e( 'Your Subscription ID is set in wp-config.php', 'elasticpress' ); ?></p> |
| 116 |
<?php else : ?> |
| 117 |
<p class="description"><?php esc_html_e( 'Plug in your subscription ID (or subscription name) here.', 'elasticpress' ); ?></p> |
| 118 |
<?php endif; ?> |
| 119 |
</td> |
| 120 |
</tr> |
| 121 |
|
| 122 |
<tr class="ep-additional-fields <?php if ( $host && ! $is_epio ) { ?>hidden<?php } ?>" aria-hidden="<?php if ( $host && ! $is_epio ) { ?>true<?php } else { ?>false<?php } ?>"> |
| 123 |
<th scope="row"> |
| 124 |
<label for="ep_token"><?php esc_html_e( 'Subscription Token', 'elasticpress' ); ?></label> |
| 125 |
</th> |
| 126 |
<td> |
| 127 |
<?php |
| 128 |
/** |
| 129 |
* Filter whether to show epio credentials fields in admin UI or not |
| 130 |
* |
| 131 |
* @hook ep_admin_show_credentials |
| 132 |
* @param {boolean} $show True to show |
| 133 |
* @return {boolean} New value |
| 134 |
*/ |
| 135 |
if ( apply_filters( 'ep_admin_show_credentials', true ) ) : |
| 136 |
?> |
| 137 |
<input <?php if ( defined( 'EP_CREDENTIALS' ) && EP_CREDENTIALS ) : ?>disabled<?php endif; ?> type="password" value="" autocomplete="off" placeholder="<?php echo esc_attr( $credentials['token'] ? '••••••••' : '' ); ?>" name="ep_credentials[token]" id="ep_token"> |
| 138 |
<?php endif ?> |
| 139 |
<?php if ( defined( 'EP_CREDENTIALS' ) && EP_CREDENTIALS ) : ?> |
| 140 |
<p class="description"><?php esc_html_e( 'Your subscription token is defined in wp-config.php and is hidden for security.', 'elasticpress' ); ?></p> |
| 141 |
<?php else : ?> |
| 142 |
<p class="description"><?php esc_html_e( 'Your subscription token is saved and is hidden for security. Enter a new value to update it.', 'elasticpress' ); ?></p> |
| 143 |
<?php endif; ?> |
| 144 |
</td> |
| 145 |
</tr> |
| 146 |
<?php endif; ?> |
| 147 |
</tbody> |
| 148 |
</table> |
| 149 |
</fieldset> |
| 150 |
</div> |
| 151 |
|
| 152 |
<div class="ep-credentials-general"> |
| 153 |
<table class="form-table"> |
| 154 |
<tbody> |
| 155 |
<tr> |
| 156 |
<th scope="row"> |
| 157 |
<label for="ep_language"><?php esc_html_e( 'Elasticsearch Language', 'elasticpress' ); ?></label> |
| 158 |
</th> |
| 159 |
<td> |
| 160 |
<?php |
| 161 |
$ep_language = Utils\get_language(); |
| 162 |
|
| 163 |
wp_dropdown_languages( |
| 164 |
[ |
| 165 |
'id' => 'ep_language', |
| 166 |
'name' => 'ep_language', |
| 167 |
'selected' => $ep_language, |
| 168 |
'languages' => Dashboard\get_available_languages( 'locales' ), |
| 169 |
'show_option_site_default' => true, |
| 170 |
'explicit_option_en_us' => true, |
| 171 |
'show_available_translations' => false, |
| 172 |
] |
| 173 |
); |
| 174 |
?> |
| 175 |
<p class="description"><?php esc_html_e( 'Default language for your Elasticsearch mapping.', 'elasticpress' ); ?></p> |
| 176 |
</td> |
| 177 |
</tr> |
| 178 |
<tr> |
| 179 |
<th scope="row"> |
| 180 |
<label><?php esc_html_e( 'Elasticsearch Version', 'elasticpress' ); ?></label></th> |
| 181 |
<td> |
| 182 |
<?php if ( $is_epio ) : ?> |
| 183 |
<?php esc_html_e( 'ElasticPress.io Managed Platform' ); ?> |
| 184 |
<?php else : ?> |
| 185 |
<?php if ( ! empty( $version ) ) : ?> |
| 186 |
<?php echo esc_html( $version ); ?> |
| 187 |
<?php else : ?> |
| 188 |
— |
| 189 |
<?php endif; ?> |
| 190 |
<?php endif; ?> |
| 191 |
</td> |
| 192 |
</tr> |
| 193 |
<?php if ( ! empty( $host ) && ! has_filter( 'ep_index_posts_per_page' ) ) : ?> |
| 194 |
<tr> |
| 195 |
<th scope="row"> |
| 196 |
<label for="ep_bulk_setting"><?php esc_html_e( 'Content Items per Index Cycle ', 'elasticpress' ); ?></label> |
| 197 |
</th> |
| 198 |
<td> |
| 199 |
<input type="text" name="ep_bulk_setting" id="ep_bulk_setting" value="<?php echo absint( $bulk_setting ); ?>"> |
| 200 |
</td> |
| 201 |
</tr> |
| 202 |
<?php endif; ?> |
| 203 |
</tbody> |
| 204 |
</table> |
| 205 |
</div> |
| 206 |
|
| 207 |
<?php |
| 208 |
/** |
| 209 |
* Fires after settings table is displayed for inserting custom settings. |
| 210 |
* |
| 211 |
* @hook ep_settings_custom |
| 212 |
*/ |
| 213 |
do_action( 'ep_settings_custom' ); |
| 214 |
?> |
| 215 |
|
| 216 |
<input type="submit" <?php if ( ! empty( $index_meta ) ) : ?>disabled<?php endif; ?> name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'elasticpress' ); ?>"> |
| 217 |
</form> |
| 218 |
</div> |
| 219 |
|