get_current_screen() ) { return; } wp_enqueue_script( 'ep_settings_scripts', EP_URL . 'dist/js/settings-script.js', Utils\get_asset_info( 'settings-script', 'dependencies' ), Utils\get_asset_info( 'settings-script', 'version' ), true ); wp_set_script_translations( 'ep_settings_scripts', 'elasticpress' ); } /** * Admin-init actions * * Sets up Settings API. */ public function action_admin_init() { $post = wp_unslash( $_POST ); if ( empty( $post['ep_settings_nonce'] ) || ! wp_verify_nonce( $post['ep_settings_nonce'], 'elasticpress_settings' ) ) { return; } $this->prev_ep_language = Utils\get_language(); $this->prev_ep_host = Utils\get_host(); $this->prev_ep_credentials = Utils\get_epio_credentials(); $this->prev_ep_bulk_setting = Utils\get_option( 'ep_bulk_setting', 350 ); $language = sanitize_text_field( $post['ep_language'] ); Utils\update_option( 'ep_language', $language ); if ( isset( $post['ep_host'] ) ) { $host = esc_url_raw( trim( $post['ep_host'] ) ); Utils\update_option( 'ep_host', $host ); } if ( isset( $post['ep_credentials'] ) && ( ! defined( 'EP_CREDENTIALS' ) || ! EP_CREDENTIALS ) ) { $credentials = Utils\sanitize_credentials( $post['ep_credentials'] ); // Preserve the existing token if the field was left empty (it is always empty on load). if ( empty( $credentials['token'] ) ) { $credentials['token'] = $this->prev_ep_credentials['token']; } Utils\update_option( 'ep_credentials', $credentials ); } if ( isset( $post['ep_bulk_setting'] ) ) { Utils\update_option( 'ep_bulk_setting', $this->sanitize_bulk_settings( $post['ep_bulk_setting'] ) ); } $es_info = \ElasticPress\Elasticsearch::factory()->get_elasticsearch_info( true ); if ( empty( $es_info['version'] ) ) { if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { add_action( 'network_admin_notices', [ $this, 'add_validation_notice' ] ); } else { add_action( 'admin_notices', [ $this, 'add_validation_notice' ] ); } unset( $_POST['ep_host'] ); // Needed to prevent going to the next installation step $this->reset_settings(); } } /** * Add a notice to the Settings form when the host was not set yet */ public function add_validation_notice() { $target = ( Utils\is_epio() ) ? _x( 'ElasticPress.io account', 'Settings validation message', 'elasticpress' ) : _x( 'Elasticsearch server', 'Settings validation message', 'elasticpress' ); $is_first_setup = empty( $this->prev_ep_host ); if ( $is_first_setup ) { // Setting it for the first time -- probably during the install process. $message = sprintf( /* translators: EP.io account or ES server. */ __( 'It was not possible to connect to your %s. Please check your settings and try again.', 'elasticpress' ), $target ); } else { $message = sprintf( /* translators: EP.io account or ES server. */ __( 'It was not possible to connect to your %s. Your settings were reverted.', 'elasticpress' ), $target ); } ?>

prev_ep_language ); Utils\update_option( 'ep_host', $this->prev_ep_host ); Utils\update_option( 'ep_credentials', $this->prev_ep_credentials ); Utils\update_option( 'ep_bulk_setting', $this->prev_ep_bulk_setting ); \ElasticPress\Elasticsearch::factory()->get_elasticsearch_info( true ); } }