ACF_Assets::add_action()publicACF 5.9.0

  1. Renames $action depending on the current page (customizer, login, front-end).
  2. Alters the priotiry or calls the method directly if the action has already passed.

{} Это метод класса: ACF_Assets{}

Хуков нет.

Возвращает

null. Ничего.

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

$ACF_Assets = new ACF_Assets();
$ACF_Assets->add_action( $action, $method, $priority, $accepted_args );
$action(строка) (обязательный)
The action name.
$method(строка) (обязательный)
The method name.
$priority(int)
See add_action().
По умолчанию: 10
$accepted_args(int)
See add_action().
По умолчанию: 1

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

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

Код ACF_Assets::add_action() ACF 5.10.2

public function add_action( $action, $method, $priority = 10, $accepted_args = 1 ) {

	// Generate an array of action replacements.
	$replacements = array(
		'customizer' => array(
			'admin_enqueue_scripts'      => 'admin_enqueue_scripts',
			'admin_print_scripts'        => 'customize_controls_print_scripts',
			'admin_head'                 => 'customize_controls_print_scripts',
			'admin_footer'               => 'customize_controls_print_footer_scripts',
			'admin_print_footer_scripts' => 'customize_controls_print_footer_scripts',
		),
		'login'      => array(
			'admin_enqueue_scripts'      => 'login_enqueue_scripts',
			'admin_print_scripts'        => 'login_head',
			'admin_head'                 => 'login_head',
			'admin_footer'               => 'login_footer',
			'admin_print_footer_scripts' => 'login_footer',
		),
		'wp'         => array(
			'admin_enqueue_scripts'      => 'wp_enqueue_scripts',
			'admin_print_scripts'        => 'wp_print_scripts',
			'admin_head'                 => 'wp_head',
			'admin_footer'               => 'wp_footer',
			'admin_print_footer_scripts' => 'wp_print_footer_scripts',
		),
	);

	// Determine the current context.
	if ( did_action( 'customize_controls_init' ) ) {
		$context = 'customizer';
	} elseif ( did_action( 'login_form_register' ) ) {
		$context = 'login';
	} elseif ( is_admin() ) {
		$context = 'admin';
	} else {
		$context = 'wp';
	}

	// Replace action if possible.
	if ( isset( $replacements[ $context ][ $action ] ) ) {
		$action = $replacements[ $context ][ $action ];
	}

	// Check if action is currently being or has already been run.
	if ( did_action( $action ) ) {
		$doing = acf_doing_action( $action );
		if ( $doing && $doing < $priority ) {
			// Allow action to be added as per usual.
		} else {
			// Call method directly.
			return call_user_func( array( $this, $method ) );
		}
	}

	// Add action.
	add_action( $action, array( $this, $method ), $priority, $accepted_args );
}