wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_get_position_support_styles › WordPress Function

Since7.2.0
Deprecatedn/a
› wp_get_position_support_styles ( $selector, $position, $allowed_position_types )
Parameters: (3)
  • (string) $selector CSS selector to scope the rules to.
    Required: Yes
  • (mixed) $position Position style configuration.
    Required: Yes
  • (array) $allowed_position_types Position types the theme supports.
    Required: Yes
Returns:
  • (array) CSS rules, or an empty array when the configuration is not allowed.
Defined at:
Codex:

Returns the CSS rules for a position style configuration.



Source

function wp_get_position_support_styles( $selector, $position, $allowed_position_types ) {
	$styles = array();

	if ( ! is_array( $position ) || ! is_string( $position['type'] ?? null ) ) {
		return $styles;
	}

	$position_type = $position['type'];

	if ( ! in_array( $position_type, $allowed_position_types, true ) ) {
		return $styles;
	}

	$sides = array( 'top', 'right', 'bottom', 'left' );

	foreach ( $sides as $side ) {
		$side_value = $position[ $side ] ?? null;
		if ( null !== $side_value ) {
			/*
			 * For fixed or sticky top positions,
			 * ensure the value includes an offset for the logged in admin bar.
			 */
			if ( 'top' === $side ) {
				// Ensure 0 values can be used in `calc()` calculations.
				if ( '0' === $side_value || 0 === $side_value ) {
					$side_value = '0px';
				}

				// Ensure current side value also factors in the height of the logged in admin bar.
				$side_value = "calc($side_value + var(--wp-admin--admin-bar--position-offset, 0px))";
			}

			$styles[] = array(
				'selector'     => $selector,
				'declarations' => array(
					$side => $side_value,
				),
			);
		}
	}

	$styles[] = array(
		'selector'     => $selector,
		'declarations' => array(
			'position' => $position_type,
			'z-index'  => '10',
		),
	);

	return $styles;
}