layers_inline_styles

The Layers layers inline styles function.

Description

layers_inline_styles( (constant) $arg1 = NULL, (constant) $arg2 = NULL, (null) $arg3 = null ); 

Parameters (3)

0. $arg1 — Optional. (constant) => NULL
The arg1.
1. $arg2 — Optional. (constant) => NULL
The arg2.
2. $arg3 — Optional. (null) => null
The arg3.

Usage

  1. if ( !function_exists( 'layers_inline_styles' ) ) { 
  2. require_once '/core/helpers/template.php'; 
  3.  
  4. // The arg1. 
  5. $arg1 = NULL; 
  6.  
  7. // The arg2. 
  8. $arg2 = NULL; 
  9.  
  10. // The arg3. 
  11. $arg3 = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = layers_inline_styles($arg1, $arg2, $arg3); 
  15.  

Defined (1)

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

/core/helpers/template.php  
  1. function layers_inline_styles( $arg1 = NULL, $arg2 = NULL, $arg3 = NULL ) { 
  2.  
  3. if ( 3 == func_num_args() ) { 
  4. // layers_inline_styles( '#element', 'background', array( 'selectors' => '.element', 'background' => array( 'color' => '#FFF' ) ) ); 
  5. $container_id = $arg1; $type = $arg2; $args = $arg3; 
  6. elseif ( 2 == func_num_args() ) { 
  7. // layers_inline_styles( '#element', array( 'selectors' => array( '.element' ), 'css' => array( 'color' => '#FFF' ) ) ); 
  8. $container_id = $arg1; $type = 'css'; $args = $arg2; 
  9. elseif ( 1 == func_num_args() ) { 
  10. // layers_inline_styles( array( 'selectors' => array( '.element' ), 'css' => array( 'color' => '#FFF' ) ) ); 
  11. // layers_inline_styles( '.element { color: #FFF; }' ); 
  12. $container_id = NULL; $type = 'css'; $args = $arg1; 
  13.  
  14. // Get the generated CSS 
  15. global $layers_inline_css; 
  16.  
  17. $css = ''; 
  18.  
  19. if( empty( $args ) || ( !is_array( $args ) && '' == $args ) ) return; 
  20.  
  21. switch ( $type ) { 
  22.  
  23. case 'background' : 
  24.  
  25. // Set the background array 
  26. $bg_args = $args['background']; 
  27.  
  28. if( isset( $bg_args['color'] ) && '' != $bg_args['color'] ) { 
  29. $css .= 'background-color: ' . $bg_args['color'] . '; '; 
  30.  
  31. if( isset( $bg_args['repeat'] ) && '' != $bg_args['repeat'] ) { 
  32. $css .= 'background-repeat: ' . $bg_args['repeat'] . ';'; 
  33.  
  34. if( isset( $bg_args['position'] ) && '' != $bg_args['position'] ) { 
  35. $css .= 'background-position: ' . $bg_args['position'] . ';'; 
  36.  
  37. if( isset( $bg_args['stretch'] ) && '' != $bg_args['stretch'] ) { 
  38. $css .= 'background-size: cover;'; 
  39.  
  40. if( isset( $bg_args['fixed'] ) && '' != $bg_args['fixed'] ) { 
  41. $css .= 'background-attachment: fixed;'; 
  42.  
  43. if( isset( $bg_args['image'] ) && '' != $bg_args['image'] ) { 
  44. $image = wp_get_attachment_image_src( $bg_args['image'] , 'full' ); 
  45. $css.= 'background-image: url(\'' . $image[0] .'\');'; 
  46. break; 
  47.  
  48. case 'button' : 
  49.  
  50. // Set the background array 
  51. $button_args = $args['button']; 
  52.  
  53. if( isset( $button_args['background-color'] ) && '' != $button_args['background-color'] ) { 
  54. $css .= 'background-color: ' . $button_args['background-color'] . '; '; 
  55.  
  56. if( isset( $button_args['color'] ) && '' != $button_args['color'] ) { 
  57. $css .= 'color: ' . $button_args['color'] . '; '; 
  58.  
  59. break; 
  60.  
  61. case 'margin' : 
  62. case 'padding' : 
  63.  
  64. // Set the Margin or Padding array 
  65. $trbl_args = $args[ $type ]; 
  66.  
  67. if( isset( $trbl_args['top'] ) && '' != $trbl_args['top'] ) { 
  68. $css .= $type . '-top: ' . $trbl_args['top'] . 'px; '; 
  69.  
  70. if( isset( $trbl_args['right'] ) && '' != $trbl_args['right'] ) { 
  71. $css .= $type . '-right: ' . $trbl_args['right'] . 'px; '; 
  72.  
  73. if( isset( $trbl_args['bottom'] ) && '' != $trbl_args['bottom'] ) { 
  74. $css .= $type . '-bottom: ' . $trbl_args['bottom'] . 'px; '; 
  75.  
  76. if( isset( $trbl_args['left'] ) && '' != $trbl_args['left'] ) { 
  77. $css .= $type . '-left: ' . $trbl_args['left'] . 'px; '; 
  78.  
  79. break; 
  80.  
  81. case 'border' : 
  82.  
  83. // Set the background array 
  84. $border_args = $args['border']; 
  85.  
  86. if( isset( $border_args['color'] ) && '' != $border_args['color'] ) { 
  87. $css .= 'border-color: ' . $border_args[ 'color' ] . ';'; 
  88.  
  89. if( isset( $border_args['width'] ) && '' != $border_args['width'] ) { 
  90. $css .= 'border-width: ' . $border_args[ 'width' ] . 'px;'; 
  91. break; 
  92.  
  93. case 'color' : 
  94.  
  95. if( '' == $args[ 'color' ] ) return ; 
  96. $css .= 'color: ' . $args[ 'color' ] . ';'; 
  97.  
  98. break; 
  99.  
  100. case 'font-family' : 
  101.  
  102. if( '' == $args[ 'font-family' ] ) return ; 
  103. $css .= 'font-family: "' . $args[ 'font-family' ] . '", Helvetica, sans-serif;'; 
  104.  
  105. break; 
  106.  
  107. case 'text-shadow' : 
  108.  
  109. if( '' == $args[ 'text-shadow' ] ) return ; 
  110. $css .= 'text-shadow: 0px 0px 10px rgba(' . implode( ', ' , layers_hex2rgb( $args[ 'text-shadow' ] ) ) . ', 0.75);'; 
  111.  
  112. break; 
  113.  
  114. case 'css' : 
  115. default : 
  116.  
  117. if ( is_array( $args ) ) { 
  118.  
  119. if ( isset( $args['css'] ) ) { 
  120. if ( is_array( $args['css'] ) ) { 
  121. foreach ( $args['css'] as $css_atribute => $css_value ) { 
  122. // Skip this if a css value is not sent. 
  123. if ( ! isset( $css_value ) || '' == $css_value || NULL == $css_value ) continue; 
  124. $css .= "$css_atribute: $css_value;"; 
  125. else { 
  126. $css .= $args['css']; 
  127. else if ( is_string( $args ) ) { 
  128.  
  129. $css .= $args; 
  130.  
  131. break; 
  132.  
  133.  
  134. $css = apply_filters( 'layers_inline_' . $type . '_css' , $css, $args); 
  135.  
  136. // Bail if no css is generated 
  137. if ( '' == trim( $css ) ) return false; 
  138.  
  139. $inline_css = ''; 
  140.  
  141. // If there is a container ID specified, append it to the beginning of the declaration 
  142. if( NULL !== $container_id ) { 
  143. $inline_css = ' ' . $container_id . ' ' . $inline_css; 
  144.  
  145. if( isset( $args['selectors'] ) ) { 
  146. if ( is_string( $args['selectors'] ) && '' != $args['selectors'] ) { 
  147. $inline_css .= $args['selectors']; 
  148. } else if( is_array( $args['selectors'] ) && !empty( $args['selectors'] ) ) { 
  149. $inline_css .= implode( ', ' . $inline_css . ' ', $args['selectors'] ); 
  150.  
  151. // Apply inline CSS 
  152. if( '' == trim( $inline_css ) ) { 
  153. $inline_css .= $css; 
  154. } else { 
  155. $inline_css .= '{ ' . $css . '} '; 
  156.  
  157. // Format/Clean the CSS. 
  158. $inline_css = str_replace( "\n", '', $inline_css ); 
  159. $inline_css = str_replace( "\r", '', $inline_css ); 
  160. $inline_css = str_replace( "\t", '', $inline_css ); 
  161. $inline_css = "\n" . $inline_css; 
  162.  
  163. // Add the new CSS to the existing CSS 
  164. $layers_inline_css .= $inline_css; 
  165.  
  166. return $inline_css;