beans_add_action

Hooks a function on to a specific action.

This function is similar to add_action() with the exception of being registered by ID in order to be manipulated by the other Beans Actions functions.

beans_add_action( string $id, string $hook, callback $callback, int $priority = 10, int $args = 1 )

Return: (bool) Will always return true.

Parameters

NameTypeRequiredDefaultDescription
$idstringtrue-A unique string used as a reference.
$hookstringtrue-The name of the action to which the $callback is hooked.
$callbackcallbacktrue-The name of the function you wish to be called.
$priorityintfalse10Used to specify the order in which the functions associated with a particular action are executed. Default 10. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
$argsintfalse1The number of arguments the function accepts. Default 1.

Source

function beans_add_action( $id, $hook, $callback, $priority = 10, $args = 1 ) {

	$action = array(
		'hook'     => $hook,
		'callback' => $callback,
		'priority' => $priority,
		'args'     => $args,
	);

	// Replace original if set.
	if ( $replaced = _beans_get_action( $id, 'replaced' ) ) {
		$action = array_merge( $action, $replaced );
	}

	$action = _beans_set_action( $id, $action, 'added', true );

	// Stop here if removed.
	if ( _beans_get_action( $id, 'removed' ) ) {
		return;
	}

	// Merge modified.
	if ( $modified = _beans_get_action( $id, 'modified' ) ) {
		$action = array_merge( $action, $modified );
	}

	// Validate action arguments.
	if ( count( $action ) == 4 ) {
		add_action( $action['hook'], $action['callback'], $action['priority'], $action['args'] );
	}

	return true;

}