beans_modify_action

Modify an action.

This function modifies an action registered using beans_add_action() or beans_add_smart_action(). Each optional argument must be set to NULL to keep the orginal value.

The original action can be reset using beans_reset_action().

beans_modify_action( string $id, string $hook = null, callback $callback = null, int $priority = null, int $args = null )

Return: (bool) Will always return true.

Parameters

NameTypeRequiredDefaultDescription
$idstringtrue-The action ID.
$hookstringfalsenullThe name of the new action to which the $callback is hooked. Use NULL to keep the original value.
$callbackcallbackfalsenullThe name of the new function you wish to be called. Use NULL to keep the original value.
$priorityintfalsenullThe new priority. Use NULL to keep the original value.
$argsintfalsenullThe new number of arguments the function accept. Use NULL to keep the original value.

Source

function beans_modify_action( $id, $hook = null, $callback = null, $priority = null, $args = null ) {

	// Remove action.
	if ( $current = _beans_get_current_action( $id ) ) {
		remove_action( $current['hook'], $current['callback'], $current['priority'], $current['args'] );
	}

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

	// Merge modified.
	$action = _beans_merge_action( $id, $action, 'modified' );

	// Replace if needed.
	if ( $current ) {

		$action = array_merge( $current, $action );

		add_action( $action['hook'], $action['callback'], $action['priority'], $action['args'] );

	}

	return true;

}