PluginProbe
Posts Table with Search & Sort / 1.3.8
Posts Table with Search & Sort v1.3.8
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 All 39 releases
posts-data-table / lib / CSS_Util.php

CSS_Util.php in Posts Table with Search & Sort 1.3.8, at lib/CSS_Util.php

99 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Barn2\PTS_Lib;
4
5 /**
6 * Utility functions for building CSS.
7 *
8 * @package Barn2\barn2-lib
9 * @author Barn2 Plugins <support@barn2.com>
10 * @license GPL-3.0
11 * @copyright Barn2 Media Ltd
12 * @version 1.1
13 */
14 class CSS_Util {
15
16 public static function build_background_style( $bg_color, $important = false ) {
17 if ( ! $bg_color ) {
18 return '';
19 }
20
21 $important_dec = $important ? ' !important' : '';
22
23 return sprintf( 'background-color: %1$s%2$s;', $bg_color, $important_dec );
24 }
25
26 public static function build_border_style( $option, $borders = 'all', $important = false ) {
27 $option = wp_parse_args(
28 $option,
29 [
30 'size' => '',
31 'color' => ''
32 ]
33 );
34
35 if ( ! is_numeric( $option['size'] ) && empty( $option['color'] ) ) {
36 return '';
37 }
38
39 if ( ! is_array( $borders ) ) {
40 $borders = array_filter( (array) $borders );
41 }
42
43 $result = '';
44 $border_size = is_numeric( $option['size'] ) ? $option['size'] . 'px' : '';
45 $border_color = $option['color'];
46 $important_dec = $important ? ' !important' : '';
47
48 foreach ( $borders as $border ) {
49 $border_edge = '';
50
51 if ( in_array( $border, [ 'top', 'left', 'bottom', 'right' ], true ) ) {
52 $border_edge = $border . '-';
53 }
54
55 if ( $border_size || $border_color ) {
56 $result .= sprintf( 'border-%1$sstyle: solid%2$s;', $border_edge, $important_dec );
57 }
58
59 if ( $border_size ) {
60 $result .= sprintf( 'border-%1$swidth: %2$s%3$s;', $border_edge, $border_size, $important_dec );
61 }
62
63 if ( $border_color ) {
64 $result .= sprintf( 'border-%1$scolor: %2$s%3$s;', $border_edge, $border_color, $important_dec );
65 }
66 }
67
68 return $result;
69 }
70
71 public static function build_font_style( $option, $important = false ) {
72 $option = wp_parse_args(
73 $option,
74 [
75 'size' => '',
76 'color' => ''
77 ]
78 );
79
80 if ( ! is_numeric( $option['size'] ) && empty( $option['color'] ) ) {
81 return '';
82 }
83
84 $style = '';
85 $important_dec = $important ? ' !important' : '';
86
87 if ( is_numeric( $option['size'] ) ) {
88 $style .= sprintf( 'font-size: %1$upx%2$s;', $option['size'], $important_dec );
89 }
90
91 if ( ! empty( $option['color'] ) ) {
92 $style .= sprintf( 'color: %1$s%2$s;', $option['color'], $important_dec );
93 }
94
95 return $style;
96 }
97
98 }
99