HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //proc/self/cwd/wp-content/plugins/automatewoo/includes/Fields/Searchable_Select_Abstract.php
<?php

namespace AutomateWoo\Fields;

use AutomateWoo\Clean;

/**
 * Class Searchable_Select_Abstract
 *
 * Abstract base class for AJAX searchable select fields.
 *
 * @since 4.6.0
 * @package AutomateWoo\Fields
 */
abstract class Searchable_Select_Abstract extends Field {

	/**
	 * Field type.
	 *
	 * @var string
	 */
	protected $type = 'searchable-select';

	/**
	 * Whether to allow multiple selections.
	 *
	 * @var bool
	 */
	protected $multiple = false;

	/**
	 * Get the ajax action to use for the search.
	 *
	 * @return string
	 */
	abstract protected function get_search_ajax_action();

	/**
	 * Searchable_Select_Abstract constructor.
	 */
	public function __construct() {
		parent::__construct();
		$this->classes[] = 'wc-product-search';
	}

	/**
	 * Get the displayed value of a selected option.
	 *
	 * @param string $value
	 *
	 * @return string
	 */
	protected function get_select_option_display_value( $value ) {
		return $value;
	}

	/**
	 * Output field HTML.
	 *
	 * @param int|array|string $values
	 */
	public function render( $values ) {
		$options = [];
		$values  = array_filter( (array) $values );

		foreach ( $values as $value ) {
			$options[ $value ] = $this->get_select_option_display_value( $value );
		}

		?>

		<select class="<?php echo esc_attr( $this->get_classes() ); ?>"
				<?php echo $this->is_multiple() ? 'multiple="multiple"' : ''; ?>
				name="<?php echo esc_attr( $this->get_full_name() ); ?><?php echo $this->is_multiple() ? '[]' : ''; ?>"
				data-placeholder="<?php esc_attr_e( 'Search&hellip;', 'automatewoo' ); ?>"
				data-action="<?php echo esc_attr( $this->get_search_ajax_action() ); ?>">
			<?php
			foreach ( $options as $option_key => $option_value ) {
				echo '<option value="' . esc_attr( $option_key ) . '" selected="selected">' . wp_kses_post( $option_value ) . '</option>';
			}
			?>
		</select>

		<script type="text/javascript">
			jQuery( 'body' ).trigger( 'wc-enhanced-select-init' );
		</script>

		<?php
	}

	/**
	 * Sanitizes the value of the field.
	 *
	 * @param array|string $value
	 *
	 * @return array|string
	 */
	public function sanitize_value( $value ) {
		if ( $this->is_multiple() ) {
			return Clean::recursive( $value );
		} else {
			return Clean::string( $value );
		}
	}

	/**
	 * Set multiple prop.
	 *
	 * @param bool $multiple
	 *
	 * @return $this
	 */
	public function set_multiple( $multiple ) {
		$this->multiple = $multiple;
		return $this;
	}

	/**
	 * Is multiple prop enabled.
	 *
	 * @return bool
	 */
	public function is_multiple() {
		return $this->multiple;
	}

}