← All changes
|
includes/blocks/modules/general-style-functions.php
+119
-109
1.1.1
→
3.6.6
View file →
| @@ -1,109 +1,119 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | - | |
| 4 | -namespace Jet_Form_Builder\Blocks\Modules; | |
| 5 | - | |
| 6 | - | |
| 7 | -trait General_Style_Functions { | |
| 8 | - | |
| 9 | - private $namespace = 'jet-form-builder'; | |
| 10 | - | |
| 11 | - public function maybe_add_controls_type( $type ) { | |
| 12 | - if ( ! in_array( $type, $this->general_style_unregister() ) ) { | |
| 13 | - | |
| 14 | - if ( is_callable( $this->general_controls_callbacks()[ $type ] ) ) { | |
| 15 | - $this->general_controls_callbacks()[$type](); | |
| 16 | - } | |
| 17 | - } | |
| 18 | - } | |
| 19 | - | |
| 20 | - public function additional_selectors_for_controls() { | |
| 21 | - return array(); | |
| 22 | - } | |
| 23 | - | |
| 24 | - public function get_additional_styles( $id ) { | |
| 25 | - $styles = $this->additional_selectors_for_controls(); | |
| 26 | - | |
| 27 | - return isset( $styles[ $id ] ) ? $styles[ $id ] : array(); | |
| 28 | - } | |
| 29 | - | |
| 30 | - public function selector( $selector = '', $prefix_base = '', $additional = '' ) { | |
| 31 | - $base = $prefix_base . ".$this->namespace"; | |
| 32 | - | |
| 33 | - if ( $selector && isset( $this->css_scheme[ $selector ] ) ) { | |
| 34 | - $selector = $this->css_scheme[ $selector ]; | |
| 35 | - } | |
| 36 | - | |
| 37 | - $result = "{{WRAPPER}} $base" . sprintf( $selector, $this->namespace ); | |
| 38 | - | |
| 39 | - if ( $additional ) { | |
| 40 | - $result .= $additional; | |
| 41 | - } | |
| 42 | - | |
| 43 | - return $result; | |
| 44 | - } | |
| 45 | - | |
| 46 | - public function button_selector( $selector, $additional = '' ) { | |
| 47 | - return $this->selector( $selector, 'button', $additional ); | |
| 48 | - } | |
| 49 | - | |
| 50 | - public function div_selector( $selector, $additional = '' ) { | |
| 51 | - return $this->selector( $selector, 'div', $additional ); | |
| 52 | - } | |
| 53 | - | |
| 54 | - | |
| 55 | - public function get_default_margin_control( $selector ) { | |
| 56 | - return array( | |
| 57 | - 'type' => 'dimensions', | |
| 58 | - 'label' => __( 'Margin', 'jet-form-builder' ), | |
| 59 | - 'units' => array( 'px', '%' ), | |
| 60 | - 'css_selector' => array( | |
| 61 | - '{{WRAPPER}} ' . $selector => 'margin: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', | |
| 62 | - ), | |
| 63 | - ); | |
| 64 | - } | |
| 65 | - | |
| 66 | - public function get_default_padding_control( $selector ) { | |
| 67 | - return array( | |
| 68 | - 'type' => 'dimensions', | |
| 69 | - 'label' => __( 'Padding', 'jet-form-builder' ), | |
| 70 | - 'units' => array( 'px', '%' ), | |
| 71 | - 'css_selector' => array( | |
| 72 | - $selector => 'padding: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', | |
| 73 | - ), | |
| 74 | - ); | |
| 75 | - } | |
| 76 | - | |
| 77 | - public function add_margin_padding( $selector, $control_options ) { | |
| 78 | - if ( isset( $control_options['margin'] ) ) { | |
| 79 | - | |
| 80 | - $options = $this->merge_controls_or_add_id( | |
| 81 | - $this->get_default_margin_control( $selector ), | |
| 82 | - $control_options['margin'] | |
| 83 | - ); | |
| 84 | - $this->controls_manager->add_control( $options ); | |
| 85 | - } | |
| 86 | - | |
| 87 | - if ( isset( $control_options['padding'] ) ) { | |
| 88 | - | |
| 89 | - $options = $this->merge_controls_or_add_id( | |
| 90 | - $this->get_default_padding_control( $selector ), | |
| 91 | - $control_options['padding'] | |
| 92 | - ); | |
| 93 | - $this->controls_manager->add_control( $options ); | |
| 94 | - } | |
| 95 | - } | |
| 96 | - | |
| 97 | - public function merge_controls_or_add_id( $control, $options ) { | |
| 98 | - if ( is_array( $options ) ) { | |
| 99 | - return array_merge( $control, $options ); | |
| 100 | - | |
| 101 | - } elseif ( is_string( $options ) ) { | |
| 102 | - | |
| 103 | - $control['id'] = $options; | |
| 104 | - | |
| 105 | - return $control; | |
| 106 | - } | |
| 107 | - } | |
| 108 | - | |
| 109 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | + | |
| 4 | +namespace Jet_Form_Builder\Blocks\Modules; | |
| 5 | + | |
| 6 | +// If this file is called directly, abort. | |
| 7 | +if ( ! defined( 'WPINC' ) ) { | |
| 8 | + die; | |
| 9 | +} | |
| 10 | + | |
| 11 | +trait General_Style_Functions { | |
| 12 | + | |
| 13 | + private $namespace = 'jet-form-builder'; | |
| 14 | + | |
| 15 | + public function maybe_add_controls_type( $type ) { | |
| 16 | + if ( ! in_array( $type, $this->general_style_unregister(), true ) ) { | |
| 17 | + | |
| 18 | + if ( is_callable( $this->general_controls_callbacks()[ $type ] ) ) { | |
| 19 | + $this->general_controls_callbacks()[ $type ](); | |
| 20 | + } | |
| 21 | + } | |
| 22 | + } | |
| 23 | + | |
| 24 | + public function additional_selectors_for_controls() { | |
| 25 | + return array(); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public function get_additional_styles( $id ) { | |
| 29 | + $styles = $this->additional_selectors_for_controls(); | |
| 30 | + | |
| 31 | + return isset( $styles[ $id ] ) ? $styles[ $id ] : array(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + public function selector( $selector = '', $prefix_base = '', $additional = '' ) { | |
| 35 | + $base = $prefix_base . ".$this->namespace"; | |
| 36 | + | |
| 37 | + if ( $selector && isset( $this->css_scheme[ $selector ] ) ) { | |
| 38 | + $selector = $this->css_scheme[ $selector ]; | |
| 39 | + } | |
| 40 | + | |
| 41 | + $result = "{{WRAPPER}} $base" . sprintf( $selector, $this->namespace ); | |
| 42 | + | |
| 43 | + if ( $additional ) { | |
| 44 | + $result .= $additional; | |
| 45 | + } | |
| 46 | + | |
| 47 | + return $result; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public function selector_no_space( $selector = '' ) { | |
| 51 | + return ( '{{WRAPPER}}' . sprintf( $selector, $this->namespace ) ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + public function button_selector( $selector, $additional = '' ) { | |
| 55 | + return $this->selector( $selector, 'button', $additional ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + public function div_selector( $selector, $additional = '' ) { | |
| 59 | + return $this->selector( $selector, 'div', $additional ); | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | + public function get_default_margin_control( $selector ) { | |
| 64 | + return array( | |
| 65 | + 'type' => 'dimensions', | |
| 66 | + 'label' => __( 'Margin', 'jet-form-builder' ), | |
| 67 | + 'units' => array( 'px', '%' ), | |
| 68 | + 'css_selector' => array( | |
| 69 | + '{{WRAPPER}} ' . $selector => 'margin: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', | |
| 70 | + ), | |
| 71 | + ); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public function get_default_padding_control( $selector ) { | |
| 75 | + return array( | |
| 76 | + 'type' => 'dimensions', | |
| 77 | + 'label' => __( 'Padding', 'jet-form-builder' ), | |
| 78 | + 'units' => array( 'px', '%' ), | |
| 79 | + 'css_selector' => array( | |
| 80 | + $selector => 'padding: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', | |
| 81 | + ), | |
| 82 | + ); | |
| 83 | + } | |
| 84 | + | |
| 85 | + public function add_margin_padding( $selector, $control_options ) { | |
| 86 | + if ( isset( $control_options['margin'] ) ) { | |
| 87 | + | |
| 88 | + $options = $this->merge_controls_or_add_id( | |
| 89 | + $this->get_default_margin_control( $selector ), | |
| 90 | + $control_options['margin'] | |
| 91 | + ); | |
| 92 | + $this->controls_manager->add_control( $options ); | |
| 93 | + } | |
| 94 | + | |
| 95 | + if ( isset( $control_options['padding'] ) ) { | |
| 96 | + | |
| 97 | + $options = $this->merge_controls_or_add_id( | |
| 98 | + $this->get_default_padding_control( $selector ), | |
| 99 | + $control_options['padding'] | |
| 100 | + ); | |
| 101 | + $this->controls_manager->add_control( $options ); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | + public function merge_controls_or_add_id( $control, $options ) { | |
| 106 | + if ( is_array( $options ) ) { | |
| 107 | + return array_merge( $control, $options ); | |
| 108 | + | |
| 109 | + } elseif ( is_string( $options ) ) { | |
| 110 | + | |
| 111 | + $control['id'] = $options; | |
| 112 | + | |
| 113 | + return $control; | |
| 114 | + } | |
| 115 | + | |
| 116 | + return $control; | |
| 117 | + } | |
| 118 | + | |
| 119 | +} | |