layers_inline_button_styles

The Layers layers inline button styles function.

Description

layers_inline_button_styles( (constant) $container_id = NULL, (string) $type = 'background', (array) $args = array() ); 

Parameters (3)

0. $container_id — Optional. (constant) => NULL
The container id.
1. $type — Optional. (string) => 'background'
The type.
2. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'layers_inline_button_styles' ) ) { 
  2. require_once '/core/helpers/template.php'; 
  3.  
  4. // The container id. 
  5. $container_id = NULL; 
  6.  
  7. // The type. 
  8. $type = 'background'; 
  9.  
  10. // The args. 
  11. $args = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = layers_inline_button_styles($container_id, $type, $args); 
  15.  

Defined (1)

The function is defined in the following location(s).

/core/helpers/template.php  
  1. function layers_inline_button_styles( $container_id = NULL, $type = 'background' , $args = array() ) { 
  2.  
  3. $styles = ''; 
  4.  
  5. // Auto text color based on background color 
  6. if( isset( $args[ 'button' ][ 'background-color' ] ) && NULL !== layers_is_light_or_dark( $args[ 'button' ][ 'background-color' ] ) ) { 
  7.  
  8. // temporarily darken the background color, so we only switch text color if very light 
  9. $background_darker = layers_hex_darker( $args[ 'button' ][ 'background-color' ], 28 ); 
  10.  
  11. if ( 'light' == layers_is_light_or_dark( $background_darker ) ) { 
  12. $args['button']['color'] = 'rgba(0, 0, 0, .85)'; 
  13. else if ( 'dark' == layers_is_light_or_dark( $background_darker ) ) { 
  14. $args['button']['color'] = '#FFFFFF'; 
  15.  
  16. // Add styling for the standard colors 
  17. $styles .= layers_inline_styles( $container_id, $type, $args ); 
  18.  
  19. // Add styling for the hover colors 
  20. if( isset( $args['selectors'] ) ) { 
  21.  
  22. if ( ! is_array( $args['selectors'] ) ) { 
  23. // Make sure selectors is array if comma seperated string is passed 
  24. $args['selectors'] = explode( ', ', $args['selectors'] ); 
  25. $args['selectors'] = array_map( 'trim', $args['selectors'] ); 
  26.  
  27. $hover_args = $args; 
  28.  
  29. foreach( $args['selectors'] as $selector ) { 
  30. $new_selectors[] = $selector . ':hover'; 
  31. $hover_args['selectors'] = $new_selectors; 
  32.  
  33. // Generate a lighter text background color 
  34. if( isset( $args[ 'button' ][ 'background-color' ] ) ) { 
  35. $hover_args[ 'button' ]['background-color'] = layers_hex_lighter( $args[ 'button' ][ 'background-color' ] ); 
  36.  
  37. // Apply hover colors 
  38. if( isset( $hover_args ) ) { 
  39. $styles .= layers_inline_styles( $container_id, $type, $hover_args );// Add styling for the standard colors 
  40.  
  41. return $styles;