acf_field_select::input_admin_enqueue_scriptspublicACF 5.3.2

Enqueues admin scripts for the Select field.

Метод класса: acf_field_select{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$acf_field_select = new acf_field_select();
$acf_field_select->input_admin_enqueue_scripts();

Список изменений

С версии 5.3.2 Введена.

Код acf_field_select::input_admin_enqueue_scripts() ACF 6.4.2

public function input_admin_enqueue_scripts() {
	// Bail early if not enqueuing select2.
	if ( ! acf_get_setting( 'enqueue_select2' ) ) {
		return;
	}

	global $wp_scripts;

	$min   = defined( 'ACF_DEVELOPMENT_MODE' ) && ACF_DEVELOPMENT_MODE ? '' : '.min';
	$major = acf_get_setting( 'select2_version' );

	// attempt to find 3rd party Select2 version
	// - avoid including v3 CSS when v4 JS is already enqueued.
	if ( isset( $wp_scripts->registered['select2'] ) ) {
		$major = (int) $wp_scripts->registered['select2']->ver;
	}

	if ( $major === 3 ) {
		// Use v3 if necessary.
		$version = '3.5.2';
		$script  = acf_get_url( "assets/inc/select2/3/select2{$min}.js" );
		$style   = acf_get_url( 'assets/inc/select2/3/select2.css' );
	} else {
		// Default to v4.
		$version = '4.0.13';
		$script  = acf_get_url( "assets/inc/select2/4/select2.full{$min}.js" );
		$style   = acf_get_url( "assets/inc/select2/4/select2{$min}.css" );
	}

	wp_enqueue_script( 'select2', $script, array( 'jquery' ), $version );
	wp_enqueue_style( 'select2', $style, '', $version );

	acf_localize_data(
		array(
			'select2L10n' => array(
				'matches_1'            => _x( 'One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf' ),
				/* translators: %d - number of results available in select field */
				'matches_n'            => _x( '%d results are available, use up and down arrow keys to navigate.', 'Select2 JS matches_n', 'acf' ),
				'matches_0'            => _x( 'No matches found', 'Select2 JS matches_0', 'acf' ),
				'input_too_short_1'    => _x( 'Please enter 1 or more characters', 'Select2 JS input_too_short_1', 'acf' ),
				/* translators: %d - number of characters to enter into select field input */
				'input_too_short_n'    => _x( 'Please enter %d or more characters', 'Select2 JS input_too_short_n', 'acf' ),
				'input_too_long_1'     => _x( 'Please delete 1 character', 'Select2 JS input_too_long_1', 'acf' ),
				/* translators: %d - number of characters that should be removed from select field */
				'input_too_long_n'     => _x( 'Please delete %d characters', 'Select2 JS input_too_long_n', 'acf' ),
				'selection_too_long_1' => _x( 'You can only select 1 item', 'Select2 JS selection_too_long_1', 'acf' ),
				/* translators: %d - maximum number of items that can be selected in the select field */
				'selection_too_long_n' => _x( 'You can only select %d items', 'Select2 JS selection_too_long_n', 'acf' ),
				'load_more'            => _x( 'Loading more results…', 'Select2 JS load_more', 'acf' ),
				'searching'            => _x( 'Searching…', 'Select2 JS searching', 'acf' ),
				'load_fail'            => _x( 'Loading failed', 'Select2 JS load_fail', 'acf' ),
			),
		)
	);
}