beans_open_markup

Register open markup and attributes by ID.

The Beans HTML “markups” and “attributes” functions make it really easy to modify, replace, extend, remove or hook into registered markup or attributes.

The “data-markup-id” is added as a HTML attribute if the development mode is enabled. This makes it very easy to find the content ID when inspecting an element in a web browser.

Since this function uses beans_apply_filters(), the $id argument may contain sub-hook(s).

beans_open_markup( string $id, string|bool $tag, string|array $attributes = array() )

Return: (string) The output.

Parameters

NameTypeRequiredDefaultDescription
$idstringtrue-A unique string used as a reference. The $id argument may contain sub-hooks(s).
$tagstring|booltrue-The HTML tag. If set to False or empty, the markup HTML tag will be removed but the actions hook will be called. If set the Null, both markup HTML tag and actions hooks will be removed.
$attributesstring|arrayfalsearray()Query string or array of attributes. The array key defines the attribute name and the array value defines the attribute value. Setting the array value to '' will display the attribute value as empty (e.g. class=""). Setting it to 'false' will only display the attribute name (e.g. data-example). Setting it to 'null' will not display anything.
$varmixedfalse-Additional variables passed to the functions hooked to $id.

Source

function beans_open_markup( $id, $tag, $attributes = array() ) {

	global $_temp_beans_selfclose_markup;

	$args = func_get_args();
	$attributes_args = $args;

	// Set markup tag filter id.
	$args[0] = $id . '_markup';

	if ( isset( $args[2] ) ) {
		unset( $args[2] );
	}

	// Remove function $tag argument.
	unset( $attributes_args[1] );

	// Stop here if the tag is set to false, the before and after actions won't run in this case.
	if ( null === ( $tag = call_user_func_array( 'beans_apply_filters', $args ) ) ) {
		return;
	}

	// Remove function $tag argument.
	unset( $args[1] );

	// Set before action id.
	$args[0] = $id . '_before_markup';

	$output = call_user_func_array( '_beans_render_action', $args );

		// Don't output the tag if empty, the before and after actions still run.
		if ( $tag ) {
			$output .= '<' . $tag . ' ' . call_user_func_array( 'beans_add_attributes', $attributes_args ) . ( _beans_is_html_dev_mode() ? ' data-markup-id="' . $id . '"' : null ) . ( $_temp_beans_selfclose_markup ? '/' : '' ) . '>';
		}

	// Set after action id.
	$args[0] = $id . ( $_temp_beans_selfclose_markup ? '_after_markup' : '_prepend_markup' );

	$output .= call_user_func_array( '_beans_render_action', $args );

	// Reset temp selfclose global to reduce memory usage.
	unset( $GLOBALS['_temp_beans_selfclose_markup'] );

	return $output;

}