@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * @param string $id |
| 394 | 394 | * @param string $search_for_id |
| 395 | 395 | * |
| 396 | - * @return mixed |
|
| 396 | + * @return string |
|
| 397 | 397 | */ |
| 398 | 398 | public static function shortcode_button( $id = '', $search_for_id = '' ) { |
| 399 | 399 | ob_start(); |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | * Makes SD work with the siteOrigin page builder. |
| 424 | 424 | * |
| 425 | 425 | * @since 1.0.6 |
| 426 | - * @return mixed |
|
| 426 | + * @return string |
|
| 427 | 427 | */ |
| 428 | 428 | public static function siteorigin_js() { |
| 429 | 429 | ob_start(); |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | /** |
| 999 | 999 | * Gets some CSS for the widgets screen. |
| 1000 | 1000 | * |
| 1001 | - * @return mixed |
|
| 1001 | + * @return string |
|
| 1002 | 1002 | */ |
| 1003 | 1003 | public function widget_css() { |
| 1004 | 1004 | ob_start(); |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | /** |
| 1053 | 1053 | * Gets some JS for the widgets screen. |
| 1054 | 1054 | * |
| 1055 | - * @return mixed |
|
| 1055 | + * @return string |
|
| 1056 | 1056 | */ |
| 1057 | 1057 | public function widget_js() { |
| 1058 | 1058 | ob_start(); |
@@ -1592,7 +1592,7 @@ discard block |
||
| 1592 | 1592 | * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
| 1593 | 1593 | * @since 1.0.9 Save numbers as numbers and not strings. |
| 1594 | 1594 | * @since 1.1.0 Font Awesome classes can be used for icons. |
| 1595 | - * @return mixed |
|
| 1595 | + * @return string |
|
| 1596 | 1596 | */ |
| 1597 | 1597 | public function block() { |
| 1598 | 1598 | ob_start(); |
@@ -1,261 +1,261 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | if ( ! class_exists( 'WP_Super_Duper' ) ) { |
| 7 | 7 | |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
| 11 | - * |
|
| 12 | - * Should not be called direct but extended instead. |
|
| 13 | - * |
|
| 14 | - * Class WP_Super_Duper |
|
| 15 | - * @since 1.0.3 is_block_content_call() method added. |
|
| 16 | - * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
| 17 | - * @since 1.0.4 is_elementor_widget_output() method added. |
|
| 18 | - * @since 1.0.4 is_elementor_preview() method added. |
|
| 19 | - * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
| 20 | - * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
| 21 | - * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
| 22 | - * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
| 23 | - * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
| 24 | - * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
| 25 | - * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
| 26 | - * @since 1.0.12 A checkbox default value can make a argument true even when unchecked - FIXED |
|
| 27 | - * @since 1.0.13 Block values can break JS if contains a comma - FIXED |
|
| 28 | - * @since 1.0.14 Use of additional css class in block editor breaks the block html - FIXED |
|
| 29 | - * @since 1.0.15 Fix conflicts with GeneratePress sections - FIXED |
|
| 30 | - * @since 1.0.15 `group` setting option added to be able to group settings - ADDED |
|
| 31 | - * @since 1.0.15 `block-supports` options array now supported - ADDED |
|
| 32 | - * @since 1.0.15 `block-icon` now supports Font Awesome class - ADDED |
|
| 33 | - * @since 1.0.15 Fusion builder (Avada) elements automatically created - ADDED |
|
| 34 | - * @ver 1.0.15 |
|
| 35 | - */ |
|
| 36 | - class WP_Super_Duper extends WP_Widget { |
|
| 37 | - |
|
| 38 | - public $version = "1.0.15"; |
|
| 39 | - public $font_awesome_icon_version = "5.11.2"; |
|
| 40 | - public $block_code; |
|
| 41 | - public $options; |
|
| 42 | - public $base_id; |
|
| 43 | - public $arguments = array(); |
|
| 44 | - public $instance = array(); |
|
| 45 | - private $class_name; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * The relative url to the current folder. |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - public $url = ''; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Take the array options and use them to build. |
|
| 56 | - */ |
|
| 57 | - public function __construct( $options ) { |
|
| 58 | - global $sd_widgets; |
|
| 59 | - |
|
| 60 | - $sd_widgets[ $options['base_id'] ] = array( |
|
| 61 | - 'name' => $options['name'], |
|
| 62 | - 'class_name' => $options['class_name'] |
|
| 63 | - ); |
|
| 64 | - $this->base_id = $options['base_id']; |
|
| 65 | - // lets filter the options before we do anything |
|
| 66 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 67 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 68 | - $options = $this->add_name_from_key( $options ); |
|
| 69 | - $this->options = $options; |
|
| 70 | - |
|
| 71 | - $this->base_id = $options['base_id']; |
|
| 72 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 73 | - |
|
| 74 | - // init parent |
|
| 75 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 76 | - |
|
| 77 | - if ( isset( $options['class_name'] ) ) { |
|
| 78 | - // register widget |
|
| 79 | - $this->class_name = $options['class_name']; |
|
| 80 | - |
|
| 81 | - // register shortcode |
|
| 82 | - $this->register_shortcode(); |
|
| 83 | - |
|
| 84 | - // Fusion Builder (avada) support |
|
| 85 | - if( function_exists('fusion_builder_map') ){ $this->register_fusion_element(); } |
|
| 86 | - |
|
| 87 | - // register block |
|
| 88 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // add the CSS and JS we need ONCE |
|
| 92 | - global $sd_widget_scripts; |
|
| 93 | - |
|
| 94 | - if ( ! $sd_widget_scripts ) { |
|
| 95 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 96 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 97 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 98 | - |
|
| 99 | - $sd_widget_scripts = true; |
|
| 100 | - |
|
| 101 | - // add shortcode insert button once |
|
| 102 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 103 | - // generatepress theme sections compatibility |
|
| 104 | - if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
| 105 | - add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 106 | - } |
|
| 107 | - if ( $this->is_preview() ) { |
|
| 108 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 109 | - // this makes the insert button work for elementor |
|
| 110 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 111 | - $this, |
|
| 112 | - 'shortcode_insert_button_script' |
|
| 113 | - ) ); // for elementor |
|
| 114 | - } |
|
| 115 | - // this makes the insert button work for cornerstone |
|
| 116 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
| 117 | - |
|
| 118 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 119 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 120 | - |
|
| 121 | - // add generator text to admin head |
|
| 122 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function register_fusion_element(){ |
|
| 129 | - |
|
| 130 | - $options = $this->options; |
|
| 131 | - |
|
| 132 | - if($this->base_id){ |
|
| 133 | - |
|
| 134 | - $params = $this->get_fusion_params(); |
|
| 135 | - |
|
| 136 | - $args = array( |
|
| 137 | - 'name' => $options['name'], |
|
| 138 | - 'shortcode' => $this->base_id, |
|
| 139 | - 'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square', |
|
| 140 | - 'allow_generator' => true, |
|
| 141 | - ); |
|
| 142 | - |
|
| 143 | - if(!empty($params)){ |
|
| 144 | - $args['params'] = $params; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - fusion_builder_map($args); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function get_fusion_params(){ |
|
| 153 | - $params = array(); |
|
| 154 | - $arguments = $this->get_arguments(); |
|
| 155 | - |
|
| 156 | - if(!empty($arguments)){ |
|
| 157 | - foreach($arguments as $key => $val){ |
|
| 158 | - $param = array(); |
|
| 159 | - // type |
|
| 160 | - $param['type'] = str_replace( |
|
| 161 | - array( |
|
| 162 | - "text", |
|
| 163 | - "number", |
|
| 164 | - "email", |
|
| 165 | - "color", |
|
| 166 | - "checkbox" |
|
| 167 | - ), |
|
| 168 | - array( |
|
| 169 | - "textfield", |
|
| 170 | - "textfield", |
|
| 171 | - "textfield", |
|
| 172 | - "colorpicker", |
|
| 173 | - "select", |
|
| 174 | - |
|
| 175 | - ), |
|
| 176 | - $val['type']); |
|
| 177 | - |
|
| 178 | - // heading |
|
| 179 | - $param['heading'] = $val['title']; |
|
| 180 | - |
|
| 181 | - // description |
|
| 182 | - $param['description'] = isset($val['desc']) ? $val['desc'] : ''; |
|
| 183 | - |
|
| 184 | - // param_name |
|
| 185 | - $param['param_name'] = $key; |
|
| 9 | + /** |
|
| 10 | + * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
| 11 | + * |
|
| 12 | + * Should not be called direct but extended instead. |
|
| 13 | + * |
|
| 14 | + * Class WP_Super_Duper |
|
| 15 | + * @since 1.0.3 is_block_content_call() method added. |
|
| 16 | + * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
| 17 | + * @since 1.0.4 is_elementor_widget_output() method added. |
|
| 18 | + * @since 1.0.4 is_elementor_preview() method added. |
|
| 19 | + * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
| 20 | + * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
| 21 | + * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
| 22 | + * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
| 23 | + * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
| 24 | + * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
| 25 | + * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
| 26 | + * @since 1.0.12 A checkbox default value can make a argument true even when unchecked - FIXED |
|
| 27 | + * @since 1.0.13 Block values can break JS if contains a comma - FIXED |
|
| 28 | + * @since 1.0.14 Use of additional css class in block editor breaks the block html - FIXED |
|
| 29 | + * @since 1.0.15 Fix conflicts with GeneratePress sections - FIXED |
|
| 30 | + * @since 1.0.15 `group` setting option added to be able to group settings - ADDED |
|
| 31 | + * @since 1.0.15 `block-supports` options array now supported - ADDED |
|
| 32 | + * @since 1.0.15 `block-icon` now supports Font Awesome class - ADDED |
|
| 33 | + * @since 1.0.15 Fusion builder (Avada) elements automatically created - ADDED |
|
| 34 | + * @ver 1.0.15 |
|
| 35 | + */ |
|
| 36 | + class WP_Super_Duper extends WP_Widget { |
|
| 37 | + |
|
| 38 | + public $version = "1.0.15"; |
|
| 39 | + public $font_awesome_icon_version = "5.11.2"; |
|
| 40 | + public $block_code; |
|
| 41 | + public $options; |
|
| 42 | + public $base_id; |
|
| 43 | + public $arguments = array(); |
|
| 44 | + public $instance = array(); |
|
| 45 | + private $class_name; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * The relative url to the current folder. |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + public $url = ''; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Take the array options and use them to build. |
|
| 56 | + */ |
|
| 57 | + public function __construct( $options ) { |
|
| 58 | + global $sd_widgets; |
|
| 59 | + |
|
| 60 | + $sd_widgets[ $options['base_id'] ] = array( |
|
| 61 | + 'name' => $options['name'], |
|
| 62 | + 'class_name' => $options['class_name'] |
|
| 63 | + ); |
|
| 64 | + $this->base_id = $options['base_id']; |
|
| 65 | + // lets filter the options before we do anything |
|
| 66 | + $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 67 | + $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 68 | + $options = $this->add_name_from_key( $options ); |
|
| 69 | + $this->options = $options; |
|
| 70 | + |
|
| 71 | + $this->base_id = $options['base_id']; |
|
| 72 | + $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 73 | + |
|
| 74 | + // init parent |
|
| 75 | + parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 76 | + |
|
| 77 | + if ( isset( $options['class_name'] ) ) { |
|
| 78 | + // register widget |
|
| 79 | + $this->class_name = $options['class_name']; |
|
| 80 | + |
|
| 81 | + // register shortcode |
|
| 82 | + $this->register_shortcode(); |
|
| 83 | + |
|
| 84 | + // Fusion Builder (avada) support |
|
| 85 | + if( function_exists('fusion_builder_map') ){ $this->register_fusion_element(); } |
|
| 86 | + |
|
| 87 | + // register block |
|
| 88 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // add the CSS and JS we need ONCE |
|
| 92 | + global $sd_widget_scripts; |
|
| 93 | + |
|
| 94 | + if ( ! $sd_widget_scripts ) { |
|
| 95 | + wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 96 | + wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 97 | + wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 98 | + |
|
| 99 | + $sd_widget_scripts = true; |
|
| 100 | + |
|
| 101 | + // add shortcode insert button once |
|
| 102 | + add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 103 | + // generatepress theme sections compatibility |
|
| 104 | + if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
| 105 | + add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 106 | + } |
|
| 107 | + if ( $this->is_preview() ) { |
|
| 108 | + add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 109 | + // this makes the insert button work for elementor |
|
| 110 | + add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 111 | + $this, |
|
| 112 | + 'shortcode_insert_button_script' |
|
| 113 | + ) ); // for elementor |
|
| 114 | + } |
|
| 115 | + // this makes the insert button work for cornerstone |
|
| 116 | + add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
| 117 | + |
|
| 118 | + add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 119 | + add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 120 | + |
|
| 121 | + // add generator text to admin head |
|
| 122 | + add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function register_fusion_element(){ |
|
| 129 | + |
|
| 130 | + $options = $this->options; |
|
| 131 | + |
|
| 132 | + if($this->base_id){ |
|
| 133 | + |
|
| 134 | + $params = $this->get_fusion_params(); |
|
| 135 | + |
|
| 136 | + $args = array( |
|
| 137 | + 'name' => $options['name'], |
|
| 138 | + 'shortcode' => $this->base_id, |
|
| 139 | + 'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square', |
|
| 140 | + 'allow_generator' => true, |
|
| 141 | + ); |
|
| 142 | + |
|
| 143 | + if(!empty($params)){ |
|
| 144 | + $args['params'] = $params; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + fusion_builder_map($args); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function get_fusion_params(){ |
|
| 153 | + $params = array(); |
|
| 154 | + $arguments = $this->get_arguments(); |
|
| 155 | + |
|
| 156 | + if(!empty($arguments)){ |
|
| 157 | + foreach($arguments as $key => $val){ |
|
| 158 | + $param = array(); |
|
| 159 | + // type |
|
| 160 | + $param['type'] = str_replace( |
|
| 161 | + array( |
|
| 162 | + "text", |
|
| 163 | + "number", |
|
| 164 | + "email", |
|
| 165 | + "color", |
|
| 166 | + "checkbox" |
|
| 167 | + ), |
|
| 168 | + array( |
|
| 169 | + "textfield", |
|
| 170 | + "textfield", |
|
| 171 | + "textfield", |
|
| 172 | + "colorpicker", |
|
| 173 | + "select", |
|
| 174 | + |
|
| 175 | + ), |
|
| 176 | + $val['type']); |
|
| 177 | + |
|
| 178 | + // heading |
|
| 179 | + $param['heading'] = $val['title']; |
|
| 180 | + |
|
| 181 | + // description |
|
| 182 | + $param['description'] = isset($val['desc']) ? $val['desc'] : ''; |
|
| 183 | + |
|
| 184 | + // param_name |
|
| 185 | + $param['param_name'] = $key; |
|
| 186 | 186 | |
| 187 | - // Default |
|
| 188 | - $param['default'] = isset($val['default']) ? $val['default'] : ''; |
|
| 189 | - |
|
| 190 | - // Group |
|
| 191 | - if(isset($val['group'])){ |
|
| 192 | - $param['group'] = $val['group']; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // value |
|
| 196 | - if($val['type'] == 'checkbox'){ |
|
| 197 | - if(isset($val['default']) && $val['default'] == '0'){ |
|
| 198 | - unset($param['default']); |
|
| 199 | - } |
|
| 200 | - $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
|
| 201 | - }elseif($param['type'] == 'select'){ |
|
| 202 | - $param['value'] = isset($val['options']) ? $val['options'] : array(); |
|
| 203 | - }else{ |
|
| 204 | - $param['value'] = isset($val['default']) ? $val['default'] : ''; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // setup the param |
|
| 208 | - $params[] = $param; |
|
| 209 | - |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - return $params; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
| 219 | - */ |
|
| 220 | - public static function maybe_cornerstone_builder(){ |
|
| 221 | - if(did_action('cornerstone_before_boot_app')){ |
|
| 222 | - self::shortcode_insert_button_script(); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * A function to ge the shortcode builder picker html. |
|
| 228 | - * |
|
| 229 | - * @param string $editor_id |
|
| 230 | - * |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - public static function get_picker( $editor_id = '' ) { |
|
| 234 | - |
|
| 235 | - ob_start(); |
|
| 236 | - if ( isset( $_POST['editor_id'] ) ) { |
|
| 237 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 238 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 239 | - $editor_id = 'main_content_content_vb_tiny_mce'; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - global $sd_widgets; |
|
| 243 | - ?> |
|
| 187 | + // Default |
|
| 188 | + $param['default'] = isset($val['default']) ? $val['default'] : ''; |
|
| 189 | + |
|
| 190 | + // Group |
|
| 191 | + if(isset($val['group'])){ |
|
| 192 | + $param['group'] = $val['group']; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // value |
|
| 196 | + if($val['type'] == 'checkbox'){ |
|
| 197 | + if(isset($val['default']) && $val['default'] == '0'){ |
|
| 198 | + unset($param['default']); |
|
| 199 | + } |
|
| 200 | + $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
|
| 201 | + }elseif($param['type'] == 'select'){ |
|
| 202 | + $param['value'] = isset($val['options']) ? $val['options'] : array(); |
|
| 203 | + }else{ |
|
| 204 | + $param['value'] = isset($val['default']) ? $val['default'] : ''; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // setup the param |
|
| 208 | + $params[] = $param; |
|
| 209 | + |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + return $params; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
| 219 | + */ |
|
| 220 | + public static function maybe_cornerstone_builder(){ |
|
| 221 | + if(did_action('cornerstone_before_boot_app')){ |
|
| 222 | + self::shortcode_insert_button_script(); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * A function to ge the shortcode builder picker html. |
|
| 228 | + * |
|
| 229 | + * @param string $editor_id |
|
| 230 | + * |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + public static function get_picker( $editor_id = '' ) { |
|
| 234 | + |
|
| 235 | + ob_start(); |
|
| 236 | + if ( isset( $_POST['editor_id'] ) ) { |
|
| 237 | + $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 238 | + } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 239 | + $editor_id = 'main_content_content_vb_tiny_mce'; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + global $sd_widgets; |
|
| 243 | + ?> |
|
| 244 | 244 | |
| 245 | 245 | <div class="sd-shortcode-left-wrap"> |
| 246 | 246 | <?php |
| 247 | - ksort( $sd_widgets ); |
|
| 247 | + ksort( $sd_widgets ); |
|
| 248 | 248 | // print_r($sd_widgets);exit; |
| 249 | - if ( ! empty( $sd_widgets ) ) { |
|
| 250 | - echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
| 251 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 252 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 253 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 254 | - } |
|
| 255 | - echo "</select>"; |
|
| 256 | - |
|
| 257 | - } |
|
| 258 | - ?> |
|
| 249 | + if ( ! empty( $sd_widgets ) ) { |
|
| 250 | + echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
| 251 | + echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 252 | + foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 253 | + echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 254 | + } |
|
| 255 | + echo "</select>"; |
|
| 256 | + |
|
| 257 | + } |
|
| 258 | + ?> |
|
| 259 | 259 | <div class="sd-shortcode-settings"></div> |
| 260 | 260 | |
| 261 | 261 | </div> |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | <?php if ( $editor_id != '' ) { ?> |
| 267 | 267 | <button class="button sd-insert-shortcode-button" |
| 268 | 268 | onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
| 269 | - echo "'" . $editor_id . "'"; |
|
| 270 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 269 | + echo "'" . $editor_id . "'"; |
|
| 270 | + } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 271 | 271 | <?php } ?> |
| 272 | 272 | <button class="button" |
| 273 | 273 | onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
@@ -275,134 +275,134 @@ discard block |
||
| 275 | 275 | </div> |
| 276 | 276 | <?php |
| 277 | 277 | |
| 278 | - $html = ob_get_clean(); |
|
| 279 | - |
|
| 280 | - if ( wp_doing_ajax() ) { |
|
| 281 | - echo $html; |
|
| 282 | - $should_die = true; |
|
| 283 | - |
|
| 284 | - // some builder get the editor via ajax so we should not die on those ocasions |
|
| 285 | - $dont_die = array( |
|
| 286 | - 'parent_tag',// WP Bakery |
|
| 287 | - 'avia_request' // enfold |
|
| 288 | - ); |
|
| 289 | - |
|
| 290 | - foreach ( $dont_die as $request ) { |
|
| 291 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 292 | - $should_die = false; |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - if ( $should_die ) { |
|
| 297 | - wp_die(); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - } else { |
|
| 301 | - return $html; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return ''; |
|
| 305 | - |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Output the version in the admin header. |
|
| 310 | - */ |
|
| 311 | - public function generator() { |
|
| 312 | - echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Get widget settings. |
|
| 317 | - * |
|
| 318 | - * @since 1.0.0 |
|
| 319 | - */ |
|
| 320 | - public static function get_widget_settings() { |
|
| 321 | - global $sd_widgets; |
|
| 322 | - |
|
| 323 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 324 | - if ( ! $shortcode ) { |
|
| 325 | - wp_die(); |
|
| 326 | - } |
|
| 327 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 328 | - if ( ! $widget_args ) { |
|
| 329 | - wp_die(); |
|
| 330 | - } |
|
| 331 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 332 | - if ( ! $class_name ) { |
|
| 333 | - wp_die(); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - // invoke an instance method |
|
| 337 | - $widget = new $class_name; |
|
| 338 | - |
|
| 339 | - ob_start(); |
|
| 340 | - $widget->form( array() ); |
|
| 341 | - $form = ob_get_clean(); |
|
| 342 | - echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 343 | - echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 344 | - echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 345 | - ?> |
|
| 278 | + $html = ob_get_clean(); |
|
| 279 | + |
|
| 280 | + if ( wp_doing_ajax() ) { |
|
| 281 | + echo $html; |
|
| 282 | + $should_die = true; |
|
| 283 | + |
|
| 284 | + // some builder get the editor via ajax so we should not die on those ocasions |
|
| 285 | + $dont_die = array( |
|
| 286 | + 'parent_tag',// WP Bakery |
|
| 287 | + 'avia_request' // enfold |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + foreach ( $dont_die as $request ) { |
|
| 291 | + if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 292 | + $should_die = false; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + if ( $should_die ) { |
|
| 297 | + wp_die(); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + } else { |
|
| 301 | + return $html; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return ''; |
|
| 305 | + |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Output the version in the admin header. |
|
| 310 | + */ |
|
| 311 | + public function generator() { |
|
| 312 | + echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Get widget settings. |
|
| 317 | + * |
|
| 318 | + * @since 1.0.0 |
|
| 319 | + */ |
|
| 320 | + public static function get_widget_settings() { |
|
| 321 | + global $sd_widgets; |
|
| 322 | + |
|
| 323 | + $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 324 | + if ( ! $shortcode ) { |
|
| 325 | + wp_die(); |
|
| 326 | + } |
|
| 327 | + $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 328 | + if ( ! $widget_args ) { |
|
| 329 | + wp_die(); |
|
| 330 | + } |
|
| 331 | + $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 332 | + if ( ! $class_name ) { |
|
| 333 | + wp_die(); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + // invoke an instance method |
|
| 337 | + $widget = new $class_name; |
|
| 338 | + |
|
| 339 | + ob_start(); |
|
| 340 | + $widget->form( array() ); |
|
| 341 | + $form = ob_get_clean(); |
|
| 342 | + echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 343 | + echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 344 | + echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 345 | + ?> |
|
| 346 | 346 | <?php |
| 347 | - wp_die(); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 352 | - * |
|
| 353 | - * @since 1.0.0 |
|
| 354 | - * |
|
| 355 | - * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 356 | - * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 357 | - */ |
|
| 358 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 359 | - global $sd_widgets, $shortcode_insert_button_once; |
|
| 360 | - if ( $shortcode_insert_button_once ) { |
|
| 361 | - return; |
|
| 362 | - } |
|
| 363 | - add_thickbox(); |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Cornerstone makes us play dirty tricks :/ |
|
| 368 | - * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
| 369 | - */ |
|
| 370 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 371 | - echo '<span id="insert-media-button">'; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - echo self::shortcode_button( 'this', 'true' ); |
|
| 375 | - |
|
| 376 | - // see opening note |
|
| 377 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 378 | - echo '</span>'; // end #insert-media-button |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - // Add separate script for generatepress theme sections |
|
| 382 | - if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
| 383 | - } else { |
|
| 384 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $shortcode_insert_button_once = true; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Gets the shortcode insert button html. |
|
| 392 | - * |
|
| 393 | - * @param string $id |
|
| 394 | - * @param string $search_for_id |
|
| 395 | - * |
|
| 396 | - * @return mixed |
|
| 397 | - */ |
|
| 398 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 399 | - ob_start(); |
|
| 400 | - ?> |
|
| 347 | + wp_die(); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 352 | + * |
|
| 353 | + * @since 1.0.0 |
|
| 354 | + * |
|
| 355 | + * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 356 | + * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 357 | + */ |
|
| 358 | + public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 359 | + global $sd_widgets, $shortcode_insert_button_once; |
|
| 360 | + if ( $shortcode_insert_button_once ) { |
|
| 361 | + return; |
|
| 362 | + } |
|
| 363 | + add_thickbox(); |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Cornerstone makes us play dirty tricks :/ |
|
| 368 | + * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
| 369 | + */ |
|
| 370 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 371 | + echo '<span id="insert-media-button">'; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + echo self::shortcode_button( 'this', 'true' ); |
|
| 375 | + |
|
| 376 | + // see opening note |
|
| 377 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 378 | + echo '</span>'; // end #insert-media-button |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + // Add separate script for generatepress theme sections |
|
| 382 | + if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
| 383 | + } else { |
|
| 384 | + self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $shortcode_insert_button_once = true; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Gets the shortcode insert button html. |
|
| 392 | + * |
|
| 393 | + * @param string $id |
|
| 394 | + * @param string $search_for_id |
|
| 395 | + * |
|
| 396 | + * @return mixed |
|
| 397 | + */ |
|
| 398 | + public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 399 | + ob_start(); |
|
| 400 | + ?> |
|
| 401 | 401 | <span class="sd-lable-shortcode-inserter"> |
| 402 | 402 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
| 403 | - if ( $search_for_id ) { |
|
| 404 | - echo "," . $search_for_id; |
|
| 405 | - } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
| 403 | + if ( $search_for_id ) { |
|
| 404 | + echo "," . $search_for_id; |
|
| 405 | + } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
| 406 | 406 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
| 407 | 407 | <span style="vertical-align: middle;line-height: 18px;font-size: 20px;" |
| 408 | 408 | class="dashicons dashicons-screenoptions"></span> |
@@ -413,21 +413,21 @@ discard block |
||
| 413 | 413 | </span> |
| 414 | 414 | |
| 415 | 415 | <?php |
| 416 | - $html = ob_get_clean(); |
|
| 417 | - |
|
| 418 | - // remove line breaks so we can use it in js |
|
| 419 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Makes SD work with the siteOrigin page builder. |
|
| 424 | - * |
|
| 425 | - * @since 1.0.6 |
|
| 426 | - * @return mixed |
|
| 427 | - */ |
|
| 428 | - public static function siteorigin_js() { |
|
| 429 | - ob_start(); |
|
| 430 | - ?> |
|
| 416 | + $html = ob_get_clean(); |
|
| 417 | + |
|
| 418 | + // remove line breaks so we can use it in js |
|
| 419 | + return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Makes SD work with the siteOrigin page builder. |
|
| 424 | + * |
|
| 425 | + * @since 1.0.6 |
|
| 426 | + * @return mixed |
|
| 427 | + */ |
|
| 428 | + public static function siteorigin_js() { |
|
| 429 | + ob_start(); |
|
| 430 | + ?> |
|
| 431 | 431 | <script> |
| 432 | 432 | /** |
| 433 | 433 | * Check a form to see what items shoudl be shown or hidden. |
@@ -505,28 +505,28 @@ discard block |
||
| 505 | 505 | }); |
| 506 | 506 | </script> |
| 507 | 507 | <?php |
| 508 | - $output = ob_get_clean(); |
|
| 508 | + $output = ob_get_clean(); |
|
| 509 | 509 | |
| 510 | - /* |
|
| 510 | + /* |
|
| 511 | 511 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 512 | 512 | */ |
| 513 | 513 | |
| 514 | - return str_replace( array( |
|
| 515 | - '<script>', |
|
| 516 | - '</script>' |
|
| 517 | - ), '', $output ); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Output the JS and CSS for the shortcode insert button. |
|
| 522 | - * |
|
| 523 | - * @since 1.0.6 |
|
| 524 | - * |
|
| 525 | - * @param string $editor_id |
|
| 526 | - * @param string $insert_shortcode_function |
|
| 527 | - */ |
|
| 528 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 529 | - ?> |
|
| 514 | + return str_replace( array( |
|
| 515 | + '<script>', |
|
| 516 | + '</script>' |
|
| 517 | + ), '', $output ); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Output the JS and CSS for the shortcode insert button. |
|
| 522 | + * |
|
| 523 | + * @since 1.0.6 |
|
| 524 | + * |
|
| 525 | + * @param string $editor_id |
|
| 526 | + * @param string $insert_shortcode_function |
|
| 527 | + */ |
|
| 528 | + public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 529 | + ?> |
|
| 530 | 530 | <style> |
| 531 | 531 | .sd-shortcode-left-wrap { |
| 532 | 532 | float: left; |
@@ -650,35 +650,35 @@ discard block |
||
| 650 | 650 | <?php } ?> |
| 651 | 651 | </style> |
| 652 | 652 | <?php |
| 653 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 654 | - echo "<script>" . self::siteorigin_js() . "</script>"; |
|
| 655 | - } |
|
| 656 | - ?> |
|
| 653 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 654 | + echo "<script>" . self::siteorigin_js() . "</script>"; |
|
| 655 | + } |
|
| 656 | + ?> |
|
| 657 | 657 | <script> |
| 658 | 658 | <?php |
| 659 | - if(! empty( $insert_shortcode_function )){ |
|
| 660 | - echo $insert_shortcode_function; |
|
| 661 | - }else{ |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Function for super duper insert shortcode. |
|
| 665 | - * |
|
| 666 | - * @since 1.0.0 |
|
| 667 | - */ |
|
| 668 | - ?> |
|
| 659 | + if(! empty( $insert_shortcode_function )){ |
|
| 660 | + echo $insert_shortcode_function; |
|
| 661 | + }else{ |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Function for super duper insert shortcode. |
|
| 665 | + * |
|
| 666 | + * @since 1.0.0 |
|
| 667 | + */ |
|
| 668 | + ?> |
|
| 669 | 669 | function sd_insert_shortcode($editor_id) { |
| 670 | 670 | $shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val(); |
| 671 | 671 | if ($shortcode) { |
| 672 | 672 | if (!$editor_id) { |
| 673 | 673 | <?php |
| 674 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 675 | - echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
| 676 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 677 | - echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
| 678 | - } else { |
|
| 679 | - echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
| 680 | - } |
|
| 681 | - ?> |
|
| 674 | + if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 675 | + echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
| 676 | + } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 677 | + echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
| 678 | + } else { |
|
| 679 | + echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
| 680 | + } |
|
| 681 | + ?> |
|
| 682 | 682 | } else { |
| 683 | 683 | $editor_id = '#' + $editor_id; |
| 684 | 684 | } |
@@ -993,16 +993,16 @@ discard block |
||
| 993 | 993 | |
| 994 | 994 | </script> |
| 995 | 995 | <?php |
| 996 | - } |
|
| 997 | - |
|
| 998 | - /** |
|
| 999 | - * Gets some CSS for the widgets screen. |
|
| 1000 | - * |
|
| 1001 | - * @return mixed |
|
| 1002 | - */ |
|
| 1003 | - public function widget_css() { |
|
| 1004 | - ob_start(); |
|
| 1005 | - ?> |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + /** |
|
| 999 | + * Gets some CSS for the widgets screen. |
|
| 1000 | + * |
|
| 1001 | + * @return mixed |
|
| 1002 | + */ |
|
| 1003 | + public function widget_css() { |
|
| 1004 | + ob_start(); |
|
| 1005 | + ?> |
|
| 1006 | 1006 | <style> |
| 1007 | 1007 | .sd-advanced-setting { |
| 1008 | 1008 | display: none; |
@@ -1037,26 +1037,26 @@ discard block |
||
| 1037 | 1037 | } |
| 1038 | 1038 | </style> |
| 1039 | 1039 | <?php |
| 1040 | - $output = ob_get_clean(); |
|
| 1040 | + $output = ob_get_clean(); |
|
| 1041 | 1041 | |
| 1042 | - /* |
|
| 1042 | + /* |
|
| 1043 | 1043 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1044 | 1044 | */ |
| 1045 | 1045 | |
| 1046 | - return str_replace( array( |
|
| 1047 | - '<style>', |
|
| 1048 | - '</style>' |
|
| 1049 | - ), '', $output ); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * Gets some JS for the widgets screen. |
|
| 1054 | - * |
|
| 1055 | - * @return mixed |
|
| 1056 | - */ |
|
| 1057 | - public function widget_js() { |
|
| 1058 | - ob_start(); |
|
| 1059 | - ?> |
|
| 1046 | + return str_replace( array( |
|
| 1047 | + '<style>', |
|
| 1048 | + '</style>' |
|
| 1049 | + ), '', $output ); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * Gets some JS for the widgets screen. |
|
| 1054 | + * |
|
| 1055 | + * @return mixed |
|
| 1056 | + */ |
|
| 1057 | + public function widget_js() { |
|
| 1058 | + ob_start(); |
|
| 1059 | + ?> |
|
| 1060 | 1060 | <script> |
| 1061 | 1061 | |
| 1062 | 1062 | /** |
@@ -1211,392 +1211,392 @@ discard block |
||
| 1211 | 1211 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
| 1212 | 1212 | </script> |
| 1213 | 1213 | <?php |
| 1214 | - $output = ob_get_clean(); |
|
| 1214 | + $output = ob_get_clean(); |
|
| 1215 | 1215 | |
| 1216 | - /* |
|
| 1216 | + /* |
|
| 1217 | 1217 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1218 | 1218 | */ |
| 1219 | 1219 | |
| 1220 | - return str_replace( array( |
|
| 1221 | - '<script>', |
|
| 1222 | - '</script>' |
|
| 1223 | - ), '', $output ); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * Set the name from the argument key. |
|
| 1229 | - * |
|
| 1230 | - * @param $options |
|
| 1231 | - * |
|
| 1232 | - * @return mixed |
|
| 1233 | - */ |
|
| 1234 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 1235 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 1236 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 1237 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 1238 | - } |
|
| 1239 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1240 | - foreach ( $options as $key => $val ) { |
|
| 1241 | - $options[ $key ]['name'] = $key; |
|
| 1242 | - } |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - return $options; |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - /** |
|
| 1249 | - * Register the parent shortcode. |
|
| 1250 | - * |
|
| 1251 | - * @since 1.0.0 |
|
| 1252 | - */ |
|
| 1253 | - public function register_shortcode() { |
|
| 1254 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1255 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 1260 | - * |
|
| 1261 | - * @since 1.0.0 |
|
| 1262 | - */ |
|
| 1263 | - public static function render_shortcode() { |
|
| 1264 | - |
|
| 1265 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1266 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1267 | - wp_die(); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - // we might need the $post value here so lets set it. |
|
| 1271 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1272 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1273 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1274 | - global $post; |
|
| 1275 | - $post = $post_obj; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1280 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1281 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1282 | - $attributes = ''; |
|
| 1283 | - if ( ! empty( $attributes_array ) ) { |
|
| 1284 | - foreach ( $attributes_array as $key => $value ) { |
|
| 1285 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 1290 | - |
|
| 1291 | - echo do_shortcode( $shortcode ); |
|
| 1292 | - |
|
| 1293 | - } |
|
| 1294 | - wp_die(); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - /** |
|
| 1298 | - * Output the shortcode. |
|
| 1299 | - * |
|
| 1300 | - * @param array $args |
|
| 1301 | - * @param string $content |
|
| 1302 | - * |
|
| 1303 | - * @return string |
|
| 1304 | - */ |
|
| 1305 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1306 | - $args = self::argument_values( $args ); |
|
| 1307 | - |
|
| 1308 | - // add extra argument so we know its a output to gutenberg |
|
| 1309 | - //$args |
|
| 1310 | - $args = $this->string_to_bool( $args ); |
|
| 1311 | - |
|
| 1312 | - |
|
| 1313 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1314 | - |
|
| 1315 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 1316 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 1317 | - |
|
| 1318 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1319 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 1320 | - |
|
| 1321 | - $shortcode_args = array(); |
|
| 1322 | - $output = ''; |
|
| 1323 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1324 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1325 | - if ( $main_content && ! $no_wrap ) { |
|
| 1326 | - // wrap the shortcode in a dive with the same class as the widget |
|
| 1327 | - $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
| 1328 | - if ( ! empty( $args['title'] ) ) { |
|
| 1329 | - // if its a shortcode and there is a title try to grab the title wrappers |
|
| 1330 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1331 | - if ( empty( $instance ) ) { |
|
| 1332 | - global $wp_registered_sidebars; |
|
| 1333 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1334 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1335 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1336 | - $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 1337 | - $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 1338 | - break; |
|
| 1339 | - } |
|
| 1340 | - } |
|
| 1341 | - } |
|
| 1342 | - } |
|
| 1343 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1344 | - } |
|
| 1345 | - $output .= $main_content; |
|
| 1346 | - $output .= '</div>'; |
|
| 1347 | - } elseif ( $main_content && $no_wrap ) { |
|
| 1348 | - $output .= $main_content; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - // if preview show a placeholder if empty |
|
| 1352 | - if ( $this->is_preview() && $output == '' ) { |
|
| 1353 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - /** |
|
| 1360 | - * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
| 1361 | - * |
|
| 1362 | - * @param string $name |
|
| 1363 | - * |
|
| 1364 | - * @return string |
|
| 1365 | - */ |
|
| 1366 | - public function preview_placeholder_text( $name = '' ) { |
|
| 1367 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - /** |
|
| 1371 | - * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 1372 | - * |
|
| 1373 | - * @param $options |
|
| 1374 | - * |
|
| 1375 | - * @return mixed |
|
| 1376 | - */ |
|
| 1377 | - public function string_to_bool( $options ) { |
|
| 1378 | - // convert bool strings to booleans |
|
| 1379 | - foreach ( $options as $key => $val ) { |
|
| 1380 | - if ( $val == 'false' ) { |
|
| 1381 | - $options[ $key ] = false; |
|
| 1382 | - } elseif ( $val == 'true' ) { |
|
| 1383 | - $options[ $key ] = true; |
|
| 1384 | - } |
|
| 1385 | - } |
|
| 1386 | - |
|
| 1387 | - return $options; |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * Get the argument values that are also filterable. |
|
| 1392 | - * |
|
| 1393 | - * @param $instance |
|
| 1394 | - * |
|
| 1395 | - * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
| 1396 | - * |
|
| 1397 | - * @return array |
|
| 1398 | - */ |
|
| 1399 | - public function argument_values( $instance ) { |
|
| 1400 | - $argument_values = array(); |
|
| 1401 | - |
|
| 1402 | - // set widget instance |
|
| 1403 | - $this->instance = $instance; |
|
| 1404 | - |
|
| 1405 | - if ( empty( $this->arguments ) ) { |
|
| 1406 | - $this->arguments = $this->get_arguments(); |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - if ( ! empty( $this->arguments ) ) { |
|
| 1410 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1411 | - // set the input name from the key |
|
| 1412 | - $args['name'] = $key; |
|
| 1413 | - // |
|
| 1414 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1415 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
| 1416 | - // don't set default for an empty checkbox |
|
| 1417 | - } |
|
| 1418 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1419 | - $argument_values[ $key ] = $args['default']; |
|
| 1420 | - } |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - return $argument_values; |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - /** |
|
| 1428 | - * Set arguments in super duper. |
|
| 1429 | - * |
|
| 1430 | - * @since 1.0.0 |
|
| 1431 | - * |
|
| 1432 | - * @return array Set arguments. |
|
| 1433 | - */ |
|
| 1434 | - public function set_arguments() { |
|
| 1435 | - return $this->arguments; |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - /** |
|
| 1439 | - * Get arguments in super duper. |
|
| 1440 | - * |
|
| 1441 | - * @since 1.0.0 |
|
| 1442 | - * |
|
| 1443 | - * @return array Get arguments. |
|
| 1444 | - */ |
|
| 1445 | - public function get_arguments() { |
|
| 1446 | - if ( empty( $this->arguments ) ) { |
|
| 1447 | - $this->arguments = $this->set_arguments(); |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1451 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1452 | - |
|
| 1453 | - return $this->arguments; |
|
| 1454 | - } |
|
| 1455 | - |
|
| 1456 | - /** |
|
| 1457 | - * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 1458 | - * |
|
| 1459 | - * @param array $args |
|
| 1460 | - * @param array $widget_args |
|
| 1461 | - * @param string $content |
|
| 1462 | - */ |
|
| 1463 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1464 | - |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 1469 | - */ |
|
| 1470 | - public function register_block() { |
|
| 1471 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1472 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1473 | - |
|
| 1474 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1475 | - |
|
| 1476 | - } |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - /** |
|
| 1480 | - * Check if we need to show advanced options. |
|
| 1481 | - * |
|
| 1482 | - * @return bool |
|
| 1483 | - */ |
|
| 1484 | - public function block_show_advanced() { |
|
| 1485 | - |
|
| 1486 | - $show = false; |
|
| 1487 | - $arguments = $this->arguments; |
|
| 1488 | - |
|
| 1489 | - if ( empty( $arguments ) ) { |
|
| 1490 | - $arguments = $this->get_arguments(); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - if ( ! empty( $arguments ) ) { |
|
| 1494 | - foreach ( $arguments as $argument ) { |
|
| 1495 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1496 | - $show = true; |
|
| 1497 | - break; // no need to continue if we know we have it |
|
| 1498 | - } |
|
| 1499 | - } |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - return $show; |
|
| 1503 | - } |
|
| 1504 | - |
|
| 1505 | - /** |
|
| 1506 | - * Get the url path to the current folder. |
|
| 1507 | - * |
|
| 1508 | - * @return string |
|
| 1509 | - */ |
|
| 1510 | - public function get_url() { |
|
| 1511 | - |
|
| 1512 | - $url = $this->url; |
|
| 1513 | - |
|
| 1514 | - if(!$url){ |
|
| 1515 | - // check if we are inside a plugin |
|
| 1516 | - $file_dir = str_replace("/includes","", dirname( __FILE__ )); |
|
| 1517 | - |
|
| 1518 | - $dir_parts = explode("/wp-content/",$file_dir); |
|
| 1519 | - $url_parts = explode("/wp-content/",plugins_url()); |
|
| 1520 | - |
|
| 1521 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
| 1522 | - $url = trailingslashit( $url_parts[0]."/wp-content/".$dir_parts[1] ); |
|
| 1523 | - $this->url = $url; |
|
| 1524 | - } |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - return $url; |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - /** |
|
| 1532 | - * Generate the block icon. |
|
| 1533 | - * |
|
| 1534 | - * Enables the use of Font Awesome icons. |
|
| 1535 | - * |
|
| 1536 | - * @note xlink:href is actually deprecated but href is not supported by all so we use both. |
|
| 1537 | - * @param $icon |
|
| 1538 | - * @since 1.1.0 |
|
| 1539 | - * @return string |
|
| 1540 | - */ |
|
| 1541 | - public function get_block_icon($icon){ |
|
| 1542 | - |
|
| 1543 | - // check if we have a Font Awesome icon |
|
| 1544 | - $fa_type = ''; |
|
| 1545 | - if(substr( $icon, 0, 7 ) === "fas fa-"){ |
|
| 1546 | - $fa_type = 'solid'; |
|
| 1547 | - }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
| 1548 | - $fa_type = 'regular'; |
|
| 1549 | - }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
| 1550 | - $fa_type = 'brands'; |
|
| 1551 | - }else{ |
|
| 1552 | - $icon = "'".$icon."'"; |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - // set the icon if we found one |
|
| 1556 | - if($fa_type){ |
|
| 1557 | - $fa_icon = str_replace(array("fas fa-","far fa-","fab fa-"),"",$icon); |
|
| 1558 | - $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."','href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."'}))"; |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - return $icon; |
|
| 1562 | - } |
|
| 1563 | - |
|
| 1564 | - public function group_arguments($arguments){ |
|
| 1220 | + return str_replace( array( |
|
| 1221 | + '<script>', |
|
| 1222 | + '</script>' |
|
| 1223 | + ), '', $output ); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Set the name from the argument key. |
|
| 1229 | + * |
|
| 1230 | + * @param $options |
|
| 1231 | + * |
|
| 1232 | + * @return mixed |
|
| 1233 | + */ |
|
| 1234 | + private function add_name_from_key( $options, $arguments = false ) { |
|
| 1235 | + if ( ! empty( $options['arguments'] ) ) { |
|
| 1236 | + foreach ( $options['arguments'] as $key => $val ) { |
|
| 1237 | + $options['arguments'][ $key ]['name'] = $key; |
|
| 1238 | + } |
|
| 1239 | + } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1240 | + foreach ( $options as $key => $val ) { |
|
| 1241 | + $options[ $key ]['name'] = $key; |
|
| 1242 | + } |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + return $options; |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + /** |
|
| 1249 | + * Register the parent shortcode. |
|
| 1250 | + * |
|
| 1251 | + * @since 1.0.0 |
|
| 1252 | + */ |
|
| 1253 | + public function register_shortcode() { |
|
| 1254 | + add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1255 | + add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 1260 | + * |
|
| 1261 | + * @since 1.0.0 |
|
| 1262 | + */ |
|
| 1263 | + public static function render_shortcode() { |
|
| 1264 | + |
|
| 1265 | + check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1266 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1267 | + wp_die(); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + // we might need the $post value here so lets set it. |
|
| 1271 | + if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1272 | + $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1273 | + if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1274 | + global $post; |
|
| 1275 | + $post = $post_obj; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1280 | + $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1281 | + $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1282 | + $attributes = ''; |
|
| 1283 | + if ( ! empty( $attributes_array ) ) { |
|
| 1284 | + foreach ( $attributes_array as $key => $value ) { |
|
| 1285 | + $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 1290 | + |
|
| 1291 | + echo do_shortcode( $shortcode ); |
|
| 1292 | + |
|
| 1293 | + } |
|
| 1294 | + wp_die(); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + /** |
|
| 1298 | + * Output the shortcode. |
|
| 1299 | + * |
|
| 1300 | + * @param array $args |
|
| 1301 | + * @param string $content |
|
| 1302 | + * |
|
| 1303 | + * @return string |
|
| 1304 | + */ |
|
| 1305 | + public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1306 | + $args = self::argument_values( $args ); |
|
| 1307 | + |
|
| 1308 | + // add extra argument so we know its a output to gutenberg |
|
| 1309 | + //$args |
|
| 1310 | + $args = $this->string_to_bool( $args ); |
|
| 1311 | + |
|
| 1312 | + |
|
| 1313 | + $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1314 | + |
|
| 1315 | + $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 1316 | + $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 1317 | + |
|
| 1318 | + $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1319 | + $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 1320 | + |
|
| 1321 | + $shortcode_args = array(); |
|
| 1322 | + $output = ''; |
|
| 1323 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1324 | + $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1325 | + if ( $main_content && ! $no_wrap ) { |
|
| 1326 | + // wrap the shortcode in a dive with the same class as the widget |
|
| 1327 | + $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
| 1328 | + if ( ! empty( $args['title'] ) ) { |
|
| 1329 | + // if its a shortcode and there is a title try to grab the title wrappers |
|
| 1330 | + $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1331 | + if ( empty( $instance ) ) { |
|
| 1332 | + global $wp_registered_sidebars; |
|
| 1333 | + if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1334 | + foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1335 | + if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1336 | + $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 1337 | + $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 1338 | + break; |
|
| 1339 | + } |
|
| 1340 | + } |
|
| 1341 | + } |
|
| 1342 | + } |
|
| 1343 | + $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1344 | + } |
|
| 1345 | + $output .= $main_content; |
|
| 1346 | + $output .= '</div>'; |
|
| 1347 | + } elseif ( $main_content && $no_wrap ) { |
|
| 1348 | + $output .= $main_content; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + // if preview show a placeholder if empty |
|
| 1352 | + if ( $this->is_preview() && $output == '' ) { |
|
| 1353 | + $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + /** |
|
| 1360 | + * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
| 1361 | + * |
|
| 1362 | + * @param string $name |
|
| 1363 | + * |
|
| 1364 | + * @return string |
|
| 1365 | + */ |
|
| 1366 | + public function preview_placeholder_text( $name = '' ) { |
|
| 1367 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + /** |
|
| 1371 | + * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 1372 | + * |
|
| 1373 | + * @param $options |
|
| 1374 | + * |
|
| 1375 | + * @return mixed |
|
| 1376 | + */ |
|
| 1377 | + public function string_to_bool( $options ) { |
|
| 1378 | + // convert bool strings to booleans |
|
| 1379 | + foreach ( $options as $key => $val ) { |
|
| 1380 | + if ( $val == 'false' ) { |
|
| 1381 | + $options[ $key ] = false; |
|
| 1382 | + } elseif ( $val == 'true' ) { |
|
| 1383 | + $options[ $key ] = true; |
|
| 1384 | + } |
|
| 1385 | + } |
|
| 1386 | + |
|
| 1387 | + return $options; |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * Get the argument values that are also filterable. |
|
| 1392 | + * |
|
| 1393 | + * @param $instance |
|
| 1394 | + * |
|
| 1395 | + * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
| 1396 | + * |
|
| 1397 | + * @return array |
|
| 1398 | + */ |
|
| 1399 | + public function argument_values( $instance ) { |
|
| 1400 | + $argument_values = array(); |
|
| 1401 | + |
|
| 1402 | + // set widget instance |
|
| 1403 | + $this->instance = $instance; |
|
| 1404 | + |
|
| 1405 | + if ( empty( $this->arguments ) ) { |
|
| 1406 | + $this->arguments = $this->get_arguments(); |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + if ( ! empty( $this->arguments ) ) { |
|
| 1410 | + foreach ( $this->arguments as $key => $args ) { |
|
| 1411 | + // set the input name from the key |
|
| 1412 | + $args['name'] = $key; |
|
| 1413 | + // |
|
| 1414 | + $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1415 | + if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
| 1416 | + // don't set default for an empty checkbox |
|
| 1417 | + } |
|
| 1418 | + elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1419 | + $argument_values[ $key ] = $args['default']; |
|
| 1420 | + } |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + return $argument_values; |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + /** |
|
| 1428 | + * Set arguments in super duper. |
|
| 1429 | + * |
|
| 1430 | + * @since 1.0.0 |
|
| 1431 | + * |
|
| 1432 | + * @return array Set arguments. |
|
| 1433 | + */ |
|
| 1434 | + public function set_arguments() { |
|
| 1435 | + return $this->arguments; |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + /** |
|
| 1439 | + * Get arguments in super duper. |
|
| 1440 | + * |
|
| 1441 | + * @since 1.0.0 |
|
| 1442 | + * |
|
| 1443 | + * @return array Get arguments. |
|
| 1444 | + */ |
|
| 1445 | + public function get_arguments() { |
|
| 1446 | + if ( empty( $this->arguments ) ) { |
|
| 1447 | + $this->arguments = $this->set_arguments(); |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1451 | + $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1452 | + |
|
| 1453 | + return $this->arguments; |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + /** |
|
| 1457 | + * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 1458 | + * |
|
| 1459 | + * @param array $args |
|
| 1460 | + * @param array $widget_args |
|
| 1461 | + * @param string $content |
|
| 1462 | + */ |
|
| 1463 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1464 | + |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 1469 | + */ |
|
| 1470 | + public function register_block() { |
|
| 1471 | + wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1472 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1473 | + |
|
| 1474 | + wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1475 | + |
|
| 1476 | + } |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + /** |
|
| 1480 | + * Check if we need to show advanced options. |
|
| 1481 | + * |
|
| 1482 | + * @return bool |
|
| 1483 | + */ |
|
| 1484 | + public function block_show_advanced() { |
|
| 1485 | + |
|
| 1486 | + $show = false; |
|
| 1487 | + $arguments = $this->arguments; |
|
| 1488 | + |
|
| 1489 | + if ( empty( $arguments ) ) { |
|
| 1490 | + $arguments = $this->get_arguments(); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + if ( ! empty( $arguments ) ) { |
|
| 1494 | + foreach ( $arguments as $argument ) { |
|
| 1495 | + if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1496 | + $show = true; |
|
| 1497 | + break; // no need to continue if we know we have it |
|
| 1498 | + } |
|
| 1499 | + } |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + return $show; |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + /** |
|
| 1506 | + * Get the url path to the current folder. |
|
| 1507 | + * |
|
| 1508 | + * @return string |
|
| 1509 | + */ |
|
| 1510 | + public function get_url() { |
|
| 1511 | + |
|
| 1512 | + $url = $this->url; |
|
| 1513 | + |
|
| 1514 | + if(!$url){ |
|
| 1515 | + // check if we are inside a plugin |
|
| 1516 | + $file_dir = str_replace("/includes","", dirname( __FILE__ )); |
|
| 1517 | + |
|
| 1518 | + $dir_parts = explode("/wp-content/",$file_dir); |
|
| 1519 | + $url_parts = explode("/wp-content/",plugins_url()); |
|
| 1520 | + |
|
| 1521 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
| 1522 | + $url = trailingslashit( $url_parts[0]."/wp-content/".$dir_parts[1] ); |
|
| 1523 | + $this->url = $url; |
|
| 1524 | + } |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + return $url; |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + /** |
|
| 1532 | + * Generate the block icon. |
|
| 1533 | + * |
|
| 1534 | + * Enables the use of Font Awesome icons. |
|
| 1535 | + * |
|
| 1536 | + * @note xlink:href is actually deprecated but href is not supported by all so we use both. |
|
| 1537 | + * @param $icon |
|
| 1538 | + * @since 1.1.0 |
|
| 1539 | + * @return string |
|
| 1540 | + */ |
|
| 1541 | + public function get_block_icon($icon){ |
|
| 1542 | + |
|
| 1543 | + // check if we have a Font Awesome icon |
|
| 1544 | + $fa_type = ''; |
|
| 1545 | + if(substr( $icon, 0, 7 ) === "fas fa-"){ |
|
| 1546 | + $fa_type = 'solid'; |
|
| 1547 | + }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
| 1548 | + $fa_type = 'regular'; |
|
| 1549 | + }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
| 1550 | + $fa_type = 'brands'; |
|
| 1551 | + }else{ |
|
| 1552 | + $icon = "'".$icon."'"; |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + // set the icon if we found one |
|
| 1556 | + if($fa_type){ |
|
| 1557 | + $fa_icon = str_replace(array("fas fa-","far fa-","fab fa-"),"",$icon); |
|
| 1558 | + $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."','href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."'}))"; |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + return $icon; |
|
| 1562 | + } |
|
| 1563 | + |
|
| 1564 | + public function group_arguments($arguments){ |
|
| 1565 | 1565 | // echo '###';print_r($arguments); |
| 1566 | - if(!empty($arguments)){ |
|
| 1567 | - $temp_arguments = array(); |
|
| 1568 | - $general = __("General"); |
|
| 1569 | - $add_sections = false; |
|
| 1570 | - foreach($arguments as $key => $args){ |
|
| 1571 | - if(isset($args['group'])){ |
|
| 1572 | - $temp_arguments[$args['group']][$key] = $args; |
|
| 1573 | - $add_sections = true; |
|
| 1574 | - }else{ |
|
| 1575 | - $temp_arguments[$general][$key] = $args; |
|
| 1576 | - } |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - // only add sections if more than one |
|
| 1580 | - if($add_sections){ |
|
| 1581 | - $arguments = $temp_arguments; |
|
| 1582 | - } |
|
| 1583 | - } |
|
| 1566 | + if(!empty($arguments)){ |
|
| 1567 | + $temp_arguments = array(); |
|
| 1568 | + $general = __("General"); |
|
| 1569 | + $add_sections = false; |
|
| 1570 | + foreach($arguments as $key => $args){ |
|
| 1571 | + if(isset($args['group'])){ |
|
| 1572 | + $temp_arguments[$args['group']][$key] = $args; |
|
| 1573 | + $add_sections = true; |
|
| 1574 | + }else{ |
|
| 1575 | + $temp_arguments[$general][$key] = $args; |
|
| 1576 | + } |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + // only add sections if more than one |
|
| 1580 | + if($add_sections){ |
|
| 1581 | + $arguments = $temp_arguments; |
|
| 1582 | + } |
|
| 1583 | + } |
|
| 1584 | 1584 | // echo '###';print_r($arguments); |
| 1585 | - return $arguments; |
|
| 1586 | - } |
|
| 1587 | - |
|
| 1588 | - |
|
| 1589 | - /** |
|
| 1590 | - * Output the JS for building the dynamic Guntenberg block. |
|
| 1591 | - * |
|
| 1592 | - * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
| 1593 | - * @since 1.0.9 Save numbers as numbers and not strings. |
|
| 1594 | - * @since 1.1.0 Font Awesome classes can be used for icons. |
|
| 1595 | - * @return mixed |
|
| 1596 | - */ |
|
| 1597 | - public function block() { |
|
| 1598 | - ob_start(); |
|
| 1599 | - ?> |
|
| 1585 | + return $arguments; |
|
| 1586 | + } |
|
| 1587 | + |
|
| 1588 | + |
|
| 1589 | + /** |
|
| 1590 | + * Output the JS for building the dynamic Guntenberg block. |
|
| 1591 | + * |
|
| 1592 | + * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
| 1593 | + * @since 1.0.9 Save numbers as numbers and not strings. |
|
| 1594 | + * @since 1.1.0 Font Awesome classes can be used for icons. |
|
| 1595 | + * @return mixed |
|
| 1596 | + */ |
|
| 1597 | + public function block() { |
|
| 1598 | + ob_start(); |
|
| 1599 | + ?> |
|
| 1600 | 1600 | <script> |
| 1601 | 1601 | /** |
| 1602 | 1602 | * BLOCK: Basic |
@@ -1635,88 +1635,88 @@ discard block |
||
| 1635 | 1635 | icon: <?php echo $this->get_block_icon($this->options['block-icon']);?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
| 1636 | 1636 | supports: { |
| 1637 | 1637 | <?php |
| 1638 | - if(isset($this->options['block-supports'])){ |
|
| 1639 | - echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
| 1640 | - } |
|
| 1641 | - ?> |
|
| 1638 | + if(isset($this->options['block-supports'])){ |
|
| 1639 | + echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
| 1640 | + } |
|
| 1641 | + ?> |
|
| 1642 | 1642 | }, |
| 1643 | 1643 | category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
| 1644 | 1644 | <?php if ( isset( $this->options['block-keywords'] ) ) { |
| 1645 | - echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 1646 | - }?> |
|
| 1645 | + echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 1646 | + }?> |
|
| 1647 | 1647 | |
| 1648 | 1648 | <?php |
| 1649 | 1649 | |
| 1650 | - $show_advanced = $this->block_show_advanced(); |
|
| 1650 | + $show_advanced = $this->block_show_advanced(); |
|
| 1651 | 1651 | |
| 1652 | - $show_alignment = false; |
|
| 1653 | - // align feature |
|
| 1654 | - /*echo "supports: {"; |
|
| 1652 | + $show_alignment = false; |
|
| 1653 | + // align feature |
|
| 1654 | + /*echo "supports: {"; |
|
| 1655 | 1655 | echo " align: true,"; |
| 1656 | 1656 | echo " html: false"; |
| 1657 | 1657 | echo "},";*/ |
| 1658 | 1658 | |
| 1659 | - if ( ! empty( $this->arguments ) ) { |
|
| 1660 | - echo "attributes : {"; |
|
| 1661 | - |
|
| 1662 | - if ( $show_advanced ) { |
|
| 1663 | - echo "show_advanced: {"; |
|
| 1664 | - echo " type: 'boolean',"; |
|
| 1665 | - echo " default: false,"; |
|
| 1666 | - echo "},"; |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - // block wrap element |
|
| 1670 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1671 | - echo "block_wrap: {"; |
|
| 1672 | - echo " type: 'string',"; |
|
| 1673 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1674 | - echo "},"; |
|
| 1675 | - } |
|
| 1676 | - |
|
| 1677 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1678 | - |
|
| 1679 | - // set if we should show alignment |
|
| 1680 | - if ( $key == 'alignment' ) { |
|
| 1681 | - $show_alignment = true; |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - $extra = ''; |
|
| 1685 | - |
|
| 1686 | - if ( $args['type'] == 'checkbox' ) { |
|
| 1687 | - $type = 'boolean'; |
|
| 1688 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1689 | - } elseif ( $args['type'] == 'number' ) { |
|
| 1690 | - $type = 'number'; |
|
| 1691 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1692 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1693 | - $type = 'array'; |
|
| 1694 | - if ( is_array( $args['default'] ) ) { |
|
| 1695 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1696 | - } else { |
|
| 1697 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1698 | - } |
|
| 1699 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1700 | - $type = 'array'; |
|
| 1701 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1702 | - } else { |
|
| 1703 | - $type = 'string'; |
|
| 1704 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1705 | - } |
|
| 1706 | - echo $key . " : {"; |
|
| 1707 | - echo "type : '$type',"; |
|
| 1708 | - echo "default : $default,"; |
|
| 1709 | - echo "},"; |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 1713 | - echo "className: { type: 'string', default: '' },"; |
|
| 1714 | - |
|
| 1715 | - echo "},"; |
|
| 1716 | - |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - ?> |
|
| 1659 | + if ( ! empty( $this->arguments ) ) { |
|
| 1660 | + echo "attributes : {"; |
|
| 1661 | + |
|
| 1662 | + if ( $show_advanced ) { |
|
| 1663 | + echo "show_advanced: {"; |
|
| 1664 | + echo " type: 'boolean',"; |
|
| 1665 | + echo " default: false,"; |
|
| 1666 | + echo "},"; |
|
| 1667 | + } |
|
| 1668 | + |
|
| 1669 | + // block wrap element |
|
| 1670 | + if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1671 | + echo "block_wrap: {"; |
|
| 1672 | + echo " type: 'string',"; |
|
| 1673 | + echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1674 | + echo "},"; |
|
| 1675 | + } |
|
| 1676 | + |
|
| 1677 | + foreach ( $this->arguments as $key => $args ) { |
|
| 1678 | + |
|
| 1679 | + // set if we should show alignment |
|
| 1680 | + if ( $key == 'alignment' ) { |
|
| 1681 | + $show_alignment = true; |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + $extra = ''; |
|
| 1685 | + |
|
| 1686 | + if ( $args['type'] == 'checkbox' ) { |
|
| 1687 | + $type = 'boolean'; |
|
| 1688 | + $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1689 | + } elseif ( $args['type'] == 'number' ) { |
|
| 1690 | + $type = 'number'; |
|
| 1691 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1692 | + } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1693 | + $type = 'array'; |
|
| 1694 | + if ( is_array( $args['default'] ) ) { |
|
| 1695 | + $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1696 | + } else { |
|
| 1697 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1698 | + } |
|
| 1699 | + } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1700 | + $type = 'array'; |
|
| 1701 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1702 | + } else { |
|
| 1703 | + $type = 'string'; |
|
| 1704 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1705 | + } |
|
| 1706 | + echo $key . " : {"; |
|
| 1707 | + echo "type : '$type',"; |
|
| 1708 | + echo "default : $default,"; |
|
| 1709 | + echo "},"; |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 1713 | + echo "className: { type: 'string', default: '' },"; |
|
| 1714 | + |
|
| 1715 | + echo "},"; |
|
| 1716 | + |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + ?> |
|
| 1720 | 1720 | |
| 1721 | 1721 | // The "edit" property must be a valid function. |
| 1722 | 1722 | edit: function (props) { |
@@ -1735,8 +1735,8 @@ discard block |
||
| 1735 | 1735 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
| 1736 | 1736 | 'attributes': props.attributes, |
| 1737 | 1737 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
| 1738 | - echo $post->ID; |
|
| 1739 | - }?>, |
|
| 1738 | + echo $post->ID; |
|
| 1739 | + }?>, |
|
| 1740 | 1740 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
| 1741 | 1741 | }; |
| 1742 | 1742 | |
@@ -1783,10 +1783,10 @@ discard block |
||
| 1783 | 1783 | |
| 1784 | 1784 | <?php |
| 1785 | 1785 | |
| 1786 | - if(! empty( $this->arguments )){ |
|
| 1786 | + if(! empty( $this->arguments )){ |
|
| 1787 | 1787 | |
| 1788 | - if ( $show_advanced ) { |
|
| 1789 | - ?> |
|
| 1788 | + if ( $show_advanced ) { |
|
| 1789 | + ?> |
|
| 1790 | 1790 | el( |
| 1791 | 1791 | wp.components.ToggleControl, |
| 1792 | 1792 | { |
@@ -1799,61 +1799,61 @@ discard block |
||
| 1799 | 1799 | ), |
| 1800 | 1800 | <?php |
| 1801 | 1801 | |
| 1802 | - } |
|
| 1802 | + } |
|
| 1803 | 1803 | |
| 1804 | - $arguments = $this->group_arguments($this->arguments); |
|
| 1804 | + $arguments = $this->group_arguments($this->arguments); |
|
| 1805 | 1805 | |
| 1806 | - // Do we have sections? |
|
| 1807 | - $has_sections = $arguments == $this->arguments ? false : true; |
|
| 1806 | + // Do we have sections? |
|
| 1807 | + $has_sections = $arguments == $this->arguments ? false : true; |
|
| 1808 | 1808 | |
| 1809 | 1809 | |
| 1810 | - if($has_sections){ |
|
| 1811 | - $panel_count = 0; |
|
| 1812 | - foreach($arguments as $key => $args){ |
|
| 1813 | - ?> |
|
| 1810 | + if($has_sections){ |
|
| 1811 | + $panel_count = 0; |
|
| 1812 | + foreach($arguments as $key => $args){ |
|
| 1813 | + ?> |
|
| 1814 | 1814 | el(wp.components.PanelBody, { |
| 1815 | 1815 | title: '<?php esc_attr_e($key); ?>', |
| 1816 | 1816 | initialOpen: <?php if($panel_count){echo "false";}else{echo "true";}?> |
| 1817 | 1817 | }, |
| 1818 | 1818 | <?php |
| 1819 | 1819 | |
| 1820 | - foreach($args as $k => $a){ |
|
| 1821 | - $this->build_block_arguments($k, $a); |
|
| 1822 | - } |
|
| 1823 | - ?> |
|
| 1820 | + foreach($args as $k => $a){ |
|
| 1821 | + $this->build_block_arguments($k, $a); |
|
| 1822 | + } |
|
| 1823 | + ?> |
|
| 1824 | 1824 | ), |
| 1825 | 1825 | <?php |
| 1826 | - $panel_count++; |
|
| 1826 | + $panel_count++; |
|
| 1827 | 1827 | |
| 1828 | - } |
|
| 1829 | - }else{ |
|
| 1830 | - foreach($this->arguments as $key => $args){ |
|
| 1831 | - $this->build_block_arguments($key, $args); |
|
| 1832 | - } |
|
| 1833 | - } |
|
| 1828 | + } |
|
| 1829 | + }else{ |
|
| 1830 | + foreach($this->arguments as $key => $args){ |
|
| 1831 | + $this->build_block_arguments($key, $args); |
|
| 1832 | + } |
|
| 1833 | + } |
|
| 1834 | 1834 | |
| 1835 | 1835 | |
| 1836 | 1836 | |
| 1837 | - } |
|
| 1838 | - ?> |
|
| 1837 | + } |
|
| 1838 | + ?> |
|
| 1839 | 1839 | |
| 1840 | 1840 | ), |
| 1841 | 1841 | |
| 1842 | 1842 | <?php |
| 1843 | - // If the user sets block-output array then build it |
|
| 1844 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1845 | - $this->block_element( $this->options['block-output'] ); |
|
| 1846 | - }else{ |
|
| 1847 | - // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1848 | - ?> |
|
| 1843 | + // If the user sets block-output array then build it |
|
| 1844 | + if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1845 | + $this->block_element( $this->options['block-output'] ); |
|
| 1846 | + }else{ |
|
| 1847 | + // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1848 | + ?> |
|
| 1849 | 1849 | el('div', { |
| 1850 | 1850 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
| 1851 | 1851 | className: props.className, |
| 1852 | 1852 | style: {'min-height': '30px'} |
| 1853 | 1853 | }) |
| 1854 | 1854 | <?php |
| 1855 | - } |
|
| 1856 | - ?> |
|
| 1855 | + } |
|
| 1856 | + ?> |
|
| 1857 | 1857 | ]; // end return |
| 1858 | 1858 | }, |
| 1859 | 1859 | |
@@ -1870,17 +1870,17 @@ discard block |
||
| 1870 | 1870 | var content = "[<?php echo $this->options['base_id'];?>"; |
| 1871 | 1871 | <?php |
| 1872 | 1872 | |
| 1873 | - if(! empty( $this->arguments )){ |
|
| 1874 | - foreach($this->arguments as $key => $args){ |
|
| 1875 | - ?> |
|
| 1873 | + if(! empty( $this->arguments )){ |
|
| 1874 | + foreach($this->arguments as $key => $args){ |
|
| 1875 | + ?> |
|
| 1876 | 1876 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
| 1877 | 1877 | content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
| 1878 | 1878 | } |
| 1879 | 1879 | <?php |
| 1880 | - } |
|
| 1881 | - } |
|
| 1880 | + } |
|
| 1881 | + } |
|
| 1882 | 1882 | |
| 1883 | - ?> |
|
| 1883 | + ?> |
|
| 1884 | 1884 | content += "]"; |
| 1885 | 1885 | |
| 1886 | 1886 | |
@@ -1909,83 +1909,83 @@ discard block |
||
| 1909 | 1909 | })(); |
| 1910 | 1910 | </script> |
| 1911 | 1911 | <?php |
| 1912 | - $output = ob_get_clean(); |
|
| 1912 | + $output = ob_get_clean(); |
|
| 1913 | 1913 | |
| 1914 | - /* |
|
| 1914 | + /* |
|
| 1915 | 1915 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1916 | 1916 | */ |
| 1917 | 1917 | |
| 1918 | - return str_replace( array( |
|
| 1919 | - '<script>', |
|
| 1920 | - '</script>' |
|
| 1921 | - ), '', $output ); |
|
| 1922 | - } |
|
| 1923 | - |
|
| 1924 | - public function build_block_arguments($key,$args){ |
|
| 1925 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 1926 | - $options = ''; |
|
| 1927 | - $extra = ''; |
|
| 1928 | - $require = ''; |
|
| 1929 | - $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 1930 | - $value = "props.attributes.$key"; |
|
| 1931 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1932 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 1933 | - $type = 'TextControl'; |
|
| 1934 | - // Save numbers as numbers and not strings |
|
| 1935 | - if ( $args['type'] == 'number' ) { |
|
| 1936 | - $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
| 1937 | - } |
|
| 1938 | - } |
|
| 1939 | - // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we use html5 color input for now https://github.com/WordPress/gutenberg/issues/14378 |
|
| 1940 | - // $type = 'ColorPicker'; |
|
| 1941 | - // } |
|
| 1942 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 1943 | - $type = 'CheckboxControl'; |
|
| 1944 | - $extra .= "checked: props.attributes.$key,"; |
|
| 1945 | - $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 1946 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1947 | - $type = 'SelectControl'; |
|
| 1948 | - if ( ! empty( $args['options'] ) ) { |
|
| 1949 | - $options .= "options : ["; |
|
| 1950 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1951 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1952 | - } |
|
| 1953 | - $options .= "],"; |
|
| 1954 | - } |
|
| 1955 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1956 | - $extra .= ' multiple: true, '; |
|
| 1957 | - //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
| 1958 | - //$value = "['edit', 'delete']"; |
|
| 1959 | - } |
|
| 1960 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 1961 | - $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 1962 | - } else { |
|
| 1963 | - return;// if we have not implemented the control then don't break the JS. |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - // add show only if advanced |
|
| 1967 | - if ( ! empty( $args['advanced'] ) ) { |
|
| 1968 | - echo "props.attributes.show_advanced && "; |
|
| 1969 | - } |
|
| 1970 | - // add setting require if defined |
|
| 1971 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 1972 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1973 | - } |
|
| 1974 | - ?> |
|
| 1918 | + return str_replace( array( |
|
| 1919 | + '<script>', |
|
| 1920 | + '</script>' |
|
| 1921 | + ), '', $output ); |
|
| 1922 | + } |
|
| 1923 | + |
|
| 1924 | + public function build_block_arguments($key,$args){ |
|
| 1925 | + $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 1926 | + $options = ''; |
|
| 1927 | + $extra = ''; |
|
| 1928 | + $require = ''; |
|
| 1929 | + $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 1930 | + $value = "props.attributes.$key"; |
|
| 1931 | + $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1932 | + if ( in_array( $args['type'], $text_type ) ) { |
|
| 1933 | + $type = 'TextControl'; |
|
| 1934 | + // Save numbers as numbers and not strings |
|
| 1935 | + if ( $args['type'] == 'number' ) { |
|
| 1936 | + $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
| 1937 | + } |
|
| 1938 | + } |
|
| 1939 | + // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we use html5 color input for now https://github.com/WordPress/gutenberg/issues/14378 |
|
| 1940 | + // $type = 'ColorPicker'; |
|
| 1941 | + // } |
|
| 1942 | + elseif ( $args['type'] == 'checkbox' ) { |
|
| 1943 | + $type = 'CheckboxControl'; |
|
| 1944 | + $extra .= "checked: props.attributes.$key,"; |
|
| 1945 | + $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 1946 | + } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1947 | + $type = 'SelectControl'; |
|
| 1948 | + if ( ! empty( $args['options'] ) ) { |
|
| 1949 | + $options .= "options : ["; |
|
| 1950 | + foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1951 | + $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1952 | + } |
|
| 1953 | + $options .= "],"; |
|
| 1954 | + } |
|
| 1955 | + if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1956 | + $extra .= ' multiple: true, '; |
|
| 1957 | + //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
| 1958 | + //$value = "['edit', 'delete']"; |
|
| 1959 | + } |
|
| 1960 | + } elseif ( $args['type'] == 'alignment' ) { |
|
| 1961 | + $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 1962 | + } else { |
|
| 1963 | + return;// if we have not implemented the control then don't break the JS. |
|
| 1964 | + } |
|
| 1965 | + |
|
| 1966 | + // add show only if advanced |
|
| 1967 | + if ( ! empty( $args['advanced'] ) ) { |
|
| 1968 | + echo "props.attributes.show_advanced && "; |
|
| 1969 | + } |
|
| 1970 | + // add setting require if defined |
|
| 1971 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 1972 | + echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1973 | + } |
|
| 1974 | + ?> |
|
| 1975 | 1975 | el( |
| 1976 | 1976 | wp.components.<?php echo esc_attr( $type );?>, |
| 1977 | 1977 | { |
| 1978 | 1978 | label: '<?php echo esc_attr( $args['title'] );?>', |
| 1979 | 1979 | help: '<?php if ( isset( $args['desc'] ) ) { |
| 1980 | - echo esc_attr( $args['desc'] ); |
|
| 1981 | - }?>', |
|
| 1980 | + echo esc_attr( $args['desc'] ); |
|
| 1981 | + }?>', |
|
| 1982 | 1982 | value: <?php echo $value;?>, |
| 1983 | 1983 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
| 1984 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1985 | - }?> |
|
| 1984 | + echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1985 | + }?> |
|
| 1986 | 1986 | <?php if ( ! empty( $args['placeholder'] ) ) { |
| 1987 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1988 | - }?> |
|
| 1987 | + echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1988 | + }?> |
|
| 1989 | 1989 | <?php echo $options;?> |
| 1990 | 1990 | <?php echo $extra;?> |
| 1991 | 1991 | <?php echo $custom_attributes;?> |
@@ -1995,503 +1995,503 @@ discard block |
||
| 1995 | 1995 | } |
| 1996 | 1996 | ), |
| 1997 | 1997 | <?php |
| 1998 | - } |
|
| 1999 | - |
|
| 2000 | - /** |
|
| 2001 | - * Convert an array of attributes to block string. |
|
| 2002 | - * |
|
| 2003 | - * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 2004 | - * |
|
| 2005 | - * @param $custom_attributes |
|
| 2006 | - * |
|
| 2007 | - * @return string |
|
| 2008 | - */ |
|
| 2009 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 2010 | - $attributes = ''; |
|
| 2011 | - if ( ! empty( $custom_attributes ) ) { |
|
| 2012 | - |
|
| 2013 | - if ( $html ) { |
|
| 2014 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2015 | - $attributes .= " $key='$val' "; |
|
| 2016 | - } |
|
| 2017 | - } else { |
|
| 2018 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2019 | - $attributes .= "'$key': '$val',"; |
|
| 2020 | - } |
|
| 2021 | - } |
|
| 2022 | - } |
|
| 2023 | - |
|
| 2024 | - return $attributes; |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - /** |
|
| 2028 | - * A self looping function to create the output for JS block elements. |
|
| 2029 | - * |
|
| 2030 | - * This is what is output in the WP Editor visual view. |
|
| 2031 | - * |
|
| 2032 | - * @param $args |
|
| 2033 | - */ |
|
| 2034 | - public function block_element( $args ) { |
|
| 2035 | - |
|
| 2036 | - |
|
| 2037 | - if ( ! empty( $args ) ) { |
|
| 2038 | - foreach ( $args as $element => $new_args ) { |
|
| 2039 | - |
|
| 2040 | - if ( is_array( $new_args ) ) { // its an element |
|
| 2041 | - |
|
| 2042 | - |
|
| 2043 | - if ( isset( $new_args['element'] ) ) { |
|
| 2044 | - |
|
| 2045 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 2046 | - echo str_replace( array( |
|
| 2047 | - "'+", |
|
| 2048 | - "+'" |
|
| 2049 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 2050 | - unset( $new_args['element_require'] ); |
|
| 2051 | - } |
|
| 2052 | - |
|
| 2053 | - echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 2054 | - |
|
| 2055 | - // get the attributes |
|
| 2056 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2057 | - |
|
| 2058 | - |
|
| 2059 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 2060 | - // do nothing |
|
| 2061 | - } else { |
|
| 2062 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 2063 | - } |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - echo "},";// end attributes |
|
| 2067 | - |
|
| 2068 | - // get the content |
|
| 2069 | - $first_item = 0; |
|
| 2070 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2071 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 2072 | - |
|
| 2073 | - if ( $new_key === 'content' ) { |
|
| 2074 | - echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
| 2075 | - } |
|
| 2076 | - |
|
| 2077 | - if ( is_array( $new_value ) ) { |
|
| 2078 | - |
|
| 2079 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 2080 | - echo str_replace( array( |
|
| 2081 | - "'+", |
|
| 2082 | - "+'" |
|
| 2083 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 2084 | - unset( $new_value['element_require'] ); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 2088 | - $x = 1; |
|
| 2089 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 2090 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2091 | - $x ++; |
|
| 2092 | - } |
|
| 2093 | - } else { |
|
| 2094 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2095 | - } |
|
| 2096 | - } |
|
| 2097 | - $first_item ++; |
|
| 2098 | - } |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - echo ")";// end content |
|
| 2102 | - |
|
| 2103 | - echo ", \n"; |
|
| 2104 | - |
|
| 2105 | - } |
|
| 2106 | - } else { |
|
| 2107 | - |
|
| 2108 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 2109 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 2110 | - } elseif ( $element == 'style' ) { |
|
| 2111 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 2112 | - } else { |
|
| 2113 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - } |
|
| 2117 | - } |
|
| 2118 | - } |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * Replace block attributes placeholders with the proper naming. |
|
| 2123 | - * |
|
| 2124 | - * @param $string |
|
| 2125 | - * |
|
| 2126 | - * @return mixed |
|
| 2127 | - */ |
|
| 2128 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 2129 | - |
|
| 2130 | - if ( $no_wrap ) { |
|
| 2131 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 2132 | - } else { |
|
| 2133 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 2134 | - } |
|
| 2135 | - |
|
| 2136 | - return $string; |
|
| 2137 | - } |
|
| 2138 | - |
|
| 2139 | - /** |
|
| 2140 | - * Outputs the content of the widget |
|
| 2141 | - * |
|
| 2142 | - * @param array $args |
|
| 2143 | - * @param array $instance |
|
| 2144 | - */ |
|
| 2145 | - public function widget( $args, $instance ) { |
|
| 2146 | - |
|
| 2147 | - // get the filtered values |
|
| 2148 | - $argument_values = $this->argument_values( $instance ); |
|
| 2149 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 2150 | - $output = $this->output( $argument_values, $args ); |
|
| 2151 | - |
|
| 2152 | - ob_start(); |
|
| 2153 | - if ( $output ) { |
|
| 2154 | - // Before widget |
|
| 2155 | - $before_widget = $args['before_widget']; |
|
| 2156 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 2157 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 2158 | - |
|
| 2159 | - // After widget |
|
| 2160 | - $after_widget = $args['after_widget']; |
|
| 2161 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 2162 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 2163 | - |
|
| 2164 | - echo $before_widget; |
|
| 2165 | - // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 2166 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2167 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 2168 | - } |
|
| 2169 | - echo $this->output_title( $args, $instance ); |
|
| 2170 | - echo $output; |
|
| 2171 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2172 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 2173 | - } |
|
| 2174 | - echo $after_widget; |
|
| 2175 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 2176 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 2177 | - echo $output; |
|
| 2178 | - } |
|
| 2179 | - $output = ob_get_clean(); |
|
| 2180 | - |
|
| 2181 | - $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
| 2182 | - |
|
| 2183 | - echo $output; |
|
| 2184 | - } |
|
| 2185 | - |
|
| 2186 | - /** |
|
| 2187 | - * Tests if the current output is inside a elementor container. |
|
| 2188 | - * |
|
| 2189 | - * @since 1.0.4 |
|
| 2190 | - * @return bool |
|
| 2191 | - */ |
|
| 2192 | - public function is_elementor_widget_output() { |
|
| 2193 | - $result = false; |
|
| 2194 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 2195 | - $result = true; |
|
| 2196 | - } |
|
| 2197 | - |
|
| 2198 | - return $result; |
|
| 2199 | - } |
|
| 2200 | - |
|
| 2201 | - /** |
|
| 2202 | - * Tests if the current output is inside a elementor preview. |
|
| 2203 | - * |
|
| 2204 | - * @since 1.0.4 |
|
| 2205 | - * @return bool |
|
| 2206 | - */ |
|
| 2207 | - public function is_elementor_preview() { |
|
| 2208 | - $result = false; |
|
| 2209 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 2210 | - $result = true; |
|
| 2211 | - } |
|
| 2212 | - |
|
| 2213 | - return $result; |
|
| 2214 | - } |
|
| 2215 | - |
|
| 2216 | - /** |
|
| 2217 | - * Tests if the current output is inside a Divi preview. |
|
| 2218 | - * |
|
| 2219 | - * @since 1.0.6 |
|
| 2220 | - * @return bool |
|
| 2221 | - */ |
|
| 2222 | - public function is_divi_preview() { |
|
| 2223 | - $result = false; |
|
| 2224 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 2225 | - $result = true; |
|
| 2226 | - } |
|
| 2227 | - |
|
| 2228 | - return $result; |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - /** |
|
| 2232 | - * Tests if the current output is inside a Beaver builder preview. |
|
| 2233 | - * |
|
| 2234 | - * @since 1.0.6 |
|
| 2235 | - * @return bool |
|
| 2236 | - */ |
|
| 2237 | - public function is_beaver_preview() { |
|
| 2238 | - $result = false; |
|
| 2239 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 2240 | - $result = true; |
|
| 2241 | - } |
|
| 2242 | - |
|
| 2243 | - return $result; |
|
| 2244 | - } |
|
| 2245 | - |
|
| 2246 | - /** |
|
| 2247 | - * Tests if the current output is inside a siteorigin builder preview. |
|
| 2248 | - * |
|
| 2249 | - * @since 1.0.6 |
|
| 2250 | - * @return bool |
|
| 2251 | - */ |
|
| 2252 | - public function is_siteorigin_preview() { |
|
| 2253 | - $result = false; |
|
| 2254 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 2255 | - $result = true; |
|
| 2256 | - } |
|
| 2257 | - |
|
| 2258 | - return $result; |
|
| 2259 | - } |
|
| 2260 | - |
|
| 2261 | - /** |
|
| 2262 | - * Tests if the current output is inside a cornerstone builder preview. |
|
| 2263 | - * |
|
| 2264 | - * @since 1.0.8 |
|
| 2265 | - * @return bool |
|
| 2266 | - */ |
|
| 2267 | - public function is_cornerstone_preview() { |
|
| 2268 | - $result = false; |
|
| 2269 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 2270 | - $result = true; |
|
| 2271 | - } |
|
| 2272 | - |
|
| 2273 | - return $result; |
|
| 2274 | - } |
|
| 2275 | - |
|
| 2276 | - /** |
|
| 2277 | - * Tests if the current output is inside a fusion builder preview. |
|
| 2278 | - * |
|
| 2279 | - * @since 1.1.0 |
|
| 2280 | - * @return bool |
|
| 2281 | - */ |
|
| 2282 | - public function is_fusion_preview() { |
|
| 2283 | - $result = false; |
|
| 2284 | - if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
| 2285 | - $result = true; |
|
| 2286 | - } |
|
| 2287 | - |
|
| 2288 | - return $result; |
|
| 2289 | - } |
|
| 2290 | - |
|
| 2291 | - /** |
|
| 2292 | - * General function to check if we are in a preview situation. |
|
| 2293 | - * |
|
| 2294 | - * @since 1.0.6 |
|
| 2295 | - * @return bool |
|
| 2296 | - */ |
|
| 2297 | - public function is_preview() { |
|
| 2298 | - $preview = false; |
|
| 2299 | - if ( $this->is_divi_preview() ) { |
|
| 2300 | - $preview = true; |
|
| 2301 | - } elseif ( $this->is_elementor_preview() ) { |
|
| 2302 | - $preview = true; |
|
| 2303 | - } elseif ( $this->is_beaver_preview() ) { |
|
| 2304 | - $preview = true; |
|
| 2305 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2306 | - $preview = true; |
|
| 2307 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2308 | - $preview = true; |
|
| 2309 | - } elseif ( $this->is_fusion_preview() ) { |
|
| 2310 | - $preview = true; |
|
| 2311 | - } |
|
| 2312 | - |
|
| 2313 | - return $preview; |
|
| 2314 | - } |
|
| 2315 | - |
|
| 2316 | - /** |
|
| 2317 | - * Output the super title. |
|
| 2318 | - * |
|
| 2319 | - * @param $args |
|
| 2320 | - * @param array $instance |
|
| 2321 | - * |
|
| 2322 | - * @return string |
|
| 2323 | - */ |
|
| 2324 | - public function output_title( $args, $instance = array() ) { |
|
| 2325 | - $output = ''; |
|
| 2326 | - if ( ! empty( $instance['title'] ) ) { |
|
| 2327 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 2328 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2329 | - $output = $args['before_title'] . $title . $args['after_title']; |
|
| 2330 | - } |
|
| 2331 | - |
|
| 2332 | - return $output; |
|
| 2333 | - } |
|
| 2334 | - |
|
| 2335 | - /** |
|
| 2336 | - * Outputs the options form inputs for the widget. |
|
| 2337 | - * |
|
| 2338 | - * @param array $instance The widget options. |
|
| 2339 | - */ |
|
| 2340 | - public function form( $instance ) { |
|
| 2341 | - |
|
| 2342 | - // set widget instance |
|
| 2343 | - $this->instance = $instance; |
|
| 2344 | - |
|
| 2345 | - // set it as a SD widget |
|
| 2346 | - echo $this->widget_advanced_toggle(); |
|
| 2347 | - |
|
| 2348 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2349 | - $arguments_raw = $this->get_arguments(); |
|
| 2350 | - |
|
| 2351 | - if ( is_array( $arguments_raw ) ) { |
|
| 2352 | - |
|
| 2353 | - $arguments = $this->group_arguments($arguments_raw); |
|
| 2354 | - |
|
| 2355 | - // Do we have sections? |
|
| 2356 | - $has_sections = $arguments == $arguments_raw ? false : true; |
|
| 2357 | - |
|
| 2358 | - |
|
| 2359 | - if($has_sections){ |
|
| 2360 | - $panel_count = 0; |
|
| 2361 | - foreach($arguments as $key => $args){ |
|
| 2362 | - |
|
| 2363 | - ?> |
|
| 1998 | + } |
|
| 1999 | + |
|
| 2000 | + /** |
|
| 2001 | + * Convert an array of attributes to block string. |
|
| 2002 | + * |
|
| 2003 | + * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 2004 | + * |
|
| 2005 | + * @param $custom_attributes |
|
| 2006 | + * |
|
| 2007 | + * @return string |
|
| 2008 | + */ |
|
| 2009 | + public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 2010 | + $attributes = ''; |
|
| 2011 | + if ( ! empty( $custom_attributes ) ) { |
|
| 2012 | + |
|
| 2013 | + if ( $html ) { |
|
| 2014 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 2015 | + $attributes .= " $key='$val' "; |
|
| 2016 | + } |
|
| 2017 | + } else { |
|
| 2018 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 2019 | + $attributes .= "'$key': '$val',"; |
|
| 2020 | + } |
|
| 2021 | + } |
|
| 2022 | + } |
|
| 2023 | + |
|
| 2024 | + return $attributes; |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + /** |
|
| 2028 | + * A self looping function to create the output for JS block elements. |
|
| 2029 | + * |
|
| 2030 | + * This is what is output in the WP Editor visual view. |
|
| 2031 | + * |
|
| 2032 | + * @param $args |
|
| 2033 | + */ |
|
| 2034 | + public function block_element( $args ) { |
|
| 2035 | + |
|
| 2036 | + |
|
| 2037 | + if ( ! empty( $args ) ) { |
|
| 2038 | + foreach ( $args as $element => $new_args ) { |
|
| 2039 | + |
|
| 2040 | + if ( is_array( $new_args ) ) { // its an element |
|
| 2041 | + |
|
| 2042 | + |
|
| 2043 | + if ( isset( $new_args['element'] ) ) { |
|
| 2044 | + |
|
| 2045 | + if ( isset( $new_args['element_require'] ) ) { |
|
| 2046 | + echo str_replace( array( |
|
| 2047 | + "'+", |
|
| 2048 | + "+'" |
|
| 2049 | + ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 2050 | + unset( $new_args['element_require'] ); |
|
| 2051 | + } |
|
| 2052 | + |
|
| 2053 | + echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 2054 | + |
|
| 2055 | + // get the attributes |
|
| 2056 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 2057 | + |
|
| 2058 | + |
|
| 2059 | + if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 2060 | + // do nothing |
|
| 2061 | + } else { |
|
| 2062 | + echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 2063 | + } |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + echo "},";// end attributes |
|
| 2067 | + |
|
| 2068 | + // get the content |
|
| 2069 | + $first_item = 0; |
|
| 2070 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 2071 | + if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 2072 | + |
|
| 2073 | + if ( $new_key === 'content' ) { |
|
| 2074 | + echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
| 2075 | + } |
|
| 2076 | + |
|
| 2077 | + if ( is_array( $new_value ) ) { |
|
| 2078 | + |
|
| 2079 | + if ( isset( $new_value['element_require'] ) ) { |
|
| 2080 | + echo str_replace( array( |
|
| 2081 | + "'+", |
|
| 2082 | + "+'" |
|
| 2083 | + ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 2084 | + unset( $new_value['element_require'] ); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + if ( isset( $new_value['element_repeat'] ) ) { |
|
| 2088 | + $x = 1; |
|
| 2089 | + while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 2090 | + $this->block_element( array( '' => $new_value ) ); |
|
| 2091 | + $x ++; |
|
| 2092 | + } |
|
| 2093 | + } else { |
|
| 2094 | + $this->block_element( array( '' => $new_value ) ); |
|
| 2095 | + } |
|
| 2096 | + } |
|
| 2097 | + $first_item ++; |
|
| 2098 | + } |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + echo ")";// end content |
|
| 2102 | + |
|
| 2103 | + echo ", \n"; |
|
| 2104 | + |
|
| 2105 | + } |
|
| 2106 | + } else { |
|
| 2107 | + |
|
| 2108 | + if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 2109 | + echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 2110 | + } elseif ( $element == 'style' ) { |
|
| 2111 | + echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 2112 | + } else { |
|
| 2113 | + echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + } |
|
| 2117 | + } |
|
| 2118 | + } |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + /** |
|
| 2122 | + * Replace block attributes placeholders with the proper naming. |
|
| 2123 | + * |
|
| 2124 | + * @param $string |
|
| 2125 | + * |
|
| 2126 | + * @return mixed |
|
| 2127 | + */ |
|
| 2128 | + public function block_props_replace( $string, $no_wrap = false ) { |
|
| 2129 | + |
|
| 2130 | + if ( $no_wrap ) { |
|
| 2131 | + $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 2132 | + } else { |
|
| 2133 | + $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 2134 | + } |
|
| 2135 | + |
|
| 2136 | + return $string; |
|
| 2137 | + } |
|
| 2138 | + |
|
| 2139 | + /** |
|
| 2140 | + * Outputs the content of the widget |
|
| 2141 | + * |
|
| 2142 | + * @param array $args |
|
| 2143 | + * @param array $instance |
|
| 2144 | + */ |
|
| 2145 | + public function widget( $args, $instance ) { |
|
| 2146 | + |
|
| 2147 | + // get the filtered values |
|
| 2148 | + $argument_values = $this->argument_values( $instance ); |
|
| 2149 | + $argument_values = $this->string_to_bool( $argument_values ); |
|
| 2150 | + $output = $this->output( $argument_values, $args ); |
|
| 2151 | + |
|
| 2152 | + ob_start(); |
|
| 2153 | + if ( $output ) { |
|
| 2154 | + // Before widget |
|
| 2155 | + $before_widget = $args['before_widget']; |
|
| 2156 | + $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 2157 | + $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 2158 | + |
|
| 2159 | + // After widget |
|
| 2160 | + $after_widget = $args['after_widget']; |
|
| 2161 | + $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 2162 | + $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 2163 | + |
|
| 2164 | + echo $before_widget; |
|
| 2165 | + // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 2166 | + if ( $this->is_elementor_widget_output() ) { |
|
| 2167 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 2168 | + } |
|
| 2169 | + echo $this->output_title( $args, $instance ); |
|
| 2170 | + echo $output; |
|
| 2171 | + if ( $this->is_elementor_widget_output() ) { |
|
| 2172 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 2173 | + } |
|
| 2174 | + echo $after_widget; |
|
| 2175 | + } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 2176 | + $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 2177 | + echo $output; |
|
| 2178 | + } |
|
| 2179 | + $output = ob_get_clean(); |
|
| 2180 | + |
|
| 2181 | + $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
| 2182 | + |
|
| 2183 | + echo $output; |
|
| 2184 | + } |
|
| 2185 | + |
|
| 2186 | + /** |
|
| 2187 | + * Tests if the current output is inside a elementor container. |
|
| 2188 | + * |
|
| 2189 | + * @since 1.0.4 |
|
| 2190 | + * @return bool |
|
| 2191 | + */ |
|
| 2192 | + public function is_elementor_widget_output() { |
|
| 2193 | + $result = false; |
|
| 2194 | + if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 2195 | + $result = true; |
|
| 2196 | + } |
|
| 2197 | + |
|
| 2198 | + return $result; |
|
| 2199 | + } |
|
| 2200 | + |
|
| 2201 | + /** |
|
| 2202 | + * Tests if the current output is inside a elementor preview. |
|
| 2203 | + * |
|
| 2204 | + * @since 1.0.4 |
|
| 2205 | + * @return bool |
|
| 2206 | + */ |
|
| 2207 | + public function is_elementor_preview() { |
|
| 2208 | + $result = false; |
|
| 2209 | + if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 2210 | + $result = true; |
|
| 2211 | + } |
|
| 2212 | + |
|
| 2213 | + return $result; |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + /** |
|
| 2217 | + * Tests if the current output is inside a Divi preview. |
|
| 2218 | + * |
|
| 2219 | + * @since 1.0.6 |
|
| 2220 | + * @return bool |
|
| 2221 | + */ |
|
| 2222 | + public function is_divi_preview() { |
|
| 2223 | + $result = false; |
|
| 2224 | + if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 2225 | + $result = true; |
|
| 2226 | + } |
|
| 2227 | + |
|
| 2228 | + return $result; |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + /** |
|
| 2232 | + * Tests if the current output is inside a Beaver builder preview. |
|
| 2233 | + * |
|
| 2234 | + * @since 1.0.6 |
|
| 2235 | + * @return bool |
|
| 2236 | + */ |
|
| 2237 | + public function is_beaver_preview() { |
|
| 2238 | + $result = false; |
|
| 2239 | + if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 2240 | + $result = true; |
|
| 2241 | + } |
|
| 2242 | + |
|
| 2243 | + return $result; |
|
| 2244 | + } |
|
| 2245 | + |
|
| 2246 | + /** |
|
| 2247 | + * Tests if the current output is inside a siteorigin builder preview. |
|
| 2248 | + * |
|
| 2249 | + * @since 1.0.6 |
|
| 2250 | + * @return bool |
|
| 2251 | + */ |
|
| 2252 | + public function is_siteorigin_preview() { |
|
| 2253 | + $result = false; |
|
| 2254 | + if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 2255 | + $result = true; |
|
| 2256 | + } |
|
| 2257 | + |
|
| 2258 | + return $result; |
|
| 2259 | + } |
|
| 2260 | + |
|
| 2261 | + /** |
|
| 2262 | + * Tests if the current output is inside a cornerstone builder preview. |
|
| 2263 | + * |
|
| 2264 | + * @since 1.0.8 |
|
| 2265 | + * @return bool |
|
| 2266 | + */ |
|
| 2267 | + public function is_cornerstone_preview() { |
|
| 2268 | + $result = false; |
|
| 2269 | + if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 2270 | + $result = true; |
|
| 2271 | + } |
|
| 2272 | + |
|
| 2273 | + return $result; |
|
| 2274 | + } |
|
| 2275 | + |
|
| 2276 | + /** |
|
| 2277 | + * Tests if the current output is inside a fusion builder preview. |
|
| 2278 | + * |
|
| 2279 | + * @since 1.1.0 |
|
| 2280 | + * @return bool |
|
| 2281 | + */ |
|
| 2282 | + public function is_fusion_preview() { |
|
| 2283 | + $result = false; |
|
| 2284 | + if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
| 2285 | + $result = true; |
|
| 2286 | + } |
|
| 2287 | + |
|
| 2288 | + return $result; |
|
| 2289 | + } |
|
| 2290 | + |
|
| 2291 | + /** |
|
| 2292 | + * General function to check if we are in a preview situation. |
|
| 2293 | + * |
|
| 2294 | + * @since 1.0.6 |
|
| 2295 | + * @return bool |
|
| 2296 | + */ |
|
| 2297 | + public function is_preview() { |
|
| 2298 | + $preview = false; |
|
| 2299 | + if ( $this->is_divi_preview() ) { |
|
| 2300 | + $preview = true; |
|
| 2301 | + } elseif ( $this->is_elementor_preview() ) { |
|
| 2302 | + $preview = true; |
|
| 2303 | + } elseif ( $this->is_beaver_preview() ) { |
|
| 2304 | + $preview = true; |
|
| 2305 | + } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2306 | + $preview = true; |
|
| 2307 | + } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2308 | + $preview = true; |
|
| 2309 | + } elseif ( $this->is_fusion_preview() ) { |
|
| 2310 | + $preview = true; |
|
| 2311 | + } |
|
| 2312 | + |
|
| 2313 | + return $preview; |
|
| 2314 | + } |
|
| 2315 | + |
|
| 2316 | + /** |
|
| 2317 | + * Output the super title. |
|
| 2318 | + * |
|
| 2319 | + * @param $args |
|
| 2320 | + * @param array $instance |
|
| 2321 | + * |
|
| 2322 | + * @return string |
|
| 2323 | + */ |
|
| 2324 | + public function output_title( $args, $instance = array() ) { |
|
| 2325 | + $output = ''; |
|
| 2326 | + if ( ! empty( $instance['title'] ) ) { |
|
| 2327 | + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 2328 | + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2329 | + $output = $args['before_title'] . $title . $args['after_title']; |
|
| 2330 | + } |
|
| 2331 | + |
|
| 2332 | + return $output; |
|
| 2333 | + } |
|
| 2334 | + |
|
| 2335 | + /** |
|
| 2336 | + * Outputs the options form inputs for the widget. |
|
| 2337 | + * |
|
| 2338 | + * @param array $instance The widget options. |
|
| 2339 | + */ |
|
| 2340 | + public function form( $instance ) { |
|
| 2341 | + |
|
| 2342 | + // set widget instance |
|
| 2343 | + $this->instance = $instance; |
|
| 2344 | + |
|
| 2345 | + // set it as a SD widget |
|
| 2346 | + echo $this->widget_advanced_toggle(); |
|
| 2347 | + |
|
| 2348 | + echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2349 | + $arguments_raw = $this->get_arguments(); |
|
| 2350 | + |
|
| 2351 | + if ( is_array( $arguments_raw ) ) { |
|
| 2352 | + |
|
| 2353 | + $arguments = $this->group_arguments($arguments_raw); |
|
| 2354 | + |
|
| 2355 | + // Do we have sections? |
|
| 2356 | + $has_sections = $arguments == $arguments_raw ? false : true; |
|
| 2357 | + |
|
| 2358 | + |
|
| 2359 | + if($has_sections){ |
|
| 2360 | + $panel_count = 0; |
|
| 2361 | + foreach($arguments as $key => $args){ |
|
| 2362 | + |
|
| 2363 | + ?> |
|
| 2364 | 2364 | <script> |
| 2365 | 2365 | // jQuery(this).find("i").toggleClass("fas fa-chevron-up fas fa-chevron-down");jQuery(this).next().toggle(); |
| 2366 | 2366 | </script> |
| 2367 | 2367 | <?php |
| 2368 | 2368 | |
| 2369 | - $hide = $panel_count ? ' style="display:none;" ' : ''; |
|
| 2370 | - $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
|
| 2371 | - echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle".sanitize_title_with_dashes($key)."'>".esc_attr($key)." <i style='float:right;' class='".$icon_class."'></i></button>"; |
|
| 2372 | - echo "<div class='sd-toggle-group sd-input-group-".sanitize_title_with_dashes($key)."' $hide>"; |
|
| 2373 | - |
|
| 2374 | - foreach($args as $k => $a){ |
|
| 2375 | - $this->widget_inputs($a, $instance); |
|
| 2376 | - } |
|
| 2377 | - |
|
| 2378 | - echo "</div>"; |
|
| 2379 | - |
|
| 2380 | - $panel_count++; |
|
| 2381 | - |
|
| 2382 | - } |
|
| 2383 | - }else{ |
|
| 2384 | - foreach ( $arguments as $key => $args ) { |
|
| 2385 | - $this->widget_inputs( $args, $instance ); |
|
| 2386 | - } |
|
| 2387 | - } |
|
| 2388 | - |
|
| 2389 | - } |
|
| 2390 | - } |
|
| 2391 | - |
|
| 2392 | - /** |
|
| 2393 | - * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 2394 | - * |
|
| 2395 | - * @return string |
|
| 2396 | - */ |
|
| 2397 | - public function widget_advanced_toggle() { |
|
| 2398 | - |
|
| 2399 | - $output = ''; |
|
| 2400 | - if ( $this->block_show_advanced() ) { |
|
| 2401 | - $val = 1; |
|
| 2402 | - } else { |
|
| 2403 | - $val = 0; |
|
| 2404 | - } |
|
| 2405 | - |
|
| 2406 | - $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 2407 | - |
|
| 2408 | - return $output; |
|
| 2409 | - } |
|
| 2410 | - |
|
| 2411 | - /** |
|
| 2412 | - * Convert require element. |
|
| 2413 | - * |
|
| 2414 | - * @since 1.0.0 |
|
| 2415 | - * |
|
| 2416 | - * @param string $input Input element. |
|
| 2417 | - * |
|
| 2418 | - * @return string $output |
|
| 2419 | - */ |
|
| 2420 | - public function convert_element_require( $input ) { |
|
| 2421 | - |
|
| 2422 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2423 | - |
|
| 2424 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2425 | - "jQuery(form).find('[data-argument=\"", |
|
| 2426 | - "\"]').find('input,select').val()" |
|
| 2427 | - ), $input ) ); |
|
| 2428 | - |
|
| 2429 | - return $output; |
|
| 2430 | - } |
|
| 2431 | - |
|
| 2432 | - /** |
|
| 2433 | - * Builds the inputs for the widget options. |
|
| 2434 | - * |
|
| 2435 | - * @param $args |
|
| 2436 | - * @param $instance |
|
| 2437 | - */ |
|
| 2438 | - public function widget_inputs( $args, $instance ) { |
|
| 2439 | - |
|
| 2440 | - $class = ""; |
|
| 2441 | - $element_require = ""; |
|
| 2442 | - $custom_attributes = ""; |
|
| 2443 | - |
|
| 2444 | - // get value |
|
| 2445 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2446 | - $value = $instance[ $args['name'] ]; |
|
| 2447 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2448 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2449 | - } else { |
|
| 2450 | - $value = ''; |
|
| 2451 | - } |
|
| 2452 | - |
|
| 2453 | - // get placeholder |
|
| 2454 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 2455 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2456 | - } else { |
|
| 2457 | - $placeholder = ''; |
|
| 2458 | - } |
|
| 2459 | - |
|
| 2460 | - // get if advanced |
|
| 2461 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2462 | - $class .= " sd-advanced-setting "; |
|
| 2463 | - } |
|
| 2464 | - |
|
| 2465 | - // element_require |
|
| 2466 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2467 | - $element_require = $args['element_require']; |
|
| 2468 | - } |
|
| 2469 | - |
|
| 2470 | - // custom_attributes |
|
| 2471 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2472 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2473 | - } |
|
| 2474 | - |
|
| 2475 | - // before wrapper |
|
| 2476 | - ?> |
|
| 2369 | + $hide = $panel_count ? ' style="display:none;" ' : ''; |
|
| 2370 | + $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
|
| 2371 | + echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle".sanitize_title_with_dashes($key)."'>".esc_attr($key)." <i style='float:right;' class='".$icon_class."'></i></button>"; |
|
| 2372 | + echo "<div class='sd-toggle-group sd-input-group-".sanitize_title_with_dashes($key)."' $hide>"; |
|
| 2373 | + |
|
| 2374 | + foreach($args as $k => $a){ |
|
| 2375 | + $this->widget_inputs($a, $instance); |
|
| 2376 | + } |
|
| 2377 | + |
|
| 2378 | + echo "</div>"; |
|
| 2379 | + |
|
| 2380 | + $panel_count++; |
|
| 2381 | + |
|
| 2382 | + } |
|
| 2383 | + }else{ |
|
| 2384 | + foreach ( $arguments as $key => $args ) { |
|
| 2385 | + $this->widget_inputs( $args, $instance ); |
|
| 2386 | + } |
|
| 2387 | + } |
|
| 2388 | + |
|
| 2389 | + } |
|
| 2390 | + } |
|
| 2391 | + |
|
| 2392 | + /** |
|
| 2393 | + * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 2394 | + * |
|
| 2395 | + * @return string |
|
| 2396 | + */ |
|
| 2397 | + public function widget_advanced_toggle() { |
|
| 2398 | + |
|
| 2399 | + $output = ''; |
|
| 2400 | + if ( $this->block_show_advanced() ) { |
|
| 2401 | + $val = 1; |
|
| 2402 | + } else { |
|
| 2403 | + $val = 0; |
|
| 2404 | + } |
|
| 2405 | + |
|
| 2406 | + $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 2407 | + |
|
| 2408 | + return $output; |
|
| 2409 | + } |
|
| 2410 | + |
|
| 2411 | + /** |
|
| 2412 | + * Convert require element. |
|
| 2413 | + * |
|
| 2414 | + * @since 1.0.0 |
|
| 2415 | + * |
|
| 2416 | + * @param string $input Input element. |
|
| 2417 | + * |
|
| 2418 | + * @return string $output |
|
| 2419 | + */ |
|
| 2420 | + public function convert_element_require( $input ) { |
|
| 2421 | + |
|
| 2422 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2423 | + |
|
| 2424 | + $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2425 | + "jQuery(form).find('[data-argument=\"", |
|
| 2426 | + "\"]').find('input,select').val()" |
|
| 2427 | + ), $input ) ); |
|
| 2428 | + |
|
| 2429 | + return $output; |
|
| 2430 | + } |
|
| 2431 | + |
|
| 2432 | + /** |
|
| 2433 | + * Builds the inputs for the widget options. |
|
| 2434 | + * |
|
| 2435 | + * @param $args |
|
| 2436 | + * @param $instance |
|
| 2437 | + */ |
|
| 2438 | + public function widget_inputs( $args, $instance ) { |
|
| 2439 | + |
|
| 2440 | + $class = ""; |
|
| 2441 | + $element_require = ""; |
|
| 2442 | + $custom_attributes = ""; |
|
| 2443 | + |
|
| 2444 | + // get value |
|
| 2445 | + if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2446 | + $value = $instance[ $args['name'] ]; |
|
| 2447 | + } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2448 | + $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2449 | + } else { |
|
| 2450 | + $value = ''; |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + // get placeholder |
|
| 2454 | + if ( ! empty( $args['placeholder'] ) ) { |
|
| 2455 | + $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2456 | + } else { |
|
| 2457 | + $placeholder = ''; |
|
| 2458 | + } |
|
| 2459 | + |
|
| 2460 | + // get if advanced |
|
| 2461 | + if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2462 | + $class .= " sd-advanced-setting "; |
|
| 2463 | + } |
|
| 2464 | + |
|
| 2465 | + // element_require |
|
| 2466 | + if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2467 | + $element_require = $args['element_require']; |
|
| 2468 | + } |
|
| 2469 | + |
|
| 2470 | + // custom_attributes |
|
| 2471 | + if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2472 | + $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2473 | + } |
|
| 2474 | + |
|
| 2475 | + // before wrapper |
|
| 2476 | + ?> |
|
| 2477 | 2477 | <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
| 2478 | 2478 | data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
| 2479 | 2479 | data-element_require='<?php if ( $element_require ) { |
| 2480 | - echo $this->convert_element_require( $element_require ); |
|
| 2481 | - } ?>' |
|
| 2480 | + echo $this->convert_element_require( $element_require ); |
|
| 2481 | + } ?>' |
|
| 2482 | 2482 | > |
| 2483 | 2483 | <?php |
| 2484 | 2484 | |
| 2485 | - switch ( $args['type'] ) { |
|
| 2486 | - //array('text','password','number','email','tel','url','color') |
|
| 2487 | - case "text": |
|
| 2488 | - case "password": |
|
| 2489 | - case "number": |
|
| 2490 | - case "email": |
|
| 2491 | - case "tel": |
|
| 2492 | - case "url": |
|
| 2493 | - case "color": |
|
| 2494 | - ?> |
|
| 2485 | + switch ( $args['type'] ) { |
|
| 2486 | + //array('text','password','number','email','tel','url','color') |
|
| 2487 | + case "text": |
|
| 2488 | + case "password": |
|
| 2489 | + case "number": |
|
| 2490 | + case "email": |
|
| 2491 | + case "tel": |
|
| 2492 | + case "url": |
|
| 2493 | + case "color": |
|
| 2494 | + ?> |
|
| 2495 | 2495 | <label |
| 2496 | 2496 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
| 2497 | 2497 | <input <?php echo $placeholder; ?> class="widefat" |
@@ -2502,47 +2502,47 @@ discard block |
||
| 2502 | 2502 | value="<?php echo esc_attr( $value ); ?>"> |
| 2503 | 2503 | <?php |
| 2504 | 2504 | |
| 2505 | - break; |
|
| 2506 | - case "select": |
|
| 2507 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2508 | - if ( $multiple ) { |
|
| 2509 | - if ( empty( $value ) ) { |
|
| 2510 | - $value = array(); |
|
| 2511 | - } |
|
| 2512 | - } |
|
| 2513 | - ?> |
|
| 2505 | + break; |
|
| 2506 | + case "select": |
|
| 2507 | + $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2508 | + if ( $multiple ) { |
|
| 2509 | + if ( empty( $value ) ) { |
|
| 2510 | + $value = array(); |
|
| 2511 | + } |
|
| 2512 | + } |
|
| 2513 | + ?> |
|
| 2514 | 2514 | <label |
| 2515 | 2515 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
| 2516 | 2516 | <select <?php echo $placeholder; ?> class="widefat" |
| 2517 | 2517 | <?php echo $custom_attributes; ?> |
| 2518 | 2518 | id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 2519 | 2519 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
| 2520 | - if ( $multiple ) { |
|
| 2521 | - echo "[]"; |
|
| 2522 | - } ?>" |
|
| 2520 | + if ( $multiple ) { |
|
| 2521 | + echo "[]"; |
|
| 2522 | + } ?>" |
|
| 2523 | 2523 | <?php if ( $multiple ) { |
| 2524 | - echo "multiple"; |
|
| 2525 | - } //@todo not implemented yet due to gutenberg not supporting it |
|
| 2526 | - ?> |
|
| 2524 | + echo "multiple"; |
|
| 2525 | + } //@todo not implemented yet due to gutenberg not supporting it |
|
| 2526 | + ?> |
|
| 2527 | 2527 | > |
| 2528 | 2528 | <?php |
| 2529 | 2529 | |
| 2530 | - if ( ! empty( $args['options'] ) ) { |
|
| 2531 | - foreach ( $args['options'] as $val => $label ) { |
|
| 2532 | - if ( $multiple ) { |
|
| 2533 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2534 | - } else { |
|
| 2535 | - $selected = selected( $value, $val, false ); |
|
| 2536 | - } |
|
| 2537 | - echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 2538 | - } |
|
| 2539 | - } |
|
| 2540 | - ?> |
|
| 2530 | + if ( ! empty( $args['options'] ) ) { |
|
| 2531 | + foreach ( $args['options'] as $val => $label ) { |
|
| 2532 | + if ( $multiple ) { |
|
| 2533 | + $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2534 | + } else { |
|
| 2535 | + $selected = selected( $value, $val, false ); |
|
| 2536 | + } |
|
| 2537 | + echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 2538 | + } |
|
| 2539 | + } |
|
| 2540 | + ?> |
|
| 2541 | 2541 | </select> |
| 2542 | 2542 | <?php |
| 2543 | - break; |
|
| 2544 | - case "checkbox": |
|
| 2545 | - ?> |
|
| 2543 | + break; |
|
| 2544 | + case "checkbox": |
|
| 2545 | + ?> |
|
| 2546 | 2546 | <input <?php echo $placeholder; ?> |
| 2547 | 2547 | <?php checked( 1, $value, true ) ?> |
| 2548 | 2548 | <?php echo $custom_attributes; ?> |
@@ -2552,136 +2552,136 @@ discard block |
||
| 2552 | 2552 | <label |
| 2553 | 2553 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
| 2554 | 2554 | <?php |
| 2555 | - break; |
|
| 2556 | - case "hidden": |
|
| 2557 | - ?> |
|
| 2555 | + break; |
|
| 2556 | + case "hidden": |
|
| 2557 | + ?> |
|
| 2558 | 2558 | <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 2559 | 2559 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
| 2560 | 2560 | value="<?php echo esc_attr( $value ); ?>"> |
| 2561 | 2561 | <?php |
| 2562 | - break; |
|
| 2563 | - default: |
|
| 2564 | - echo "No input type found!"; // @todo we need to add more input types. |
|
| 2565 | - } |
|
| 2562 | + break; |
|
| 2563 | + default: |
|
| 2564 | + echo "No input type found!"; // @todo we need to add more input types. |
|
| 2565 | + } |
|
| 2566 | 2566 | |
| 2567 | - // after wrapper |
|
| 2568 | - ?> |
|
| 2567 | + // after wrapper |
|
| 2568 | + ?> |
|
| 2569 | 2569 | </p> |
| 2570 | 2570 | <?php |
| 2571 | 2571 | |
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - /** |
|
| 2575 | - * Get the widget input description html. |
|
| 2576 | - * |
|
| 2577 | - * @param $args |
|
| 2578 | - * |
|
| 2579 | - * @return string |
|
| 2580 | - * @todo, need to make its own tooltip script |
|
| 2581 | - */ |
|
| 2582 | - public function widget_field_desc( $args ) { |
|
| 2583 | - |
|
| 2584 | - $description = ''; |
|
| 2585 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2586 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2587 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 2588 | - } else { |
|
| 2589 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2590 | - } |
|
| 2591 | - } |
|
| 2592 | - |
|
| 2593 | - return $description; |
|
| 2594 | - } |
|
| 2595 | - |
|
| 2596 | - /** |
|
| 2597 | - * Get the tool tip html. |
|
| 2598 | - * |
|
| 2599 | - * @param $tip |
|
| 2600 | - * @param bool $allow_html |
|
| 2601 | - * |
|
| 2602 | - * @return string |
|
| 2603 | - */ |
|
| 2604 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 2605 | - if ( $allow_html ) { |
|
| 2606 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 2607 | - } else { |
|
| 2608 | - $tip = esc_attr( $tip ); |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 2612 | - } |
|
| 2613 | - |
|
| 2614 | - /** |
|
| 2615 | - * Sanitize a string destined to be a tooltip. |
|
| 2616 | - * |
|
| 2617 | - * @param string $var |
|
| 2618 | - * |
|
| 2619 | - * @return string |
|
| 2620 | - */ |
|
| 2621 | - public function sanitize_tooltip( $var ) { |
|
| 2622 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2623 | - 'br' => array(), |
|
| 2624 | - 'em' => array(), |
|
| 2625 | - 'strong' => array(), |
|
| 2626 | - 'small' => array(), |
|
| 2627 | - 'span' => array(), |
|
| 2628 | - 'ul' => array(), |
|
| 2629 | - 'li' => array(), |
|
| 2630 | - 'ol' => array(), |
|
| 2631 | - 'p' => array(), |
|
| 2632 | - ) ) ); |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - /** |
|
| 2636 | - * Processing widget options on save |
|
| 2637 | - * |
|
| 2638 | - * @param array $new_instance The new options |
|
| 2639 | - * @param array $old_instance The previous options |
|
| 2640 | - * |
|
| 2641 | - * @return array |
|
| 2642 | - * @todo we should add some sanitation here. |
|
| 2643 | - */ |
|
| 2644 | - public function update( $new_instance, $old_instance ) { |
|
| 2645 | - |
|
| 2646 | - //save the widget |
|
| 2647 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2648 | - |
|
| 2649 | - // set widget instance |
|
| 2650 | - $this->instance = $instance; |
|
| 2651 | - |
|
| 2652 | - if ( empty( $this->arguments ) ) { |
|
| 2653 | - $this->get_arguments(); |
|
| 2654 | - } |
|
| 2655 | - |
|
| 2656 | - // check for checkboxes |
|
| 2657 | - if ( ! empty( $this->arguments ) ) { |
|
| 2658 | - foreach ( $this->arguments as $argument ) { |
|
| 2659 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2660 | - $instance[ $argument['name'] ] = '0'; |
|
| 2661 | - } |
|
| 2662 | - } |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - return $instance; |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - /** |
|
| 2669 | - * Checks if the current call is a ajax call to get the block content. |
|
| 2670 | - * |
|
| 2671 | - * This can be used in your widget to return different content as the block content. |
|
| 2672 | - * |
|
| 2673 | - * @since 1.0.3 |
|
| 2674 | - * @return bool |
|
| 2675 | - */ |
|
| 2676 | - public function is_block_content_call() { |
|
| 2677 | - $result = false; |
|
| 2678 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2679 | - $result = true; |
|
| 2680 | - } |
|
| 2681 | - |
|
| 2682 | - return $result; |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - } |
|
| 2572 | + } |
|
| 2573 | + |
|
| 2574 | + /** |
|
| 2575 | + * Get the widget input description html. |
|
| 2576 | + * |
|
| 2577 | + * @param $args |
|
| 2578 | + * |
|
| 2579 | + * @return string |
|
| 2580 | + * @todo, need to make its own tooltip script |
|
| 2581 | + */ |
|
| 2582 | + public function widget_field_desc( $args ) { |
|
| 2583 | + |
|
| 2584 | + $description = ''; |
|
| 2585 | + if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2586 | + if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2587 | + $description = $this->desc_tip( $args['desc'] ); |
|
| 2588 | + } else { |
|
| 2589 | + $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2590 | + } |
|
| 2591 | + } |
|
| 2592 | + |
|
| 2593 | + return $description; |
|
| 2594 | + } |
|
| 2595 | + |
|
| 2596 | + /** |
|
| 2597 | + * Get the tool tip html. |
|
| 2598 | + * |
|
| 2599 | + * @param $tip |
|
| 2600 | + * @param bool $allow_html |
|
| 2601 | + * |
|
| 2602 | + * @return string |
|
| 2603 | + */ |
|
| 2604 | + function desc_tip( $tip, $allow_html = false ) { |
|
| 2605 | + if ( $allow_html ) { |
|
| 2606 | + $tip = $this->sanitize_tooltip( $tip ); |
|
| 2607 | + } else { |
|
| 2608 | + $tip = esc_attr( $tip ); |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 2612 | + } |
|
| 2613 | + |
|
| 2614 | + /** |
|
| 2615 | + * Sanitize a string destined to be a tooltip. |
|
| 2616 | + * |
|
| 2617 | + * @param string $var |
|
| 2618 | + * |
|
| 2619 | + * @return string |
|
| 2620 | + */ |
|
| 2621 | + public function sanitize_tooltip( $var ) { |
|
| 2622 | + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2623 | + 'br' => array(), |
|
| 2624 | + 'em' => array(), |
|
| 2625 | + 'strong' => array(), |
|
| 2626 | + 'small' => array(), |
|
| 2627 | + 'span' => array(), |
|
| 2628 | + 'ul' => array(), |
|
| 2629 | + 'li' => array(), |
|
| 2630 | + 'ol' => array(), |
|
| 2631 | + 'p' => array(), |
|
| 2632 | + ) ) ); |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + /** |
|
| 2636 | + * Processing widget options on save |
|
| 2637 | + * |
|
| 2638 | + * @param array $new_instance The new options |
|
| 2639 | + * @param array $old_instance The previous options |
|
| 2640 | + * |
|
| 2641 | + * @return array |
|
| 2642 | + * @todo we should add some sanitation here. |
|
| 2643 | + */ |
|
| 2644 | + public function update( $new_instance, $old_instance ) { |
|
| 2645 | + |
|
| 2646 | + //save the widget |
|
| 2647 | + $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2648 | + |
|
| 2649 | + // set widget instance |
|
| 2650 | + $this->instance = $instance; |
|
| 2651 | + |
|
| 2652 | + if ( empty( $this->arguments ) ) { |
|
| 2653 | + $this->get_arguments(); |
|
| 2654 | + } |
|
| 2655 | + |
|
| 2656 | + // check for checkboxes |
|
| 2657 | + if ( ! empty( $this->arguments ) ) { |
|
| 2658 | + foreach ( $this->arguments as $argument ) { |
|
| 2659 | + if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2660 | + $instance[ $argument['name'] ] = '0'; |
|
| 2661 | + } |
|
| 2662 | + } |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + return $instance; |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + /** |
|
| 2669 | + * Checks if the current call is a ajax call to get the block content. |
|
| 2670 | + * |
|
| 2671 | + * This can be used in your widget to return different content as the block content. |
|
| 2672 | + * |
|
| 2673 | + * @since 1.0.3 |
|
| 2674 | + * @return bool |
|
| 2675 | + */ |
|
| 2676 | + public function is_block_content_call() { |
|
| 2677 | + $result = false; |
|
| 2678 | + if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2679 | + $result = true; |
|
| 2680 | + } |
|
| 2681 | + |
|
| 2682 | + return $result; |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + } |
|
| 2686 | 2686 | |
| 2687 | 2687 | } |
| 2688 | 2688 | \ No newline at end of file |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | -if ( ! class_exists( 'WP_Super_Duper' ) ) { |
|
| 6 | +if (!class_exists('WP_Super_Duper')) { |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | /** |
@@ -54,27 +54,27 @@ discard block |
||
| 54 | 54 | /** |
| 55 | 55 | * Take the array options and use them to build. |
| 56 | 56 | */ |
| 57 | - public function __construct( $options ) { |
|
| 57 | + public function __construct($options) { |
|
| 58 | 58 | global $sd_widgets; |
| 59 | 59 | |
| 60 | - $sd_widgets[ $options['base_id'] ] = array( |
|
| 60 | + $sd_widgets[$options['base_id']] = array( |
|
| 61 | 61 | 'name' => $options['name'], |
| 62 | 62 | 'class_name' => $options['class_name'] |
| 63 | 63 | ); |
| 64 | - $this->base_id = $options['base_id']; |
|
| 64 | + $this->base_id = $options['base_id']; |
|
| 65 | 65 | // lets filter the options before we do anything |
| 66 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 67 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 68 | - $options = $this->add_name_from_key( $options ); |
|
| 66 | + $options = apply_filters("wp_super_duper_options", $options); |
|
| 67 | + $options = apply_filters("wp_super_duper_options_{$this->base_id}", $options); |
|
| 68 | + $options = $this->add_name_from_key($options); |
|
| 69 | 69 | $this->options = $options; |
| 70 | 70 | |
| 71 | 71 | $this->base_id = $options['base_id']; |
| 72 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 72 | + $this->arguments = isset($options['arguments']) ? $options['arguments'] : array(); |
|
| 73 | 73 | |
| 74 | 74 | // init parent |
| 75 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 75 | + parent::__construct($options['base_id'], $options['name'], $options['widget_ops']); |
|
| 76 | 76 | |
| 77 | - if ( isset( $options['class_name'] ) ) { |
|
| 77 | + if (isset($options['class_name'])) { |
|
| 78 | 78 | // register widget |
| 79 | 79 | $this->class_name = $options['class_name']; |
| 80 | 80 | |
@@ -82,54 +82,54 @@ discard block |
||
| 82 | 82 | $this->register_shortcode(); |
| 83 | 83 | |
| 84 | 84 | // Fusion Builder (avada) support |
| 85 | - if( function_exists('fusion_builder_map') ){ $this->register_fusion_element(); } |
|
| 85 | + if (function_exists('fusion_builder_map')) { $this->register_fusion_element(); } |
|
| 86 | 86 | |
| 87 | 87 | // register block |
| 88 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 88 | + add_action('admin_enqueue_scripts', array($this, 'register_block')); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // add the CSS and JS we need ONCE |
| 92 | 92 | global $sd_widget_scripts; |
| 93 | 93 | |
| 94 | - if ( ! $sd_widget_scripts ) { |
|
| 95 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 96 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 97 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 94 | + if (!$sd_widget_scripts) { |
|
| 95 | + wp_add_inline_script('admin-widgets', $this->widget_js()); |
|
| 96 | + wp_add_inline_script('customize-controls', $this->widget_js()); |
|
| 97 | + wp_add_inline_style('widgets', $this->widget_css()); |
|
| 98 | 98 | |
| 99 | 99 | $sd_widget_scripts = true; |
| 100 | 100 | |
| 101 | 101 | // add shortcode insert button once |
| 102 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 102 | + add_action('media_buttons', array($this, 'shortcode_insert_button')); |
|
| 103 | 103 | // generatepress theme sections compatibility |
| 104 | - if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
| 105 | - add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 104 | + if (function_exists('generate_sections_sections_metabox')) { |
|
| 105 | + add_action('generate_sections_metabox', array($this, 'shortcode_insert_button_script')); |
|
| 106 | 106 | } |
| 107 | - if ( $this->is_preview() ) { |
|
| 108 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 107 | + if ($this->is_preview()) { |
|
| 108 | + add_action('wp_footer', array($this, 'shortcode_insert_button_script')); |
|
| 109 | 109 | // this makes the insert button work for elementor |
| 110 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 110 | + add_action('elementor/editor/after_enqueue_scripts', array( |
|
| 111 | 111 | $this, |
| 112 | 112 | 'shortcode_insert_button_script' |
| 113 | - ) ); // for elementor |
|
| 113 | + )); // for elementor |
|
| 114 | 114 | } |
| 115 | 115 | // this makes the insert button work for cornerstone |
| 116 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
| 116 | + add_action('wp_print_footer_scripts', array(__CLASS__, 'maybe_cornerstone_builder')); |
|
| 117 | 117 | |
| 118 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 119 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 118 | + add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings')); |
|
| 119 | + add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker')); |
|
| 120 | 120 | |
| 121 | 121 | // add generator text to admin head |
| 122 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 122 | + add_action('admin_head', array($this, 'generator')); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 125 | + do_action('wp_super_duper_widget_init', $options, $this); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public function register_fusion_element(){ |
|
| 128 | + public function register_fusion_element() { |
|
| 129 | 129 | |
| 130 | 130 | $options = $this->options; |
| 131 | 131 | |
| 132 | - if($this->base_id){ |
|
| 132 | + if ($this->base_id) { |
|
| 133 | 133 | |
| 134 | 134 | $params = $this->get_fusion_params(); |
| 135 | 135 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | 'allow_generator' => true, |
| 141 | 141 | ); |
| 142 | 142 | |
| 143 | - if(!empty($params)){ |
|
| 143 | + if (!empty($params)) { |
|
| 144 | 144 | $args['params'] = $params; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - public function get_fusion_params(){ |
|
| 152 | + public function get_fusion_params() { |
|
| 153 | 153 | $params = array(); |
| 154 | 154 | $arguments = $this->get_arguments(); |
| 155 | 155 | |
| 156 | - if(!empty($arguments)){ |
|
| 157 | - foreach($arguments as $key => $val){ |
|
| 156 | + if (!empty($arguments)) { |
|
| 157 | + foreach ($arguments as $key => $val) { |
|
| 158 | 158 | $param = array(); |
| 159 | 159 | // type |
| 160 | 160 | $param['type'] = str_replace( |
@@ -188,19 +188,19 @@ discard block |
||
| 188 | 188 | $param['default'] = isset($val['default']) ? $val['default'] : ''; |
| 189 | 189 | |
| 190 | 190 | // Group |
| 191 | - if(isset($val['group'])){ |
|
| 191 | + if (isset($val['group'])) { |
|
| 192 | 192 | $param['group'] = $val['group']; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // value |
| 196 | - if($val['type'] == 'checkbox'){ |
|
| 197 | - if(isset($val['default']) && $val['default'] == '0'){ |
|
| 196 | + if ($val['type'] == 'checkbox') { |
|
| 197 | + if (isset($val['default']) && $val['default'] == '0') { |
|
| 198 | 198 | unset($param['default']); |
| 199 | 199 | } |
| 200 | - $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
|
| 201 | - }elseif($param['type'] == 'select'){ |
|
| 200 | + $param['value'] = array(''=>__("No"), '1'=>__("Yes")); |
|
| 201 | + }elseif ($param['type'] == 'select') { |
|
| 202 | 202 | $param['value'] = isset($val['options']) ? $val['options'] : array(); |
| 203 | - }else{ |
|
| 203 | + } else { |
|
| 204 | 204 | $param['value'] = isset($val['default']) ? $val['default'] : ''; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | /** |
| 218 | 218 | * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
| 219 | 219 | */ |
| 220 | - public static function maybe_cornerstone_builder(){ |
|
| 221 | - if(did_action('cornerstone_before_boot_app')){ |
|
| 220 | + public static function maybe_cornerstone_builder() { |
|
| 221 | + if (did_action('cornerstone_before_boot_app')) { |
|
| 222 | 222 | self::shortcode_insert_button_script(); |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | - public static function get_picker( $editor_id = '' ) { |
|
| 233 | + public static function get_picker($editor_id = '') { |
|
| 234 | 234 | |
| 235 | 235 | ob_start(); |
| 236 | - if ( isset( $_POST['editor_id'] ) ) { |
|
| 237 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 238 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 236 | + if (isset($_POST['editor_id'])) { |
|
| 237 | + $editor_id = esc_attr($_POST['editor_id']); |
|
| 238 | + } elseif (isset($_REQUEST['et_fb'])) { |
|
| 239 | 239 | $editor_id = 'main_content_content_vb_tiny_mce'; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | <div class="sd-shortcode-left-wrap"> |
| 246 | 246 | <?php |
| 247 | - ksort( $sd_widgets ); |
|
| 247 | + ksort($sd_widgets); |
|
| 248 | 248 | // print_r($sd_widgets);exit; |
| 249 | - if ( ! empty( $sd_widgets ) ) { |
|
| 249 | + if (!empty($sd_widgets)) { |
|
| 250 | 250 | echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
| 251 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 252 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 253 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 251 | + echo "<option>" . __('Select shortcode') . "</option>"; |
|
| 252 | + foreach ($sd_widgets as $shortcode => $class) { |
|
| 253 | + echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>"; |
|
| 254 | 254 | } |
| 255 | 255 | echo "</select>"; |
| 256 | 256 | |
@@ -263,37 +263,37 @@ discard block |
||
| 263 | 263 | <div class="sd-shortcode-right-wrap"> |
| 264 | 264 | <textarea id='sd-shortcode-output' disabled></textarea> |
| 265 | 265 | <div id='sd-shortcode-output-actions'> |
| 266 | - <?php if ( $editor_id != '' ) { ?> |
|
| 266 | + <?php if ($editor_id != '') { ?> |
|
| 267 | 267 | <button class="button sd-insert-shortcode-button" |
| 268 | - onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
|
| 268 | + onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) { |
|
| 269 | 269 | echo "'" . $editor_id . "'"; |
| 270 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 270 | + } ?>)"><?php _e('Insert shortcode'); ?></button> |
|
| 271 | 271 | <?php } ?> |
| 272 | 272 | <button class="button" |
| 273 | - onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
|
| 273 | + onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button> |
|
| 274 | 274 | </div> |
| 275 | 275 | </div> |
| 276 | 276 | <?php |
| 277 | 277 | |
| 278 | 278 | $html = ob_get_clean(); |
| 279 | 279 | |
| 280 | - if ( wp_doing_ajax() ) { |
|
| 280 | + if (wp_doing_ajax()) { |
|
| 281 | 281 | echo $html; |
| 282 | 282 | $should_die = true; |
| 283 | 283 | |
| 284 | 284 | // some builder get the editor via ajax so we should not die on those ocasions |
| 285 | 285 | $dont_die = array( |
| 286 | - 'parent_tag',// WP Bakery |
|
| 286 | + 'parent_tag', // WP Bakery |
|
| 287 | 287 | 'avia_request' // enfold |
| 288 | 288 | ); |
| 289 | 289 | |
| 290 | - foreach ( $dont_die as $request ) { |
|
| 291 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 290 | + foreach ($dont_die as $request) { |
|
| 291 | + if (isset($_REQUEST[$request])) { |
|
| 292 | 292 | $should_die = false; |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( $should_die ) { |
|
| 296 | + if ($should_die) { |
|
| 297 | 297 | wp_die(); |
| 298 | 298 | } |
| 299 | 299 | |
@@ -320,16 +320,16 @@ discard block |
||
| 320 | 320 | public static function get_widget_settings() { |
| 321 | 321 | global $sd_widgets; |
| 322 | 322 | |
| 323 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 324 | - if ( ! $shortcode ) { |
|
| 323 | + $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : ''; |
|
| 324 | + if (!$shortcode) { |
|
| 325 | 325 | wp_die(); |
| 326 | 326 | } |
| 327 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 328 | - if ( ! $widget_args ) { |
|
| 327 | + $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : ''; |
|
| 328 | + if (!$widget_args) { |
|
| 329 | 329 | wp_die(); |
| 330 | 330 | } |
| 331 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 332 | - if ( ! $class_name ) { |
|
| 331 | + $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 332 | + if (!$class_name) { |
|
| 333 | 333 | wp_die(); |
| 334 | 334 | } |
| 335 | 335 | |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | $widget = new $class_name; |
| 338 | 338 | |
| 339 | 339 | ob_start(); |
| 340 | - $widget->form( array() ); |
|
| 340 | + $widget->form(array()); |
|
| 341 | 341 | $form = ob_get_clean(); |
| 342 | 342 | echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
| 343 | 343 | echo "<style>" . $widget->widget_css() . "</style>"; |
@@ -355,9 +355,9 @@ discard block |
||
| 355 | 355 | * @param string $editor_id Optional. Shortcode editor id. Default null. |
| 356 | 356 | * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
| 357 | 357 | */ |
| 358 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 358 | + public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') { |
|
| 359 | 359 | global $sd_widgets, $shortcode_insert_button_once; |
| 360 | - if ( $shortcode_insert_button_once ) { |
|
| 360 | + if ($shortcode_insert_button_once) { |
|
| 361 | 361 | return; |
| 362 | 362 | } |
| 363 | 363 | add_thickbox(); |
@@ -367,21 +367,21 @@ discard block |
||
| 367 | 367 | * Cornerstone makes us play dirty tricks :/ |
| 368 | 368 | * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
| 369 | 369 | */ |
| 370 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 370 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 371 | 371 | echo '<span id="insert-media-button">'; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - echo self::shortcode_button( 'this', 'true' ); |
|
| 374 | + echo self::shortcode_button('this', 'true'); |
|
| 375 | 375 | |
| 376 | 376 | // see opening note |
| 377 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 377 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 378 | 378 | echo '</span>'; // end #insert-media-button |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | // Add separate script for generatepress theme sections |
| 382 | - if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
| 382 | + if (function_exists('generate_sections_sections_metabox') && did_action('generate_sections_metabox')) { |
|
| 383 | 383 | } else { |
| 384 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 384 | + self::shortcode_insert_button_script($editor_id, $insert_shortcode_function); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | $shortcode_insert_button_once = true; |
@@ -395,12 +395,12 @@ discard block |
||
| 395 | 395 | * |
| 396 | 396 | * @return mixed |
| 397 | 397 | */ |
| 398 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 398 | + public static function shortcode_button($id = '', $search_for_id = '') { |
|
| 399 | 399 | ob_start(); |
| 400 | 400 | ?> |
| 401 | 401 | <span class="sd-lable-shortcode-inserter"> |
| 402 | 402 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
| 403 | - if ( $search_for_id ) { |
|
| 403 | + if ($search_for_id) { |
|
| 404 | 404 | echo "," . $search_for_id; |
| 405 | 405 | } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
| 406 | 406 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | $html = ob_get_clean(); |
| 417 | 417 | |
| 418 | 418 | // remove line breaks so we can use it in js |
| 419 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 419 | + return preg_replace("/\r|\n/", "", trim($html)); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | jQuery($this).data('sd-widget-enabled', true); |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 477 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 478 | 478 | var form = jQuery($this).parents('' + $selector + ''); |
| 479 | 479 | |
| 480 | 480 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 512 | 512 | */ |
| 513 | 513 | |
| 514 | - return str_replace( array( |
|
| 514 | + return str_replace(array( |
|
| 515 | 515 | '<script>', |
| 516 | 516 | '</script>' |
| 517 | - ), '', $output ); |
|
| 517 | + ), '', $output); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @param string $editor_id |
| 526 | 526 | * @param string $insert_shortcode_function |
| 527 | 527 | */ |
| 528 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 528 | + public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') { |
|
| 529 | 529 | ?> |
| 530 | 530 | <style> |
| 531 | 531 | .sd-shortcode-left-wrap { |
@@ -643,22 +643,22 @@ discard block |
||
| 643 | 643 | height: 250px; |
| 644 | 644 | width: 100%; |
| 645 | 645 | } |
| 646 | - <?php if ( function_exists( 'generate_sections_sections_metabox' ) ) { ?> |
|
| 646 | + <?php if (function_exists('generate_sections_sections_metabox')) { ?> |
|
| 647 | 647 | .generate-sections-modal #custom-media-buttons > .sd-lable-shortcode-inserter { |
| 648 | 648 | display: inline; |
| 649 | 649 | } |
| 650 | 650 | <?php } ?> |
| 651 | 651 | </style> |
| 652 | 652 | <?php |
| 653 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 653 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 654 | 654 | echo "<script>" . self::siteorigin_js() . "</script>"; |
| 655 | 655 | } |
| 656 | 656 | ?> |
| 657 | 657 | <script> |
| 658 | 658 | <?php |
| 659 | - if(! empty( $insert_shortcode_function )){ |
|
| 659 | + if (!empty($insert_shortcode_function)) { |
|
| 660 | 660 | echo $insert_shortcode_function; |
| 661 | - }else{ |
|
| 661 | + } else { |
|
| 662 | 662 | |
| 663 | 663 | /** |
| 664 | 664 | * Function for super duper insert shortcode. |
@@ -671,9 +671,9 @@ discard block |
||
| 671 | 671 | if ($shortcode) { |
| 672 | 672 | if (!$editor_id) { |
| 673 | 673 | <?php |
| 674 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 674 | + if (isset($_REQUEST['et_fb'])) { |
|
| 675 | 675 | echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
| 676 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 676 | + } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') { |
|
| 677 | 677 | echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
| 678 | 678 | } else { |
| 679 | 679 | echo '$editor_id = "#wp-content-editor-container textarea";'; |
@@ -758,11 +758,11 @@ discard block |
||
| 758 | 758 | 'shortcode': $short_code, |
| 759 | 759 | 'attributes': 123, |
| 760 | 760 | 'post_id': 321, |
| 761 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 761 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 762 | 762 | }; |
| 763 | 763 | |
| 764 | 764 | if (typeof ajaxurl === 'undefined') { |
| 765 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>"; |
|
| 765 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | jQuery.post(ajaxurl, data, function (response) { |
@@ -960,11 +960,11 @@ discard block |
||
| 960 | 960 | var data = { |
| 961 | 961 | 'action': 'super_duper_get_picker', |
| 962 | 962 | 'editor_id': $id, |
| 963 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>' |
|
| 963 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>' |
|
| 964 | 964 | }; |
| 965 | 965 | |
| 966 | 966 | if (!ajaxurl) { |
| 967 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; |
|
| 967 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | jQuery.post(ajaxurl, data, function (response) { |
@@ -985,9 +985,9 @@ discard block |
||
| 985 | 985 | */ |
| 986 | 986 | function sd_shortcode_button($id) { |
| 987 | 987 | if ($id) { |
| 988 | - return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>'; |
|
| 988 | + return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>'; |
|
| 989 | 989 | } else { |
| 990 | - return '<?php echo self::shortcode_button();?>'; |
|
| 990 | + return '<?php echo self::shortcode_button(); ?>'; |
|
| 991 | 991 | } |
| 992 | 992 | } |
| 993 | 993 | |
@@ -1043,10 +1043,10 @@ discard block |
||
| 1043 | 1043 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1044 | 1044 | */ |
| 1045 | 1045 | |
| 1046 | - return str_replace( array( |
|
| 1046 | + return str_replace(array( |
|
| 1047 | 1047 | '<style>', |
| 1048 | 1048 | '</style>' |
| 1049 | - ), '', $output ); |
|
| 1049 | + ), '', $output); |
|
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | /** |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | jQuery($this).data('sd-widget-enabled', true); |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
| 1119 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
| 1120 | 1120 | var form = jQuery($this).parents('' + $selector + ''); |
| 1121 | 1121 | |
| 1122 | 1122 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -1208,7 +1208,7 @@ discard block |
||
| 1208 | 1208 | }); |
| 1209 | 1209 | |
| 1210 | 1210 | } |
| 1211 | - <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 1211 | + <?php do_action('wp_super_duper_widget_js', $this); ?> |
|
| 1212 | 1212 | </script> |
| 1213 | 1213 | <?php |
| 1214 | 1214 | $output = ob_get_clean(); |
@@ -1217,10 +1217,10 @@ discard block |
||
| 1217 | 1217 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1218 | 1218 | */ |
| 1219 | 1219 | |
| 1220 | - return str_replace( array( |
|
| 1220 | + return str_replace(array( |
|
| 1221 | 1221 | '<script>', |
| 1222 | 1222 | '</script>' |
| 1223 | - ), '', $output ); |
|
| 1223 | + ), '', $output); |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | |
@@ -1231,14 +1231,14 @@ discard block |
||
| 1231 | 1231 | * |
| 1232 | 1232 | * @return mixed |
| 1233 | 1233 | */ |
| 1234 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 1235 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 1236 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 1237 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 1234 | + private function add_name_from_key($options, $arguments = false) { |
|
| 1235 | + if (!empty($options['arguments'])) { |
|
| 1236 | + foreach ($options['arguments'] as $key => $val) { |
|
| 1237 | + $options['arguments'][$key]['name'] = $key; |
|
| 1238 | 1238 | } |
| 1239 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1240 | - foreach ( $options as $key => $val ) { |
|
| 1241 | - $options[ $key ]['name'] = $key; |
|
| 1239 | + } elseif ($arguments && is_array($options) && !empty($options)) { |
|
| 1240 | + foreach ($options as $key => $val) { |
|
| 1241 | + $options[$key]['name'] = $key; |
|
| 1242 | 1242 | } |
| 1243 | 1243 | } |
| 1244 | 1244 | |
@@ -1251,8 +1251,8 @@ discard block |
||
| 1251 | 1251 | * @since 1.0.0 |
| 1252 | 1252 | */ |
| 1253 | 1253 | public function register_shortcode() { |
| 1254 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1255 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1254 | + add_shortcode($this->base_id, array($this, 'shortcode_output')); |
|
| 1255 | + add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode')); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | /** |
@@ -1262,33 +1262,33 @@ discard block |
||
| 1262 | 1262 | */ |
| 1263 | 1263 | public static function render_shortcode() { |
| 1264 | 1264 | |
| 1265 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1266 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1265 | + check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true); |
|
| 1266 | + if (!current_user_can('manage_options')) { |
|
| 1267 | 1267 | wp_die(); |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | // we might need the $post value here so lets set it. |
| 1271 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1272 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1273 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1271 | + if (isset($_POST['post_id']) && $_POST['post_id']) { |
|
| 1272 | + $post_obj = get_post(absint($_POST['post_id'])); |
|
| 1273 | + if (!empty($post_obj) && empty($post)) { |
|
| 1274 | 1274 | global $post; |
| 1275 | 1275 | $post = $post_obj; |
| 1276 | 1276 | } |
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1280 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1281 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1279 | + if (isset($_POST['shortcode']) && $_POST['shortcode']) { |
|
| 1280 | + $shortcode_name = sanitize_title_with_dashes($_POST['shortcode']); |
|
| 1281 | + $attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1282 | 1282 | $attributes = ''; |
| 1283 | - if ( ! empty( $attributes_array ) ) { |
|
| 1284 | - foreach ( $attributes_array as $key => $value ) { |
|
| 1285 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1283 | + if (!empty($attributes_array)) { |
|
| 1284 | + foreach ($attributes_array as $key => $value) { |
|
| 1285 | + $attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' "; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
| 1290 | 1290 | |
| 1291 | - echo do_shortcode( $shortcode ); |
|
| 1291 | + echo do_shortcode($shortcode); |
|
| 1292 | 1292 | |
| 1293 | 1293 | } |
| 1294 | 1294 | wp_die(); |
@@ -1302,37 +1302,37 @@ discard block |
||
| 1302 | 1302 | * |
| 1303 | 1303 | * @return string |
| 1304 | 1304 | */ |
| 1305 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1306 | - $args = self::argument_values( $args ); |
|
| 1305 | + public function shortcode_output($args = array(), $content = '') { |
|
| 1306 | + $args = self::argument_values($args); |
|
| 1307 | 1307 | |
| 1308 | 1308 | // add extra argument so we know its a output to gutenberg |
| 1309 | 1309 | //$args |
| 1310 | - $args = $this->string_to_bool( $args ); |
|
| 1310 | + $args = $this->string_to_bool($args); |
|
| 1311 | 1311 | |
| 1312 | 1312 | |
| 1313 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1313 | + $calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : ''; |
|
| 1314 | 1314 | |
| 1315 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 1316 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 1315 | + $calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this); |
|
| 1316 | + $calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this); |
|
| 1317 | 1317 | |
| 1318 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1319 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 1318 | + $attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this); |
|
| 1319 | + $attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this); |
|
| 1320 | 1320 | |
| 1321 | 1321 | $shortcode_args = array(); |
| 1322 | 1322 | $output = ''; |
| 1323 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1324 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1325 | - if ( $main_content && ! $no_wrap ) { |
|
| 1323 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
| 1324 | + $main_content = $this->output($args, $shortcode_args, $content); |
|
| 1325 | + if ($main_content && !$no_wrap) { |
|
| 1326 | 1326 | // wrap the shortcode in a dive with the same class as the widget |
| 1327 | 1327 | $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
| 1328 | - if ( ! empty( $args['title'] ) ) { |
|
| 1328 | + if (!empty($args['title'])) { |
|
| 1329 | 1329 | // if its a shortcode and there is a title try to grab the title wrappers |
| 1330 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1331 | - if ( empty( $instance ) ) { |
|
| 1330 | + $shortcode_args = array('before_title' => '', 'after_title' => ''); |
|
| 1331 | + if (empty($instance)) { |
|
| 1332 | 1332 | global $wp_registered_sidebars; |
| 1333 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1334 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1335 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1333 | + if (!empty($wp_registered_sidebars)) { |
|
| 1334 | + foreach ($wp_registered_sidebars as $sidebar) { |
|
| 1335 | + if (!empty($sidebar['before_title'])) { |
|
| 1336 | 1336 | $shortcode_args['before_title'] = $sidebar['before_title']; |
| 1337 | 1337 | $shortcode_args['after_title'] = $sidebar['after_title']; |
| 1338 | 1338 | break; |
@@ -1340,20 +1340,20 @@ discard block |
||
| 1340 | 1340 | } |
| 1341 | 1341 | } |
| 1342 | 1342 | } |
| 1343 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1343 | + $output .= $this->output_title($shortcode_args, $args); |
|
| 1344 | 1344 | } |
| 1345 | 1345 | $output .= $main_content; |
| 1346 | 1346 | $output .= '</div>'; |
| 1347 | - } elseif ( $main_content && $no_wrap ) { |
|
| 1347 | + } elseif ($main_content && $no_wrap) { |
|
| 1348 | 1348 | $output .= $main_content; |
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | // if preview show a placeholder if empty |
| 1352 | - if ( $this->is_preview() && $output == '' ) { |
|
| 1353 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
| 1352 | + if ($this->is_preview() && $output == '') { |
|
| 1353 | + $output = $this->preview_placeholder_text("[{" . $this->base_id . "}]"); |
|
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | - return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
| 1356 | + return apply_filters('wp_super_duper_widget_output', $output, $args, $shortcode_args, $this); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | /** |
@@ -1363,8 +1363,8 @@ discard block |
||
| 1363 | 1363 | * |
| 1364 | 1364 | * @return string |
| 1365 | 1365 | */ |
| 1366 | - public function preview_placeholder_text( $name = '' ) { |
|
| 1367 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1366 | + public function preview_placeholder_text($name = '') { |
|
| 1367 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>"; |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | /** |
@@ -1374,13 +1374,13 @@ discard block |
||
| 1374 | 1374 | * |
| 1375 | 1375 | * @return mixed |
| 1376 | 1376 | */ |
| 1377 | - public function string_to_bool( $options ) { |
|
| 1377 | + public function string_to_bool($options) { |
|
| 1378 | 1378 | // convert bool strings to booleans |
| 1379 | - foreach ( $options as $key => $val ) { |
|
| 1380 | - if ( $val == 'false' ) { |
|
| 1381 | - $options[ $key ] = false; |
|
| 1382 | - } elseif ( $val == 'true' ) { |
|
| 1383 | - $options[ $key ] = true; |
|
| 1379 | + foreach ($options as $key => $val) { |
|
| 1380 | + if ($val == 'false') { |
|
| 1381 | + $options[$key] = false; |
|
| 1382 | + } elseif ($val == 'true') { |
|
| 1383 | + $options[$key] = true; |
|
| 1384 | 1384 | } |
| 1385 | 1385 | } |
| 1386 | 1386 | |
@@ -1396,27 +1396,27 @@ discard block |
||
| 1396 | 1396 | * |
| 1397 | 1397 | * @return array |
| 1398 | 1398 | */ |
| 1399 | - public function argument_values( $instance ) { |
|
| 1399 | + public function argument_values($instance) { |
|
| 1400 | 1400 | $argument_values = array(); |
| 1401 | 1401 | |
| 1402 | 1402 | // set widget instance |
| 1403 | 1403 | $this->instance = $instance; |
| 1404 | 1404 | |
| 1405 | - if ( empty( $this->arguments ) ) { |
|
| 1405 | + if (empty($this->arguments)) { |
|
| 1406 | 1406 | $this->arguments = $this->get_arguments(); |
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | - if ( ! empty( $this->arguments ) ) { |
|
| 1410 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1409 | + if (!empty($this->arguments)) { |
|
| 1410 | + foreach ($this->arguments as $key => $args) { |
|
| 1411 | 1411 | // set the input name from the key |
| 1412 | 1412 | $args['name'] = $key; |
| 1413 | 1413 | // |
| 1414 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1415 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
| 1414 | + $argument_values[$key] = isset($instance[$key]) ? $instance[$key] : ''; |
|
| 1415 | + if ($args['type'] == 'checkbox' && $argument_values[$key] == '') { |
|
| 1416 | 1416 | // don't set default for an empty checkbox |
| 1417 | 1417 | } |
| 1418 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1419 | - $argument_values[ $key ] = $args['default']; |
|
| 1418 | + elseif ($argument_values[$key] == '' && isset($args['default'])) { |
|
| 1419 | + $argument_values[$key] = $args['default']; |
|
| 1420 | 1420 | } |
| 1421 | 1421 | } |
| 1422 | 1422 | } |
@@ -1443,12 +1443,12 @@ discard block |
||
| 1443 | 1443 | * @return array Get arguments. |
| 1444 | 1444 | */ |
| 1445 | 1445 | public function get_arguments() { |
| 1446 | - if ( empty( $this->arguments ) ) { |
|
| 1446 | + if (empty($this->arguments)) { |
|
| 1447 | 1447 | $this->arguments = $this->set_arguments(); |
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1451 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1450 | + $this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance); |
|
| 1451 | + $this->arguments = $this->add_name_from_key($this->arguments, true); |
|
| 1452 | 1452 | |
| 1453 | 1453 | return $this->arguments; |
| 1454 | 1454 | } |
@@ -1460,7 +1460,7 @@ discard block |
||
| 1460 | 1460 | * @param array $widget_args |
| 1461 | 1461 | * @param string $content |
| 1462 | 1462 | */ |
| 1463 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1463 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 1464 | 1464 | |
| 1465 | 1465 | } |
| 1466 | 1466 | |
@@ -1468,10 +1468,10 @@ discard block |
||
| 1468 | 1468 | * Add the dynamic block code inline when the wp-block in enqueued. |
| 1469 | 1469 | */ |
| 1470 | 1470 | public function register_block() { |
| 1471 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1472 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1471 | + wp_add_inline_script('wp-blocks', $this->block()); |
|
| 1472 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 1473 | 1473 | |
| 1474 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1474 | + wp_add_inline_script('wp-blocks', $this->siteorigin_js()); |
|
| 1475 | 1475 | |
| 1476 | 1476 | } |
| 1477 | 1477 | } |
@@ -1486,13 +1486,13 @@ discard block |
||
| 1486 | 1486 | $show = false; |
| 1487 | 1487 | $arguments = $this->arguments; |
| 1488 | 1488 | |
| 1489 | - if ( empty( $arguments ) ) { |
|
| 1489 | + if (empty($arguments)) { |
|
| 1490 | 1490 | $arguments = $this->get_arguments(); |
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | - if ( ! empty( $arguments ) ) { |
|
| 1494 | - foreach ( $arguments as $argument ) { |
|
| 1495 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1493 | + if (!empty($arguments)) { |
|
| 1494 | + foreach ($arguments as $argument) { |
|
| 1495 | + if (isset($argument['advanced']) && $argument['advanced']) { |
|
| 1496 | 1496 | $show = true; |
| 1497 | 1497 | break; // no need to continue if we know we have it |
| 1498 | 1498 | } |
@@ -1511,15 +1511,15 @@ discard block |
||
| 1511 | 1511 | |
| 1512 | 1512 | $url = $this->url; |
| 1513 | 1513 | |
| 1514 | - if(!$url){ |
|
| 1514 | + if (!$url) { |
|
| 1515 | 1515 | // check if we are inside a plugin |
| 1516 | - $file_dir = str_replace("/includes","", dirname( __FILE__ )); |
|
| 1516 | + $file_dir = str_replace("/includes", "", dirname(__FILE__)); |
|
| 1517 | 1517 | |
| 1518 | - $dir_parts = explode("/wp-content/",$file_dir); |
|
| 1519 | - $url_parts = explode("/wp-content/",plugins_url()); |
|
| 1518 | + $dir_parts = explode("/wp-content/", $file_dir); |
|
| 1519 | + $url_parts = explode("/wp-content/", plugins_url()); |
|
| 1520 | 1520 | |
| 1521 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
| 1522 | - $url = trailingslashit( $url_parts[0]."/wp-content/".$dir_parts[1] ); |
|
| 1521 | + if (!empty($url_parts[0]) && !empty($dir_parts[1])) { |
|
| 1522 | + $url = trailingslashit($url_parts[0] . "/wp-content/" . $dir_parts[1]); |
|
| 1523 | 1523 | $this->url = $url; |
| 1524 | 1524 | } |
| 1525 | 1525 | } |
@@ -1538,46 +1538,46 @@ discard block |
||
| 1538 | 1538 | * @since 1.1.0 |
| 1539 | 1539 | * @return string |
| 1540 | 1540 | */ |
| 1541 | - public function get_block_icon($icon){ |
|
| 1541 | + public function get_block_icon($icon) { |
|
| 1542 | 1542 | |
| 1543 | 1543 | // check if we have a Font Awesome icon |
| 1544 | 1544 | $fa_type = ''; |
| 1545 | - if(substr( $icon, 0, 7 ) === "fas fa-"){ |
|
| 1545 | + if (substr($icon, 0, 7) === "fas fa-") { |
|
| 1546 | 1546 | $fa_type = 'solid'; |
| 1547 | - }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
| 1547 | + }elseif (substr($icon, 0, 7) === "far fa-") { |
|
| 1548 | 1548 | $fa_type = 'regular'; |
| 1549 | - }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
| 1549 | + }elseif (substr($icon, 0, 7) === "fab fa-") { |
|
| 1550 | 1550 | $fa_type = 'brands'; |
| 1551 | - }else{ |
|
| 1552 | - $icon = "'".$icon."'"; |
|
| 1551 | + } else { |
|
| 1552 | + $icon = "'" . $icon . "'"; |
|
| 1553 | 1553 | } |
| 1554 | 1554 | |
| 1555 | 1555 | // set the icon if we found one |
| 1556 | - if($fa_type){ |
|
| 1557 | - $fa_icon = str_replace(array("fas fa-","far fa-","fab fa-"),"",$icon); |
|
| 1558 | - $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."','href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."'}))"; |
|
| 1556 | + if ($fa_type) { |
|
| 1557 | + $fa_icon = str_replace(array("fas fa-", "far fa-", "fab fa-"), "", $icon); |
|
| 1558 | + $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))"; |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | return $icon; |
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | - public function group_arguments($arguments){ |
|
| 1564 | + public function group_arguments($arguments) { |
|
| 1565 | 1565 | // echo '###';print_r($arguments); |
| 1566 | - if(!empty($arguments)){ |
|
| 1566 | + if (!empty($arguments)) { |
|
| 1567 | 1567 | $temp_arguments = array(); |
| 1568 | 1568 | $general = __("General"); |
| 1569 | 1569 | $add_sections = false; |
| 1570 | - foreach($arguments as $key => $args){ |
|
| 1571 | - if(isset($args['group'])){ |
|
| 1570 | + foreach ($arguments as $key => $args) { |
|
| 1571 | + if (isset($args['group'])) { |
|
| 1572 | 1572 | $temp_arguments[$args['group']][$key] = $args; |
| 1573 | 1573 | $add_sections = true; |
| 1574 | - }else{ |
|
| 1574 | + } else { |
|
| 1575 | 1575 | $temp_arguments[$general][$key] = $args; |
| 1576 | 1576 | } |
| 1577 | 1577 | } |
| 1578 | 1578 | |
| 1579 | 1579 | // only add sections if more than one |
| 1580 | - if($add_sections){ |
|
| 1580 | + if ($add_sections) { |
|
| 1581 | 1581 | $arguments = $temp_arguments; |
| 1582 | 1582 | } |
| 1583 | 1583 | } |
@@ -1629,19 +1629,19 @@ discard block |
||
| 1629 | 1629 | * @return {?WPBlock} The block, if it has been successfully |
| 1630 | 1630 | * registered; otherwise `undefined`. |
| 1631 | 1631 | */ |
| 1632 | - registerBlockType('<?php echo str_replace( "_", "-", sanitize_title_with_dashes( $this->options['textdomain'] ) . '/' . sanitize_title_with_dashes( $this->options['class_name'] ) ); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
| 1633 | - title: '<?php echo $this->options['name'];?>', // Block title. |
|
| 1634 | - description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title. |
|
| 1635 | - icon: <?php echo $this->get_block_icon($this->options['block-icon']);?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
| 1632 | + registerBlockType('<?php echo str_replace("_", "-", sanitize_title_with_dashes($this->options['textdomain']) . '/' . sanitize_title_with_dashes($this->options['class_name'])); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
| 1633 | + title: '<?php echo $this->options['name']; ?>', // Block title. |
|
| 1634 | + description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title. |
|
| 1635 | + icon: <?php echo $this->get_block_icon($this->options['block-icon']); ?>,//'<?php echo isset($this->options['block-icon']) ? esc_attr($this->options['block-icon']) : 'shield-alt'; ?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
| 1636 | 1636 | supports: { |
| 1637 | 1637 | <?php |
| 1638 | - if(isset($this->options['block-supports'])){ |
|
| 1639 | - echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
| 1638 | + if (isset($this->options['block-supports'])) { |
|
| 1639 | + echo $this->array_to_attributes($this->options['block-supports']); |
|
| 1640 | 1640 | } |
| 1641 | 1641 | ?> |
| 1642 | 1642 | }, |
| 1643 | - category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
| 1644 | - <?php if ( isset( $this->options['block-keywords'] ) ) { |
|
| 1643 | + category: '<?php echo isset($this->options['block-category']) ? esc_attr($this->options['block-category']) : 'common'; ?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
| 1644 | + <?php if (isset($this->options['block-keywords'])) { |
|
| 1645 | 1645 | echo "keywords : " . $this->options['block-keywords'] . ","; |
| 1646 | 1646 | }?> |
| 1647 | 1647 | |
@@ -1656,10 +1656,10 @@ discard block |
||
| 1656 | 1656 | echo " html: false"; |
| 1657 | 1657 | echo "},";*/ |
| 1658 | 1658 | |
| 1659 | - if ( ! empty( $this->arguments ) ) { |
|
| 1659 | + if (!empty($this->arguments)) { |
|
| 1660 | 1660 | echo "attributes : {"; |
| 1661 | 1661 | |
| 1662 | - if ( $show_advanced ) { |
|
| 1662 | + if ($show_advanced) { |
|
| 1663 | 1663 | echo "show_advanced: {"; |
| 1664 | 1664 | echo " type: 'boolean',"; |
| 1665 | 1665 | echo " default: false,"; |
@@ -1667,41 +1667,41 @@ discard block |
||
| 1667 | 1667 | } |
| 1668 | 1668 | |
| 1669 | 1669 | // block wrap element |
| 1670 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1670 | + if (isset($this->options['block-wrap'])) { //@todo we should validate this? |
|
| 1671 | 1671 | echo "block_wrap: {"; |
| 1672 | 1672 | echo " type: 'string',"; |
| 1673 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1673 | + echo " default: '" . esc_attr($this->options['block-wrap']) . "',"; |
|
| 1674 | 1674 | echo "},"; |
| 1675 | 1675 | } |
| 1676 | 1676 | |
| 1677 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1677 | + foreach ($this->arguments as $key => $args) { |
|
| 1678 | 1678 | |
| 1679 | 1679 | // set if we should show alignment |
| 1680 | - if ( $key == 'alignment' ) { |
|
| 1680 | + if ($key == 'alignment') { |
|
| 1681 | 1681 | $show_alignment = true; |
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | 1684 | $extra = ''; |
| 1685 | 1685 | |
| 1686 | - if ( $args['type'] == 'checkbox' ) { |
|
| 1686 | + if ($args['type'] == 'checkbox') { |
|
| 1687 | 1687 | $type = 'boolean'; |
| 1688 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1689 | - } elseif ( $args['type'] == 'number' ) { |
|
| 1688 | + $default = isset($args['default']) && $args['default'] ? 'true' : 'false'; |
|
| 1689 | + } elseif ($args['type'] == 'number') { |
|
| 1690 | 1690 | $type = 'number'; |
| 1691 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1692 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1691 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1692 | + } elseif ($args['type'] == 'select' && !empty($args['multiple'])) { |
|
| 1693 | 1693 | $type = 'array'; |
| 1694 | - if ( is_array( $args['default'] ) ) { |
|
| 1695 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1694 | + if (is_array($args['default'])) { |
|
| 1695 | + $default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]"; |
|
| 1696 | 1696 | } else { |
| 1697 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1697 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1698 | 1698 | } |
| 1699 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1699 | + } elseif ($args['type'] == 'multiselect') { |
|
| 1700 | 1700 | $type = 'array'; |
| 1701 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1701 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1702 | 1702 | } else { |
| 1703 | 1703 | $type = 'string'; |
| 1704 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1704 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1705 | 1705 | } |
| 1706 | 1706 | echo $key . " : {"; |
| 1707 | 1707 | echo "type : '$type',"; |
@@ -1732,12 +1732,12 @@ discard block |
||
| 1732 | 1732 | is_fetching = true; |
| 1733 | 1733 | var data = { |
| 1734 | 1734 | 'action': 'super_duper_output_shortcode', |
| 1735 | - 'shortcode': '<?php echo $this->options['base_id'];?>', |
|
| 1735 | + 'shortcode': '<?php echo $this->options['base_id']; ?>', |
|
| 1736 | 1736 | 'attributes': props.attributes, |
| 1737 | - 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
|
| 1737 | + 'post_id': <?php global $post; if (isset($post->ID)) { |
|
| 1738 | 1738 | echo $post->ID; |
| 1739 | 1739 | }?>, |
| 1740 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 1740 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 1741 | 1741 | }; |
| 1742 | 1742 | |
| 1743 | 1743 | jQuery.post(ajaxurl, data, function (response) { |
@@ -1746,7 +1746,7 @@ discard block |
||
| 1746 | 1746 | |
| 1747 | 1747 | // if the content is empty then we place some placeholder text |
| 1748 | 1748 | if (env == '') { |
| 1749 | - env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>"; |
|
| 1749 | + env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>"; |
|
| 1750 | 1750 | } |
| 1751 | 1751 | |
| 1752 | 1752 | props.setAttributes({content: env}); |
@@ -1765,7 +1765,7 @@ discard block |
||
| 1765 | 1765 | |
| 1766 | 1766 | el(wp.editor.BlockControls, {key: 'controls'}, |
| 1767 | 1767 | |
| 1768 | - <?php if($show_alignment){?> |
|
| 1768 | + <?php if ($show_alignment) {?> |
|
| 1769 | 1769 | el( |
| 1770 | 1770 | wp.editor.AlignmentToolbar, |
| 1771 | 1771 | { |
@@ -1783,9 +1783,9 @@ discard block |
||
| 1783 | 1783 | |
| 1784 | 1784 | <?php |
| 1785 | 1785 | |
| 1786 | - if(! empty( $this->arguments )){ |
|
| 1786 | + if (!empty($this->arguments)) { |
|
| 1787 | 1787 | |
| 1788 | - if ( $show_advanced ) { |
|
| 1788 | + if ($show_advanced) { |
|
| 1789 | 1789 | ?> |
| 1790 | 1790 | el( |
| 1791 | 1791 | wp.components.ToggleControl, |
@@ -1807,17 +1807,17 @@ discard block |
||
| 1807 | 1807 | $has_sections = $arguments == $this->arguments ? false : true; |
| 1808 | 1808 | |
| 1809 | 1809 | |
| 1810 | - if($has_sections){ |
|
| 1810 | + if ($has_sections) { |
|
| 1811 | 1811 | $panel_count = 0; |
| 1812 | - foreach($arguments as $key => $args){ |
|
| 1812 | + foreach ($arguments as $key => $args) { |
|
| 1813 | 1813 | ?> |
| 1814 | 1814 | el(wp.components.PanelBody, { |
| 1815 | 1815 | title: '<?php esc_attr_e($key); ?>', |
| 1816 | - initialOpen: <?php if($panel_count){echo "false";}else{echo "true";}?> |
|
| 1816 | + initialOpen: <?php if ($panel_count) {echo "false"; } else {echo "true"; }?> |
|
| 1817 | 1817 | }, |
| 1818 | 1818 | <?php |
| 1819 | 1819 | |
| 1820 | - foreach($args as $k => $a){ |
|
| 1820 | + foreach ($args as $k => $a) { |
|
| 1821 | 1821 | $this->build_block_arguments($k, $a); |
| 1822 | 1822 | } |
| 1823 | 1823 | ?> |
@@ -1826,8 +1826,8 @@ discard block |
||
| 1826 | 1826 | $panel_count++; |
| 1827 | 1827 | |
| 1828 | 1828 | } |
| 1829 | - }else{ |
|
| 1830 | - foreach($this->arguments as $key => $args){ |
|
| 1829 | + } else { |
|
| 1830 | + foreach ($this->arguments as $key => $args) { |
|
| 1831 | 1831 | $this->build_block_arguments($key, $args); |
| 1832 | 1832 | } |
| 1833 | 1833 | } |
@@ -1841,9 +1841,9 @@ discard block |
||
| 1841 | 1841 | |
| 1842 | 1842 | <?php |
| 1843 | 1843 | // If the user sets block-output array then build it |
| 1844 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1845 | - $this->block_element( $this->options['block-output'] ); |
|
| 1846 | - }else{ |
|
| 1844 | + if (!empty($this->options['block-output'])) { |
|
| 1845 | + $this->block_element($this->options['block-output']); |
|
| 1846 | + } else { |
|
| 1847 | 1847 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1848 | 1848 | ?> |
| 1849 | 1849 | el('div', { |
@@ -1867,14 +1867,14 @@ discard block |
||
| 1867 | 1867 | var align = ''; |
| 1868 | 1868 | |
| 1869 | 1869 | // build the shortcode. |
| 1870 | - var content = "[<?php echo $this->options['base_id'];?>"; |
|
| 1870 | + var content = "[<?php echo $this->options['base_id']; ?>"; |
|
| 1871 | 1871 | <?php |
| 1872 | 1872 | |
| 1873 | - if(! empty( $this->arguments )){ |
|
| 1874 | - foreach($this->arguments as $key => $args){ |
|
| 1873 | + if (!empty($this->arguments)) { |
|
| 1874 | + foreach ($this->arguments as $key => $args) { |
|
| 1875 | 1875 | ?> |
| 1876 | - if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
|
| 1877 | - content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
|
| 1876 | + if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) { |
|
| 1877 | + content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' "; |
|
| 1878 | 1878 | } |
| 1879 | 1879 | <?php |
| 1880 | 1880 | } |
@@ -1915,82 +1915,82 @@ discard block |
||
| 1915 | 1915 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1916 | 1916 | */ |
| 1917 | 1917 | |
| 1918 | - return str_replace( array( |
|
| 1918 | + return str_replace(array( |
|
| 1919 | 1919 | '<script>', |
| 1920 | 1920 | '</script>' |
| 1921 | - ), '', $output ); |
|
| 1921 | + ), '', $output); |
|
| 1922 | 1922 | } |
| 1923 | 1923 | |
| 1924 | - public function build_block_arguments($key,$args){ |
|
| 1925 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 1924 | + public function build_block_arguments($key, $args) { |
|
| 1925 | + $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : ''; |
|
| 1926 | 1926 | $options = ''; |
| 1927 | 1927 | $extra = ''; |
| 1928 | 1928 | $require = ''; |
| 1929 | 1929 | $onchange = "props.setAttributes({ $key: $key } )"; |
| 1930 | 1930 | $value = "props.attributes.$key"; |
| 1931 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1932 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 1931 | + $text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color'); |
|
| 1932 | + if (in_array($args['type'], $text_type)) { |
|
| 1933 | 1933 | $type = 'TextControl'; |
| 1934 | 1934 | // Save numbers as numbers and not strings |
| 1935 | - if ( $args['type'] == 'number' ) { |
|
| 1935 | + if ($args['type'] == 'number') { |
|
| 1936 | 1936 | $onchange = "props.setAttributes({ $key: Number($key) } )"; |
| 1937 | 1937 | } |
| 1938 | 1938 | } |
| 1939 | 1939 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we use html5 color input for now https://github.com/WordPress/gutenberg/issues/14378 |
| 1940 | 1940 | // $type = 'ColorPicker'; |
| 1941 | 1941 | // } |
| 1942 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 1942 | + elseif ($args['type'] == 'checkbox') { |
|
| 1943 | 1943 | $type = 'CheckboxControl'; |
| 1944 | 1944 | $extra .= "checked: props.attributes.$key,"; |
| 1945 | 1945 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
| 1946 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1946 | + } elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') { |
|
| 1947 | 1947 | $type = 'SelectControl'; |
| 1948 | - if ( ! empty( $args['options'] ) ) { |
|
| 1948 | + if (!empty($args['options'])) { |
|
| 1949 | 1949 | $options .= "options : ["; |
| 1950 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1951 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1950 | + foreach ($args['options'] as $option_val => $option_label) { |
|
| 1951 | + $options .= "{ value : '" . esc_attr($option_val) . "', label : '" . esc_attr($option_label) . "' },"; |
|
| 1952 | 1952 | } |
| 1953 | 1953 | $options .= "],"; |
| 1954 | 1954 | } |
| 1955 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1955 | + if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1956 | 1956 | $extra .= ' multiple: true, '; |
| 1957 | 1957 | //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
| 1958 | 1958 | //$value = "['edit', 'delete']"; |
| 1959 | 1959 | } |
| 1960 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 1960 | + } elseif ($args['type'] == 'alignment') { |
|
| 1961 | 1961 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
| 1962 | 1962 | } else { |
| 1963 | - return;// if we have not implemented the control then don't break the JS. |
|
| 1963 | + return; // if we have not implemented the control then don't break the JS. |
|
| 1964 | 1964 | } |
| 1965 | 1965 | |
| 1966 | 1966 | // add show only if advanced |
| 1967 | - if ( ! empty( $args['advanced'] ) ) { |
|
| 1967 | + if (!empty($args['advanced'])) { |
|
| 1968 | 1968 | echo "props.attributes.show_advanced && "; |
| 1969 | 1969 | } |
| 1970 | 1970 | // add setting require if defined |
| 1971 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 1972 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1971 | + if (!empty($args['element_require'])) { |
|
| 1972 | + echo $this->block_props_replace($args['element_require'], true) . " && "; |
|
| 1973 | 1973 | } |
| 1974 | 1974 | ?> |
| 1975 | 1975 | el( |
| 1976 | - wp.components.<?php echo esc_attr( $type );?>, |
|
| 1976 | + wp.components.<?php echo esc_attr($type); ?>, |
|
| 1977 | 1977 | { |
| 1978 | - label: '<?php echo esc_attr( $args['title'] );?>', |
|
| 1979 | - help: '<?php if ( isset( $args['desc'] ) ) { |
|
| 1980 | - echo esc_attr( $args['desc'] ); |
|
| 1978 | + label: '<?php echo esc_attr($args['title']); ?>', |
|
| 1979 | + help: '<?php if (isset($args['desc'])) { |
|
| 1980 | + echo esc_attr($args['desc']); |
|
| 1981 | 1981 | }?>', |
| 1982 | - value: <?php echo $value;?>, |
|
| 1983 | - <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
|
| 1984 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1982 | + value: <?php echo $value; ?>, |
|
| 1983 | + <?php if ($type == 'TextControl' && $args['type'] != 'text') { |
|
| 1984 | + echo "type: '" . esc_attr($args['type']) . "',"; |
|
| 1985 | 1985 | }?> |
| 1986 | - <?php if ( ! empty( $args['placeholder'] ) ) { |
|
| 1987 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1986 | + <?php if (!empty($args['placeholder'])) { |
|
| 1987 | + echo "placeholder: '" . esc_attr($args['placeholder']) . "',"; |
|
| 1988 | 1988 | }?> |
| 1989 | - <?php echo $options;?> |
|
| 1990 | - <?php echo $extra;?> |
|
| 1991 | - <?php echo $custom_attributes;?> |
|
| 1992 | - onChange: function ( <?php echo $key;?> ) { |
|
| 1993 | - <?php echo $onchange;?> |
|
| 1989 | + <?php echo $options; ?> |
|
| 1990 | + <?php echo $extra; ?> |
|
| 1991 | + <?php echo $custom_attributes; ?> |
|
| 1992 | + onChange: function ( <?php echo $key; ?> ) { |
|
| 1993 | + <?php echo $onchange; ?> |
|
| 1994 | 1994 | } |
| 1995 | 1995 | } |
| 1996 | 1996 | ), |
@@ -2006,16 +2006,16 @@ discard block |
||
| 2006 | 2006 | * |
| 2007 | 2007 | * @return string |
| 2008 | 2008 | */ |
| 2009 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 2009 | + public function array_to_attributes($custom_attributes, $html = false) { |
|
| 2010 | 2010 | $attributes = ''; |
| 2011 | - if ( ! empty( $custom_attributes ) ) { |
|
| 2011 | + if (!empty($custom_attributes)) { |
|
| 2012 | 2012 | |
| 2013 | - if ( $html ) { |
|
| 2014 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2013 | + if ($html) { |
|
| 2014 | + foreach ($custom_attributes as $key => $val) { |
|
| 2015 | 2015 | $attributes .= " $key='$val' "; |
| 2016 | 2016 | } |
| 2017 | 2017 | } else { |
| 2018 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2018 | + foreach ($custom_attributes as $key => $val) { |
|
| 2019 | 2019 | $attributes .= "'$key': '$val',"; |
| 2020 | 2020 | } |
| 2021 | 2021 | } |
@@ -2031,86 +2031,86 @@ discard block |
||
| 2031 | 2031 | * |
| 2032 | 2032 | * @param $args |
| 2033 | 2033 | */ |
| 2034 | - public function block_element( $args ) { |
|
| 2034 | + public function block_element($args) { |
|
| 2035 | 2035 | |
| 2036 | 2036 | |
| 2037 | - if ( ! empty( $args ) ) { |
|
| 2038 | - foreach ( $args as $element => $new_args ) { |
|
| 2037 | + if (!empty($args)) { |
|
| 2038 | + foreach ($args as $element => $new_args) { |
|
| 2039 | 2039 | |
| 2040 | - if ( is_array( $new_args ) ) { // its an element |
|
| 2040 | + if (is_array($new_args)) { // its an element |
|
| 2041 | 2041 | |
| 2042 | 2042 | |
| 2043 | - if ( isset( $new_args['element'] ) ) { |
|
| 2043 | + if (isset($new_args['element'])) { |
|
| 2044 | 2044 | |
| 2045 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 2046 | - echo str_replace( array( |
|
| 2045 | + if (isset($new_args['element_require'])) { |
|
| 2046 | + echo str_replace(array( |
|
| 2047 | 2047 | "'+", |
| 2048 | 2048 | "+'" |
| 2049 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 2050 | - unset( $new_args['element_require'] ); |
|
| 2049 | + ), '', $this->block_props_replace($new_args['element_require'])) . " && "; |
|
| 2050 | + unset($new_args['element_require']); |
|
| 2051 | 2051 | } |
| 2052 | 2052 | |
| 2053 | 2053 | echo "\n el( '" . $new_args['element'] . "', {"; |
| 2054 | 2054 | |
| 2055 | 2055 | // get the attributes |
| 2056 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2056 | + foreach ($new_args as $new_key => $new_value) { |
|
| 2057 | 2057 | |
| 2058 | 2058 | |
| 2059 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 2059 | + if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) { |
|
| 2060 | 2060 | // do nothing |
| 2061 | 2061 | } else { |
| 2062 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 2062 | + echo $this->block_element(array($new_key => $new_value)); |
|
| 2063 | 2063 | } |
| 2064 | 2064 | } |
| 2065 | 2065 | |
| 2066 | - echo "},";// end attributes |
|
| 2066 | + echo "},"; // end attributes |
|
| 2067 | 2067 | |
| 2068 | 2068 | // get the content |
| 2069 | 2069 | $first_item = 0; |
| 2070 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2071 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 2070 | + foreach ($new_args as $new_key => $new_value) { |
|
| 2071 | + if ($new_key === 'content' || is_array($new_value)) { |
|
| 2072 | 2072 | |
| 2073 | - if ( $new_key === 'content' ) { |
|
| 2074 | - echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
| 2073 | + if ($new_key === 'content') { |
|
| 2074 | + echo "'" . $this->block_props_replace(wp_slash($new_value)) . "'"; |
|
| 2075 | 2075 | } |
| 2076 | 2076 | |
| 2077 | - if ( is_array( $new_value ) ) { |
|
| 2077 | + if (is_array($new_value)) { |
|
| 2078 | 2078 | |
| 2079 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 2080 | - echo str_replace( array( |
|
| 2079 | + if (isset($new_value['element_require'])) { |
|
| 2080 | + echo str_replace(array( |
|
| 2081 | 2081 | "'+", |
| 2082 | 2082 | "+'" |
| 2083 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 2084 | - unset( $new_value['element_require'] ); |
|
| 2083 | + ), '', $this->block_props_replace($new_value['element_require'])) . " && "; |
|
| 2084 | + unset($new_value['element_require']); |
|
| 2085 | 2085 | } |
| 2086 | 2086 | |
| 2087 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 2087 | + if (isset($new_value['element_repeat'])) { |
|
| 2088 | 2088 | $x = 1; |
| 2089 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 2090 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2091 | - $x ++; |
|
| 2089 | + while ($x <= absint($new_value['element_repeat'])) { |
|
| 2090 | + $this->block_element(array('' => $new_value)); |
|
| 2091 | + $x++; |
|
| 2092 | 2092 | } |
| 2093 | 2093 | } else { |
| 2094 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2094 | + $this->block_element(array('' => $new_value)); |
|
| 2095 | 2095 | } |
| 2096 | 2096 | } |
| 2097 | - $first_item ++; |
|
| 2097 | + $first_item++; |
|
| 2098 | 2098 | } |
| 2099 | 2099 | } |
| 2100 | 2100 | |
| 2101 | - echo ")";// end content |
|
| 2101 | + echo ")"; // end content |
|
| 2102 | 2102 | |
| 2103 | 2103 | echo ", \n"; |
| 2104 | 2104 | |
| 2105 | 2105 | } |
| 2106 | 2106 | } else { |
| 2107 | 2107 | |
| 2108 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 2109 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 2110 | - } elseif ( $element == 'style' ) { |
|
| 2111 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 2108 | + if (substr($element, 0, 3) === "if_") { |
|
| 2109 | + echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ","; |
|
| 2110 | + } elseif ($element == 'style') { |
|
| 2111 | + echo $element . ": " . $this->block_props_replace($new_args) . ","; |
|
| 2112 | 2112 | } else { |
| 2113 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 2113 | + echo $element . ": '" . $this->block_props_replace($new_args) . "',"; |
|
| 2114 | 2114 | } |
| 2115 | 2115 | |
| 2116 | 2116 | } |
@@ -2125,12 +2125,12 @@ discard block |
||
| 2125 | 2125 | * |
| 2126 | 2126 | * @return mixed |
| 2127 | 2127 | */ |
| 2128 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 2128 | + public function block_props_replace($string, $no_wrap = false) { |
|
| 2129 | 2129 | |
| 2130 | - if ( $no_wrap ) { |
|
| 2131 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 2130 | + if ($no_wrap) { |
|
| 2131 | + $string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string); |
|
| 2132 | 2132 | } else { |
| 2133 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 2133 | + $string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string); |
|
| 2134 | 2134 | } |
| 2135 | 2135 | |
| 2136 | 2136 | return $string; |
@@ -2142,43 +2142,43 @@ discard block |
||
| 2142 | 2142 | * @param array $args |
| 2143 | 2143 | * @param array $instance |
| 2144 | 2144 | */ |
| 2145 | - public function widget( $args, $instance ) { |
|
| 2145 | + public function widget($args, $instance) { |
|
| 2146 | 2146 | |
| 2147 | 2147 | // get the filtered values |
| 2148 | - $argument_values = $this->argument_values( $instance ); |
|
| 2149 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 2150 | - $output = $this->output( $argument_values, $args ); |
|
| 2148 | + $argument_values = $this->argument_values($instance); |
|
| 2149 | + $argument_values = $this->string_to_bool($argument_values); |
|
| 2150 | + $output = $this->output($argument_values, $args); |
|
| 2151 | 2151 | |
| 2152 | 2152 | ob_start(); |
| 2153 | - if ( $output ) { |
|
| 2153 | + if ($output) { |
|
| 2154 | 2154 | // Before widget |
| 2155 | 2155 | $before_widget = $args['before_widget']; |
| 2156 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 2157 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 2156 | + $before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this); |
|
| 2157 | + $before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this); |
|
| 2158 | 2158 | |
| 2159 | 2159 | // After widget |
| 2160 | 2160 | $after_widget = $args['after_widget']; |
| 2161 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 2162 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 2161 | + $after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this); |
|
| 2162 | + $after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this); |
|
| 2163 | 2163 | |
| 2164 | 2164 | echo $before_widget; |
| 2165 | 2165 | // elementor strips the widget wrapping div so we check for and add it back if needed |
| 2166 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2167 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 2166 | + if ($this->is_elementor_widget_output()) { |
|
| 2167 | + echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : ''; |
|
| 2168 | 2168 | } |
| 2169 | - echo $this->output_title( $args, $instance ); |
|
| 2169 | + echo $this->output_title($args, $instance); |
|
| 2170 | 2170 | echo $output; |
| 2171 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2172 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 2171 | + if ($this->is_elementor_widget_output()) { |
|
| 2172 | + echo !empty($this->options['widget_ops']['classname']) ? "</span>" : ''; |
|
| 2173 | 2173 | } |
| 2174 | 2174 | echo $after_widget; |
| 2175 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 2176 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 2175 | + } elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty |
|
| 2176 | + $output = $this->preview_placeholder_text("{{" . $this->base_id . "}}"); |
|
| 2177 | 2177 | echo $output; |
| 2178 | 2178 | } |
| 2179 | 2179 | $output = ob_get_clean(); |
| 2180 | 2180 | |
| 2181 | - $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
| 2181 | + $output = apply_filters('wp_super_duper_widget_output', $output, $instance, $args, $this); |
|
| 2182 | 2182 | |
| 2183 | 2183 | echo $output; |
| 2184 | 2184 | } |
@@ -2191,7 +2191,7 @@ discard block |
||
| 2191 | 2191 | */ |
| 2192 | 2192 | public function is_elementor_widget_output() { |
| 2193 | 2193 | $result = false; |
| 2194 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 2194 | + if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') { |
|
| 2195 | 2195 | $result = true; |
| 2196 | 2196 | } |
| 2197 | 2197 | |
@@ -2206,7 +2206,7 @@ discard block |
||
| 2206 | 2206 | */ |
| 2207 | 2207 | public function is_elementor_preview() { |
| 2208 | 2208 | $result = false; |
| 2209 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 2209 | + if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) { |
|
| 2210 | 2210 | $result = true; |
| 2211 | 2211 | } |
| 2212 | 2212 | |
@@ -2221,7 +2221,7 @@ discard block |
||
| 2221 | 2221 | */ |
| 2222 | 2222 | public function is_divi_preview() { |
| 2223 | 2223 | $result = false; |
| 2224 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 2224 | + if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) { |
|
| 2225 | 2225 | $result = true; |
| 2226 | 2226 | } |
| 2227 | 2227 | |
@@ -2236,7 +2236,7 @@ discard block |
||
| 2236 | 2236 | */ |
| 2237 | 2237 | public function is_beaver_preview() { |
| 2238 | 2238 | $result = false; |
| 2239 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 2239 | + if (isset($_REQUEST['fl_builder'])) { |
|
| 2240 | 2240 | $result = true; |
| 2241 | 2241 | } |
| 2242 | 2242 | |
@@ -2251,7 +2251,7 @@ discard block |
||
| 2251 | 2251 | */ |
| 2252 | 2252 | public function is_siteorigin_preview() { |
| 2253 | 2253 | $result = false; |
| 2254 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 2254 | + if (!empty($_REQUEST['siteorigin_panels_live_editor'])) { |
|
| 2255 | 2255 | $result = true; |
| 2256 | 2256 | } |
| 2257 | 2257 | |
@@ -2266,7 +2266,7 @@ discard block |
||
| 2266 | 2266 | */ |
| 2267 | 2267 | public function is_cornerstone_preview() { |
| 2268 | 2268 | $result = false; |
| 2269 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 2269 | + if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') { |
|
| 2270 | 2270 | $result = true; |
| 2271 | 2271 | } |
| 2272 | 2272 | |
@@ -2281,7 +2281,7 @@ discard block |
||
| 2281 | 2281 | */ |
| 2282 | 2282 | public function is_fusion_preview() { |
| 2283 | 2283 | $result = false; |
| 2284 | - if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
| 2284 | + if (!empty($_REQUEST['fb-edit']) || !empty($_REQUEST['fusion_load_nonce'])) { |
|
| 2285 | 2285 | $result = true; |
| 2286 | 2286 | } |
| 2287 | 2287 | |
@@ -2296,17 +2296,17 @@ discard block |
||
| 2296 | 2296 | */ |
| 2297 | 2297 | public function is_preview() { |
| 2298 | 2298 | $preview = false; |
| 2299 | - if ( $this->is_divi_preview() ) { |
|
| 2299 | + if ($this->is_divi_preview()) { |
|
| 2300 | 2300 | $preview = true; |
| 2301 | - } elseif ( $this->is_elementor_preview() ) { |
|
| 2301 | + } elseif ($this->is_elementor_preview()) { |
|
| 2302 | 2302 | $preview = true; |
| 2303 | - } elseif ( $this->is_beaver_preview() ) { |
|
| 2303 | + } elseif ($this->is_beaver_preview()) { |
|
| 2304 | 2304 | $preview = true; |
| 2305 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2305 | + } elseif ($this->is_siteorigin_preview()) { |
|
| 2306 | 2306 | $preview = true; |
| 2307 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2307 | + } elseif ($this->is_cornerstone_preview()) { |
|
| 2308 | 2308 | $preview = true; |
| 2309 | - } elseif ( $this->is_fusion_preview() ) { |
|
| 2309 | + } elseif ($this->is_fusion_preview()) { |
|
| 2310 | 2310 | $preview = true; |
| 2311 | 2311 | } |
| 2312 | 2312 | |
@@ -2321,11 +2321,11 @@ discard block |
||
| 2321 | 2321 | * |
| 2322 | 2322 | * @return string |
| 2323 | 2323 | */ |
| 2324 | - public function output_title( $args, $instance = array() ) { |
|
| 2324 | + public function output_title($args, $instance = array()) { |
|
| 2325 | 2325 | $output = ''; |
| 2326 | - if ( ! empty( $instance['title'] ) ) { |
|
| 2326 | + if (!empty($instance['title'])) { |
|
| 2327 | 2327 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 2328 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2328 | + $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
|
| 2329 | 2329 | $output = $args['before_title'] . $title . $args['after_title']; |
| 2330 | 2330 | } |
| 2331 | 2331 | |
@@ -2337,7 +2337,7 @@ discard block |
||
| 2337 | 2337 | * |
| 2338 | 2338 | * @param array $instance The widget options. |
| 2339 | 2339 | */ |
| 2340 | - public function form( $instance ) { |
|
| 2340 | + public function form($instance) { |
|
| 2341 | 2341 | |
| 2342 | 2342 | // set widget instance |
| 2343 | 2343 | $this->instance = $instance; |
@@ -2345,10 +2345,10 @@ discard block |
||
| 2345 | 2345 | // set it as a SD widget |
| 2346 | 2346 | echo $this->widget_advanced_toggle(); |
| 2347 | 2347 | |
| 2348 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2348 | + echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>"; |
|
| 2349 | 2349 | $arguments_raw = $this->get_arguments(); |
| 2350 | 2350 | |
| 2351 | - if ( is_array( $arguments_raw ) ) { |
|
| 2351 | + if (is_array($arguments_raw)) { |
|
| 2352 | 2352 | |
| 2353 | 2353 | $arguments = $this->group_arguments($arguments_raw); |
| 2354 | 2354 | |
@@ -2356,9 +2356,9 @@ discard block |
||
| 2356 | 2356 | $has_sections = $arguments == $arguments_raw ? false : true; |
| 2357 | 2357 | |
| 2358 | 2358 | |
| 2359 | - if($has_sections){ |
|
| 2359 | + if ($has_sections) { |
|
| 2360 | 2360 | $panel_count = 0; |
| 2361 | - foreach($arguments as $key => $args){ |
|
| 2361 | + foreach ($arguments as $key => $args) { |
|
| 2362 | 2362 | |
| 2363 | 2363 | ?> |
| 2364 | 2364 | <script> |
@@ -2368,10 +2368,10 @@ discard block |
||
| 2368 | 2368 | |
| 2369 | 2369 | $hide = $panel_count ? ' style="display:none;" ' : ''; |
| 2370 | 2370 | $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
| 2371 | - echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle".sanitize_title_with_dashes($key)."'>".esc_attr($key)." <i style='float:right;' class='".$icon_class."'></i></button>"; |
|
| 2372 | - echo "<div class='sd-toggle-group sd-input-group-".sanitize_title_with_dashes($key)."' $hide>"; |
|
| 2371 | + echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes($key) . "'>" . esc_attr($key) . " <i style='float:right;' class='" . $icon_class . "'></i></button>"; |
|
| 2372 | + echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes($key) . "' $hide>"; |
|
| 2373 | 2373 | |
| 2374 | - foreach($args as $k => $a){ |
|
| 2374 | + foreach ($args as $k => $a) { |
|
| 2375 | 2375 | $this->widget_inputs($a, $instance); |
| 2376 | 2376 | } |
| 2377 | 2377 | |
@@ -2380,9 +2380,9 @@ discard block |
||
| 2380 | 2380 | $panel_count++; |
| 2381 | 2381 | |
| 2382 | 2382 | } |
| 2383 | - }else{ |
|
| 2384 | - foreach ( $arguments as $key => $args ) { |
|
| 2385 | - $this->widget_inputs( $args, $instance ); |
|
| 2383 | + } else { |
|
| 2384 | + foreach ($arguments as $key => $args) { |
|
| 2385 | + $this->widget_inputs($args, $instance); |
|
| 2386 | 2386 | } |
| 2387 | 2387 | } |
| 2388 | 2388 | |
@@ -2397,7 +2397,7 @@ discard block |
||
| 2397 | 2397 | public function widget_advanced_toggle() { |
| 2398 | 2398 | |
| 2399 | 2399 | $output = ''; |
| 2400 | - if ( $this->block_show_advanced() ) { |
|
| 2400 | + if ($this->block_show_advanced()) { |
|
| 2401 | 2401 | $val = 1; |
| 2402 | 2402 | } else { |
| 2403 | 2403 | $val = 0; |
@@ -2417,14 +2417,14 @@ discard block |
||
| 2417 | 2417 | * |
| 2418 | 2418 | * @return string $output |
| 2419 | 2419 | */ |
| 2420 | - public function convert_element_require( $input ) { |
|
| 2420 | + public function convert_element_require($input) { |
|
| 2421 | 2421 | |
| 2422 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2422 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
| 2423 | 2423 | |
| 2424 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2424 | + $output = esc_attr(str_replace(array("[%", "%]"), array( |
|
| 2425 | 2425 | "jQuery(form).find('[data-argument=\"", |
| 2426 | 2426 | "\"]').find('input,select').val()" |
| 2427 | - ), $input ) ); |
|
| 2427 | + ), $input)); |
|
| 2428 | 2428 | |
| 2429 | 2429 | return $output; |
| 2430 | 2430 | } |
@@ -2435,54 +2435,54 @@ discard block |
||
| 2435 | 2435 | * @param $args |
| 2436 | 2436 | * @param $instance |
| 2437 | 2437 | */ |
| 2438 | - public function widget_inputs( $args, $instance ) { |
|
| 2438 | + public function widget_inputs($args, $instance) { |
|
| 2439 | 2439 | |
| 2440 | 2440 | $class = ""; |
| 2441 | 2441 | $element_require = ""; |
| 2442 | 2442 | $custom_attributes = ""; |
| 2443 | 2443 | |
| 2444 | 2444 | // get value |
| 2445 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2446 | - $value = $instance[ $args['name'] ]; |
|
| 2447 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2448 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2445 | + if (isset($instance[$args['name']])) { |
|
| 2446 | + $value = $instance[$args['name']]; |
|
| 2447 | + } elseif (!isset($instance[$args['name']]) && !empty($args['default'])) { |
|
| 2448 | + $value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']); |
|
| 2449 | 2449 | } else { |
| 2450 | 2450 | $value = ''; |
| 2451 | 2451 | } |
| 2452 | 2452 | |
| 2453 | 2453 | // get placeholder |
| 2454 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 2455 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2454 | + if (!empty($args['placeholder'])) { |
|
| 2455 | + $placeholder = "placeholder='" . esc_html($args['placeholder']) . "'"; |
|
| 2456 | 2456 | } else { |
| 2457 | 2457 | $placeholder = ''; |
| 2458 | 2458 | } |
| 2459 | 2459 | |
| 2460 | 2460 | // get if advanced |
| 2461 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2461 | + if (isset($args['advanced']) && $args['advanced']) { |
|
| 2462 | 2462 | $class .= " sd-advanced-setting "; |
| 2463 | 2463 | } |
| 2464 | 2464 | |
| 2465 | 2465 | // element_require |
| 2466 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2466 | + if (isset($args['element_require']) && $args['element_require']) { |
|
| 2467 | 2467 | $element_require = $args['element_require']; |
| 2468 | 2468 | } |
| 2469 | 2469 | |
| 2470 | 2470 | // custom_attributes |
| 2471 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2472 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2471 | + if (isset($args['custom_attributes']) && $args['custom_attributes']) { |
|
| 2472 | + $custom_attributes = $this->array_to_attributes($args['custom_attributes'], true); |
|
| 2473 | 2473 | } |
| 2474 | 2474 | |
| 2475 | 2475 | // before wrapper |
| 2476 | 2476 | ?> |
| 2477 | - <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
|
| 2478 | - data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
|
| 2479 | - data-element_require='<?php if ( $element_require ) { |
|
| 2480 | - echo $this->convert_element_require( $element_require ); |
|
| 2477 | + <p class="sd-argument <?php echo esc_attr($class); ?>" |
|
| 2478 | + data-argument='<?php echo esc_attr($args['name']); ?>' |
|
| 2479 | + data-element_require='<?php if ($element_require) { |
|
| 2480 | + echo $this->convert_element_require($element_require); |
|
| 2481 | 2481 | } ?>' |
| 2482 | 2482 | > |
| 2483 | 2483 | <?php |
| 2484 | 2484 | |
| 2485 | - switch ( $args['type'] ) { |
|
| 2485 | + switch ($args['type']) { |
|
| 2486 | 2486 | //array('text','password','number','email','tel','url','color') |
| 2487 | 2487 | case "text": |
| 2488 | 2488 | case "password": |
@@ -2493,46 +2493,46 @@ discard block |
||
| 2493 | 2493 | case "color": |
| 2494 | 2494 | ?> |
| 2495 | 2495 | <label |
| 2496 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2496 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2497 | 2497 | <input <?php echo $placeholder; ?> class="widefat" |
| 2498 | 2498 | <?php echo $custom_attributes; ?> |
| 2499 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2500 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
| 2501 | - type="<?php echo esc_attr( $args['type'] ); ?>" |
|
| 2502 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2499 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2500 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
| 2501 | + type="<?php echo esc_attr($args['type']); ?>" |
|
| 2502 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2503 | 2503 | <?php |
| 2504 | 2504 | |
| 2505 | 2505 | break; |
| 2506 | 2506 | case "select": |
| 2507 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2508 | - if ( $multiple ) { |
|
| 2509 | - if ( empty( $value ) ) { |
|
| 2507 | + $multiple = isset($args['multiple']) && $args['multiple'] ? true : false; |
|
| 2508 | + if ($multiple) { |
|
| 2509 | + if (empty($value)) { |
|
| 2510 | 2510 | $value = array(); |
| 2511 | 2511 | } |
| 2512 | 2512 | } |
| 2513 | 2513 | ?> |
| 2514 | 2514 | <label |
| 2515 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2515 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2516 | 2516 | <select <?php echo $placeholder; ?> class="widefat" |
| 2517 | 2517 | <?php echo $custom_attributes; ?> |
| 2518 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2519 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
|
| 2520 | - if ( $multiple ) { |
|
| 2518 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2519 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); |
|
| 2520 | + if ($multiple) { |
|
| 2521 | 2521 | echo "[]"; |
| 2522 | 2522 | } ?>" |
| 2523 | - <?php if ( $multiple ) { |
|
| 2523 | + <?php if ($multiple) { |
|
| 2524 | 2524 | echo "multiple"; |
| 2525 | 2525 | } //@todo not implemented yet due to gutenberg not supporting it |
| 2526 | 2526 | ?> |
| 2527 | 2527 | > |
| 2528 | 2528 | <?php |
| 2529 | 2529 | |
| 2530 | - if ( ! empty( $args['options'] ) ) { |
|
| 2531 | - foreach ( $args['options'] as $val => $label ) { |
|
| 2532 | - if ( $multiple ) { |
|
| 2533 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2530 | + if (!empty($args['options'])) { |
|
| 2531 | + foreach ($args['options'] as $val => $label) { |
|
| 2532 | + if ($multiple) { |
|
| 2533 | + $selected = in_array($val, $value) ? 'selected="selected"' : ''; |
|
| 2534 | 2534 | } else { |
| 2535 | - $selected = selected( $value, $val, false ); |
|
| 2535 | + $selected = selected($value, $val, false); |
|
| 2536 | 2536 | } |
| 2537 | 2537 | echo "<option value='$val' " . $selected . ">$label</option>"; |
| 2538 | 2538 | } |
@@ -2544,20 +2544,20 @@ discard block |
||
| 2544 | 2544 | case "checkbox": |
| 2545 | 2545 | ?> |
| 2546 | 2546 | <input <?php echo $placeholder; ?> |
| 2547 | - <?php checked( 1, $value, true ) ?> |
|
| 2547 | + <?php checked(1, $value, true) ?> |
|
| 2548 | 2548 | <?php echo $custom_attributes; ?> |
| 2549 | - class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2550 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" |
|
| 2549 | + class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2550 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox" |
|
| 2551 | 2551 | value="1"> |
| 2552 | 2552 | <label |
| 2553 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2553 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2554 | 2554 | <?php |
| 2555 | 2555 | break; |
| 2556 | 2556 | case "hidden": |
| 2557 | 2557 | ?> |
| 2558 | - <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2559 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
|
| 2560 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2558 | + <input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2559 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden" |
|
| 2560 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2561 | 2561 | <?php |
| 2562 | 2562 | break; |
| 2563 | 2563 | default: |
@@ -2579,14 +2579,14 @@ discard block |
||
| 2579 | 2579 | * @return string |
| 2580 | 2580 | * @todo, need to make its own tooltip script |
| 2581 | 2581 | */ |
| 2582 | - public function widget_field_desc( $args ) { |
|
| 2582 | + public function widget_field_desc($args) { |
|
| 2583 | 2583 | |
| 2584 | 2584 | $description = ''; |
| 2585 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2586 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2587 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 2585 | + if (isset($args['desc']) && $args['desc']) { |
|
| 2586 | + if (isset($args['desc_tip']) && $args['desc_tip']) { |
|
| 2587 | + $description = $this->desc_tip($args['desc']); |
|
| 2588 | 2588 | } else { |
| 2589 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2589 | + $description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>'; |
|
| 2590 | 2590 | } |
| 2591 | 2591 | } |
| 2592 | 2592 | |
@@ -2601,11 +2601,11 @@ discard block |
||
| 2601 | 2601 | * |
| 2602 | 2602 | * @return string |
| 2603 | 2603 | */ |
| 2604 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 2605 | - if ( $allow_html ) { |
|
| 2606 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 2604 | + function desc_tip($tip, $allow_html = false) { |
|
| 2605 | + if ($allow_html) { |
|
| 2606 | + $tip = $this->sanitize_tooltip($tip); |
|
| 2607 | 2607 | } else { |
| 2608 | - $tip = esc_attr( $tip ); |
|
| 2608 | + $tip = esc_attr($tip); |
|
| 2609 | 2609 | } |
| 2610 | 2610 | |
| 2611 | 2611 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -2618,8 +2618,8 @@ discard block |
||
| 2618 | 2618 | * |
| 2619 | 2619 | * @return string |
| 2620 | 2620 | */ |
| 2621 | - public function sanitize_tooltip( $var ) { |
|
| 2622 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2621 | + public function sanitize_tooltip($var) { |
|
| 2622 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
| 2623 | 2623 | 'br' => array(), |
| 2624 | 2624 | 'em' => array(), |
| 2625 | 2625 | 'strong' => array(), |
@@ -2629,7 +2629,7 @@ discard block |
||
| 2629 | 2629 | 'li' => array(), |
| 2630 | 2630 | 'ol' => array(), |
| 2631 | 2631 | 'p' => array(), |
| 2632 | - ) ) ); |
|
| 2632 | + ))); |
|
| 2633 | 2633 | } |
| 2634 | 2634 | |
| 2635 | 2635 | /** |
@@ -2641,23 +2641,23 @@ discard block |
||
| 2641 | 2641 | * @return array |
| 2642 | 2642 | * @todo we should add some sanitation here. |
| 2643 | 2643 | */ |
| 2644 | - public function update( $new_instance, $old_instance ) { |
|
| 2644 | + public function update($new_instance, $old_instance) { |
|
| 2645 | 2645 | |
| 2646 | 2646 | //save the widget |
| 2647 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2647 | + $instance = array_merge((array)$old_instance, (array)$new_instance); |
|
| 2648 | 2648 | |
| 2649 | 2649 | // set widget instance |
| 2650 | 2650 | $this->instance = $instance; |
| 2651 | 2651 | |
| 2652 | - if ( empty( $this->arguments ) ) { |
|
| 2652 | + if (empty($this->arguments)) { |
|
| 2653 | 2653 | $this->get_arguments(); |
| 2654 | 2654 | } |
| 2655 | 2655 | |
| 2656 | 2656 | // check for checkboxes |
| 2657 | - if ( ! empty( $this->arguments ) ) { |
|
| 2658 | - foreach ( $this->arguments as $argument ) { |
|
| 2659 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2660 | - $instance[ $argument['name'] ] = '0'; |
|
| 2657 | + if (!empty($this->arguments)) { |
|
| 2658 | + foreach ($this->arguments as $argument) { |
|
| 2659 | + if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) { |
|
| 2660 | + $instance[$argument['name']] = '0'; |
|
| 2661 | 2661 | } |
| 2662 | 2662 | } |
| 2663 | 2663 | } |
@@ -2675,7 +2675,7 @@ discard block |
||
| 2675 | 2675 | */ |
| 2676 | 2676 | public function is_block_content_call() { |
| 2677 | 2677 | $result = false; |
| 2678 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2678 | + if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') { |
|
| 2679 | 2679 | $result = true; |
| 2680 | 2680 | } |
| 2681 | 2681 | |
@@ -198,9 +198,9 @@ discard block |
||
| 198 | 198 | unset($param['default']); |
| 199 | 199 | } |
| 200 | 200 | $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
| 201 | - }elseif($param['type'] == 'select'){ |
|
| 201 | + } elseif($param['type'] == 'select'){ |
|
| 202 | 202 | $param['value'] = isset($val['options']) ? $val['options'] : array(); |
| 203 | - }else{ |
|
| 203 | + } else{ |
|
| 204 | 204 | $param['value'] = isset($val['default']) ? $val['default'] : ''; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | <?php |
| 659 | 659 | if(! empty( $insert_shortcode_function )){ |
| 660 | 660 | echo $insert_shortcode_function; |
| 661 | - }else{ |
|
| 661 | + } else{ |
|
| 662 | 662 | |
| 663 | 663 | /** |
| 664 | 664 | * Function for super duper insert shortcode. |
@@ -1414,8 +1414,7 @@ discard block |
||
| 1414 | 1414 | $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
| 1415 | 1415 | if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
| 1416 | 1416 | // don't set default for an empty checkbox |
| 1417 | - } |
|
| 1418 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1417 | + } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1419 | 1418 | $argument_values[ $key ] = $args['default']; |
| 1420 | 1419 | } |
| 1421 | 1420 | } |
@@ -1544,11 +1543,11 @@ discard block |
||
| 1544 | 1543 | $fa_type = ''; |
| 1545 | 1544 | if(substr( $icon, 0, 7 ) === "fas fa-"){ |
| 1546 | 1545 | $fa_type = 'solid'; |
| 1547 | - }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
| 1546 | + } elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
| 1548 | 1547 | $fa_type = 'regular'; |
| 1549 | - }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
| 1548 | + } elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
| 1550 | 1549 | $fa_type = 'brands'; |
| 1551 | - }else{ |
|
| 1550 | + } else{ |
|
| 1552 | 1551 | $icon = "'".$icon."'"; |
| 1553 | 1552 | } |
| 1554 | 1553 | |
@@ -1571,7 +1570,7 @@ discard block |
||
| 1571 | 1570 | if(isset($args['group'])){ |
| 1572 | 1571 | $temp_arguments[$args['group']][$key] = $args; |
| 1573 | 1572 | $add_sections = true; |
| 1574 | - }else{ |
|
| 1573 | + } else{ |
|
| 1575 | 1574 | $temp_arguments[$general][$key] = $args; |
| 1576 | 1575 | } |
| 1577 | 1576 | } |
@@ -1813,7 +1812,7 @@ discard block |
||
| 1813 | 1812 | ?> |
| 1814 | 1813 | el(wp.components.PanelBody, { |
| 1815 | 1814 | title: '<?php esc_attr_e($key); ?>', |
| 1816 | - initialOpen: <?php if($panel_count){echo "false";}else{echo "true";}?> |
|
| 1815 | + initialOpen: <?php if($panel_count){echo "false";} else{echo "true";}?> |
|
| 1817 | 1816 | }, |
| 1818 | 1817 | <?php |
| 1819 | 1818 | |
@@ -1826,7 +1825,7 @@ discard block |
||
| 1826 | 1825 | $panel_count++; |
| 1827 | 1826 | |
| 1828 | 1827 | } |
| 1829 | - }else{ |
|
| 1828 | + } else{ |
|
| 1830 | 1829 | foreach($this->arguments as $key => $args){ |
| 1831 | 1830 | $this->build_block_arguments($key, $args); |
| 1832 | 1831 | } |
@@ -1843,7 +1842,7 @@ discard block |
||
| 1843 | 1842 | // If the user sets block-output array then build it |
| 1844 | 1843 | if ( ! empty( $this->options['block-output'] ) ) { |
| 1845 | 1844 | $this->block_element( $this->options['block-output'] ); |
| 1846 | - }else{ |
|
| 1845 | + } else{ |
|
| 1847 | 1846 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1848 | 1847 | ?> |
| 1849 | 1848 | el('div', { |
@@ -2380,7 +2379,7 @@ discard block |
||
| 2380 | 2379 | $panel_count++; |
| 2381 | 2380 | |
| 2382 | 2381 | } |
| 2383 | - }else{ |
|
| 2382 | + } else{ |
|
| 2384 | 2383 | foreach ( $arguments as $key => $args ) { |
| 2385 | 2384 | $this->widget_inputs( $args, $instance ); |
| 2386 | 2385 | } |
@@ -12,19 +12,19 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // MUST have WordPress. |
| 15 | -if ( !defined( 'WPINC' ) ) { |
|
| 16 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 15 | +if (!defined('WPINC')) { |
|
| 16 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -if ( !defined( 'WPINV_VERSION' ) ) { |
|
| 20 | - define( 'WPINV_VERSION', '1.0.12' ); |
|
| 19 | +if (!defined('WPINV_VERSION')) { |
|
| 20 | + define('WPINV_VERSION', '1.0.12'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -if ( !defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
| 24 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 23 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
| 24 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php'; |
|
| 27 | +require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php'; |
|
| 28 | 28 | |
| 29 | 29 | function wpinv_run() { |
| 30 | 30 | global $invoicing; |