@@ -17,7 +17,7 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | public function inflectPackageVars($vars) |
| 19 | 19 | { |
| 20 | - $vars['name'] = preg_replace_callback('/(-[a-z])/', function ($matches) { |
|
| 20 | + $vars['name'] = preg_replace_callback('/(-[a-z])/', function($matches) { |
|
| 21 | 21 | return strtoupper($matches[0][1]); |
| 22 | 22 | }, $vars['name']); |
| 23 | 23 | |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | 'library' => 'libraries/{$name}/', |
| 11 | 11 | 'profile' => 'profiles/{$name}/', |
| 12 | 12 | 'drush' => 'drush/{$name}/', |
| 13 | - 'custom-theme' => 'themes/custom/{$name}/', |
|
| 14 | - 'custom-module' => 'modules/custom/{$name}/', |
|
| 13 | + 'custom-theme' => 'themes/custom/{$name}/', |
|
| 14 | + 'custom-module' => 'modules/custom/{$name}/', |
|
| 15 | 15 | ); |
| 16 | 16 | } |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | protected function inflectModuleVars($vars) |
| 37 | 37 | { |
| 38 | - $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
| 39 | - $vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- |
|
| 40 | - $vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module |
|
| 41 | - $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
| 42 | - $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
| 38 | + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
| 39 | + $vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- |
|
| 40 | + $vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module |
|
| 41 | + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
| 42 | + $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
| 43 | 43 | |
| 44 | 44 | return $vars; |
| 45 | 45 | } |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | protected function inflectThemeVars($vars) |
| 54 | 54 | { |
| 55 | - $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
| 56 | - $vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- |
|
| 57 | - $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme |
|
| 58 | - $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
| 59 | - $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
| 55 | + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
| 56 | + $vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- |
|
| 57 | + $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme |
|
| 58 | + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
| 59 | + $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
| 60 | 60 | |
| 61 | 61 | return $vars; |
| 62 | 62 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | private function correctPluginName($vars) |
| 39 | 39 | { |
| 40 | - $camelCasedName = preg_replace_callback('/(-[a-z])/', function ($matches) { |
|
| 40 | + $camelCasedName = preg_replace_callback('/(-[a-z])/', function($matches) { |
|
| 41 | 41 | return strtoupper($matches[0][1]); |
| 42 | 42 | }, $vars['name']); |
| 43 | 43 | |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | } |
| 7 | 7 | } |
| 8 | 8 | if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__ . '/../../../autoload.php'))) { |
| 9 | - die('You must set up the project dependencies, run the following commands:'.PHP_EOL. |
|
| 10 | - 'curl -s http://getcomposer.org/installer | php'.PHP_EOL. |
|
| 11 | - 'php composer.phar install'.PHP_EOL); |
|
| 9 | + die('You must set up the project dependencies, run the following commands:' . PHP_EOL . |
|
| 10 | + 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . |
|
| 11 | + 'php composer.phar install' . PHP_EOL); |
|
| 12 | 12 | } |
| 13 | 13 | return $loader; |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * Bail if we are not in WP. |
| 14 | 14 | */ |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -21,285 +21,285 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A Class to be able to change settings for Font Awesome. |
|
| 26 | - * |
|
| 27 | - * Class WP_Font_Awesome_Settings |
|
| 28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
| 29 | - * @ver 1.0.10 |
|
| 30 | - * @todo decide how to implement textdomain |
|
| 31 | - */ |
|
| 32 | - class WP_Font_Awesome_Settings { |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Class version version. |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - public $version = '1.0.10'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Class textdomain. |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - public $textdomain = 'font-awesome-settings'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Latest version of Font Awesome at time of publish published. |
|
| 50 | - * |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - public $latest = "5.6.1"; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The title. |
|
| 57 | - * |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 60 | - public $name = 'Font Awesome'; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Holds the settings values. |
|
| 64 | - * |
|
| 65 | - * @var array |
|
| 66 | - */ |
|
| 67 | - private $settings; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * WP_Font_Awesome_Settings instance. |
|
| 71 | - * |
|
| 72 | - * @access private |
|
| 73 | - * @since 1.0.0 |
|
| 74 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
| 75 | - */ |
|
| 76 | - private static $instance = null; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Main WP_Font_Awesome_Settings Instance. |
|
| 80 | - * |
|
| 81 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 82 | - * |
|
| 83 | - * @since 1.0.0 |
|
| 84 | - * @static |
|
| 85 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
| 86 | - */ |
|
| 87 | - public static function instance() { |
|
| 88 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 89 | - self::$instance = new WP_Font_Awesome_Settings; |
|
| 90 | - |
|
| 91 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 92 | - |
|
| 93 | - if ( is_admin() ) { |
|
| 94 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 95 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return self::$instance; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Initiate the settings and add the required action hooks. |
|
| 106 | - * |
|
| 107 | - * @since 1.0.8 Settings name wrong - FIXED |
|
| 108 | - */ |
|
| 109 | - public function init() { |
|
| 110 | - $this->settings = $this->get_settings(); |
|
| 111 | - |
|
| 112 | - if ( $this->settings['type'] == 'CSS' ) { |
|
| 113 | - |
|
| 114 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 115 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 119 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - } else { |
|
| 123 | - |
|
| 124 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 125 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 129 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // remove font awesome if set to do so |
|
| 134 | - if ( $this->settings['dequeue'] == '1' ) { |
|
| 135 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Adds the Font Awesome styles. |
|
| 142 | - */ |
|
| 143 | - public function enqueue_style() { |
|
| 144 | - // build url |
|
| 145 | - $url = $this->get_url(); |
|
| 146 | - |
|
| 147 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 148 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 149 | - wp_enqueue_style( 'font-awesome' ); |
|
| 150 | - |
|
| 151 | - if ( $this->settings['shims'] ) { |
|
| 152 | - $url = $this->get_url( true ); |
|
| 153 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 154 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 155 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Adds the Font Awesome JS. |
|
| 161 | - */ |
|
| 162 | - public function enqueue_scripts() { |
|
| 163 | - // build url |
|
| 164 | - $url = $this->get_url(); |
|
| 165 | - |
|
| 166 | - $deregister_function = 'wp'.'_'.'deregister'.'_'.'script'; |
|
| 167 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 168 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 169 | - wp_enqueue_script( 'font-awesome' ); |
|
| 170 | - |
|
| 171 | - if ( $this->settings['shims'] ) { |
|
| 172 | - $url = $this->get_url( true ); |
|
| 173 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 174 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 175 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get the url of the Font Awesome files. |
|
| 181 | - * |
|
| 182 | - * @param bool $shims If this is a shim file or not. |
|
| 183 | - * |
|
| 184 | - * @return string The url to the file. |
|
| 185 | - */ |
|
| 186 | - public function get_url( $shims = false ) { |
|
| 187 | - $script = $shims ? 'v4-shims' : 'all'; |
|
| 188 | - $type = $this->settings['type']; |
|
| 189 | - $version = $this->settings['version']; |
|
| 190 | - |
|
| 191 | - $url = "https://use.fontawesome.com/releases/"; // CDN |
|
| 192 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 193 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
| 194 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
| 195 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 196 | - |
|
| 197 | - return $url; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 202 | - * |
|
| 203 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 204 | - * |
|
| 205 | - * @param $url |
|
| 206 | - * @param $original_url |
|
| 207 | - * @param $_context |
|
| 208 | - * |
|
| 209 | - * @return string The filtered url. |
|
| 210 | - */ |
|
| 211 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 212 | - |
|
| 213 | - if ( $_context == 'display' |
|
| 214 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 215 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 216 | - ) {// it's a font-awesome-url (probably) |
|
| 217 | - |
|
| 218 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 219 | - if ( $this->settings['type'] == 'JS' ) { |
|
| 220 | - if ( $this->settings['js-pseudo'] ) { |
|
| 221 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 222 | - } else { |
|
| 223 | - $url .= "' defer='defer"; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } else { |
|
| 227 | - $url = ''; // removing the url removes the file |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - return $url; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Register the database settings with WordPress. |
|
| 237 | - */ |
|
| 238 | - public function register_settings() { |
|
| 239 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Add the WordPress settings menu item. |
|
| 244 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 245 | - */ |
|
| 246 | - public function menu_item() { |
|
| 247 | - $menu_function = 'add'.'_'.'options'.'_'.'page'; // won't pass theme check if function name present in theme |
|
| 248 | - call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 249 | - $this, |
|
| 250 | - 'settings_page' |
|
| 251 | - ) ); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Get the current Font Awesome output settings. |
|
| 256 | - * |
|
| 257 | - * @return array The array of settings. |
|
| 258 | - */ |
|
| 259 | - public function get_settings() { |
|
| 260 | - |
|
| 261 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 262 | - |
|
| 263 | - $defaults = array( |
|
| 264 | - 'type' => 'CSS', // type to use, CSS or JS |
|
| 265 | - 'version' => '', // latest |
|
| 266 | - 'enqueue' => '', // front and backend |
|
| 267 | - 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
| 268 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 269 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Filter the Font Awesome settings. |
|
| 276 | - * |
|
| 277 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 278 | - */ |
|
| 279 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * The settings page html output. |
|
| 285 | - */ |
|
| 286 | - public function settings_page() { |
|
| 287 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 288 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
| 292 | - if(isset($_REQUEST['force-version-check'])){ |
|
| 293 | - $this->get_latest_version($force_api = true); |
|
| 294 | - } |
|
| 295 | - ?> |
|
| 24 | + /** |
|
| 25 | + * A Class to be able to change settings for Font Awesome. |
|
| 26 | + * |
|
| 27 | + * Class WP_Font_Awesome_Settings |
|
| 28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
| 29 | + * @ver 1.0.10 |
|
| 30 | + * @todo decide how to implement textdomain |
|
| 31 | + */ |
|
| 32 | + class WP_Font_Awesome_Settings { |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Class version version. |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + public $version = '1.0.10'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Class textdomain. |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + public $textdomain = 'font-awesome-settings'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Latest version of Font Awesome at time of publish published. |
|
| 50 | + * |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + public $latest = "5.6.1"; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The title. |
|
| 57 | + * |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | + public $name = 'Font Awesome'; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Holds the settings values. |
|
| 64 | + * |
|
| 65 | + * @var array |
|
| 66 | + */ |
|
| 67 | + private $settings; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * WP_Font_Awesome_Settings instance. |
|
| 71 | + * |
|
| 72 | + * @access private |
|
| 73 | + * @since 1.0.0 |
|
| 74 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
| 75 | + */ |
|
| 76 | + private static $instance = null; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Main WP_Font_Awesome_Settings Instance. |
|
| 80 | + * |
|
| 81 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 82 | + * |
|
| 83 | + * @since 1.0.0 |
|
| 84 | + * @static |
|
| 85 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
| 86 | + */ |
|
| 87 | + public static function instance() { |
|
| 88 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 89 | + self::$instance = new WP_Font_Awesome_Settings; |
|
| 90 | + |
|
| 91 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 92 | + |
|
| 93 | + if ( is_admin() ) { |
|
| 94 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 95 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return self::$instance; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Initiate the settings and add the required action hooks. |
|
| 106 | + * |
|
| 107 | + * @since 1.0.8 Settings name wrong - FIXED |
|
| 108 | + */ |
|
| 109 | + public function init() { |
|
| 110 | + $this->settings = $this->get_settings(); |
|
| 111 | + |
|
| 112 | + if ( $this->settings['type'] == 'CSS' ) { |
|
| 113 | + |
|
| 114 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 115 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 119 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + } else { |
|
| 123 | + |
|
| 124 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 125 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 129 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // remove font awesome if set to do so |
|
| 134 | + if ( $this->settings['dequeue'] == '1' ) { |
|
| 135 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Adds the Font Awesome styles. |
|
| 142 | + */ |
|
| 143 | + public function enqueue_style() { |
|
| 144 | + // build url |
|
| 145 | + $url = $this->get_url(); |
|
| 146 | + |
|
| 147 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 148 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 149 | + wp_enqueue_style( 'font-awesome' ); |
|
| 150 | + |
|
| 151 | + if ( $this->settings['shims'] ) { |
|
| 152 | + $url = $this->get_url( true ); |
|
| 153 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 154 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 155 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Adds the Font Awesome JS. |
|
| 161 | + */ |
|
| 162 | + public function enqueue_scripts() { |
|
| 163 | + // build url |
|
| 164 | + $url = $this->get_url(); |
|
| 165 | + |
|
| 166 | + $deregister_function = 'wp'.'_'.'deregister'.'_'.'script'; |
|
| 167 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 168 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 169 | + wp_enqueue_script( 'font-awesome' ); |
|
| 170 | + |
|
| 171 | + if ( $this->settings['shims'] ) { |
|
| 172 | + $url = $this->get_url( true ); |
|
| 173 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 174 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 175 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get the url of the Font Awesome files. |
|
| 181 | + * |
|
| 182 | + * @param bool $shims If this is a shim file or not. |
|
| 183 | + * |
|
| 184 | + * @return string The url to the file. |
|
| 185 | + */ |
|
| 186 | + public function get_url( $shims = false ) { |
|
| 187 | + $script = $shims ? 'v4-shims' : 'all'; |
|
| 188 | + $type = $this->settings['type']; |
|
| 189 | + $version = $this->settings['version']; |
|
| 190 | + |
|
| 191 | + $url = "https://use.fontawesome.com/releases/"; // CDN |
|
| 192 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 193 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
| 194 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
| 195 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 196 | + |
|
| 197 | + return $url; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 202 | + * |
|
| 203 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 204 | + * |
|
| 205 | + * @param $url |
|
| 206 | + * @param $original_url |
|
| 207 | + * @param $_context |
|
| 208 | + * |
|
| 209 | + * @return string The filtered url. |
|
| 210 | + */ |
|
| 211 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 212 | + |
|
| 213 | + if ( $_context == 'display' |
|
| 214 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 215 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 216 | + ) {// it's a font-awesome-url (probably) |
|
| 217 | + |
|
| 218 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 219 | + if ( $this->settings['type'] == 'JS' ) { |
|
| 220 | + if ( $this->settings['js-pseudo'] ) { |
|
| 221 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 222 | + } else { |
|
| 223 | + $url .= "' defer='defer"; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } else { |
|
| 227 | + $url = ''; // removing the url removes the file |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + return $url; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Register the database settings with WordPress. |
|
| 237 | + */ |
|
| 238 | + public function register_settings() { |
|
| 239 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Add the WordPress settings menu item. |
|
| 244 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 245 | + */ |
|
| 246 | + public function menu_item() { |
|
| 247 | + $menu_function = 'add'.'_'.'options'.'_'.'page'; // won't pass theme check if function name present in theme |
|
| 248 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 249 | + $this, |
|
| 250 | + 'settings_page' |
|
| 251 | + ) ); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Get the current Font Awesome output settings. |
|
| 256 | + * |
|
| 257 | + * @return array The array of settings. |
|
| 258 | + */ |
|
| 259 | + public function get_settings() { |
|
| 260 | + |
|
| 261 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 262 | + |
|
| 263 | + $defaults = array( |
|
| 264 | + 'type' => 'CSS', // type to use, CSS or JS |
|
| 265 | + 'version' => '', // latest |
|
| 266 | + 'enqueue' => '', // front and backend |
|
| 267 | + 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
| 268 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 269 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Filter the Font Awesome settings. |
|
| 276 | + * |
|
| 277 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 278 | + */ |
|
| 279 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * The settings page html output. |
|
| 285 | + */ |
|
| 286 | + public function settings_page() { |
|
| 287 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 288 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
| 292 | + if(isset($_REQUEST['force-version-check'])){ |
|
| 293 | + $this->get_latest_version($force_api = true); |
|
| 294 | + } |
|
| 295 | + ?> |
|
| 296 | 296 | <div class="wrap"> |
| 297 | 297 | <h1><?php echo $this->name; ?></h1> |
| 298 | 298 | <form method="post" action="options.php"> |
| 299 | 299 | <?php |
| 300 | - settings_fields( 'wp-font-awesome-settings' ); |
|
| 301 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 302 | - ?> |
|
| 300 | + settings_fields( 'wp-font-awesome-settings' ); |
|
| 301 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 302 | + ?> |
|
| 303 | 303 | <table class="form-table"> |
| 304 | 304 | <tr valign="top"> |
| 305 | 305 | <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
@@ -396,87 +396,87 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | </table> |
| 398 | 398 | <?php |
| 399 | - submit_button(); |
|
| 400 | - ?> |
|
| 399 | + submit_button(); |
|
| 400 | + ?> |
|
| 401 | 401 | </form> |
| 402 | 402 | |
| 403 | 403 | <div id="wpfas-version"><?php echo $this->version; ?></div> |
| 404 | 404 | </div> |
| 405 | 405 | |
| 406 | 406 | <?php |
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Check a version number is valid and if so return it or else return an empty string. |
|
| 411 | - * |
|
| 412 | - * @param $version string The version number to check. |
|
| 413 | - * @since 1.0.6 |
|
| 414 | - * |
|
| 415 | - * @return string Either a valid version number or an empty string. |
|
| 416 | - */ |
|
| 417 | - public function validate_version_number( $version ) { |
|
| 418 | - |
|
| 419 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 420 | - // valid |
|
| 421 | - } else { |
|
| 422 | - $version = '';// not validated |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return $version; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Get the latest version of Font Awesome. |
|
| 431 | - * |
|
| 432 | - * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
| 433 | - * |
|
| 434 | - * @since 1.0.7 |
|
| 435 | - * @return mixed|string The latest version number found. |
|
| 436 | - */ |
|
| 437 | - public function get_latest_version($force_api = false) { |
|
| 438 | - $latest_version = $this->latest; |
|
| 439 | - |
|
| 440 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 441 | - |
|
| 442 | - if ( $cache === false || $force_api) { // its not set |
|
| 443 | - $api_ver = $this->get_latest_version_from_api(); |
|
| 444 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 445 | - $latest_version = $api_ver; |
|
| 446 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 447 | - } |
|
| 448 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 449 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 450 | - $latest_version = $cache; |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return $latest_version; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Get the latest Font Awesome version from the github API. |
|
| 459 | - * |
|
| 460 | - * @since 1.0.7 |
|
| 461 | - * @return string The latest version number or `0` on API fail. |
|
| 462 | - */ |
|
| 463 | - public function get_latest_version_from_api() { |
|
| 464 | - $version = "0"; |
|
| 465 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 466 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 467 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 468 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 469 | - $version = $api_response['tag_name']; |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - return $version; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Run the class if found. |
|
| 480 | - */ |
|
| 481 | - WP_Font_Awesome_Settings::instance(); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Check a version number is valid and if so return it or else return an empty string. |
|
| 411 | + * |
|
| 412 | + * @param $version string The version number to check. |
|
| 413 | + * @since 1.0.6 |
|
| 414 | + * |
|
| 415 | + * @return string Either a valid version number or an empty string. |
|
| 416 | + */ |
|
| 417 | + public function validate_version_number( $version ) { |
|
| 418 | + |
|
| 419 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 420 | + // valid |
|
| 421 | + } else { |
|
| 422 | + $version = '';// not validated |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return $version; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Get the latest version of Font Awesome. |
|
| 431 | + * |
|
| 432 | + * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
| 433 | + * |
|
| 434 | + * @since 1.0.7 |
|
| 435 | + * @return mixed|string The latest version number found. |
|
| 436 | + */ |
|
| 437 | + public function get_latest_version($force_api = false) { |
|
| 438 | + $latest_version = $this->latest; |
|
| 439 | + |
|
| 440 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 441 | + |
|
| 442 | + if ( $cache === false || $force_api) { // its not set |
|
| 443 | + $api_ver = $this->get_latest_version_from_api(); |
|
| 444 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 445 | + $latest_version = $api_ver; |
|
| 446 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 447 | + } |
|
| 448 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 449 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 450 | + $latest_version = $cache; |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return $latest_version; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Get the latest Font Awesome version from the github API. |
|
| 459 | + * |
|
| 460 | + * @since 1.0.7 |
|
| 461 | + * @return string The latest version number or `0` on API fail. |
|
| 462 | + */ |
|
| 463 | + public function get_latest_version_from_api() { |
|
| 464 | + $version = "0"; |
|
| 465 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 466 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 467 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 468 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 469 | + $version = $api_response['tag_name']; |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + return $version; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Run the class if found. |
|
| 480 | + */ |
|
| 481 | + WP_Font_Awesome_Settings::instance(); |
|
| 482 | 482 | } |
| 483 | 483 | \ No newline at end of file |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * Bail if we are not in WP. |
| 14 | 14 | */ |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if (!defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Only add if the class does not already exist. |
| 21 | 21 | */ |
| 22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
| 22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -85,17 +85,17 @@ discard block |
||
| 85 | 85 | * @return WP_Font_Awesome_Settings - Main instance. |
| 86 | 86 | */ |
| 87 | 87 | public static function instance() { |
| 88 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 88 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
| 89 | 89 | self::$instance = new WP_Font_Awesome_Settings; |
| 90 | 90 | |
| 91 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 91 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
| 92 | 92 | |
| 93 | - if ( is_admin() ) { |
|
| 94 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 95 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 93 | + if (is_admin()) { |
|
| 94 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
| 95 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 98 | + do_action('wp_font_awesome_settings_loaded'); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | return self::$instance; |
@@ -109,30 +109,30 @@ discard block |
||
| 109 | 109 | public function init() { |
| 110 | 110 | $this->settings = $this->get_settings(); |
| 111 | 111 | |
| 112 | - if ( $this->settings['type'] == 'CSS' ) { |
|
| 112 | + if ($this->settings['type'] == 'CSS') { |
|
| 113 | 113 | |
| 114 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 115 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit; |
|
| 114 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
| 115 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); //echo '###';exit; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 119 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 118 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
| 119 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | } else { |
| 123 | 123 | |
| 124 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 125 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit; |
|
| 124 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
| 125 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); //echo '###';exit; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 129 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 128 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
| 129 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // remove font awesome if set to do so |
| 134 | - if ( $this->settings['dequeue'] == '1' ) { |
|
| 135 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 134 | + if ($this->settings['dequeue'] == '1') { |
|
| 135 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | } |
@@ -144,15 +144,15 @@ discard block |
||
| 144 | 144 | // build url |
| 145 | 145 | $url = $this->get_url(); |
| 146 | 146 | |
| 147 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 148 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 149 | - wp_enqueue_style( 'font-awesome' ); |
|
| 147 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
| 148 | + wp_register_style('font-awesome', $url, array(), null); |
|
| 149 | + wp_enqueue_style('font-awesome'); |
|
| 150 | 150 | |
| 151 | - if ( $this->settings['shims'] ) { |
|
| 152 | - $url = $this->get_url( true ); |
|
| 153 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 154 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 155 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
| 151 | + if ($this->settings['shims']) { |
|
| 152 | + $url = $this->get_url(true); |
|
| 153 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
| 154 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
| 155 | + wp_enqueue_style('font-awesome-shims'); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
@@ -163,16 +163,16 @@ discard block |
||
| 163 | 163 | // build url |
| 164 | 164 | $url = $this->get_url(); |
| 165 | 165 | |
| 166 | - $deregister_function = 'wp'.'_'.'deregister'.'_'.'script'; |
|
| 167 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 168 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 169 | - wp_enqueue_script( 'font-awesome' ); |
|
| 166 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
| 167 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
| 168 | + wp_register_script('font-awesome', $url, array(), null); |
|
| 169 | + wp_enqueue_script('font-awesome'); |
|
| 170 | 170 | |
| 171 | - if ( $this->settings['shims'] ) { |
|
| 172 | - $url = $this->get_url( true ); |
|
| 173 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 174 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 175 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
| 171 | + if ($this->settings['shims']) { |
|
| 172 | + $url = $this->get_url(true); |
|
| 173 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
| 174 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
| 175 | + wp_enqueue_script('font-awesome-shims'); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
@@ -183,13 +183,13 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @return string The url to the file. |
| 185 | 185 | */ |
| 186 | - public function get_url( $shims = false ) { |
|
| 186 | + public function get_url($shims = false) { |
|
| 187 | 187 | $script = $shims ? 'v4-shims' : 'all'; |
| 188 | 188 | $type = $this->settings['type']; |
| 189 | 189 | $version = $this->settings['version']; |
| 190 | 190 | |
| 191 | 191 | $url = "https://use.fontawesome.com/releases/"; // CDN |
| 192 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 192 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 193 | 193 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
| 194 | 194 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
| 195 | 195 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -208,16 +208,16 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @return string The filtered url. |
| 210 | 210 | */ |
| 211 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 211 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
| 212 | 212 | |
| 213 | - if ( $_context == 'display' |
|
| 214 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 215 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 213 | + if ($_context == 'display' |
|
| 214 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
| 215 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
| 216 | 216 | ) {// it's a font-awesome-url (probably) |
| 217 | 217 | |
| 218 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 219 | - if ( $this->settings['type'] == 'JS' ) { |
|
| 220 | - if ( $this->settings['js-pseudo'] ) { |
|
| 218 | + if (strstr($url, "wpfas=true") !== false) { |
|
| 219 | + if ($this->settings['type'] == 'JS') { |
|
| 220 | + if ($this->settings['js-pseudo']) { |
|
| 221 | 221 | $url .= "' data-search-pseudo-elements defer='defer"; |
| 222 | 222 | } else { |
| 223 | 223 | $url .= "' defer='defer"; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * Register the database settings with WordPress. |
| 237 | 237 | */ |
| 238 | 238 | public function register_settings() { |
| 239 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 239 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -244,11 +244,11 @@ discard block |
||
| 244 | 244 | * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
| 245 | 245 | */ |
| 246 | 246 | public function menu_item() { |
| 247 | - $menu_function = 'add'.'_'.'options'.'_'.'page'; // won't pass theme check if function name present in theme |
|
| 247 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 248 | 248 | call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
| 249 | 249 | $this, |
| 250 | 250 | 'settings_page' |
| 251 | - ) ); |
|
| 251 | + )); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function get_settings() { |
| 260 | 260 | |
| 261 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 261 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
| 262 | 262 | |
| 263 | 263 | $defaults = array( |
| 264 | 264 | 'type' => 'CSS', // type to use, CSS or JS |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
| 270 | 270 | ); |
| 271 | 271 | |
| 272 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 272 | + $settings = wp_parse_args($db_settings, $defaults); |
|
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | 275 | * Filter the Font Awesome settings. |
| 276 | 276 | * |
| 277 | 277 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
| 278 | 278 | */ |
| 279 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 279 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | * The settings page html output. |
| 285 | 285 | */ |
| 286 | 286 | public function settings_page() { |
| 287 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 288 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 287 | + if (!current_user_can('manage_options')) { |
|
| 288 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
| 292 | - if(isset($_REQUEST['force-version-check'])){ |
|
| 292 | + if (isset($_REQUEST['force-version-check'])) { |
|
| 293 | 293 | $this->get_latest_version($force_api = true); |
| 294 | 294 | } |
| 295 | 295 | ?> |
@@ -297,47 +297,47 @@ discard block |
||
| 297 | 297 | <h1><?php echo $this->name; ?></h1> |
| 298 | 298 | <form method="post" action="options.php"> |
| 299 | 299 | <?php |
| 300 | - settings_fields( 'wp-font-awesome-settings' ); |
|
| 301 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 300 | + settings_fields('wp-font-awesome-settings'); |
|
| 301 | + do_settings_sections('wp-font-awesome-settings'); |
|
| 302 | 302 | ?> |
| 303 | 303 | <table class="form-table"> |
| 304 | 304 | <tr valign="top"> |
| 305 | - <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
| 305 | + <th scope="row"><label for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
| 306 | 306 | <td> |
| 307 | 307 | <select name="wp-font-awesome-settings[type]" id="wpfas-type"> |
| 308 | 308 | <option |
| 309 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
| 310 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
| 309 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
| 310 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
| 311 | 311 | </select> |
| 312 | 312 | </td> |
| 313 | 313 | </tr> |
| 314 | 314 | |
| 315 | 315 | <tr valign="top"> |
| 316 | - <th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
| 316 | + <th scope="row"><label for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
| 317 | 317 | <td> |
| 318 | 318 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
| 319 | 319 | <option |
| 320 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
| 320 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
| 321 | 321 | </option> |
| 322 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
| 322 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
| 323 | 323 | 5.6.0 |
| 324 | 324 | </option> |
| 325 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
| 325 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
| 326 | 326 | 5.5.0 |
| 327 | 327 | </option> |
| 328 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
| 328 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
| 329 | 329 | 5.4.0 |
| 330 | 330 | </option> |
| 331 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
| 331 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
| 332 | 332 | 5.3.0 |
| 333 | 333 | </option> |
| 334 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
| 334 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
| 335 | 335 | 5.2.0 |
| 336 | 336 | </option> |
| 337 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
| 337 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
| 338 | 338 | 5.1.0 |
| 339 | 339 | </option> |
| 340 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
| 340 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
| 341 | 341 | 4.7.1 (CSS only) |
| 342 | 342 | </option> |
| 343 | 343 | </select> |
@@ -345,51 +345,51 @@ discard block |
||
| 345 | 345 | </tr> |
| 346 | 346 | |
| 347 | 347 | <tr valign="top"> |
| 348 | - <th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
| 348 | + <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
| 349 | 349 | <td> |
| 350 | 350 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
| 351 | 351 | <option |
| 352 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
| 352 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
| 353 | 353 | <option |
| 354 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
| 354 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
| 355 | 355 | <option |
| 356 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
| 356 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
| 357 | 357 | </select> |
| 358 | 358 | </td> |
| 359 | 359 | </tr> |
| 360 | 360 | |
| 361 | 361 | <tr valign="top"> |
| 362 | 362 | <th scope="row"><label |
| 363 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label></th> |
|
| 363 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label></th> |
|
| 364 | 364 | <td> |
| 365 | 365 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
| 366 | 366 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
| 367 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
| 368 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
| 367 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
| 368 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
| 369 | 369 | </td> |
| 370 | 370 | </tr> |
| 371 | 371 | |
| 372 | 372 | <tr valign="top"> |
| 373 | 373 | <th scope="row"><label |
| 374 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
| 374 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
| 375 | 375 | </th> |
| 376 | 376 | <td> |
| 377 | 377 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
| 378 | 378 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
| 379 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
| 379 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
| 380 | 380 | id="wpfas-js-pseudo"/> |
| 381 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
| 381 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
| 382 | 382 | </td> |
| 383 | 383 | </tr> |
| 384 | 384 | |
| 385 | 385 | <tr valign="top"> |
| 386 | - <th scope="row"><label for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
| 386 | + <th scope="row"><label for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
| 387 | 387 | <td> |
| 388 | 388 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
| 389 | 389 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
| 390 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
| 390 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
| 391 | 391 | id="wpfas-dequeue"/> |
| 392 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
| 392 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
| 393 | 393 | </td> |
| 394 | 394 | </tr> |
| 395 | 395 | |
@@ -414,12 +414,12 @@ discard block |
||
| 414 | 414 | * |
| 415 | 415 | * @return string Either a valid version number or an empty string. |
| 416 | 416 | */ |
| 417 | - public function validate_version_number( $version ) { |
|
| 417 | + public function validate_version_number($version) { |
|
| 418 | 418 | |
| 419 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 419 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
| 420 | 420 | // valid |
| 421 | 421 | } else { |
| 422 | - $version = '';// not validated |
|
| 422 | + $version = ''; // not validated |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | return $version; |
@@ -437,16 +437,16 @@ discard block |
||
| 437 | 437 | public function get_latest_version($force_api = false) { |
| 438 | 438 | $latest_version = $this->latest; |
| 439 | 439 | |
| 440 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 440 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
| 441 | 441 | |
| 442 | - if ( $cache === false || $force_api) { // its not set |
|
| 442 | + if ($cache === false || $force_api) { // its not set |
|
| 443 | 443 | $api_ver = $this->get_latest_version_from_api(); |
| 444 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 444 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
| 445 | 445 | $latest_version = $api_ver; |
| 446 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 446 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
| 447 | 447 | } |
| 448 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 449 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 448 | + } elseif ($this->validate_version_number($cache)) { |
|
| 449 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
| 450 | 450 | $latest_version = $cache; |
| 451 | 451 | } |
| 452 | 452 | } |
@@ -462,10 +462,10 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | public function get_latest_version_from_api() { |
| 464 | 464 | $version = "0"; |
| 465 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 466 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 467 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 468 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 465 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
| 466 | + if (!is_wp_error($response) && is_array($response)) { |
|
| 467 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
| 468 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
| 469 | 469 | $version = $api_response['tag_name']; |
| 470 | 470 | } |
| 471 | 471 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @param string $id |
| 269 | 269 | * @param string $search_for_id |
| 270 | 270 | * |
| 271 | - * @return mixed |
|
| 271 | + * @return string |
|
| 272 | 272 | */ |
| 273 | 273 | public static function shortcode_button( $id = '', $search_for_id = '' ) { |
| 274 | 274 | ob_start(); |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * Makes SD work with the siteOrigin page builder. |
| 299 | 299 | * |
| 300 | 300 | * @since 1.0.6 |
| 301 | - * @return mixed |
|
| 301 | + * @return string |
|
| 302 | 302 | */ |
| 303 | 303 | public static function siteorigin_js() { |
| 304 | 304 | ob_start(); |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | /** |
| 858 | 858 | * Gets some CSS for the widgets screen. |
| 859 | 859 | * |
| 860 | - * @return mixed |
|
| 860 | + * @return string |
|
| 861 | 861 | */ |
| 862 | 862 | public function widget_css() { |
| 863 | 863 | ob_start(); |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | /** |
| 898 | 898 | * Gets some JS for the widgets screen. |
| 899 | 899 | * |
| 900 | - * @return mixed |
|
| 900 | + * @return string |
|
| 901 | 901 | */ |
| 902 | 902 | public function widget_js() { |
| 903 | 903 | ob_start(); |
@@ -1347,7 +1347,7 @@ discard block |
||
| 1347 | 1347 | * |
| 1348 | 1348 | * @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. |
| 1349 | 1349 | * @since 1.0.9 Save numbers as numbers and not strings. |
| 1350 | - * @return mixed |
|
| 1350 | + * @return string |
|
| 1351 | 1351 | */ |
| 1352 | 1352 | public function block() { |
| 1353 | 1353 | ob_start(); |
@@ -1,149 +1,149 @@ 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 | - * @ver 1.0.12 |
|
| 28 | - */ |
|
| 29 | - class WP_Super_Duper extends WP_Widget { |
|
| 30 | - |
|
| 31 | - public $version = "1.0.12"; |
|
| 32 | - public $block_code; |
|
| 33 | - public $options; |
|
| 34 | - public $base_id; |
|
| 35 | - public $arguments = array(); |
|
| 36 | - public $instance = array(); |
|
| 37 | - private $class_name; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Take the array options and use them to build. |
|
| 41 | - */ |
|
| 42 | - public function __construct( $options ) { |
|
| 43 | - global $sd_widgets; |
|
| 44 | - |
|
| 45 | - $sd_widgets[ $options['base_id'] ] = array( |
|
| 46 | - 'name' => $options['name'], |
|
| 47 | - 'class_name' => $options['class_name'] |
|
| 48 | - ); |
|
| 49 | - $this->base_id = $options['base_id']; |
|
| 50 | - // lets filter the options before we do anything |
|
| 51 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 52 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 53 | - $options = $this->add_name_from_key( $options ); |
|
| 54 | - $this->options = $options; |
|
| 55 | - |
|
| 56 | - $this->base_id = $options['base_id']; |
|
| 57 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 58 | - |
|
| 59 | - // init parent |
|
| 60 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 61 | - |
|
| 62 | - if ( isset( $options['class_name'] ) ) { |
|
| 63 | - // register widget |
|
| 64 | - $this->class_name = $options['class_name']; |
|
| 65 | - |
|
| 66 | - // register shortcode |
|
| 67 | - $this->register_shortcode(); |
|
| 68 | - |
|
| 69 | - // register block |
|
| 70 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // add the CSS and JS we need ONCE |
|
| 74 | - global $sd_widget_scripts; |
|
| 75 | - |
|
| 76 | - if ( ! $sd_widget_scripts ) { |
|
| 77 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 78 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 79 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 80 | - |
|
| 81 | - $sd_widget_scripts = true; |
|
| 82 | - |
|
| 83 | - // add shortcode insert button once |
|
| 84 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 85 | - if ( $this->is_preview() ) { |
|
| 86 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 87 | - // this makes the insert button work for elementor |
|
| 88 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 89 | - $this, |
|
| 90 | - 'shortcode_insert_button_script' |
|
| 91 | - ) ); // for elementor |
|
| 92 | - } |
|
| 93 | - // this makes the insert button work for cornerstone |
|
| 94 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
| 95 | - |
|
| 96 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 97 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 98 | - |
|
| 99 | - // add generator text to admin head |
|
| 100 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
| 108 | - */ |
|
| 109 | - public static function maybe_cornerstone_builder(){ |
|
| 110 | - if(did_action('cornerstone_before_boot_app')){ |
|
| 111 | - self::shortcode_insert_button_script(); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * A function to ge the shortcode builder picker html. |
|
| 117 | - * |
|
| 118 | - * @param string $editor_id |
|
| 119 | - * |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public static function get_picker( $editor_id = '' ) { |
|
| 123 | - |
|
| 124 | - ob_start(); |
|
| 125 | - if ( isset( $_POST['editor_id'] ) ) { |
|
| 126 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 127 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 128 | - $editor_id = 'main_content_content_vb_tiny_mce'; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - global $sd_widgets; |
|
| 132 | - ?> |
|
| 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 | + * @ver 1.0.12 |
|
| 28 | + */ |
|
| 29 | + class WP_Super_Duper extends WP_Widget { |
|
| 30 | + |
|
| 31 | + public $version = "1.0.12"; |
|
| 32 | + public $block_code; |
|
| 33 | + public $options; |
|
| 34 | + public $base_id; |
|
| 35 | + public $arguments = array(); |
|
| 36 | + public $instance = array(); |
|
| 37 | + private $class_name; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Take the array options and use them to build. |
|
| 41 | + */ |
|
| 42 | + public function __construct( $options ) { |
|
| 43 | + global $sd_widgets; |
|
| 44 | + |
|
| 45 | + $sd_widgets[ $options['base_id'] ] = array( |
|
| 46 | + 'name' => $options['name'], |
|
| 47 | + 'class_name' => $options['class_name'] |
|
| 48 | + ); |
|
| 49 | + $this->base_id = $options['base_id']; |
|
| 50 | + // lets filter the options before we do anything |
|
| 51 | + $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 52 | + $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 53 | + $options = $this->add_name_from_key( $options ); |
|
| 54 | + $this->options = $options; |
|
| 55 | + |
|
| 56 | + $this->base_id = $options['base_id']; |
|
| 57 | + $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 58 | + |
|
| 59 | + // init parent |
|
| 60 | + parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 61 | + |
|
| 62 | + if ( isset( $options['class_name'] ) ) { |
|
| 63 | + // register widget |
|
| 64 | + $this->class_name = $options['class_name']; |
|
| 65 | + |
|
| 66 | + // register shortcode |
|
| 67 | + $this->register_shortcode(); |
|
| 68 | + |
|
| 69 | + // register block |
|
| 70 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // add the CSS and JS we need ONCE |
|
| 74 | + global $sd_widget_scripts; |
|
| 75 | + |
|
| 76 | + if ( ! $sd_widget_scripts ) { |
|
| 77 | + wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 78 | + wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 79 | + wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 80 | + |
|
| 81 | + $sd_widget_scripts = true; |
|
| 82 | + |
|
| 83 | + // add shortcode insert button once |
|
| 84 | + add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 85 | + if ( $this->is_preview() ) { |
|
| 86 | + add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 87 | + // this makes the insert button work for elementor |
|
| 88 | + add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 89 | + $this, |
|
| 90 | + 'shortcode_insert_button_script' |
|
| 91 | + ) ); // for elementor |
|
| 92 | + } |
|
| 93 | + // this makes the insert button work for cornerstone |
|
| 94 | + add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
| 95 | + |
|
| 96 | + add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 97 | + add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 98 | + |
|
| 99 | + // add generator text to admin head |
|
| 100 | + add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
| 108 | + */ |
|
| 109 | + public static function maybe_cornerstone_builder(){ |
|
| 110 | + if(did_action('cornerstone_before_boot_app')){ |
|
| 111 | + self::shortcode_insert_button_script(); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * A function to ge the shortcode builder picker html. |
|
| 117 | + * |
|
| 118 | + * @param string $editor_id |
|
| 119 | + * |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public static function get_picker( $editor_id = '' ) { |
|
| 123 | + |
|
| 124 | + ob_start(); |
|
| 125 | + if ( isset( $_POST['editor_id'] ) ) { |
|
| 126 | + $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 127 | + } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 128 | + $editor_id = 'main_content_content_vb_tiny_mce'; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + global $sd_widgets; |
|
| 132 | + ?> |
|
| 133 | 133 | |
| 134 | 134 | <div class="sd-shortcode-left-wrap"> |
| 135 | 135 | <?php |
| 136 | - asort( $sd_widgets ); |
|
| 137 | - if ( ! empty( $sd_widgets ) ) { |
|
| 138 | - echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
| 139 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 140 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 141 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 142 | - } |
|
| 143 | - echo "</select>"; |
|
| 144 | - |
|
| 145 | - } |
|
| 146 | - ?> |
|
| 136 | + asort( $sd_widgets ); |
|
| 137 | + if ( ! empty( $sd_widgets ) ) { |
|
| 138 | + echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
| 139 | + echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 140 | + foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 141 | + echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 142 | + } |
|
| 143 | + echo "</select>"; |
|
| 144 | + |
|
| 145 | + } |
|
| 146 | + ?> |
|
| 147 | 147 | <div class="sd-shortcode-settings"></div> |
| 148 | 148 | |
| 149 | 149 | </div> |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | <?php if ( $editor_id != '' ) { ?> |
| 155 | 155 | <button class="button sd-insert-shortcode-button" |
| 156 | 156 | onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
| 157 | - echo "'" . $editor_id . "'"; |
|
| 158 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 157 | + echo "'" . $editor_id . "'"; |
|
| 158 | + } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 159 | 159 | <?php } ?> |
| 160 | 160 | <button class="button" |
| 161 | 161 | onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
@@ -163,129 +163,129 @@ discard block |
||
| 163 | 163 | </div> |
| 164 | 164 | <?php |
| 165 | 165 | |
| 166 | - $html = ob_get_clean(); |
|
| 167 | - |
|
| 168 | - if ( wp_doing_ajax() ) { |
|
| 169 | - echo $html; |
|
| 170 | - $should_die = true; |
|
| 171 | - |
|
| 172 | - // some builder get the editor via ajax so we should not die on those ocasions |
|
| 173 | - $dont_die = array( |
|
| 174 | - 'parent_tag',// WP Bakery |
|
| 175 | - 'avia_request' // enfold |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - foreach ( $dont_die as $request ) { |
|
| 179 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 180 | - $should_die = false; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ( $should_die ) { |
|
| 185 | - wp_die(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - } else { |
|
| 189 | - return $html; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - return ''; |
|
| 193 | - |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Output the version in the admin header. |
|
| 198 | - */ |
|
| 199 | - public function generator() { |
|
| 200 | - echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Get widget settings. |
|
| 205 | - * |
|
| 206 | - * @since 1.0.0 |
|
| 207 | - */ |
|
| 208 | - public static function get_widget_settings() { |
|
| 209 | - global $sd_widgets; |
|
| 210 | - |
|
| 211 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 212 | - if ( ! $shortcode ) { |
|
| 213 | - wp_die(); |
|
| 214 | - } |
|
| 215 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 216 | - if ( ! $widget_args ) { |
|
| 217 | - wp_die(); |
|
| 218 | - } |
|
| 219 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 220 | - if ( ! $class_name ) { |
|
| 221 | - wp_die(); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // invoke an instance method |
|
| 225 | - $widget = new $class_name; |
|
| 226 | - |
|
| 227 | - ob_start(); |
|
| 228 | - $widget->form( array() ); |
|
| 229 | - $form = ob_get_clean(); |
|
| 230 | - echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 231 | - echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 232 | - echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 233 | - ?> |
|
| 166 | + $html = ob_get_clean(); |
|
| 167 | + |
|
| 168 | + if ( wp_doing_ajax() ) { |
|
| 169 | + echo $html; |
|
| 170 | + $should_die = true; |
|
| 171 | + |
|
| 172 | + // some builder get the editor via ajax so we should not die on those ocasions |
|
| 173 | + $dont_die = array( |
|
| 174 | + 'parent_tag',// WP Bakery |
|
| 175 | + 'avia_request' // enfold |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + foreach ( $dont_die as $request ) { |
|
| 179 | + if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 180 | + $should_die = false; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ( $should_die ) { |
|
| 185 | + wp_die(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + } else { |
|
| 189 | + return $html; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + return ''; |
|
| 193 | + |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Output the version in the admin header. |
|
| 198 | + */ |
|
| 199 | + public function generator() { |
|
| 200 | + echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Get widget settings. |
|
| 205 | + * |
|
| 206 | + * @since 1.0.0 |
|
| 207 | + */ |
|
| 208 | + public static function get_widget_settings() { |
|
| 209 | + global $sd_widgets; |
|
| 210 | + |
|
| 211 | + $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 212 | + if ( ! $shortcode ) { |
|
| 213 | + wp_die(); |
|
| 214 | + } |
|
| 215 | + $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 216 | + if ( ! $widget_args ) { |
|
| 217 | + wp_die(); |
|
| 218 | + } |
|
| 219 | + $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 220 | + if ( ! $class_name ) { |
|
| 221 | + wp_die(); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // invoke an instance method |
|
| 225 | + $widget = new $class_name; |
|
| 226 | + |
|
| 227 | + ob_start(); |
|
| 228 | + $widget->form( array() ); |
|
| 229 | + $form = ob_get_clean(); |
|
| 230 | + echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 231 | + echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 232 | + echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 233 | + ?> |
|
| 234 | 234 | <?php |
| 235 | - wp_die(); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 240 | - * |
|
| 241 | - * @since 1.0.0 |
|
| 242 | - * |
|
| 243 | - * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 244 | - * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 245 | - */ |
|
| 246 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 247 | - global $sd_widgets, $shortcode_insert_button_once; |
|
| 248 | - if ( $shortcode_insert_button_once ) { |
|
| 249 | - return; |
|
| 250 | - } |
|
| 251 | - add_thickbox(); |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Cornerstone makes us play dirty tricks :/ |
|
| 256 | - * 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. |
|
| 257 | - */ |
|
| 258 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 259 | - echo '<span id="insert-media-button">'; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - echo self::shortcode_button( 'this', 'true' ); |
|
| 263 | - |
|
| 264 | - // see opening note |
|
| 265 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 266 | - echo '</span>'; // end #insert-media-button |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 270 | - $shortcode_insert_button_once = true; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Gets the shortcode insert button html. |
|
| 275 | - * |
|
| 276 | - * @param string $id |
|
| 277 | - * @param string $search_for_id |
|
| 278 | - * |
|
| 279 | - * @return mixed |
|
| 280 | - */ |
|
| 281 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 282 | - ob_start(); |
|
| 283 | - ?> |
|
| 235 | + wp_die(); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 240 | + * |
|
| 241 | + * @since 1.0.0 |
|
| 242 | + * |
|
| 243 | + * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 244 | + * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 245 | + */ |
|
| 246 | + public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 247 | + global $sd_widgets, $shortcode_insert_button_once; |
|
| 248 | + if ( $shortcode_insert_button_once ) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 251 | + add_thickbox(); |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Cornerstone makes us play dirty tricks :/ |
|
| 256 | + * 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. |
|
| 257 | + */ |
|
| 258 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 259 | + echo '<span id="insert-media-button">'; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + echo self::shortcode_button( 'this', 'true' ); |
|
| 263 | + |
|
| 264 | + // see opening note |
|
| 265 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 266 | + echo '</span>'; // end #insert-media-button |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 270 | + $shortcode_insert_button_once = true; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Gets the shortcode insert button html. |
|
| 275 | + * |
|
| 276 | + * @param string $id |
|
| 277 | + * @param string $search_for_id |
|
| 278 | + * |
|
| 279 | + * @return mixed |
|
| 280 | + */ |
|
| 281 | + public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 282 | + ob_start(); |
|
| 283 | + ?> |
|
| 284 | 284 | <span class="sd-lable-shortcode-inserter"> |
| 285 | 285 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
| 286 | - if ( $search_for_id ) { |
|
| 287 | - echo "," . $search_for_id; |
|
| 288 | - } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
| 286 | + if ( $search_for_id ) { |
|
| 287 | + echo "," . $search_for_id; |
|
| 288 | + } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
| 289 | 289 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
| 290 | 290 | <span style="vertical-align: middle;line-height: 18px;font-size: 20px;" |
| 291 | 291 | class="dashicons dashicons-screenoptions"></span> |
@@ -296,21 +296,21 @@ discard block |
||
| 296 | 296 | </span> |
| 297 | 297 | |
| 298 | 298 | <?php |
| 299 | - $html = ob_get_clean(); |
|
| 300 | - |
|
| 301 | - // remove line breaks so we can use it in js |
|
| 302 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Makes SD work with the siteOrigin page builder. |
|
| 307 | - * |
|
| 308 | - * @since 1.0.6 |
|
| 309 | - * @return mixed |
|
| 310 | - */ |
|
| 311 | - public static function siteorigin_js() { |
|
| 312 | - ob_start(); |
|
| 313 | - ?> |
|
| 299 | + $html = ob_get_clean(); |
|
| 300 | + |
|
| 301 | + // remove line breaks so we can use it in js |
|
| 302 | + return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Makes SD work with the siteOrigin page builder. |
|
| 307 | + * |
|
| 308 | + * @since 1.0.6 |
|
| 309 | + * @return mixed |
|
| 310 | + */ |
|
| 311 | + public static function siteorigin_js() { |
|
| 312 | + ob_start(); |
|
| 313 | + ?> |
|
| 314 | 314 | <script> |
| 315 | 315 | /** |
| 316 | 316 | * Check a form to see what items shoudl be shown or hidden. |
@@ -388,28 +388,28 @@ discard block |
||
| 388 | 388 | }); |
| 389 | 389 | </script> |
| 390 | 390 | <?php |
| 391 | - $output = ob_get_clean(); |
|
| 391 | + $output = ob_get_clean(); |
|
| 392 | 392 | |
| 393 | - /* |
|
| 393 | + /* |
|
| 394 | 394 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 395 | 395 | */ |
| 396 | 396 | |
| 397 | - return str_replace( array( |
|
| 398 | - '<script>', |
|
| 399 | - '</script>' |
|
| 400 | - ), '', $output ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Output the JS and CSS for the shortcode insert button. |
|
| 405 | - * |
|
| 406 | - * @since 1.0.6 |
|
| 407 | - * |
|
| 408 | - * @param string $editor_id |
|
| 409 | - * @param string $insert_shortcode_function |
|
| 410 | - */ |
|
| 411 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 412 | - ?> |
|
| 397 | + return str_replace( array( |
|
| 398 | + '<script>', |
|
| 399 | + '</script>' |
|
| 400 | + ), '', $output ); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Output the JS and CSS for the shortcode insert button. |
|
| 405 | + * |
|
| 406 | + * @since 1.0.6 |
|
| 407 | + * |
|
| 408 | + * @param string $editor_id |
|
| 409 | + * @param string $insert_shortcode_function |
|
| 410 | + */ |
|
| 411 | + public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 412 | + ?> |
|
| 413 | 413 | <style> |
| 414 | 414 | .sd-shortcode-left-wrap { |
| 415 | 415 | float: left; |
@@ -528,22 +528,22 @@ discard block |
||
| 528 | 528 | } |
| 529 | 529 | </style> |
| 530 | 530 | <?php |
| 531 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 532 | - echo "<script>" . self::siteorigin_js() . "</script>"; |
|
| 533 | - } |
|
| 534 | - ?> |
|
| 531 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 532 | + echo "<script>" . self::siteorigin_js() . "</script>"; |
|
| 533 | + } |
|
| 534 | + ?> |
|
| 535 | 535 | <script> |
| 536 | 536 | <?php |
| 537 | - if(! empty( $insert_shortcode_function )){ |
|
| 538 | - echo $insert_shortcode_function; |
|
| 539 | - }else{ |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Function for super duper insert shortcode. |
|
| 543 | - * |
|
| 544 | - * @since 1.0.0 |
|
| 545 | - */ |
|
| 546 | - ?> |
|
| 537 | + if(! empty( $insert_shortcode_function )){ |
|
| 538 | + echo $insert_shortcode_function; |
|
| 539 | + }else{ |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Function for super duper insert shortcode. |
|
| 543 | + * |
|
| 544 | + * @since 1.0.0 |
|
| 545 | + */ |
|
| 546 | + ?> |
|
| 547 | 547 | function sd_insert_shortcode($editor_id) { |
| 548 | 548 | $shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val(); |
| 549 | 549 | if ($shortcode) { |
@@ -551,14 +551,14 @@ discard block |
||
| 551 | 551 | if (!$editor_id) { |
| 552 | 552 | |
| 553 | 553 | <?php |
| 554 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 555 | - echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
| 556 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 557 | - echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
| 558 | - } else { |
|
| 559 | - echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
| 560 | - } |
|
| 561 | - ?> |
|
| 554 | + if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 555 | + echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
| 556 | + } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 557 | + echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
| 558 | + } else { |
|
| 559 | + echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
| 560 | + } |
|
| 561 | + ?> |
|
| 562 | 562 | } else { |
| 563 | 563 | $editor_id = '#' + $editor_id; |
| 564 | 564 | } |
@@ -868,16 +868,16 @@ discard block |
||
| 868 | 868 | |
| 869 | 869 | </script> |
| 870 | 870 | <?php |
| 871 | - } |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * Gets some CSS for the widgets screen. |
|
| 875 | - * |
|
| 876 | - * @return mixed |
|
| 877 | - */ |
|
| 878 | - public function widget_css() { |
|
| 879 | - ob_start(); |
|
| 880 | - ?> |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * Gets some CSS for the widgets screen. |
|
| 875 | + * |
|
| 876 | + * @return mixed |
|
| 877 | + */ |
|
| 878 | + public function widget_css() { |
|
| 879 | + ob_start(); |
|
| 880 | + ?> |
|
| 881 | 881 | <style> |
| 882 | 882 | .sd-advanced-setting { |
| 883 | 883 | display: none; |
@@ -898,26 +898,26 @@ discard block |
||
| 898 | 898 | } |
| 899 | 899 | </style> |
| 900 | 900 | <?php |
| 901 | - $output = ob_get_clean(); |
|
| 901 | + $output = ob_get_clean(); |
|
| 902 | 902 | |
| 903 | - /* |
|
| 903 | + /* |
|
| 904 | 904 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 905 | 905 | */ |
| 906 | 906 | |
| 907 | - return str_replace( array( |
|
| 908 | - '<style>', |
|
| 909 | - '</style>' |
|
| 910 | - ), '', $output ); |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * Gets some JS for the widgets screen. |
|
| 915 | - * |
|
| 916 | - * @return mixed |
|
| 917 | - */ |
|
| 918 | - public function widget_js() { |
|
| 919 | - ob_start(); |
|
| 920 | - ?> |
|
| 907 | + return str_replace( array( |
|
| 908 | + '<style>', |
|
| 909 | + '</style>' |
|
| 910 | + ), '', $output ); |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * Gets some JS for the widgets screen. |
|
| 915 | + * |
|
| 916 | + * @return mixed |
|
| 917 | + */ |
|
| 918 | + public function widget_js() { |
|
| 919 | + ob_start(); |
|
| 920 | + ?> |
|
| 921 | 921 | <script> |
| 922 | 922 | |
| 923 | 923 | /** |
@@ -1072,307 +1072,307 @@ discard block |
||
| 1072 | 1072 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
| 1073 | 1073 | </script> |
| 1074 | 1074 | <?php |
| 1075 | - $output = ob_get_clean(); |
|
| 1075 | + $output = ob_get_clean(); |
|
| 1076 | 1076 | |
| 1077 | - /* |
|
| 1077 | + /* |
|
| 1078 | 1078 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1079 | 1079 | */ |
| 1080 | 1080 | |
| 1081 | - return str_replace( array( |
|
| 1082 | - '<script>', |
|
| 1083 | - '</script>' |
|
| 1084 | - ), '', $output ); |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - |
|
| 1088 | - /** |
|
| 1089 | - * Set the name from the argument key. |
|
| 1090 | - * |
|
| 1091 | - * @param $options |
|
| 1092 | - * |
|
| 1093 | - * @return mixed |
|
| 1094 | - */ |
|
| 1095 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 1096 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 1097 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 1098 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 1099 | - } |
|
| 1100 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1101 | - foreach ( $options as $key => $val ) { |
|
| 1102 | - $options[ $key ]['name'] = $key; |
|
| 1103 | - } |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - return $options; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - /** |
|
| 1110 | - * Register the parent shortcode. |
|
| 1111 | - * |
|
| 1112 | - * @since 1.0.0 |
|
| 1113 | - */ |
|
| 1114 | - public function register_shortcode() { |
|
| 1115 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1116 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1120 | - * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 1121 | - * |
|
| 1122 | - * @since 1.0.0 |
|
| 1123 | - */ |
|
| 1124 | - public static function render_shortcode() { |
|
| 1125 | - |
|
| 1126 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1127 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1128 | - wp_die(); |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - // we might need the $post value here so lets set it. |
|
| 1132 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1133 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1134 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1135 | - global $post; |
|
| 1136 | - $post = $post_obj; |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1141 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1142 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1143 | - $attributes = ''; |
|
| 1144 | - if ( ! empty( $attributes_array ) ) { |
|
| 1145 | - foreach ( $attributes_array as $key => $value ) { |
|
| 1146 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1147 | - } |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 1151 | - |
|
| 1152 | - echo do_shortcode( $shortcode ); |
|
| 1153 | - |
|
| 1154 | - } |
|
| 1155 | - wp_die(); |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * Output the shortcode. |
|
| 1160 | - * |
|
| 1161 | - * @param array $args |
|
| 1162 | - * @param string $content |
|
| 1163 | - * |
|
| 1164 | - * @return string |
|
| 1165 | - */ |
|
| 1166 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1167 | - $args = self::argument_values( $args ); |
|
| 1168 | - |
|
| 1169 | - // add extra argument so we know its a output to gutenberg |
|
| 1170 | - //$args |
|
| 1171 | - $args = $this->string_to_bool( $args ); |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1175 | - |
|
| 1176 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 1177 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 1178 | - |
|
| 1179 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1180 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 1181 | - |
|
| 1182 | - $shortcode_args = array(); |
|
| 1183 | - $output = ''; |
|
| 1184 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1185 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1186 | - if ( $main_content && ! $no_wrap ) { |
|
| 1187 | - // wrap the shortcode in a dive with the same class as the widget |
|
| 1188 | - $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
| 1189 | - if ( ! empty( $args['title'] ) ) { |
|
| 1190 | - // if its a shortcode and there is a title try to grab the title wrappers |
|
| 1191 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1192 | - if ( empty( $instance ) ) { |
|
| 1193 | - global $wp_registered_sidebars; |
|
| 1194 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1195 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1196 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1197 | - $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 1198 | - $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 1199 | - break; |
|
| 1200 | - } |
|
| 1201 | - } |
|
| 1202 | - } |
|
| 1203 | - } |
|
| 1204 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1205 | - } |
|
| 1206 | - $output .= $main_content; |
|
| 1207 | - $output .= '</div>'; |
|
| 1208 | - } elseif ( $main_content && $no_wrap ) { |
|
| 1209 | - $output .= $main_content; |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - // if preview show a placeholder if empty |
|
| 1213 | - if ( $this->is_preview() && $output == '' ) { |
|
| 1214 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - return $output; |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - /** |
|
| 1221 | - * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
| 1222 | - * |
|
| 1223 | - * @param string $name |
|
| 1224 | - * |
|
| 1225 | - * @return string |
|
| 1226 | - */ |
|
| 1227 | - public function preview_placeholder_text( $name = '' ) { |
|
| 1228 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - /** |
|
| 1232 | - * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 1233 | - * |
|
| 1234 | - * @param $options |
|
| 1235 | - * |
|
| 1236 | - * @return mixed |
|
| 1237 | - */ |
|
| 1238 | - public function string_to_bool( $options ) { |
|
| 1239 | - // convert bool strings to booleans |
|
| 1240 | - foreach ( $options as $key => $val ) { |
|
| 1241 | - if ( $val == 'false' ) { |
|
| 1242 | - $options[ $key ] = false; |
|
| 1243 | - } elseif ( $val == 'true' ) { |
|
| 1244 | - $options[ $key ] = true; |
|
| 1245 | - } |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - return $options; |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - /** |
|
| 1252 | - * Get the argument values that are also filterable. |
|
| 1253 | - * |
|
| 1254 | - * @param $instance |
|
| 1255 | - * |
|
| 1256 | - * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
| 1257 | - * |
|
| 1258 | - * @return array |
|
| 1259 | - */ |
|
| 1260 | - public function argument_values( $instance ) { |
|
| 1261 | - $argument_values = array(); |
|
| 1262 | - |
|
| 1263 | - // set widget instance |
|
| 1264 | - $this->instance = $instance; |
|
| 1265 | - |
|
| 1266 | - if ( empty( $this->arguments ) ) { |
|
| 1267 | - $this->arguments = $this->get_arguments(); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - if ( ! empty( $this->arguments ) ) { |
|
| 1271 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1272 | - // set the input name from the key |
|
| 1273 | - $args['name'] = $key; |
|
| 1274 | - // |
|
| 1275 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1276 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
| 1277 | - // don't set default for an empty checkbox |
|
| 1278 | - } |
|
| 1279 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1280 | - $argument_values[ $key ] = $args['default']; |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - return $argument_values; |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - /** |
|
| 1289 | - * Set arguments in super duper. |
|
| 1290 | - * |
|
| 1291 | - * @since 1.0.0 |
|
| 1292 | - * |
|
| 1293 | - * @return array Set arguments. |
|
| 1294 | - */ |
|
| 1295 | - public function set_arguments() { |
|
| 1296 | - return $this->arguments; |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - /** |
|
| 1300 | - * Get arguments in super duper. |
|
| 1301 | - * |
|
| 1302 | - * @since 1.0.0 |
|
| 1303 | - * |
|
| 1304 | - * @return array Get arguments. |
|
| 1305 | - */ |
|
| 1306 | - public function get_arguments() { |
|
| 1307 | - if ( empty( $this->arguments ) ) { |
|
| 1308 | - $this->arguments = $this->set_arguments(); |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1312 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1313 | - |
|
| 1314 | - return $this->arguments; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 1319 | - * |
|
| 1320 | - * @param array $args |
|
| 1321 | - * @param array $widget_args |
|
| 1322 | - * @param string $content |
|
| 1323 | - */ |
|
| 1324 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1325 | - |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 1330 | - */ |
|
| 1331 | - public function register_block() { |
|
| 1332 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1333 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1334 | - |
|
| 1335 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1336 | - |
|
| 1337 | - } |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - /** |
|
| 1341 | - * Check if we need to show advanced options. |
|
| 1342 | - * |
|
| 1343 | - * @return bool |
|
| 1344 | - */ |
|
| 1345 | - public function block_show_advanced() { |
|
| 1346 | - |
|
| 1347 | - $show = false; |
|
| 1348 | - $arguments = $this->arguments; |
|
| 1349 | - |
|
| 1350 | - if ( empty( $arguments ) ) { |
|
| 1351 | - $arguments = $this->get_arguments(); |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - if ( ! empty( $arguments ) ) { |
|
| 1355 | - foreach ( $arguments as $argument ) { |
|
| 1356 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1357 | - $show = true; |
|
| 1358 | - } |
|
| 1359 | - } |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - return $show; |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - |
|
| 1366 | - /** |
|
| 1367 | - * Output the JS for building the dynamic Guntenberg block. |
|
| 1368 | - * |
|
| 1369 | - * @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. |
|
| 1370 | - * @since 1.0.9 Save numbers as numbers and not strings. |
|
| 1371 | - * @return mixed |
|
| 1372 | - */ |
|
| 1373 | - public function block() { |
|
| 1374 | - ob_start(); |
|
| 1375 | - ?> |
|
| 1081 | + return str_replace( array( |
|
| 1082 | + '<script>', |
|
| 1083 | + '</script>' |
|
| 1084 | + ), '', $output ); |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + |
|
| 1088 | + /** |
|
| 1089 | + * Set the name from the argument key. |
|
| 1090 | + * |
|
| 1091 | + * @param $options |
|
| 1092 | + * |
|
| 1093 | + * @return mixed |
|
| 1094 | + */ |
|
| 1095 | + private function add_name_from_key( $options, $arguments = false ) { |
|
| 1096 | + if ( ! empty( $options['arguments'] ) ) { |
|
| 1097 | + foreach ( $options['arguments'] as $key => $val ) { |
|
| 1098 | + $options['arguments'][ $key ]['name'] = $key; |
|
| 1099 | + } |
|
| 1100 | + } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1101 | + foreach ( $options as $key => $val ) { |
|
| 1102 | + $options[ $key ]['name'] = $key; |
|
| 1103 | + } |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + return $options; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * Register the parent shortcode. |
|
| 1111 | + * |
|
| 1112 | + * @since 1.0.0 |
|
| 1113 | + */ |
|
| 1114 | + public function register_shortcode() { |
|
| 1115 | + add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1116 | + add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | + * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 1121 | + * |
|
| 1122 | + * @since 1.0.0 |
|
| 1123 | + */ |
|
| 1124 | + public static function render_shortcode() { |
|
| 1125 | + |
|
| 1126 | + check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1127 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1128 | + wp_die(); |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + // we might need the $post value here so lets set it. |
|
| 1132 | + if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1133 | + $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1134 | + if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1135 | + global $post; |
|
| 1136 | + $post = $post_obj; |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1141 | + $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1142 | + $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1143 | + $attributes = ''; |
|
| 1144 | + if ( ! empty( $attributes_array ) ) { |
|
| 1145 | + foreach ( $attributes_array as $key => $value ) { |
|
| 1146 | + $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1147 | + } |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 1151 | + |
|
| 1152 | + echo do_shortcode( $shortcode ); |
|
| 1153 | + |
|
| 1154 | + } |
|
| 1155 | + wp_die(); |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * Output the shortcode. |
|
| 1160 | + * |
|
| 1161 | + * @param array $args |
|
| 1162 | + * @param string $content |
|
| 1163 | + * |
|
| 1164 | + * @return string |
|
| 1165 | + */ |
|
| 1166 | + public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1167 | + $args = self::argument_values( $args ); |
|
| 1168 | + |
|
| 1169 | + // add extra argument so we know its a output to gutenberg |
|
| 1170 | + //$args |
|
| 1171 | + $args = $this->string_to_bool( $args ); |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1175 | + |
|
| 1176 | + $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 1177 | + $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 1178 | + |
|
| 1179 | + $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1180 | + $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 1181 | + |
|
| 1182 | + $shortcode_args = array(); |
|
| 1183 | + $output = ''; |
|
| 1184 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1185 | + $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1186 | + if ( $main_content && ! $no_wrap ) { |
|
| 1187 | + // wrap the shortcode in a dive with the same class as the widget |
|
| 1188 | + $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
| 1189 | + if ( ! empty( $args['title'] ) ) { |
|
| 1190 | + // if its a shortcode and there is a title try to grab the title wrappers |
|
| 1191 | + $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1192 | + if ( empty( $instance ) ) { |
|
| 1193 | + global $wp_registered_sidebars; |
|
| 1194 | + if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1195 | + foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1196 | + if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1197 | + $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 1198 | + $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 1199 | + break; |
|
| 1200 | + } |
|
| 1201 | + } |
|
| 1202 | + } |
|
| 1203 | + } |
|
| 1204 | + $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1205 | + } |
|
| 1206 | + $output .= $main_content; |
|
| 1207 | + $output .= '</div>'; |
|
| 1208 | + } elseif ( $main_content && $no_wrap ) { |
|
| 1209 | + $output .= $main_content; |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + // if preview show a placeholder if empty |
|
| 1213 | + if ( $this->is_preview() && $output == '' ) { |
|
| 1214 | + $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + return $output; |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + /** |
|
| 1221 | + * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
| 1222 | + * |
|
| 1223 | + * @param string $name |
|
| 1224 | + * |
|
| 1225 | + * @return string |
|
| 1226 | + */ |
|
| 1227 | + public function preview_placeholder_text( $name = '' ) { |
|
| 1228 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + /** |
|
| 1232 | + * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 1233 | + * |
|
| 1234 | + * @param $options |
|
| 1235 | + * |
|
| 1236 | + * @return mixed |
|
| 1237 | + */ |
|
| 1238 | + public function string_to_bool( $options ) { |
|
| 1239 | + // convert bool strings to booleans |
|
| 1240 | + foreach ( $options as $key => $val ) { |
|
| 1241 | + if ( $val == 'false' ) { |
|
| 1242 | + $options[ $key ] = false; |
|
| 1243 | + } elseif ( $val == 'true' ) { |
|
| 1244 | + $options[ $key ] = true; |
|
| 1245 | + } |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + return $options; |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + /** |
|
| 1252 | + * Get the argument values that are also filterable. |
|
| 1253 | + * |
|
| 1254 | + * @param $instance |
|
| 1255 | + * |
|
| 1256 | + * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
| 1257 | + * |
|
| 1258 | + * @return array |
|
| 1259 | + */ |
|
| 1260 | + public function argument_values( $instance ) { |
|
| 1261 | + $argument_values = array(); |
|
| 1262 | + |
|
| 1263 | + // set widget instance |
|
| 1264 | + $this->instance = $instance; |
|
| 1265 | + |
|
| 1266 | + if ( empty( $this->arguments ) ) { |
|
| 1267 | + $this->arguments = $this->get_arguments(); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + if ( ! empty( $this->arguments ) ) { |
|
| 1271 | + foreach ( $this->arguments as $key => $args ) { |
|
| 1272 | + // set the input name from the key |
|
| 1273 | + $args['name'] = $key; |
|
| 1274 | + // |
|
| 1275 | + $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1276 | + if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
| 1277 | + // don't set default for an empty checkbox |
|
| 1278 | + } |
|
| 1279 | + elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1280 | + $argument_values[ $key ] = $args['default']; |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + return $argument_values; |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + /** |
|
| 1289 | + * Set arguments in super duper. |
|
| 1290 | + * |
|
| 1291 | + * @since 1.0.0 |
|
| 1292 | + * |
|
| 1293 | + * @return array Set arguments. |
|
| 1294 | + */ |
|
| 1295 | + public function set_arguments() { |
|
| 1296 | + return $this->arguments; |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + /** |
|
| 1300 | + * Get arguments in super duper. |
|
| 1301 | + * |
|
| 1302 | + * @since 1.0.0 |
|
| 1303 | + * |
|
| 1304 | + * @return array Get arguments. |
|
| 1305 | + */ |
|
| 1306 | + public function get_arguments() { |
|
| 1307 | + if ( empty( $this->arguments ) ) { |
|
| 1308 | + $this->arguments = $this->set_arguments(); |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1312 | + $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1313 | + |
|
| 1314 | + return $this->arguments; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 1319 | + * |
|
| 1320 | + * @param array $args |
|
| 1321 | + * @param array $widget_args |
|
| 1322 | + * @param string $content |
|
| 1323 | + */ |
|
| 1324 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1325 | + |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 1330 | + */ |
|
| 1331 | + public function register_block() { |
|
| 1332 | + wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1333 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1334 | + |
|
| 1335 | + wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1336 | + |
|
| 1337 | + } |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + /** |
|
| 1341 | + * Check if we need to show advanced options. |
|
| 1342 | + * |
|
| 1343 | + * @return bool |
|
| 1344 | + */ |
|
| 1345 | + public function block_show_advanced() { |
|
| 1346 | + |
|
| 1347 | + $show = false; |
|
| 1348 | + $arguments = $this->arguments; |
|
| 1349 | + |
|
| 1350 | + if ( empty( $arguments ) ) { |
|
| 1351 | + $arguments = $this->get_arguments(); |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + if ( ! empty( $arguments ) ) { |
|
| 1355 | + foreach ( $arguments as $argument ) { |
|
| 1356 | + if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1357 | + $show = true; |
|
| 1358 | + } |
|
| 1359 | + } |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + return $show; |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + |
|
| 1366 | + /** |
|
| 1367 | + * Output the JS for building the dynamic Guntenberg block. |
|
| 1368 | + * |
|
| 1369 | + * @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. |
|
| 1370 | + * @since 1.0.9 Save numbers as numbers and not strings. |
|
| 1371 | + * @return mixed |
|
| 1372 | + */ |
|
| 1373 | + public function block() { |
|
| 1374 | + ob_start(); |
|
| 1375 | + ?> |
|
| 1376 | 1376 | <script> |
| 1377 | 1377 | /** |
| 1378 | 1378 | * BLOCK: Basic |
@@ -1411,76 +1411,76 @@ discard block |
||
| 1411 | 1411 | 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/. |
| 1412 | 1412 | 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. |
| 1413 | 1413 | <?php if ( isset( $this->options['block-keywords'] ) ) { |
| 1414 | - echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 1415 | - }?> |
|
| 1414 | + echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 1415 | + }?> |
|
| 1416 | 1416 | |
| 1417 | 1417 | <?php |
| 1418 | 1418 | |
| 1419 | - $show_advanced = $this->block_show_advanced(); |
|
| 1420 | - |
|
| 1421 | - $show_alignment = false; |
|
| 1422 | - |
|
| 1423 | - if ( ! empty( $this->arguments ) ) { |
|
| 1424 | - echo "attributes : {"; |
|
| 1425 | - |
|
| 1426 | - if ( $show_advanced ) { |
|
| 1427 | - echo "show_advanced: {"; |
|
| 1428 | - echo " type: 'boolean',"; |
|
| 1429 | - echo " default: false,"; |
|
| 1430 | - echo "},"; |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - // block wrap element |
|
| 1434 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1435 | - echo "block_wrap: {"; |
|
| 1436 | - echo " type: 'string',"; |
|
| 1437 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1438 | - echo "},"; |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - |
|
| 1442 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1443 | - |
|
| 1444 | - // set if we should show alignment |
|
| 1445 | - if ( $key == 'alignment' ) { |
|
| 1446 | - $show_alignment = true; |
|
| 1447 | - } |
|
| 1448 | - |
|
| 1449 | - $extra = ''; |
|
| 1450 | - |
|
| 1451 | - if ( $args['type'] == 'checkbox' ) { |
|
| 1452 | - $type = 'boolean'; |
|
| 1453 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1454 | - } elseif ( $args['type'] == 'number' ) { |
|
| 1455 | - $type = 'number'; |
|
| 1456 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1457 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1458 | - $type = 'array'; |
|
| 1459 | - if ( is_array( $args['default'] ) ) { |
|
| 1460 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1461 | - } else { |
|
| 1462 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1463 | - } |
|
| 1464 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1465 | - $type = 'array'; |
|
| 1466 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1467 | - } else { |
|
| 1468 | - $type = 'string'; |
|
| 1469 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1470 | - } |
|
| 1471 | - echo $key . " : {"; |
|
| 1472 | - echo "type : '$type',"; |
|
| 1473 | - echo "default : $default,"; |
|
| 1474 | - echo "},"; |
|
| 1475 | - } |
|
| 1476 | - |
|
| 1477 | - echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 1478 | - |
|
| 1479 | - echo "},"; |
|
| 1480 | - |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - ?> |
|
| 1419 | + $show_advanced = $this->block_show_advanced(); |
|
| 1420 | + |
|
| 1421 | + $show_alignment = false; |
|
| 1422 | + |
|
| 1423 | + if ( ! empty( $this->arguments ) ) { |
|
| 1424 | + echo "attributes : {"; |
|
| 1425 | + |
|
| 1426 | + if ( $show_advanced ) { |
|
| 1427 | + echo "show_advanced: {"; |
|
| 1428 | + echo " type: 'boolean',"; |
|
| 1429 | + echo " default: false,"; |
|
| 1430 | + echo "},"; |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + // block wrap element |
|
| 1434 | + if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1435 | + echo "block_wrap: {"; |
|
| 1436 | + echo " type: 'string',"; |
|
| 1437 | + echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1438 | + echo "},"; |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + |
|
| 1442 | + foreach ( $this->arguments as $key => $args ) { |
|
| 1443 | + |
|
| 1444 | + // set if we should show alignment |
|
| 1445 | + if ( $key == 'alignment' ) { |
|
| 1446 | + $show_alignment = true; |
|
| 1447 | + } |
|
| 1448 | + |
|
| 1449 | + $extra = ''; |
|
| 1450 | + |
|
| 1451 | + if ( $args['type'] == 'checkbox' ) { |
|
| 1452 | + $type = 'boolean'; |
|
| 1453 | + $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1454 | + } elseif ( $args['type'] == 'number' ) { |
|
| 1455 | + $type = 'number'; |
|
| 1456 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1457 | + } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1458 | + $type = 'array'; |
|
| 1459 | + if ( is_array( $args['default'] ) ) { |
|
| 1460 | + $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1461 | + } else { |
|
| 1462 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1463 | + } |
|
| 1464 | + } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1465 | + $type = 'array'; |
|
| 1466 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1467 | + } else { |
|
| 1468 | + $type = 'string'; |
|
| 1469 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1470 | + } |
|
| 1471 | + echo $key . " : {"; |
|
| 1472 | + echo "type : '$type',"; |
|
| 1473 | + echo "default : $default,"; |
|
| 1474 | + echo "},"; |
|
| 1475 | + } |
|
| 1476 | + |
|
| 1477 | + echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 1478 | + |
|
| 1479 | + echo "},"; |
|
| 1480 | + |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + ?> |
|
| 1484 | 1484 | |
| 1485 | 1485 | // The "edit" property must be a valid function. |
| 1486 | 1486 | edit: function (props) { |
@@ -1499,8 +1499,8 @@ discard block |
||
| 1499 | 1499 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
| 1500 | 1500 | 'attributes': props.attributes, |
| 1501 | 1501 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
| 1502 | - echo $post->ID; |
|
| 1503 | - }?>, |
|
| 1502 | + echo $post->ID; |
|
| 1503 | + }?>, |
|
| 1504 | 1504 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
| 1505 | 1505 | }; |
| 1506 | 1506 | |
@@ -1547,10 +1547,10 @@ discard block |
||
| 1547 | 1547 | |
| 1548 | 1548 | <?php |
| 1549 | 1549 | |
| 1550 | - if(! empty( $this->arguments )){ |
|
| 1550 | + if(! empty( $this->arguments )){ |
|
| 1551 | 1551 | |
| 1552 | - if ( $show_advanced ) { |
|
| 1553 | - ?> |
|
| 1552 | + if ( $show_advanced ) { |
|
| 1553 | + ?> |
|
| 1554 | 1554 | el( |
| 1555 | 1555 | wp.components.ToggleControl, |
| 1556 | 1556 | { |
@@ -1563,73 +1563,73 @@ discard block |
||
| 1563 | 1563 | ), |
| 1564 | 1564 | <?php |
| 1565 | 1565 | |
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - foreach($this->arguments as $key => $args){ |
|
| 1569 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 1570 | - $options = ''; |
|
| 1571 | - $extra = ''; |
|
| 1572 | - $require = ''; |
|
| 1573 | - $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 1574 | - $value = "props.attributes.$key"; |
|
| 1575 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1576 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 1577 | - $type = 'TextControl'; |
|
| 1578 | - // Save numbers as numbers and not strings |
|
| 1579 | - if ( $args['type'] == 'number' ) { |
|
| 1580 | - $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
| 1581 | - } |
|
| 1582 | - } |
|
| 1566 | + } |
|
| 1567 | + |
|
| 1568 | + foreach($this->arguments as $key => $args){ |
|
| 1569 | + $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 1570 | + $options = ''; |
|
| 1571 | + $extra = ''; |
|
| 1572 | + $require = ''; |
|
| 1573 | + $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 1574 | + $value = "props.attributes.$key"; |
|
| 1575 | + $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1576 | + if ( in_array( $args['type'], $text_type ) ) { |
|
| 1577 | + $type = 'TextControl'; |
|
| 1578 | + // Save numbers as numbers and not strings |
|
| 1579 | + if ( $args['type'] == 'number' ) { |
|
| 1580 | + $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
| 1581 | + } |
|
| 1582 | + } |
|
| 1583 | 1583 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we may have to add our own https://github.com/WordPress/gutenberg/issues/14378 |
| 1584 | 1584 | // $type = 'ColorPicker'; |
| 1585 | 1585 | // } |
| 1586 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 1587 | - $type = 'CheckboxControl'; |
|
| 1588 | - $extra .= "checked: props.attributes.$key,"; |
|
| 1589 | - $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 1590 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1591 | - $type = 'SelectControl'; |
|
| 1592 | - if ( ! empty( $args['options'] ) ) { |
|
| 1593 | - $options .= "options : ["; |
|
| 1594 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1595 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1596 | - } |
|
| 1597 | - $options .= "],"; |
|
| 1598 | - } |
|
| 1599 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1600 | - $extra .= ' multiple: true, '; |
|
| 1601 | - //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
| 1602 | - //$value = "['edit', 'delete']"; |
|
| 1603 | - } |
|
| 1604 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 1605 | - $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 1606 | - } else { |
|
| 1607 | - continue;// if we have not implemented the control then don't break the JS. |
|
| 1608 | - } |
|
| 1609 | - |
|
| 1610 | - // add show only if advanced |
|
| 1611 | - if ( ! empty( $args['advanced'] ) ) { |
|
| 1612 | - echo "props.attributes.show_advanced && "; |
|
| 1613 | - } |
|
| 1614 | - // add setting require if defined |
|
| 1615 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 1616 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1617 | - } |
|
| 1618 | - ?> |
|
| 1586 | + elseif ( $args['type'] == 'checkbox' ) { |
|
| 1587 | + $type = 'CheckboxControl'; |
|
| 1588 | + $extra .= "checked: props.attributes.$key,"; |
|
| 1589 | + $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 1590 | + } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1591 | + $type = 'SelectControl'; |
|
| 1592 | + if ( ! empty( $args['options'] ) ) { |
|
| 1593 | + $options .= "options : ["; |
|
| 1594 | + foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1595 | + $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1596 | + } |
|
| 1597 | + $options .= "],"; |
|
| 1598 | + } |
|
| 1599 | + if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1600 | + $extra .= ' multiple: true, '; |
|
| 1601 | + //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
| 1602 | + //$value = "['edit', 'delete']"; |
|
| 1603 | + } |
|
| 1604 | + } elseif ( $args['type'] == 'alignment' ) { |
|
| 1605 | + $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 1606 | + } else { |
|
| 1607 | + continue;// if we have not implemented the control then don't break the JS. |
|
| 1608 | + } |
|
| 1609 | + |
|
| 1610 | + // add show only if advanced |
|
| 1611 | + if ( ! empty( $args['advanced'] ) ) { |
|
| 1612 | + echo "props.attributes.show_advanced && "; |
|
| 1613 | + } |
|
| 1614 | + // add setting require if defined |
|
| 1615 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 1616 | + echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1617 | + } |
|
| 1618 | + ?> |
|
| 1619 | 1619 | el( |
| 1620 | 1620 | wp.components.<?php echo esc_attr( $type );?>, |
| 1621 | 1621 | { |
| 1622 | 1622 | label: '<?php echo esc_attr( $args['title'] );?>', |
| 1623 | 1623 | help: '<?php if ( isset( $args['desc'] ) ) { |
| 1624 | - echo esc_attr( $args['desc'] ); |
|
| 1625 | - }?>', |
|
| 1624 | + echo esc_attr( $args['desc'] ); |
|
| 1625 | + }?>', |
|
| 1626 | 1626 | value: <?php echo $value;?>, |
| 1627 | 1627 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
| 1628 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1629 | - }?> |
|
| 1628 | + echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1629 | + }?> |
|
| 1630 | 1630 | <?php if ( ! empty( $args['placeholder'] ) ) { |
| 1631 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1632 | - }?> |
|
| 1631 | + echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1632 | + }?> |
|
| 1633 | 1633 | <?php echo $options;?> |
| 1634 | 1634 | <?php echo $extra;?> |
| 1635 | 1635 | <?php echo $custom_attributes;?> |
@@ -1639,27 +1639,27 @@ discard block |
||
| 1639 | 1639 | } |
| 1640 | 1640 | ), |
| 1641 | 1641 | <?php |
| 1642 | - } |
|
| 1643 | - } |
|
| 1644 | - ?> |
|
| 1642 | + } |
|
| 1643 | + } |
|
| 1644 | + ?> |
|
| 1645 | 1645 | |
| 1646 | 1646 | ), |
| 1647 | 1647 | |
| 1648 | 1648 | <?php |
| 1649 | - // If the user sets block-output array then build it |
|
| 1650 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1651 | - $this->block_element( $this->options['block-output'] ); |
|
| 1652 | - }else{ |
|
| 1653 | - // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1654 | - ?> |
|
| 1649 | + // If the user sets block-output array then build it |
|
| 1650 | + if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1651 | + $this->block_element( $this->options['block-output'] ); |
|
| 1652 | + }else{ |
|
| 1653 | + // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1654 | + ?> |
|
| 1655 | 1655 | el('div', { |
| 1656 | 1656 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
| 1657 | 1657 | className: props.className, |
| 1658 | 1658 | style: {'min-height': '30px'} |
| 1659 | 1659 | }) |
| 1660 | 1660 | <?php |
| 1661 | - } |
|
| 1662 | - ?> |
|
| 1661 | + } |
|
| 1662 | + ?> |
|
| 1663 | 1663 | ]; // end return |
| 1664 | 1664 | }, |
| 1665 | 1665 | |
@@ -1676,17 +1676,17 @@ discard block |
||
| 1676 | 1676 | var content = "[<?php echo $this->options['base_id'];?>"; |
| 1677 | 1677 | <?php |
| 1678 | 1678 | |
| 1679 | - if(! empty( $this->arguments )){ |
|
| 1680 | - foreach($this->arguments as $key => $args){ |
|
| 1681 | - ?> |
|
| 1679 | + if(! empty( $this->arguments )){ |
|
| 1680 | + foreach($this->arguments as $key => $args){ |
|
| 1681 | + ?> |
|
| 1682 | 1682 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
| 1683 | 1683 | content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
| 1684 | 1684 | } |
| 1685 | 1685 | <?php |
| 1686 | - } |
|
| 1687 | - } |
|
| 1686 | + } |
|
| 1687 | + } |
|
| 1688 | 1688 | |
| 1689 | - ?> |
|
| 1689 | + ?> |
|
| 1690 | 1690 | content += "]"; |
| 1691 | 1691 | |
| 1692 | 1692 | |
@@ -1715,456 +1715,456 @@ discard block |
||
| 1715 | 1715 | })(); |
| 1716 | 1716 | </script> |
| 1717 | 1717 | <?php |
| 1718 | - $output = ob_get_clean(); |
|
| 1718 | + $output = ob_get_clean(); |
|
| 1719 | 1719 | |
| 1720 | - /* |
|
| 1720 | + /* |
|
| 1721 | 1721 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1722 | 1722 | */ |
| 1723 | 1723 | |
| 1724 | - return str_replace( array( |
|
| 1725 | - '<script>', |
|
| 1726 | - '</script>' |
|
| 1727 | - ), '', $output ); |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * Convert an array of attributes to block string. |
|
| 1732 | - * |
|
| 1733 | - * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 1734 | - * |
|
| 1735 | - * @param $custom_attributes |
|
| 1736 | - * |
|
| 1737 | - * @return string |
|
| 1738 | - */ |
|
| 1739 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 1740 | - $attributes = ''; |
|
| 1741 | - if ( ! empty( $custom_attributes ) ) { |
|
| 1742 | - |
|
| 1743 | - if ( $html ) { |
|
| 1744 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1745 | - $attributes .= " $key='$val' "; |
|
| 1746 | - } |
|
| 1747 | - } else { |
|
| 1748 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1749 | - $attributes .= "'$key': '$val',"; |
|
| 1750 | - } |
|
| 1751 | - } |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - return $attributes; |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - /** |
|
| 1758 | - * A self looping function to create the output for JS block elements. |
|
| 1759 | - * |
|
| 1760 | - * This is what is output in the WP Editor visual view. |
|
| 1761 | - * |
|
| 1762 | - * @param $args |
|
| 1763 | - */ |
|
| 1764 | - public function block_element( $args ) { |
|
| 1765 | - |
|
| 1766 | - |
|
| 1767 | - if ( ! empty( $args ) ) { |
|
| 1768 | - foreach ( $args as $element => $new_args ) { |
|
| 1769 | - |
|
| 1770 | - if ( is_array( $new_args ) ) { // its an element |
|
| 1771 | - |
|
| 1772 | - |
|
| 1773 | - if ( isset( $new_args['element'] ) ) { |
|
| 1774 | - |
|
| 1775 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 1776 | - echo str_replace( array( |
|
| 1777 | - "'+", |
|
| 1778 | - "+'" |
|
| 1779 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 1780 | - unset( $new_args['element_require'] ); |
|
| 1781 | - } |
|
| 1782 | - |
|
| 1783 | - echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 1784 | - |
|
| 1785 | - // get the attributes |
|
| 1786 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1787 | - |
|
| 1788 | - |
|
| 1789 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 1790 | - // do nothing |
|
| 1791 | - } else { |
|
| 1792 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 1793 | - } |
|
| 1794 | - } |
|
| 1795 | - |
|
| 1796 | - echo "},";// end attributes |
|
| 1797 | - |
|
| 1798 | - // get the content |
|
| 1799 | - $first_item = 0; |
|
| 1800 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1801 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 1802 | - |
|
| 1803 | - if ( $new_key === 'content' ) { |
|
| 1804 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
| 1805 | - } |
|
| 1806 | - |
|
| 1807 | - if ( is_array( $new_value ) ) { |
|
| 1808 | - |
|
| 1809 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 1810 | - echo str_replace( array( |
|
| 1811 | - "'+", |
|
| 1812 | - "+'" |
|
| 1813 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 1814 | - unset( $new_value['element_require'] ); |
|
| 1815 | - } |
|
| 1816 | - |
|
| 1817 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 1818 | - $x = 1; |
|
| 1819 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 1820 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1821 | - $x ++; |
|
| 1822 | - } |
|
| 1823 | - } else { |
|
| 1824 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1825 | - } |
|
| 1826 | - } |
|
| 1827 | - $first_item ++; |
|
| 1828 | - } |
|
| 1829 | - } |
|
| 1830 | - |
|
| 1831 | - echo ")";// end content |
|
| 1832 | - |
|
| 1833 | - echo ", \n"; |
|
| 1834 | - |
|
| 1835 | - } |
|
| 1836 | - } else { |
|
| 1837 | - |
|
| 1838 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 1839 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 1840 | - } elseif ( $element == 'style' ) { |
|
| 1841 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 1842 | - } else { |
|
| 1843 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - } |
|
| 1847 | - } |
|
| 1848 | - } |
|
| 1849 | - } |
|
| 1850 | - |
|
| 1851 | - /** |
|
| 1852 | - * Replace block attributes placeholders with the proper naming. |
|
| 1853 | - * |
|
| 1854 | - * @param $string |
|
| 1855 | - * |
|
| 1856 | - * @return mixed |
|
| 1857 | - */ |
|
| 1858 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 1859 | - |
|
| 1860 | - if ( $no_wrap ) { |
|
| 1861 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 1862 | - } else { |
|
| 1863 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 1864 | - } |
|
| 1865 | - |
|
| 1866 | - return $string; |
|
| 1867 | - } |
|
| 1868 | - |
|
| 1869 | - /** |
|
| 1870 | - * Outputs the content of the widget |
|
| 1871 | - * |
|
| 1872 | - * @param array $args |
|
| 1873 | - * @param array $instance |
|
| 1874 | - */ |
|
| 1875 | - public function widget( $args, $instance ) { |
|
| 1876 | - |
|
| 1877 | - // get the filtered values |
|
| 1878 | - $argument_values = $this->argument_values( $instance ); |
|
| 1879 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 1880 | - $output = $this->output( $argument_values, $args ); |
|
| 1881 | - |
|
| 1882 | - if ( $output ) { |
|
| 1883 | - // Before widget |
|
| 1884 | - $before_widget = $args['before_widget']; |
|
| 1885 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 1886 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 1887 | - |
|
| 1888 | - // After widget |
|
| 1889 | - $after_widget = $args['after_widget']; |
|
| 1890 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 1891 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 1892 | - |
|
| 1893 | - echo $before_widget; |
|
| 1894 | - // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 1895 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1896 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 1897 | - } |
|
| 1898 | - echo $this->output_title( $args, $instance ); |
|
| 1899 | - echo $output; |
|
| 1900 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1901 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 1902 | - } |
|
| 1903 | - echo $after_widget; |
|
| 1904 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 1905 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 1906 | - echo $output; |
|
| 1907 | - } |
|
| 1908 | - } |
|
| 1909 | - |
|
| 1910 | - /** |
|
| 1911 | - * Tests if the current output is inside a elementor container. |
|
| 1912 | - * |
|
| 1913 | - * @since 1.0.4 |
|
| 1914 | - * @return bool |
|
| 1915 | - */ |
|
| 1916 | - public function is_elementor_widget_output() { |
|
| 1917 | - $result = false; |
|
| 1918 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 1919 | - $result = true; |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - return $result; |
|
| 1923 | - } |
|
| 1924 | - |
|
| 1925 | - /** |
|
| 1926 | - * Tests if the current output is inside a elementor preview. |
|
| 1927 | - * |
|
| 1928 | - * @since 1.0.4 |
|
| 1929 | - * @return bool |
|
| 1930 | - */ |
|
| 1931 | - public function is_elementor_preview() { |
|
| 1932 | - $result = false; |
|
| 1933 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 1934 | - $result = true; |
|
| 1935 | - } |
|
| 1936 | - |
|
| 1937 | - return $result; |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * Tests if the current output is inside a Divi preview. |
|
| 1942 | - * |
|
| 1943 | - * @since 1.0.6 |
|
| 1944 | - * @return bool |
|
| 1945 | - */ |
|
| 1946 | - public function is_divi_preview() { |
|
| 1947 | - $result = false; |
|
| 1948 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 1949 | - $result = true; |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - return $result; |
|
| 1953 | - } |
|
| 1954 | - |
|
| 1955 | - /** |
|
| 1956 | - * Tests if the current output is inside a Beaver builder preview. |
|
| 1957 | - * |
|
| 1958 | - * @since 1.0.6 |
|
| 1959 | - * @return bool |
|
| 1960 | - */ |
|
| 1961 | - public function is_beaver_preview() { |
|
| 1962 | - $result = false; |
|
| 1963 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 1964 | - $result = true; |
|
| 1965 | - } |
|
| 1966 | - |
|
| 1967 | - return $result; |
|
| 1968 | - } |
|
| 1969 | - |
|
| 1970 | - /** |
|
| 1971 | - * Tests if the current output is inside a siteorigin builder preview. |
|
| 1972 | - * |
|
| 1973 | - * @since 1.0.6 |
|
| 1974 | - * @return bool |
|
| 1975 | - */ |
|
| 1976 | - public function is_siteorigin_preview() { |
|
| 1977 | - $result = false; |
|
| 1978 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 1979 | - $result = true; |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - return $result; |
|
| 1983 | - } |
|
| 1984 | - |
|
| 1985 | - /** |
|
| 1986 | - * Tests if the current output is inside a cornerstone builder preview. |
|
| 1987 | - * |
|
| 1988 | - * @since 1.0.8 |
|
| 1989 | - * @return bool |
|
| 1990 | - */ |
|
| 1991 | - public function is_cornerstone_preview() { |
|
| 1992 | - $result = false; |
|
| 1993 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 1994 | - $result = true; |
|
| 1995 | - } |
|
| 1996 | - |
|
| 1997 | - return $result; |
|
| 1998 | - } |
|
| 1999 | - |
|
| 2000 | - /** |
|
| 2001 | - * General function to check if we are in a preview situation. |
|
| 2002 | - * |
|
| 2003 | - * @since 1.0.6 |
|
| 2004 | - * @return bool |
|
| 2005 | - */ |
|
| 2006 | - public function is_preview() { |
|
| 2007 | - $preview = false; |
|
| 2008 | - if ( $this->is_divi_preview() ) { |
|
| 2009 | - $preview = true; |
|
| 2010 | - } elseif ( $this->is_elementor_preview() ) { |
|
| 2011 | - $preview = true; |
|
| 2012 | - } elseif ( $this->is_beaver_preview() ) { |
|
| 2013 | - $preview = true; |
|
| 2014 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2015 | - $preview = true; |
|
| 2016 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2017 | - $preview = true; |
|
| 2018 | - } |
|
| 2019 | - |
|
| 2020 | - return $preview; |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - /** |
|
| 2024 | - * Output the super title. |
|
| 2025 | - * |
|
| 2026 | - * @param $args |
|
| 2027 | - * @param array $instance |
|
| 2028 | - * |
|
| 2029 | - * @return string |
|
| 2030 | - */ |
|
| 2031 | - public function output_title( $args, $instance = array() ) { |
|
| 2032 | - $output = ''; |
|
| 2033 | - if ( ! empty( $instance['title'] ) ) { |
|
| 2034 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 2035 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2036 | - $output = $args['before_title'] . $title . $args['after_title']; |
|
| 2037 | - } |
|
| 2038 | - |
|
| 2039 | - return $output; |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * Outputs the options form inputs for the widget. |
|
| 2044 | - * |
|
| 2045 | - * @param array $instance The widget options. |
|
| 2046 | - */ |
|
| 2047 | - public function form( $instance ) { |
|
| 2048 | - |
|
| 2049 | - // set widget instance |
|
| 2050 | - $this->instance = $instance; |
|
| 2051 | - |
|
| 2052 | - // set it as a SD widget |
|
| 2053 | - echo $this->widget_advanced_toggle(); |
|
| 2054 | - |
|
| 2055 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2056 | - $arguments = $this->get_arguments(); |
|
| 2057 | - |
|
| 2058 | - if ( is_array( $arguments ) ) { |
|
| 2059 | - foreach ( $arguments as $key => $args ) { |
|
| 2060 | - $this->widget_inputs( $args, $instance ); |
|
| 2061 | - } |
|
| 2062 | - } |
|
| 2063 | - } |
|
| 2064 | - |
|
| 2065 | - /** |
|
| 2066 | - * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 2067 | - * |
|
| 2068 | - * @return string |
|
| 2069 | - */ |
|
| 2070 | - public function widget_advanced_toggle() { |
|
| 2071 | - |
|
| 2072 | - $output = ''; |
|
| 2073 | - if ( $this->block_show_advanced() ) { |
|
| 2074 | - $val = 1; |
|
| 2075 | - } else { |
|
| 2076 | - $val = 0; |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 2080 | - |
|
| 2081 | - return $output; |
|
| 2082 | - } |
|
| 2083 | - |
|
| 2084 | - /** |
|
| 2085 | - * Convert require element. |
|
| 2086 | - * |
|
| 2087 | - * @since 1.0.0 |
|
| 2088 | - * |
|
| 2089 | - * @param string $input Input element. |
|
| 2090 | - * |
|
| 2091 | - * @return string $output |
|
| 2092 | - */ |
|
| 2093 | - public function convert_element_require( $input ) { |
|
| 2094 | - |
|
| 2095 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2096 | - |
|
| 2097 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2098 | - "jQuery(form).find('[data-argument=\"", |
|
| 2099 | - "\"]').find('input,select').val()" |
|
| 2100 | - ), $input ) ); |
|
| 2101 | - |
|
| 2102 | - return $output; |
|
| 2103 | - } |
|
| 2104 | - |
|
| 2105 | - /** |
|
| 2106 | - * Builds the inputs for the widget options. |
|
| 2107 | - * |
|
| 2108 | - * @param $args |
|
| 2109 | - * @param $instance |
|
| 2110 | - */ |
|
| 2111 | - public function widget_inputs( $args, $instance ) { |
|
| 2112 | - |
|
| 2113 | - $class = ""; |
|
| 2114 | - $element_require = ""; |
|
| 2115 | - $custom_attributes = ""; |
|
| 2116 | - |
|
| 2117 | - // get value |
|
| 2118 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2119 | - $value = $instance[ $args['name'] ]; |
|
| 2120 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2121 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2122 | - } else { |
|
| 2123 | - $value = ''; |
|
| 2124 | - } |
|
| 2125 | - |
|
| 2126 | - // get placeholder |
|
| 2127 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 2128 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2129 | - } else { |
|
| 2130 | - $placeholder = ''; |
|
| 2131 | - } |
|
| 2132 | - |
|
| 2133 | - // get if advanced |
|
| 2134 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2135 | - $class .= " sd-advanced-setting "; |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - // element_require |
|
| 2139 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2140 | - $element_require = $args['element_require']; |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - // custom_attributes |
|
| 2144 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2145 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - // before wrapper |
|
| 2149 | - ?> |
|
| 1724 | + return str_replace( array( |
|
| 1725 | + '<script>', |
|
| 1726 | + '</script>' |
|
| 1727 | + ), '', $output ); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * Convert an array of attributes to block string. |
|
| 1732 | + * |
|
| 1733 | + * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 1734 | + * |
|
| 1735 | + * @param $custom_attributes |
|
| 1736 | + * |
|
| 1737 | + * @return string |
|
| 1738 | + */ |
|
| 1739 | + public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 1740 | + $attributes = ''; |
|
| 1741 | + if ( ! empty( $custom_attributes ) ) { |
|
| 1742 | + |
|
| 1743 | + if ( $html ) { |
|
| 1744 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 1745 | + $attributes .= " $key='$val' "; |
|
| 1746 | + } |
|
| 1747 | + } else { |
|
| 1748 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 1749 | + $attributes .= "'$key': '$val',"; |
|
| 1750 | + } |
|
| 1751 | + } |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + return $attributes; |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + /** |
|
| 1758 | + * A self looping function to create the output for JS block elements. |
|
| 1759 | + * |
|
| 1760 | + * This is what is output in the WP Editor visual view. |
|
| 1761 | + * |
|
| 1762 | + * @param $args |
|
| 1763 | + */ |
|
| 1764 | + public function block_element( $args ) { |
|
| 1765 | + |
|
| 1766 | + |
|
| 1767 | + if ( ! empty( $args ) ) { |
|
| 1768 | + foreach ( $args as $element => $new_args ) { |
|
| 1769 | + |
|
| 1770 | + if ( is_array( $new_args ) ) { // its an element |
|
| 1771 | + |
|
| 1772 | + |
|
| 1773 | + if ( isset( $new_args['element'] ) ) { |
|
| 1774 | + |
|
| 1775 | + if ( isset( $new_args['element_require'] ) ) { |
|
| 1776 | + echo str_replace( array( |
|
| 1777 | + "'+", |
|
| 1778 | + "+'" |
|
| 1779 | + ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 1780 | + unset( $new_args['element_require'] ); |
|
| 1781 | + } |
|
| 1782 | + |
|
| 1783 | + echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 1784 | + |
|
| 1785 | + // get the attributes |
|
| 1786 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 1787 | + |
|
| 1788 | + |
|
| 1789 | + if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 1790 | + // do nothing |
|
| 1791 | + } else { |
|
| 1792 | + echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 1793 | + } |
|
| 1794 | + } |
|
| 1795 | + |
|
| 1796 | + echo "},";// end attributes |
|
| 1797 | + |
|
| 1798 | + // get the content |
|
| 1799 | + $first_item = 0; |
|
| 1800 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 1801 | + if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 1802 | + |
|
| 1803 | + if ( $new_key === 'content' ) { |
|
| 1804 | + echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
| 1805 | + } |
|
| 1806 | + |
|
| 1807 | + if ( is_array( $new_value ) ) { |
|
| 1808 | + |
|
| 1809 | + if ( isset( $new_value['element_require'] ) ) { |
|
| 1810 | + echo str_replace( array( |
|
| 1811 | + "'+", |
|
| 1812 | + "+'" |
|
| 1813 | + ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 1814 | + unset( $new_value['element_require'] ); |
|
| 1815 | + } |
|
| 1816 | + |
|
| 1817 | + if ( isset( $new_value['element_repeat'] ) ) { |
|
| 1818 | + $x = 1; |
|
| 1819 | + while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 1820 | + $this->block_element( array( '' => $new_value ) ); |
|
| 1821 | + $x ++; |
|
| 1822 | + } |
|
| 1823 | + } else { |
|
| 1824 | + $this->block_element( array( '' => $new_value ) ); |
|
| 1825 | + } |
|
| 1826 | + } |
|
| 1827 | + $first_item ++; |
|
| 1828 | + } |
|
| 1829 | + } |
|
| 1830 | + |
|
| 1831 | + echo ")";// end content |
|
| 1832 | + |
|
| 1833 | + echo ", \n"; |
|
| 1834 | + |
|
| 1835 | + } |
|
| 1836 | + } else { |
|
| 1837 | + |
|
| 1838 | + if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 1839 | + echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 1840 | + } elseif ( $element == 'style' ) { |
|
| 1841 | + echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 1842 | + } else { |
|
| 1843 | + echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + } |
|
| 1847 | + } |
|
| 1848 | + } |
|
| 1849 | + } |
|
| 1850 | + |
|
| 1851 | + /** |
|
| 1852 | + * Replace block attributes placeholders with the proper naming. |
|
| 1853 | + * |
|
| 1854 | + * @param $string |
|
| 1855 | + * |
|
| 1856 | + * @return mixed |
|
| 1857 | + */ |
|
| 1858 | + public function block_props_replace( $string, $no_wrap = false ) { |
|
| 1859 | + |
|
| 1860 | + if ( $no_wrap ) { |
|
| 1861 | + $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 1862 | + } else { |
|
| 1863 | + $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 1864 | + } |
|
| 1865 | + |
|
| 1866 | + return $string; |
|
| 1867 | + } |
|
| 1868 | + |
|
| 1869 | + /** |
|
| 1870 | + * Outputs the content of the widget |
|
| 1871 | + * |
|
| 1872 | + * @param array $args |
|
| 1873 | + * @param array $instance |
|
| 1874 | + */ |
|
| 1875 | + public function widget( $args, $instance ) { |
|
| 1876 | + |
|
| 1877 | + // get the filtered values |
|
| 1878 | + $argument_values = $this->argument_values( $instance ); |
|
| 1879 | + $argument_values = $this->string_to_bool( $argument_values ); |
|
| 1880 | + $output = $this->output( $argument_values, $args ); |
|
| 1881 | + |
|
| 1882 | + if ( $output ) { |
|
| 1883 | + // Before widget |
|
| 1884 | + $before_widget = $args['before_widget']; |
|
| 1885 | + $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 1886 | + $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 1887 | + |
|
| 1888 | + // After widget |
|
| 1889 | + $after_widget = $args['after_widget']; |
|
| 1890 | + $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 1891 | + $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 1892 | + |
|
| 1893 | + echo $before_widget; |
|
| 1894 | + // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 1895 | + if ( $this->is_elementor_widget_output() ) { |
|
| 1896 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 1897 | + } |
|
| 1898 | + echo $this->output_title( $args, $instance ); |
|
| 1899 | + echo $output; |
|
| 1900 | + if ( $this->is_elementor_widget_output() ) { |
|
| 1901 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 1902 | + } |
|
| 1903 | + echo $after_widget; |
|
| 1904 | + } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 1905 | + $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 1906 | + echo $output; |
|
| 1907 | + } |
|
| 1908 | + } |
|
| 1909 | + |
|
| 1910 | + /** |
|
| 1911 | + * Tests if the current output is inside a elementor container. |
|
| 1912 | + * |
|
| 1913 | + * @since 1.0.4 |
|
| 1914 | + * @return bool |
|
| 1915 | + */ |
|
| 1916 | + public function is_elementor_widget_output() { |
|
| 1917 | + $result = false; |
|
| 1918 | + if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 1919 | + $result = true; |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + return $result; |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * Tests if the current output is inside a elementor preview. |
|
| 1927 | + * |
|
| 1928 | + * @since 1.0.4 |
|
| 1929 | + * @return bool |
|
| 1930 | + */ |
|
| 1931 | + public function is_elementor_preview() { |
|
| 1932 | + $result = false; |
|
| 1933 | + if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 1934 | + $result = true; |
|
| 1935 | + } |
|
| 1936 | + |
|
| 1937 | + return $result; |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * Tests if the current output is inside a Divi preview. |
|
| 1942 | + * |
|
| 1943 | + * @since 1.0.6 |
|
| 1944 | + * @return bool |
|
| 1945 | + */ |
|
| 1946 | + public function is_divi_preview() { |
|
| 1947 | + $result = false; |
|
| 1948 | + if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 1949 | + $result = true; |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + return $result; |
|
| 1953 | + } |
|
| 1954 | + |
|
| 1955 | + /** |
|
| 1956 | + * Tests if the current output is inside a Beaver builder preview. |
|
| 1957 | + * |
|
| 1958 | + * @since 1.0.6 |
|
| 1959 | + * @return bool |
|
| 1960 | + */ |
|
| 1961 | + public function is_beaver_preview() { |
|
| 1962 | + $result = false; |
|
| 1963 | + if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 1964 | + $result = true; |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + return $result; |
|
| 1968 | + } |
|
| 1969 | + |
|
| 1970 | + /** |
|
| 1971 | + * Tests if the current output is inside a siteorigin builder preview. |
|
| 1972 | + * |
|
| 1973 | + * @since 1.0.6 |
|
| 1974 | + * @return bool |
|
| 1975 | + */ |
|
| 1976 | + public function is_siteorigin_preview() { |
|
| 1977 | + $result = false; |
|
| 1978 | + if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 1979 | + $result = true; |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + return $result; |
|
| 1983 | + } |
|
| 1984 | + |
|
| 1985 | + /** |
|
| 1986 | + * Tests if the current output is inside a cornerstone builder preview. |
|
| 1987 | + * |
|
| 1988 | + * @since 1.0.8 |
|
| 1989 | + * @return bool |
|
| 1990 | + */ |
|
| 1991 | + public function is_cornerstone_preview() { |
|
| 1992 | + $result = false; |
|
| 1993 | + if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 1994 | + $result = true; |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + return $result; |
|
| 1998 | + } |
|
| 1999 | + |
|
| 2000 | + /** |
|
| 2001 | + * General function to check if we are in a preview situation. |
|
| 2002 | + * |
|
| 2003 | + * @since 1.0.6 |
|
| 2004 | + * @return bool |
|
| 2005 | + */ |
|
| 2006 | + public function is_preview() { |
|
| 2007 | + $preview = false; |
|
| 2008 | + if ( $this->is_divi_preview() ) { |
|
| 2009 | + $preview = true; |
|
| 2010 | + } elseif ( $this->is_elementor_preview() ) { |
|
| 2011 | + $preview = true; |
|
| 2012 | + } elseif ( $this->is_beaver_preview() ) { |
|
| 2013 | + $preview = true; |
|
| 2014 | + } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2015 | + $preview = true; |
|
| 2016 | + } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2017 | + $preview = true; |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + return $preview; |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + /** |
|
| 2024 | + * Output the super title. |
|
| 2025 | + * |
|
| 2026 | + * @param $args |
|
| 2027 | + * @param array $instance |
|
| 2028 | + * |
|
| 2029 | + * @return string |
|
| 2030 | + */ |
|
| 2031 | + public function output_title( $args, $instance = array() ) { |
|
| 2032 | + $output = ''; |
|
| 2033 | + if ( ! empty( $instance['title'] ) ) { |
|
| 2034 | + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 2035 | + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2036 | + $output = $args['before_title'] . $title . $args['after_title']; |
|
| 2037 | + } |
|
| 2038 | + |
|
| 2039 | + return $output; |
|
| 2040 | + } |
|
| 2041 | + |
|
| 2042 | + /** |
|
| 2043 | + * Outputs the options form inputs for the widget. |
|
| 2044 | + * |
|
| 2045 | + * @param array $instance The widget options. |
|
| 2046 | + */ |
|
| 2047 | + public function form( $instance ) { |
|
| 2048 | + |
|
| 2049 | + // set widget instance |
|
| 2050 | + $this->instance = $instance; |
|
| 2051 | + |
|
| 2052 | + // set it as a SD widget |
|
| 2053 | + echo $this->widget_advanced_toggle(); |
|
| 2054 | + |
|
| 2055 | + echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2056 | + $arguments = $this->get_arguments(); |
|
| 2057 | + |
|
| 2058 | + if ( is_array( $arguments ) ) { |
|
| 2059 | + foreach ( $arguments as $key => $args ) { |
|
| 2060 | + $this->widget_inputs( $args, $instance ); |
|
| 2061 | + } |
|
| 2062 | + } |
|
| 2063 | + } |
|
| 2064 | + |
|
| 2065 | + /** |
|
| 2066 | + * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 2067 | + * |
|
| 2068 | + * @return string |
|
| 2069 | + */ |
|
| 2070 | + public function widget_advanced_toggle() { |
|
| 2071 | + |
|
| 2072 | + $output = ''; |
|
| 2073 | + if ( $this->block_show_advanced() ) { |
|
| 2074 | + $val = 1; |
|
| 2075 | + } else { |
|
| 2076 | + $val = 0; |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 2080 | + |
|
| 2081 | + return $output; |
|
| 2082 | + } |
|
| 2083 | + |
|
| 2084 | + /** |
|
| 2085 | + * Convert require element. |
|
| 2086 | + * |
|
| 2087 | + * @since 1.0.0 |
|
| 2088 | + * |
|
| 2089 | + * @param string $input Input element. |
|
| 2090 | + * |
|
| 2091 | + * @return string $output |
|
| 2092 | + */ |
|
| 2093 | + public function convert_element_require( $input ) { |
|
| 2094 | + |
|
| 2095 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2096 | + |
|
| 2097 | + $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2098 | + "jQuery(form).find('[data-argument=\"", |
|
| 2099 | + "\"]').find('input,select').val()" |
|
| 2100 | + ), $input ) ); |
|
| 2101 | + |
|
| 2102 | + return $output; |
|
| 2103 | + } |
|
| 2104 | + |
|
| 2105 | + /** |
|
| 2106 | + * Builds the inputs for the widget options. |
|
| 2107 | + * |
|
| 2108 | + * @param $args |
|
| 2109 | + * @param $instance |
|
| 2110 | + */ |
|
| 2111 | + public function widget_inputs( $args, $instance ) { |
|
| 2112 | + |
|
| 2113 | + $class = ""; |
|
| 2114 | + $element_require = ""; |
|
| 2115 | + $custom_attributes = ""; |
|
| 2116 | + |
|
| 2117 | + // get value |
|
| 2118 | + if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2119 | + $value = $instance[ $args['name'] ]; |
|
| 2120 | + } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2121 | + $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2122 | + } else { |
|
| 2123 | + $value = ''; |
|
| 2124 | + } |
|
| 2125 | + |
|
| 2126 | + // get placeholder |
|
| 2127 | + if ( ! empty( $args['placeholder'] ) ) { |
|
| 2128 | + $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2129 | + } else { |
|
| 2130 | + $placeholder = ''; |
|
| 2131 | + } |
|
| 2132 | + |
|
| 2133 | + // get if advanced |
|
| 2134 | + if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2135 | + $class .= " sd-advanced-setting "; |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + // element_require |
|
| 2139 | + if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2140 | + $element_require = $args['element_require']; |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + // custom_attributes |
|
| 2144 | + if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2145 | + $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + // before wrapper |
|
| 2149 | + ?> |
|
| 2150 | 2150 | <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
| 2151 | 2151 | data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
| 2152 | 2152 | data-element_require='<?php if ( $element_require ) { |
| 2153 | - echo $this->convert_element_require( $element_require ); |
|
| 2154 | - } ?>' |
|
| 2153 | + echo $this->convert_element_require( $element_require ); |
|
| 2154 | + } ?>' |
|
| 2155 | 2155 | > |
| 2156 | 2156 | <?php |
| 2157 | 2157 | |
| 2158 | - switch ( $args['type'] ) { |
|
| 2159 | - //array('text','password','number','email','tel','url','color') |
|
| 2160 | - case "text": |
|
| 2161 | - case "password": |
|
| 2162 | - case "number": |
|
| 2163 | - case "email": |
|
| 2164 | - case "tel": |
|
| 2165 | - case "url": |
|
| 2166 | - case "color": |
|
| 2167 | - ?> |
|
| 2158 | + switch ( $args['type'] ) { |
|
| 2159 | + //array('text','password','number','email','tel','url','color') |
|
| 2160 | + case "text": |
|
| 2161 | + case "password": |
|
| 2162 | + case "number": |
|
| 2163 | + case "email": |
|
| 2164 | + case "tel": |
|
| 2165 | + case "url": |
|
| 2166 | + case "color": |
|
| 2167 | + ?> |
|
| 2168 | 2168 | <label |
| 2169 | 2169 | 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> |
| 2170 | 2170 | <input <?php echo $placeholder; ?> class="widefat" |
@@ -2175,47 +2175,47 @@ discard block |
||
| 2175 | 2175 | value="<?php echo esc_attr( $value ); ?>"> |
| 2176 | 2176 | <?php |
| 2177 | 2177 | |
| 2178 | - break; |
|
| 2179 | - case "select": |
|
| 2180 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2181 | - if ( $multiple ) { |
|
| 2182 | - if ( empty( $value ) ) { |
|
| 2183 | - $value = array(); |
|
| 2184 | - } |
|
| 2185 | - } |
|
| 2186 | - ?> |
|
| 2178 | + break; |
|
| 2179 | + case "select": |
|
| 2180 | + $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2181 | + if ( $multiple ) { |
|
| 2182 | + if ( empty( $value ) ) { |
|
| 2183 | + $value = array(); |
|
| 2184 | + } |
|
| 2185 | + } |
|
| 2186 | + ?> |
|
| 2187 | 2187 | <label |
| 2188 | 2188 | 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> |
| 2189 | 2189 | <select <?php echo $placeholder; ?> class="widefat" |
| 2190 | 2190 | <?php echo $custom_attributes; ?> |
| 2191 | 2191 | id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 2192 | 2192 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
| 2193 | - if ( $multiple ) { |
|
| 2194 | - echo "[]"; |
|
| 2195 | - } ?>" |
|
| 2193 | + if ( $multiple ) { |
|
| 2194 | + echo "[]"; |
|
| 2195 | + } ?>" |
|
| 2196 | 2196 | <?php if ( $multiple ) { |
| 2197 | - echo "multiple"; |
|
| 2198 | - } //@todo not implemented yet due to gutenberg not supporting it |
|
| 2199 | - ?> |
|
| 2197 | + echo "multiple"; |
|
| 2198 | + } //@todo not implemented yet due to gutenberg not supporting it |
|
| 2199 | + ?> |
|
| 2200 | 2200 | > |
| 2201 | 2201 | <?php |
| 2202 | 2202 | |
| 2203 | - if ( ! empty( $args['options'] ) ) { |
|
| 2204 | - foreach ( $args['options'] as $val => $label ) { |
|
| 2205 | - if ( $multiple ) { |
|
| 2206 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2207 | - } else { |
|
| 2208 | - $selected = selected( $value, $val, false ); |
|
| 2209 | - } |
|
| 2210 | - echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 2211 | - } |
|
| 2212 | - } |
|
| 2213 | - ?> |
|
| 2203 | + if ( ! empty( $args['options'] ) ) { |
|
| 2204 | + foreach ( $args['options'] as $val => $label ) { |
|
| 2205 | + if ( $multiple ) { |
|
| 2206 | + $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2207 | + } else { |
|
| 2208 | + $selected = selected( $value, $val, false ); |
|
| 2209 | + } |
|
| 2210 | + echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 2211 | + } |
|
| 2212 | + } |
|
| 2213 | + ?> |
|
| 2214 | 2214 | </select> |
| 2215 | 2215 | <?php |
| 2216 | - break; |
|
| 2217 | - case "checkbox": |
|
| 2218 | - ?> |
|
| 2216 | + break; |
|
| 2217 | + case "checkbox": |
|
| 2218 | + ?> |
|
| 2219 | 2219 | <input <?php echo $placeholder; ?> |
| 2220 | 2220 | <?php checked( 1, $value, true ) ?> |
| 2221 | 2221 | <?php echo $custom_attributes; ?> |
@@ -2225,136 +2225,136 @@ discard block |
||
| 2225 | 2225 | <label |
| 2226 | 2226 | 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> |
| 2227 | 2227 | <?php |
| 2228 | - break; |
|
| 2229 | - case "hidden": |
|
| 2230 | - ?> |
|
| 2228 | + break; |
|
| 2229 | + case "hidden": |
|
| 2230 | + ?> |
|
| 2231 | 2231 | <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 2232 | 2232 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
| 2233 | 2233 | value="<?php echo esc_attr( $value ); ?>"> |
| 2234 | 2234 | <?php |
| 2235 | - break; |
|
| 2236 | - default: |
|
| 2237 | - echo "No input type found!"; // @todo we need to add more input types. |
|
| 2238 | - } |
|
| 2235 | + break; |
|
| 2236 | + default: |
|
| 2237 | + echo "No input type found!"; // @todo we need to add more input types. |
|
| 2238 | + } |
|
| 2239 | 2239 | |
| 2240 | - // after wrapper |
|
| 2241 | - ?> |
|
| 2240 | + // after wrapper |
|
| 2241 | + ?> |
|
| 2242 | 2242 | </p> |
| 2243 | 2243 | <?php |
| 2244 | 2244 | |
| 2245 | - } |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * Get the widget input description html. |
|
| 2249 | - * |
|
| 2250 | - * @param $args |
|
| 2251 | - * |
|
| 2252 | - * @return string |
|
| 2253 | - * @todo, need to make its own tooltip script |
|
| 2254 | - */ |
|
| 2255 | - public function widget_field_desc( $args ) { |
|
| 2256 | - |
|
| 2257 | - $description = ''; |
|
| 2258 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2259 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2260 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 2261 | - } else { |
|
| 2262 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2263 | - } |
|
| 2264 | - } |
|
| 2265 | - |
|
| 2266 | - return $description; |
|
| 2267 | - } |
|
| 2268 | - |
|
| 2269 | - /** |
|
| 2270 | - * Get the tool tip html. |
|
| 2271 | - * |
|
| 2272 | - * @param $tip |
|
| 2273 | - * @param bool $allow_html |
|
| 2274 | - * |
|
| 2275 | - * @return string |
|
| 2276 | - */ |
|
| 2277 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 2278 | - if ( $allow_html ) { |
|
| 2279 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 2280 | - } else { |
|
| 2281 | - $tip = esc_attr( $tip ); |
|
| 2282 | - } |
|
| 2283 | - |
|
| 2284 | - return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 2285 | - } |
|
| 2286 | - |
|
| 2287 | - /** |
|
| 2288 | - * Sanitize a string destined to be a tooltip. |
|
| 2289 | - * |
|
| 2290 | - * @param string $var |
|
| 2291 | - * |
|
| 2292 | - * @return string |
|
| 2293 | - */ |
|
| 2294 | - public function sanitize_tooltip( $var ) { |
|
| 2295 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2296 | - 'br' => array(), |
|
| 2297 | - 'em' => array(), |
|
| 2298 | - 'strong' => array(), |
|
| 2299 | - 'small' => array(), |
|
| 2300 | - 'span' => array(), |
|
| 2301 | - 'ul' => array(), |
|
| 2302 | - 'li' => array(), |
|
| 2303 | - 'ol' => array(), |
|
| 2304 | - 'p' => array(), |
|
| 2305 | - ) ) ); |
|
| 2306 | - } |
|
| 2307 | - |
|
| 2308 | - /** |
|
| 2309 | - * Processing widget options on save |
|
| 2310 | - * |
|
| 2311 | - * @param array $new_instance The new options |
|
| 2312 | - * @param array $old_instance The previous options |
|
| 2313 | - * |
|
| 2314 | - * @return array |
|
| 2315 | - * @todo we should add some sanitation here. |
|
| 2316 | - */ |
|
| 2317 | - public function update( $new_instance, $old_instance ) { |
|
| 2318 | - |
|
| 2319 | - //save the widget |
|
| 2320 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2321 | - |
|
| 2322 | - // set widget instance |
|
| 2323 | - $this->instance = $instance; |
|
| 2324 | - |
|
| 2325 | - if ( empty( $this->arguments ) ) { |
|
| 2326 | - $this->get_arguments(); |
|
| 2327 | - } |
|
| 2328 | - |
|
| 2329 | - // check for checkboxes |
|
| 2330 | - if ( ! empty( $this->arguments ) ) { |
|
| 2331 | - foreach ( $this->arguments as $argument ) { |
|
| 2332 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2333 | - $instance[ $argument['name'] ] = '0'; |
|
| 2334 | - } |
|
| 2335 | - } |
|
| 2336 | - } |
|
| 2337 | - |
|
| 2338 | - return $instance; |
|
| 2339 | - } |
|
| 2340 | - |
|
| 2341 | - /** |
|
| 2342 | - * Checks if the current call is a ajax call to get the block content. |
|
| 2343 | - * |
|
| 2344 | - * This can be used in your widget to return different content as the block content. |
|
| 2345 | - * |
|
| 2346 | - * @since 1.0.3 |
|
| 2347 | - * @return bool |
|
| 2348 | - */ |
|
| 2349 | - public function is_block_content_call() { |
|
| 2350 | - $result = false; |
|
| 2351 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2352 | - $result = true; |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - return $result; |
|
| 2356 | - } |
|
| 2357 | - |
|
| 2358 | - } |
|
| 2245 | + } |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * Get the widget input description html. |
|
| 2249 | + * |
|
| 2250 | + * @param $args |
|
| 2251 | + * |
|
| 2252 | + * @return string |
|
| 2253 | + * @todo, need to make its own tooltip script |
|
| 2254 | + */ |
|
| 2255 | + public function widget_field_desc( $args ) { |
|
| 2256 | + |
|
| 2257 | + $description = ''; |
|
| 2258 | + if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2259 | + if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2260 | + $description = $this->desc_tip( $args['desc'] ); |
|
| 2261 | + } else { |
|
| 2262 | + $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2263 | + } |
|
| 2264 | + } |
|
| 2265 | + |
|
| 2266 | + return $description; |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + /** |
|
| 2270 | + * Get the tool tip html. |
|
| 2271 | + * |
|
| 2272 | + * @param $tip |
|
| 2273 | + * @param bool $allow_html |
|
| 2274 | + * |
|
| 2275 | + * @return string |
|
| 2276 | + */ |
|
| 2277 | + function desc_tip( $tip, $allow_html = false ) { |
|
| 2278 | + if ( $allow_html ) { |
|
| 2279 | + $tip = $this->sanitize_tooltip( $tip ); |
|
| 2280 | + } else { |
|
| 2281 | + $tip = esc_attr( $tip ); |
|
| 2282 | + } |
|
| 2283 | + |
|
| 2284 | + return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 2285 | + } |
|
| 2286 | + |
|
| 2287 | + /** |
|
| 2288 | + * Sanitize a string destined to be a tooltip. |
|
| 2289 | + * |
|
| 2290 | + * @param string $var |
|
| 2291 | + * |
|
| 2292 | + * @return string |
|
| 2293 | + */ |
|
| 2294 | + public function sanitize_tooltip( $var ) { |
|
| 2295 | + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2296 | + 'br' => array(), |
|
| 2297 | + 'em' => array(), |
|
| 2298 | + 'strong' => array(), |
|
| 2299 | + 'small' => array(), |
|
| 2300 | + 'span' => array(), |
|
| 2301 | + 'ul' => array(), |
|
| 2302 | + 'li' => array(), |
|
| 2303 | + 'ol' => array(), |
|
| 2304 | + 'p' => array(), |
|
| 2305 | + ) ) ); |
|
| 2306 | + } |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * Processing widget options on save |
|
| 2310 | + * |
|
| 2311 | + * @param array $new_instance The new options |
|
| 2312 | + * @param array $old_instance The previous options |
|
| 2313 | + * |
|
| 2314 | + * @return array |
|
| 2315 | + * @todo we should add some sanitation here. |
|
| 2316 | + */ |
|
| 2317 | + public function update( $new_instance, $old_instance ) { |
|
| 2318 | + |
|
| 2319 | + //save the widget |
|
| 2320 | + $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2321 | + |
|
| 2322 | + // set widget instance |
|
| 2323 | + $this->instance = $instance; |
|
| 2324 | + |
|
| 2325 | + if ( empty( $this->arguments ) ) { |
|
| 2326 | + $this->get_arguments(); |
|
| 2327 | + } |
|
| 2328 | + |
|
| 2329 | + // check for checkboxes |
|
| 2330 | + if ( ! empty( $this->arguments ) ) { |
|
| 2331 | + foreach ( $this->arguments as $argument ) { |
|
| 2332 | + if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2333 | + $instance[ $argument['name'] ] = '0'; |
|
| 2334 | + } |
|
| 2335 | + } |
|
| 2336 | + } |
|
| 2337 | + |
|
| 2338 | + return $instance; |
|
| 2339 | + } |
|
| 2340 | + |
|
| 2341 | + /** |
|
| 2342 | + * Checks if the current call is a ajax call to get the block content. |
|
| 2343 | + * |
|
| 2344 | + * This can be used in your widget to return different content as the block content. |
|
| 2345 | + * |
|
| 2346 | + * @since 1.0.3 |
|
| 2347 | + * @return bool |
|
| 2348 | + */ |
|
| 2349 | + public function is_block_content_call() { |
|
| 2350 | + $result = false; |
|
| 2351 | + if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2352 | + $result = true; |
|
| 2353 | + } |
|
| 2354 | + |
|
| 2355 | + return $result; |
|
| 2356 | + } |
|
| 2357 | + |
|
| 2358 | + } |
|
| 2359 | 2359 | |
| 2360 | 2360 | } |
| 2361 | 2361 | \ 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 | /** |
@@ -39,27 +39,27 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * Take the array options and use them to build. |
| 41 | 41 | */ |
| 42 | - public function __construct( $options ) { |
|
| 42 | + public function __construct($options) { |
|
| 43 | 43 | global $sd_widgets; |
| 44 | 44 | |
| 45 | - $sd_widgets[ $options['base_id'] ] = array( |
|
| 45 | + $sd_widgets[$options['base_id']] = array( |
|
| 46 | 46 | 'name' => $options['name'], |
| 47 | 47 | 'class_name' => $options['class_name'] |
| 48 | 48 | ); |
| 49 | - $this->base_id = $options['base_id']; |
|
| 49 | + $this->base_id = $options['base_id']; |
|
| 50 | 50 | // lets filter the options before we do anything |
| 51 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 52 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 53 | - $options = $this->add_name_from_key( $options ); |
|
| 51 | + $options = apply_filters("wp_super_duper_options", $options); |
|
| 52 | + $options = apply_filters("wp_super_duper_options_{$this->base_id}", $options); |
|
| 53 | + $options = $this->add_name_from_key($options); |
|
| 54 | 54 | $this->options = $options; |
| 55 | 55 | |
| 56 | 56 | $this->base_id = $options['base_id']; |
| 57 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 57 | + $this->arguments = isset($options['arguments']) ? $options['arguments'] : array(); |
|
| 58 | 58 | |
| 59 | 59 | // init parent |
| 60 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 60 | + parent::__construct($options['base_id'], $options['name'], $options['widget_ops']); |
|
| 61 | 61 | |
| 62 | - if ( isset( $options['class_name'] ) ) { |
|
| 62 | + if (isset($options['class_name'])) { |
|
| 63 | 63 | // register widget |
| 64 | 64 | $this->class_name = $options['class_name']; |
| 65 | 65 | |
@@ -67,47 +67,47 @@ discard block |
||
| 67 | 67 | $this->register_shortcode(); |
| 68 | 68 | |
| 69 | 69 | // register block |
| 70 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 70 | + add_action('admin_enqueue_scripts', array($this, 'register_block')); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // add the CSS and JS we need ONCE |
| 74 | 74 | global $sd_widget_scripts; |
| 75 | 75 | |
| 76 | - if ( ! $sd_widget_scripts ) { |
|
| 77 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 78 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 79 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 76 | + if (!$sd_widget_scripts) { |
|
| 77 | + wp_add_inline_script('admin-widgets', $this->widget_js()); |
|
| 78 | + wp_add_inline_script('customize-controls', $this->widget_js()); |
|
| 79 | + wp_add_inline_style('widgets', $this->widget_css()); |
|
| 80 | 80 | |
| 81 | 81 | $sd_widget_scripts = true; |
| 82 | 82 | |
| 83 | 83 | // add shortcode insert button once |
| 84 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 85 | - if ( $this->is_preview() ) { |
|
| 86 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 84 | + add_action('media_buttons', array($this, 'shortcode_insert_button')); |
|
| 85 | + if ($this->is_preview()) { |
|
| 86 | + add_action('wp_footer', array($this, 'shortcode_insert_button_script')); |
|
| 87 | 87 | // this makes the insert button work for elementor |
| 88 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 88 | + add_action('elementor/editor/after_enqueue_scripts', array( |
|
| 89 | 89 | $this, |
| 90 | 90 | 'shortcode_insert_button_script' |
| 91 | - ) ); // for elementor |
|
| 91 | + )); // for elementor |
|
| 92 | 92 | } |
| 93 | 93 | // this makes the insert button work for cornerstone |
| 94 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
| 94 | + add_action('wp_print_footer_scripts', array(__CLASS__, 'maybe_cornerstone_builder')); |
|
| 95 | 95 | |
| 96 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 97 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 96 | + add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings')); |
|
| 97 | + add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker')); |
|
| 98 | 98 | |
| 99 | 99 | // add generator text to admin head |
| 100 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 100 | + add_action('admin_head', array($this, 'generator')); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 103 | + do_action('wp_super_duper_widget_init', $options, $this); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
| 108 | 108 | */ |
| 109 | - public static function maybe_cornerstone_builder(){ |
|
| 110 | - if(did_action('cornerstone_before_boot_app')){ |
|
| 109 | + public static function maybe_cornerstone_builder() { |
|
| 110 | + if (did_action('cornerstone_before_boot_app')) { |
|
| 111 | 111 | self::shortcode_insert_button_script(); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @return string |
| 121 | 121 | */ |
| 122 | - public static function get_picker( $editor_id = '' ) { |
|
| 122 | + public static function get_picker($editor_id = '') { |
|
| 123 | 123 | |
| 124 | 124 | ob_start(); |
| 125 | - if ( isset( $_POST['editor_id'] ) ) { |
|
| 126 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 127 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 125 | + if (isset($_POST['editor_id'])) { |
|
| 126 | + $editor_id = esc_attr($_POST['editor_id']); |
|
| 127 | + } elseif (isset($_REQUEST['et_fb'])) { |
|
| 128 | 128 | $editor_id = 'main_content_content_vb_tiny_mce'; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | <div class="sd-shortcode-left-wrap"> |
| 135 | 135 | <?php |
| 136 | - asort( $sd_widgets ); |
|
| 137 | - if ( ! empty( $sd_widgets ) ) { |
|
| 136 | + asort($sd_widgets); |
|
| 137 | + if (!empty($sd_widgets)) { |
|
| 138 | 138 | echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
| 139 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 140 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 141 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 139 | + echo "<option>" . __('Select shortcode') . "</option>"; |
|
| 140 | + foreach ($sd_widgets as $shortcode => $class) { |
|
| 141 | + echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>"; |
|
| 142 | 142 | } |
| 143 | 143 | echo "</select>"; |
| 144 | 144 | |
@@ -151,37 +151,37 @@ discard block |
||
| 151 | 151 | <div class="sd-shortcode-right-wrap"> |
| 152 | 152 | <textarea id='sd-shortcode-output' disabled></textarea> |
| 153 | 153 | <div id='sd-shortcode-output-actions'> |
| 154 | - <?php if ( $editor_id != '' ) { ?> |
|
| 154 | + <?php if ($editor_id != '') { ?> |
|
| 155 | 155 | <button class="button sd-insert-shortcode-button" |
| 156 | - onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
|
| 156 | + onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) { |
|
| 157 | 157 | echo "'" . $editor_id . "'"; |
| 158 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 158 | + } ?>)"><?php _e('Insert shortcode'); ?></button> |
|
| 159 | 159 | <?php } ?> |
| 160 | 160 | <button class="button" |
| 161 | - onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
|
| 161 | + onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button> |
|
| 162 | 162 | </div> |
| 163 | 163 | </div> |
| 164 | 164 | <?php |
| 165 | 165 | |
| 166 | 166 | $html = ob_get_clean(); |
| 167 | 167 | |
| 168 | - if ( wp_doing_ajax() ) { |
|
| 168 | + if (wp_doing_ajax()) { |
|
| 169 | 169 | echo $html; |
| 170 | 170 | $should_die = true; |
| 171 | 171 | |
| 172 | 172 | // some builder get the editor via ajax so we should not die on those ocasions |
| 173 | 173 | $dont_die = array( |
| 174 | - 'parent_tag',// WP Bakery |
|
| 174 | + 'parent_tag', // WP Bakery |
|
| 175 | 175 | 'avia_request' // enfold |
| 176 | 176 | ); |
| 177 | 177 | |
| 178 | - foreach ( $dont_die as $request ) { |
|
| 179 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 178 | + foreach ($dont_die as $request) { |
|
| 179 | + if (isset($_REQUEST[$request])) { |
|
| 180 | 180 | $should_die = false; |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if ( $should_die ) { |
|
| 184 | + if ($should_die) { |
|
| 185 | 185 | wp_die(); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -208,16 +208,16 @@ discard block |
||
| 208 | 208 | public static function get_widget_settings() { |
| 209 | 209 | global $sd_widgets; |
| 210 | 210 | |
| 211 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 212 | - if ( ! $shortcode ) { |
|
| 211 | + $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : ''; |
|
| 212 | + if (!$shortcode) { |
|
| 213 | 213 | wp_die(); |
| 214 | 214 | } |
| 215 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 216 | - if ( ! $widget_args ) { |
|
| 215 | + $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : ''; |
|
| 216 | + if (!$widget_args) { |
|
| 217 | 217 | wp_die(); |
| 218 | 218 | } |
| 219 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 220 | - if ( ! $class_name ) { |
|
| 219 | + $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 220 | + if (!$class_name) { |
|
| 221 | 221 | wp_die(); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $widget = new $class_name; |
| 226 | 226 | |
| 227 | 227 | ob_start(); |
| 228 | - $widget->form( array() ); |
|
| 228 | + $widget->form(array()); |
|
| 229 | 229 | $form = ob_get_clean(); |
| 230 | 230 | echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
| 231 | 231 | echo "<style>" . $widget->widget_css() . "</style>"; |
@@ -243,9 +243,9 @@ discard block |
||
| 243 | 243 | * @param string $editor_id Optional. Shortcode editor id. Default null. |
| 244 | 244 | * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
| 245 | 245 | */ |
| 246 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 246 | + public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') { |
|
| 247 | 247 | global $sd_widgets, $shortcode_insert_button_once; |
| 248 | - if ( $shortcode_insert_button_once ) { |
|
| 248 | + if ($shortcode_insert_button_once) { |
|
| 249 | 249 | return; |
| 250 | 250 | } |
| 251 | 251 | add_thickbox(); |
@@ -255,18 +255,18 @@ discard block |
||
| 255 | 255 | * Cornerstone makes us play dirty tricks :/ |
| 256 | 256 | * 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. |
| 257 | 257 | */ |
| 258 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 258 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 259 | 259 | echo '<span id="insert-media-button">'; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - echo self::shortcode_button( 'this', 'true' ); |
|
| 262 | + echo self::shortcode_button('this', 'true'); |
|
| 263 | 263 | |
| 264 | 264 | // see opening note |
| 265 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 265 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 266 | 266 | echo '</span>'; // end #insert-media-button |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 269 | + self::shortcode_insert_button_script($editor_id, $insert_shortcode_function); |
|
| 270 | 270 | $shortcode_insert_button_once = true; |
| 271 | 271 | } |
| 272 | 272 | |
@@ -278,12 +278,12 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return mixed |
| 280 | 280 | */ |
| 281 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 281 | + public static function shortcode_button($id = '', $search_for_id = '') { |
|
| 282 | 282 | ob_start(); |
| 283 | 283 | ?> |
| 284 | 284 | <span class="sd-lable-shortcode-inserter"> |
| 285 | 285 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
| 286 | - if ( $search_for_id ) { |
|
| 286 | + if ($search_for_id) { |
|
| 287 | 287 | echo "," . $search_for_id; |
| 288 | 288 | } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
| 289 | 289 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $html = ob_get_clean(); |
| 300 | 300 | |
| 301 | 301 | // remove line breaks so we can use it in js |
| 302 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 302 | + return preg_replace("/\r|\n/", "", trim($html)); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | jQuery($this).data('sd-widget-enabled', true); |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - 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>'; |
|
| 360 | + 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>'; |
|
| 361 | 361 | var form = jQuery($this).parents('' + $selector + ''); |
| 362 | 362 | |
| 363 | 363 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -394,10 +394,10 @@ discard block |
||
| 394 | 394 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 395 | 395 | */ |
| 396 | 396 | |
| 397 | - return str_replace( array( |
|
| 397 | + return str_replace(array( |
|
| 398 | 398 | '<script>', |
| 399 | 399 | '</script>' |
| 400 | - ), '', $output ); |
|
| 400 | + ), '', $output); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * @param string $editor_id |
| 409 | 409 | * @param string $insert_shortcode_function |
| 410 | 410 | */ |
| 411 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 411 | + public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') { |
|
| 412 | 412 | ?> |
| 413 | 413 | <style> |
| 414 | 414 | .sd-shortcode-left-wrap { |
@@ -528,15 +528,15 @@ discard block |
||
| 528 | 528 | } |
| 529 | 529 | </style> |
| 530 | 530 | <?php |
| 531 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 531 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 532 | 532 | echo "<script>" . self::siteorigin_js() . "</script>"; |
| 533 | 533 | } |
| 534 | 534 | ?> |
| 535 | 535 | <script> |
| 536 | 536 | <?php |
| 537 | - if(! empty( $insert_shortcode_function )){ |
|
| 537 | + if (!empty($insert_shortcode_function)) { |
|
| 538 | 538 | echo $insert_shortcode_function; |
| 539 | - }else{ |
|
| 539 | + } else { |
|
| 540 | 540 | |
| 541 | 541 | /** |
| 542 | 542 | * Function for super duper insert shortcode. |
@@ -551,9 +551,9 @@ discard block |
||
| 551 | 551 | if (!$editor_id) { |
| 552 | 552 | |
| 553 | 553 | <?php |
| 554 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 554 | + if (isset($_REQUEST['et_fb'])) { |
|
| 555 | 555 | echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
| 556 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 556 | + } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') { |
|
| 557 | 557 | echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
| 558 | 558 | } else { |
| 559 | 559 | echo '$editor_id = "#wp-content-editor-container textarea";'; |
@@ -633,11 +633,11 @@ discard block |
||
| 633 | 633 | 'shortcode': $short_code, |
| 634 | 634 | 'attributes': 123, |
| 635 | 635 | 'post_id': 321, |
| 636 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 636 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 637 | 637 | }; |
| 638 | 638 | |
| 639 | 639 | if (typeof ajaxurl === 'undefined') { |
| 640 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>"; |
|
| 640 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | jQuery.post(ajaxurl, data, function (response) { |
@@ -835,11 +835,11 @@ discard block |
||
| 835 | 835 | var data = { |
| 836 | 836 | 'action': 'super_duper_get_picker', |
| 837 | 837 | 'editor_id': $id, |
| 838 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>' |
|
| 838 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>' |
|
| 839 | 839 | }; |
| 840 | 840 | |
| 841 | 841 | if (!ajaxurl) { |
| 842 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; |
|
| 842 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | jQuery.post(ajaxurl, data, function (response) { |
@@ -860,9 +860,9 @@ discard block |
||
| 860 | 860 | */ |
| 861 | 861 | function sd_shortcode_button($id) { |
| 862 | 862 | if ($id) { |
| 863 | - return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>'; |
|
| 863 | + return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>'; |
|
| 864 | 864 | } else { |
| 865 | - return '<?php echo self::shortcode_button();?>'; |
|
| 865 | + return '<?php echo self::shortcode_button(); ?>'; |
|
| 866 | 866 | } |
| 867 | 867 | } |
| 868 | 868 | |
@@ -904,10 +904,10 @@ discard block |
||
| 904 | 904 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 905 | 905 | */ |
| 906 | 906 | |
| 907 | - return str_replace( array( |
|
| 907 | + return str_replace(array( |
|
| 908 | 908 | '<style>', |
| 909 | 909 | '</style>' |
| 910 | - ), '', $output ); |
|
| 910 | + ), '', $output); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | jQuery($this).data('sd-widget-enabled', true); |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | - 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>'; |
|
| 980 | + 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>'; |
|
| 981 | 981 | var form = jQuery($this).parents('' + $selector + ''); |
| 982 | 982 | |
| 983 | 983 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | }); |
| 1070 | 1070 | |
| 1071 | 1071 | } |
| 1072 | - <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 1072 | + <?php do_action('wp_super_duper_widget_js', $this); ?> |
|
| 1073 | 1073 | </script> |
| 1074 | 1074 | <?php |
| 1075 | 1075 | $output = ob_get_clean(); |
@@ -1078,10 +1078,10 @@ discard block |
||
| 1078 | 1078 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1079 | 1079 | */ |
| 1080 | 1080 | |
| 1081 | - return str_replace( array( |
|
| 1081 | + return str_replace(array( |
|
| 1082 | 1082 | '<script>', |
| 1083 | 1083 | '</script>' |
| 1084 | - ), '', $output ); |
|
| 1084 | + ), '', $output); |
|
| 1085 | 1085 | } |
| 1086 | 1086 | |
| 1087 | 1087 | |
@@ -1092,14 +1092,14 @@ discard block |
||
| 1092 | 1092 | * |
| 1093 | 1093 | * @return mixed |
| 1094 | 1094 | */ |
| 1095 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 1096 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 1097 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 1098 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 1095 | + private function add_name_from_key($options, $arguments = false) { |
|
| 1096 | + if (!empty($options['arguments'])) { |
|
| 1097 | + foreach ($options['arguments'] as $key => $val) { |
|
| 1098 | + $options['arguments'][$key]['name'] = $key; |
|
| 1099 | 1099 | } |
| 1100 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1101 | - foreach ( $options as $key => $val ) { |
|
| 1102 | - $options[ $key ]['name'] = $key; |
|
| 1100 | + } elseif ($arguments && is_array($options) && !empty($options)) { |
|
| 1101 | + foreach ($options as $key => $val) { |
|
| 1102 | + $options[$key]['name'] = $key; |
|
| 1103 | 1103 | } |
| 1104 | 1104 | } |
| 1105 | 1105 | |
@@ -1112,8 +1112,8 @@ discard block |
||
| 1112 | 1112 | * @since 1.0.0 |
| 1113 | 1113 | */ |
| 1114 | 1114 | public function register_shortcode() { |
| 1115 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1116 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1115 | + add_shortcode($this->base_id, array($this, 'shortcode_output')); |
|
| 1116 | + add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode')); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | /** |
@@ -1123,33 +1123,33 @@ discard block |
||
| 1123 | 1123 | */ |
| 1124 | 1124 | public static function render_shortcode() { |
| 1125 | 1125 | |
| 1126 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1127 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1126 | + check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true); |
|
| 1127 | + if (!current_user_can('manage_options')) { |
|
| 1128 | 1128 | wp_die(); |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | // we might need the $post value here so lets set it. |
| 1132 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1133 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1134 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1132 | + if (isset($_POST['post_id']) && $_POST['post_id']) { |
|
| 1133 | + $post_obj = get_post(absint($_POST['post_id'])); |
|
| 1134 | + if (!empty($post_obj) && empty($post)) { |
|
| 1135 | 1135 | global $post; |
| 1136 | 1136 | $post = $post_obj; |
| 1137 | 1137 | } |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1141 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1142 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1140 | + if (isset($_POST['shortcode']) && $_POST['shortcode']) { |
|
| 1141 | + $shortcode_name = sanitize_title_with_dashes($_POST['shortcode']); |
|
| 1142 | + $attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1143 | 1143 | $attributes = ''; |
| 1144 | - if ( ! empty( $attributes_array ) ) { |
|
| 1145 | - foreach ( $attributes_array as $key => $value ) { |
|
| 1146 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1144 | + if (!empty($attributes_array)) { |
|
| 1145 | + foreach ($attributes_array as $key => $value) { |
|
| 1146 | + $attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' "; |
|
| 1147 | 1147 | } |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
| 1151 | 1151 | |
| 1152 | - echo do_shortcode( $shortcode ); |
|
| 1152 | + echo do_shortcode($shortcode); |
|
| 1153 | 1153 | |
| 1154 | 1154 | } |
| 1155 | 1155 | wp_die(); |
@@ -1163,37 +1163,37 @@ discard block |
||
| 1163 | 1163 | * |
| 1164 | 1164 | * @return string |
| 1165 | 1165 | */ |
| 1166 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1167 | - $args = self::argument_values( $args ); |
|
| 1166 | + public function shortcode_output($args = array(), $content = '') { |
|
| 1167 | + $args = self::argument_values($args); |
|
| 1168 | 1168 | |
| 1169 | 1169 | // add extra argument so we know its a output to gutenberg |
| 1170 | 1170 | //$args |
| 1171 | - $args = $this->string_to_bool( $args ); |
|
| 1171 | + $args = $this->string_to_bool($args); |
|
| 1172 | 1172 | |
| 1173 | 1173 | |
| 1174 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1174 | + $calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : ''; |
|
| 1175 | 1175 | |
| 1176 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 1177 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 1176 | + $calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this); |
|
| 1177 | + $calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this); |
|
| 1178 | 1178 | |
| 1179 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1180 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 1179 | + $attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this); |
|
| 1180 | + $attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this); |
|
| 1181 | 1181 | |
| 1182 | 1182 | $shortcode_args = array(); |
| 1183 | 1183 | $output = ''; |
| 1184 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1185 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1186 | - if ( $main_content && ! $no_wrap ) { |
|
| 1184 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
| 1185 | + $main_content = $this->output($args, $shortcode_args, $content); |
|
| 1186 | + if ($main_content && !$no_wrap) { |
|
| 1187 | 1187 | // wrap the shortcode in a dive with the same class as the widget |
| 1188 | 1188 | $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
| 1189 | - if ( ! empty( $args['title'] ) ) { |
|
| 1189 | + if (!empty($args['title'])) { |
|
| 1190 | 1190 | // if its a shortcode and there is a title try to grab the title wrappers |
| 1191 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1192 | - if ( empty( $instance ) ) { |
|
| 1191 | + $shortcode_args = array('before_title' => '', 'after_title' => ''); |
|
| 1192 | + if (empty($instance)) { |
|
| 1193 | 1193 | global $wp_registered_sidebars; |
| 1194 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1195 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1196 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1194 | + if (!empty($wp_registered_sidebars)) { |
|
| 1195 | + foreach ($wp_registered_sidebars as $sidebar) { |
|
| 1196 | + if (!empty($sidebar['before_title'])) { |
|
| 1197 | 1197 | $shortcode_args['before_title'] = $sidebar['before_title']; |
| 1198 | 1198 | $shortcode_args['after_title'] = $sidebar['after_title']; |
| 1199 | 1199 | break; |
@@ -1201,17 +1201,17 @@ discard block |
||
| 1201 | 1201 | } |
| 1202 | 1202 | } |
| 1203 | 1203 | } |
| 1204 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1204 | + $output .= $this->output_title($shortcode_args, $args); |
|
| 1205 | 1205 | } |
| 1206 | 1206 | $output .= $main_content; |
| 1207 | 1207 | $output .= '</div>'; |
| 1208 | - } elseif ( $main_content && $no_wrap ) { |
|
| 1208 | + } elseif ($main_content && $no_wrap) { |
|
| 1209 | 1209 | $output .= $main_content; |
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | // if preview show a placeholder if empty |
| 1213 | - if ( $this->is_preview() && $output == '' ) { |
|
| 1214 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
| 1213 | + if ($this->is_preview() && $output == '') { |
|
| 1214 | + $output = $this->preview_placeholder_text("[{" . $this->base_id . "}]"); |
|
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | return $output; |
@@ -1224,8 +1224,8 @@ discard block |
||
| 1224 | 1224 | * |
| 1225 | 1225 | * @return string |
| 1226 | 1226 | */ |
| 1227 | - public function preview_placeholder_text( $name = '' ) { |
|
| 1228 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1227 | + public function preview_placeholder_text($name = '') { |
|
| 1228 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>"; |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1235,13 +1235,13 @@ discard block |
||
| 1235 | 1235 | * |
| 1236 | 1236 | * @return mixed |
| 1237 | 1237 | */ |
| 1238 | - public function string_to_bool( $options ) { |
|
| 1238 | + public function string_to_bool($options) { |
|
| 1239 | 1239 | // convert bool strings to booleans |
| 1240 | - foreach ( $options as $key => $val ) { |
|
| 1241 | - if ( $val == 'false' ) { |
|
| 1242 | - $options[ $key ] = false; |
|
| 1243 | - } elseif ( $val == 'true' ) { |
|
| 1244 | - $options[ $key ] = true; |
|
| 1240 | + foreach ($options as $key => $val) { |
|
| 1241 | + if ($val == 'false') { |
|
| 1242 | + $options[$key] = false; |
|
| 1243 | + } elseif ($val == 'true') { |
|
| 1244 | + $options[$key] = true; |
|
| 1245 | 1245 | } |
| 1246 | 1246 | } |
| 1247 | 1247 | |
@@ -1257,27 +1257,27 @@ discard block |
||
| 1257 | 1257 | * |
| 1258 | 1258 | * @return array |
| 1259 | 1259 | */ |
| 1260 | - public function argument_values( $instance ) { |
|
| 1260 | + public function argument_values($instance) { |
|
| 1261 | 1261 | $argument_values = array(); |
| 1262 | 1262 | |
| 1263 | 1263 | // set widget instance |
| 1264 | 1264 | $this->instance = $instance; |
| 1265 | 1265 | |
| 1266 | - if ( empty( $this->arguments ) ) { |
|
| 1266 | + if (empty($this->arguments)) { |
|
| 1267 | 1267 | $this->arguments = $this->get_arguments(); |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | - if ( ! empty( $this->arguments ) ) { |
|
| 1271 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1270 | + if (!empty($this->arguments)) { |
|
| 1271 | + foreach ($this->arguments as $key => $args) { |
|
| 1272 | 1272 | // set the input name from the key |
| 1273 | 1273 | $args['name'] = $key; |
| 1274 | 1274 | // |
| 1275 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1276 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
| 1275 | + $argument_values[$key] = isset($instance[$key]) ? $instance[$key] : ''; |
|
| 1276 | + if ($args['type'] == 'checkbox' && $argument_values[$key] == '') { |
|
| 1277 | 1277 | // don't set default for an empty checkbox |
| 1278 | 1278 | } |
| 1279 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1280 | - $argument_values[ $key ] = $args['default']; |
|
| 1279 | + elseif ($argument_values[$key] == '' && isset($args['default'])) { |
|
| 1280 | + $argument_values[$key] = $args['default']; |
|
| 1281 | 1281 | } |
| 1282 | 1282 | } |
| 1283 | 1283 | } |
@@ -1304,12 +1304,12 @@ discard block |
||
| 1304 | 1304 | * @return array Get arguments. |
| 1305 | 1305 | */ |
| 1306 | 1306 | public function get_arguments() { |
| 1307 | - if ( empty( $this->arguments ) ) { |
|
| 1307 | + if (empty($this->arguments)) { |
|
| 1308 | 1308 | $this->arguments = $this->set_arguments(); |
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1312 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1311 | + $this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance); |
|
| 1312 | + $this->arguments = $this->add_name_from_key($this->arguments, true); |
|
| 1313 | 1313 | |
| 1314 | 1314 | return $this->arguments; |
| 1315 | 1315 | } |
@@ -1321,7 +1321,7 @@ discard block |
||
| 1321 | 1321 | * @param array $widget_args |
| 1322 | 1322 | * @param string $content |
| 1323 | 1323 | */ |
| 1324 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1324 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 1325 | 1325 | |
| 1326 | 1326 | } |
| 1327 | 1327 | |
@@ -1329,10 +1329,10 @@ discard block |
||
| 1329 | 1329 | * Add the dynamic block code inline when the wp-block in enqueued. |
| 1330 | 1330 | */ |
| 1331 | 1331 | public function register_block() { |
| 1332 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1333 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1332 | + wp_add_inline_script('wp-blocks', $this->block()); |
|
| 1333 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 1334 | 1334 | |
| 1335 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1335 | + wp_add_inline_script('wp-blocks', $this->siteorigin_js()); |
|
| 1336 | 1336 | |
| 1337 | 1337 | } |
| 1338 | 1338 | } |
@@ -1347,13 +1347,13 @@ discard block |
||
| 1347 | 1347 | $show = false; |
| 1348 | 1348 | $arguments = $this->arguments; |
| 1349 | 1349 | |
| 1350 | - if ( empty( $arguments ) ) { |
|
| 1350 | + if (empty($arguments)) { |
|
| 1351 | 1351 | $arguments = $this->get_arguments(); |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | - if ( ! empty( $arguments ) ) { |
|
| 1355 | - foreach ( $arguments as $argument ) { |
|
| 1356 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1354 | + if (!empty($arguments)) { |
|
| 1355 | + foreach ($arguments as $argument) { |
|
| 1356 | + if (isset($argument['advanced']) && $argument['advanced']) { |
|
| 1357 | 1357 | $show = true; |
| 1358 | 1358 | } |
| 1359 | 1359 | } |
@@ -1405,12 +1405,12 @@ discard block |
||
| 1405 | 1405 | * @return {?WPBlock} The block, if it has been successfully |
| 1406 | 1406 | * registered; otherwise `undefined`. |
| 1407 | 1407 | */ |
| 1408 | - 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. |
|
| 1409 | - title: '<?php echo $this->options['name'];?>', // Block title. |
|
| 1410 | - description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title. |
|
| 1411 | - 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/. |
|
| 1412 | - 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. |
|
| 1413 | - <?php if ( isset( $this->options['block-keywords'] ) ) { |
|
| 1408 | + 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. |
|
| 1409 | + title: '<?php echo $this->options['name']; ?>', // Block title. |
|
| 1410 | + description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title. |
|
| 1411 | + 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/. |
|
| 1412 | + 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. |
|
| 1413 | + <?php if (isset($this->options['block-keywords'])) { |
|
| 1414 | 1414 | echo "keywords : " . $this->options['block-keywords'] . ","; |
| 1415 | 1415 | }?> |
| 1416 | 1416 | |
@@ -1420,10 +1420,10 @@ discard block |
||
| 1420 | 1420 | |
| 1421 | 1421 | $show_alignment = false; |
| 1422 | 1422 | |
| 1423 | - if ( ! empty( $this->arguments ) ) { |
|
| 1423 | + if (!empty($this->arguments)) { |
|
| 1424 | 1424 | echo "attributes : {"; |
| 1425 | 1425 | |
| 1426 | - if ( $show_advanced ) { |
|
| 1426 | + if ($show_advanced) { |
|
| 1427 | 1427 | echo "show_advanced: {"; |
| 1428 | 1428 | echo " type: 'boolean',"; |
| 1429 | 1429 | echo " default: false,"; |
@@ -1431,42 +1431,42 @@ discard block |
||
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | // block wrap element |
| 1434 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1434 | + if (isset($this->options['block-wrap'])) { //@todo we should validate this? |
|
| 1435 | 1435 | echo "block_wrap: {"; |
| 1436 | 1436 | echo " type: 'string',"; |
| 1437 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1437 | + echo " default: '" . esc_attr($this->options['block-wrap']) . "',"; |
|
| 1438 | 1438 | echo "},"; |
| 1439 | 1439 | } |
| 1440 | 1440 | |
| 1441 | 1441 | |
| 1442 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1442 | + foreach ($this->arguments as $key => $args) { |
|
| 1443 | 1443 | |
| 1444 | 1444 | // set if we should show alignment |
| 1445 | - if ( $key == 'alignment' ) { |
|
| 1445 | + if ($key == 'alignment') { |
|
| 1446 | 1446 | $show_alignment = true; |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | $extra = ''; |
| 1450 | 1450 | |
| 1451 | - if ( $args['type'] == 'checkbox' ) { |
|
| 1451 | + if ($args['type'] == 'checkbox') { |
|
| 1452 | 1452 | $type = 'boolean'; |
| 1453 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1454 | - } elseif ( $args['type'] == 'number' ) { |
|
| 1453 | + $default = isset($args['default']) && $args['default'] ? 'true' : 'false'; |
|
| 1454 | + } elseif ($args['type'] == 'number') { |
|
| 1455 | 1455 | $type = 'number'; |
| 1456 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1457 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1456 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1457 | + } elseif ($args['type'] == 'select' && !empty($args['multiple'])) { |
|
| 1458 | 1458 | $type = 'array'; |
| 1459 | - if ( is_array( $args['default'] ) ) { |
|
| 1460 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1459 | + if (is_array($args['default'])) { |
|
| 1460 | + $default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]"; |
|
| 1461 | 1461 | } else { |
| 1462 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1462 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1463 | 1463 | } |
| 1464 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1464 | + } elseif ($args['type'] == 'multiselect') { |
|
| 1465 | 1465 | $type = 'array'; |
| 1466 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1466 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1467 | 1467 | } else { |
| 1468 | 1468 | $type = 'string'; |
| 1469 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1469 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1470 | 1470 | } |
| 1471 | 1471 | echo $key . " : {"; |
| 1472 | 1472 | echo "type : '$type',"; |
@@ -1496,12 +1496,12 @@ discard block |
||
| 1496 | 1496 | is_fetching = true; |
| 1497 | 1497 | var data = { |
| 1498 | 1498 | 'action': 'super_duper_output_shortcode', |
| 1499 | - 'shortcode': '<?php echo $this->options['base_id'];?>', |
|
| 1499 | + 'shortcode': '<?php echo $this->options['base_id']; ?>', |
|
| 1500 | 1500 | 'attributes': props.attributes, |
| 1501 | - 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
|
| 1501 | + 'post_id': <?php global $post; if (isset($post->ID)) { |
|
| 1502 | 1502 | echo $post->ID; |
| 1503 | 1503 | }?>, |
| 1504 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 1504 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 1505 | 1505 | }; |
| 1506 | 1506 | |
| 1507 | 1507 | jQuery.post(ajaxurl, data, function (response) { |
@@ -1510,7 +1510,7 @@ discard block |
||
| 1510 | 1510 | |
| 1511 | 1511 | // if the content is empty then we place some placeholder text |
| 1512 | 1512 | if (env == '') { |
| 1513 | - env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>"; |
|
| 1513 | + env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>"; |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | 1516 | props.setAttributes({content: env}); |
@@ -1529,7 +1529,7 @@ discard block |
||
| 1529 | 1529 | |
| 1530 | 1530 | el(wp.editor.BlockControls, {key: 'controls'}, |
| 1531 | 1531 | |
| 1532 | - <?php if($show_alignment){?> |
|
| 1532 | + <?php if ($show_alignment) {?> |
|
| 1533 | 1533 | el( |
| 1534 | 1534 | wp.editor.AlignmentToolbar, |
| 1535 | 1535 | { |
@@ -1547,9 +1547,9 @@ discard block |
||
| 1547 | 1547 | |
| 1548 | 1548 | <?php |
| 1549 | 1549 | |
| 1550 | - if(! empty( $this->arguments )){ |
|
| 1550 | + if (!empty($this->arguments)) { |
|
| 1551 | 1551 | |
| 1552 | - if ( $show_advanced ) { |
|
| 1552 | + if ($show_advanced) { |
|
| 1553 | 1553 | ?> |
| 1554 | 1554 | el( |
| 1555 | 1555 | wp.components.ToggleControl, |
@@ -1565,76 +1565,76 @@ discard block |
||
| 1565 | 1565 | |
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | - foreach($this->arguments as $key => $args){ |
|
| 1569 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 1568 | + foreach ($this->arguments as $key => $args) { |
|
| 1569 | + $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : ''; |
|
| 1570 | 1570 | $options = ''; |
| 1571 | 1571 | $extra = ''; |
| 1572 | 1572 | $require = ''; |
| 1573 | 1573 | $onchange = "props.setAttributes({ $key: $key } )"; |
| 1574 | 1574 | $value = "props.attributes.$key"; |
| 1575 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1576 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 1575 | + $text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color'); |
|
| 1576 | + if (in_array($args['type'], $text_type)) { |
|
| 1577 | 1577 | $type = 'TextControl'; |
| 1578 | 1578 | // Save numbers as numbers and not strings |
| 1579 | - if ( $args['type'] == 'number' ) { |
|
| 1579 | + if ($args['type'] == 'number') { |
|
| 1580 | 1580 | $onchange = "props.setAttributes({ $key: Number($key) } )"; |
| 1581 | 1581 | } |
| 1582 | 1582 | } |
| 1583 | 1583 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we may have to add our own https://github.com/WordPress/gutenberg/issues/14378 |
| 1584 | 1584 | // $type = 'ColorPicker'; |
| 1585 | 1585 | // } |
| 1586 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 1586 | + elseif ($args['type'] == 'checkbox') { |
|
| 1587 | 1587 | $type = 'CheckboxControl'; |
| 1588 | 1588 | $extra .= "checked: props.attributes.$key,"; |
| 1589 | 1589 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
| 1590 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1590 | + } elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') { |
|
| 1591 | 1591 | $type = 'SelectControl'; |
| 1592 | - if ( ! empty( $args['options'] ) ) { |
|
| 1592 | + if (!empty($args['options'])) { |
|
| 1593 | 1593 | $options .= "options : ["; |
| 1594 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1595 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1594 | + foreach ($args['options'] as $option_val => $option_label) { |
|
| 1595 | + $options .= "{ value : '" . esc_attr($option_val) . "', label : '" . esc_attr($option_label) . "' },"; |
|
| 1596 | 1596 | } |
| 1597 | 1597 | $options .= "],"; |
| 1598 | 1598 | } |
| 1599 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1599 | + if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1600 | 1600 | $extra .= ' multiple: true, '; |
| 1601 | 1601 | //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
| 1602 | 1602 | //$value = "['edit', 'delete']"; |
| 1603 | 1603 | } |
| 1604 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 1604 | + } elseif ($args['type'] == 'alignment') { |
|
| 1605 | 1605 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
| 1606 | 1606 | } else { |
| 1607 | - continue;// if we have not implemented the control then don't break the JS. |
|
| 1607 | + continue; // if we have not implemented the control then don't break the JS. |
|
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | // add show only if advanced |
| 1611 | - if ( ! empty( $args['advanced'] ) ) { |
|
| 1611 | + if (!empty($args['advanced'])) { |
|
| 1612 | 1612 | echo "props.attributes.show_advanced && "; |
| 1613 | 1613 | } |
| 1614 | 1614 | // add setting require if defined |
| 1615 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 1616 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1615 | + if (!empty($args['element_require'])) { |
|
| 1616 | + echo $this->block_props_replace($args['element_require'], true) . " && "; |
|
| 1617 | 1617 | } |
| 1618 | 1618 | ?> |
| 1619 | 1619 | el( |
| 1620 | - wp.components.<?php echo esc_attr( $type );?>, |
|
| 1620 | + wp.components.<?php echo esc_attr($type); ?>, |
|
| 1621 | 1621 | { |
| 1622 | - label: '<?php echo esc_attr( $args['title'] );?>', |
|
| 1623 | - help: '<?php if ( isset( $args['desc'] ) ) { |
|
| 1624 | - echo esc_attr( $args['desc'] ); |
|
| 1622 | + label: '<?php echo esc_attr($args['title']); ?>', |
|
| 1623 | + help: '<?php if (isset($args['desc'])) { |
|
| 1624 | + echo esc_attr($args['desc']); |
|
| 1625 | 1625 | }?>', |
| 1626 | - value: <?php echo $value;?>, |
|
| 1627 | - <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
|
| 1628 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1626 | + value: <?php echo $value; ?>, |
|
| 1627 | + <?php if ($type == 'TextControl' && $args['type'] != 'text') { |
|
| 1628 | + echo "type: '" . esc_attr($args['type']) . "',"; |
|
| 1629 | 1629 | }?> |
| 1630 | - <?php if ( ! empty( $args['placeholder'] ) ) { |
|
| 1631 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1630 | + <?php if (!empty($args['placeholder'])) { |
|
| 1631 | + echo "placeholder: '" . esc_attr($args['placeholder']) . "',"; |
|
| 1632 | 1632 | }?> |
| 1633 | - <?php echo $options;?> |
|
| 1634 | - <?php echo $extra;?> |
|
| 1635 | - <?php echo $custom_attributes;?> |
|
| 1636 | - onChange: function ( <?php echo $key;?> ) { |
|
| 1637 | - <?php echo $onchange;?> |
|
| 1633 | + <?php echo $options; ?> |
|
| 1634 | + <?php echo $extra; ?> |
|
| 1635 | + <?php echo $custom_attributes; ?> |
|
| 1636 | + onChange: function ( <?php echo $key; ?> ) { |
|
| 1637 | + <?php echo $onchange; ?> |
|
| 1638 | 1638 | } |
| 1639 | 1639 | } |
| 1640 | 1640 | ), |
@@ -1647,9 +1647,9 @@ discard block |
||
| 1647 | 1647 | |
| 1648 | 1648 | <?php |
| 1649 | 1649 | // If the user sets block-output array then build it |
| 1650 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1651 | - $this->block_element( $this->options['block-output'] ); |
|
| 1652 | - }else{ |
|
| 1650 | + if (!empty($this->options['block-output'])) { |
|
| 1651 | + $this->block_element($this->options['block-output']); |
|
| 1652 | + } else { |
|
| 1653 | 1653 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1654 | 1654 | ?> |
| 1655 | 1655 | el('div', { |
@@ -1673,14 +1673,14 @@ discard block |
||
| 1673 | 1673 | var align = ''; |
| 1674 | 1674 | |
| 1675 | 1675 | // build the shortcode. |
| 1676 | - var content = "[<?php echo $this->options['base_id'];?>"; |
|
| 1676 | + var content = "[<?php echo $this->options['base_id']; ?>"; |
|
| 1677 | 1677 | <?php |
| 1678 | 1678 | |
| 1679 | - if(! empty( $this->arguments )){ |
|
| 1680 | - foreach($this->arguments as $key => $args){ |
|
| 1679 | + if (!empty($this->arguments)) { |
|
| 1680 | + foreach ($this->arguments as $key => $args) { |
|
| 1681 | 1681 | ?> |
| 1682 | - if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
|
| 1683 | - content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
|
| 1682 | + if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) { |
|
| 1683 | + content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' "; |
|
| 1684 | 1684 | } |
| 1685 | 1685 | <?php |
| 1686 | 1686 | } |
@@ -1721,10 +1721,10 @@ discard block |
||
| 1721 | 1721 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1722 | 1722 | */ |
| 1723 | 1723 | |
| 1724 | - return str_replace( array( |
|
| 1724 | + return str_replace(array( |
|
| 1725 | 1725 | '<script>', |
| 1726 | 1726 | '</script>' |
| 1727 | - ), '', $output ); |
|
| 1727 | + ), '', $output); |
|
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | 1730 | /** |
@@ -1736,16 +1736,16 @@ discard block |
||
| 1736 | 1736 | * |
| 1737 | 1737 | * @return string |
| 1738 | 1738 | */ |
| 1739 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 1739 | + public function array_to_attributes($custom_attributes, $html = false) { |
|
| 1740 | 1740 | $attributes = ''; |
| 1741 | - if ( ! empty( $custom_attributes ) ) { |
|
| 1741 | + if (!empty($custom_attributes)) { |
|
| 1742 | 1742 | |
| 1743 | - if ( $html ) { |
|
| 1744 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1743 | + if ($html) { |
|
| 1744 | + foreach ($custom_attributes as $key => $val) { |
|
| 1745 | 1745 | $attributes .= " $key='$val' "; |
| 1746 | 1746 | } |
| 1747 | 1747 | } else { |
| 1748 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1748 | + foreach ($custom_attributes as $key => $val) { |
|
| 1749 | 1749 | $attributes .= "'$key': '$val',"; |
| 1750 | 1750 | } |
| 1751 | 1751 | } |
@@ -1761,86 +1761,86 @@ discard block |
||
| 1761 | 1761 | * |
| 1762 | 1762 | * @param $args |
| 1763 | 1763 | */ |
| 1764 | - public function block_element( $args ) { |
|
| 1764 | + public function block_element($args) { |
|
| 1765 | 1765 | |
| 1766 | 1766 | |
| 1767 | - if ( ! empty( $args ) ) { |
|
| 1768 | - foreach ( $args as $element => $new_args ) { |
|
| 1767 | + if (!empty($args)) { |
|
| 1768 | + foreach ($args as $element => $new_args) { |
|
| 1769 | 1769 | |
| 1770 | - if ( is_array( $new_args ) ) { // its an element |
|
| 1770 | + if (is_array($new_args)) { // its an element |
|
| 1771 | 1771 | |
| 1772 | 1772 | |
| 1773 | - if ( isset( $new_args['element'] ) ) { |
|
| 1773 | + if (isset($new_args['element'])) { |
|
| 1774 | 1774 | |
| 1775 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 1776 | - echo str_replace( array( |
|
| 1775 | + if (isset($new_args['element_require'])) { |
|
| 1776 | + echo str_replace(array( |
|
| 1777 | 1777 | "'+", |
| 1778 | 1778 | "+'" |
| 1779 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 1780 | - unset( $new_args['element_require'] ); |
|
| 1779 | + ), '', $this->block_props_replace($new_args['element_require'])) . " && "; |
|
| 1780 | + unset($new_args['element_require']); |
|
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | echo "\n el( '" . $new_args['element'] . "', {"; |
| 1784 | 1784 | |
| 1785 | 1785 | // get the attributes |
| 1786 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1786 | + foreach ($new_args as $new_key => $new_value) { |
|
| 1787 | 1787 | |
| 1788 | 1788 | |
| 1789 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 1789 | + if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) { |
|
| 1790 | 1790 | // do nothing |
| 1791 | 1791 | } else { |
| 1792 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 1792 | + echo $this->block_element(array($new_key => $new_value)); |
|
| 1793 | 1793 | } |
| 1794 | 1794 | } |
| 1795 | 1795 | |
| 1796 | - echo "},";// end attributes |
|
| 1796 | + echo "},"; // end attributes |
|
| 1797 | 1797 | |
| 1798 | 1798 | // get the content |
| 1799 | 1799 | $first_item = 0; |
| 1800 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1801 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 1800 | + foreach ($new_args as $new_key => $new_value) { |
|
| 1801 | + if ($new_key === 'content' || is_array($new_value)) { |
|
| 1802 | 1802 | |
| 1803 | - if ( $new_key === 'content' ) { |
|
| 1804 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
| 1803 | + if ($new_key === 'content') { |
|
| 1804 | + echo "'" . $this->block_props_replace($new_value) . "'"; |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | - if ( is_array( $new_value ) ) { |
|
| 1807 | + if (is_array($new_value)) { |
|
| 1808 | 1808 | |
| 1809 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 1810 | - echo str_replace( array( |
|
| 1809 | + if (isset($new_value['element_require'])) { |
|
| 1810 | + echo str_replace(array( |
|
| 1811 | 1811 | "'+", |
| 1812 | 1812 | "+'" |
| 1813 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 1814 | - unset( $new_value['element_require'] ); |
|
| 1813 | + ), '', $this->block_props_replace($new_value['element_require'])) . " && "; |
|
| 1814 | + unset($new_value['element_require']); |
|
| 1815 | 1815 | } |
| 1816 | 1816 | |
| 1817 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 1817 | + if (isset($new_value['element_repeat'])) { |
|
| 1818 | 1818 | $x = 1; |
| 1819 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 1820 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1821 | - $x ++; |
|
| 1819 | + while ($x <= absint($new_value['element_repeat'])) { |
|
| 1820 | + $this->block_element(array('' => $new_value)); |
|
| 1821 | + $x++; |
|
| 1822 | 1822 | } |
| 1823 | 1823 | } else { |
| 1824 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1824 | + $this->block_element(array('' => $new_value)); |
|
| 1825 | 1825 | } |
| 1826 | 1826 | } |
| 1827 | - $first_item ++; |
|
| 1827 | + $first_item++; |
|
| 1828 | 1828 | } |
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | - echo ")";// end content |
|
| 1831 | + echo ")"; // end content |
|
| 1832 | 1832 | |
| 1833 | 1833 | echo ", \n"; |
| 1834 | 1834 | |
| 1835 | 1835 | } |
| 1836 | 1836 | } else { |
| 1837 | 1837 | |
| 1838 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 1839 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 1840 | - } elseif ( $element == 'style' ) { |
|
| 1841 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 1838 | + if (substr($element, 0, 3) === "if_") { |
|
| 1839 | + echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ","; |
|
| 1840 | + } elseif ($element == 'style') { |
|
| 1841 | + echo $element . ": " . $this->block_props_replace($new_args) . ","; |
|
| 1842 | 1842 | } else { |
| 1843 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 1843 | + echo $element . ": '" . $this->block_props_replace($new_args) . "',"; |
|
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | } |
@@ -1855,12 +1855,12 @@ discard block |
||
| 1855 | 1855 | * |
| 1856 | 1856 | * @return mixed |
| 1857 | 1857 | */ |
| 1858 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 1858 | + public function block_props_replace($string, $no_wrap = false) { |
|
| 1859 | 1859 | |
| 1860 | - if ( $no_wrap ) { |
|
| 1861 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 1860 | + if ($no_wrap) { |
|
| 1861 | + $string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string); |
|
| 1862 | 1862 | } else { |
| 1863 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 1863 | + $string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string); |
|
| 1864 | 1864 | } |
| 1865 | 1865 | |
| 1866 | 1866 | return $string; |
@@ -1872,37 +1872,37 @@ discard block |
||
| 1872 | 1872 | * @param array $args |
| 1873 | 1873 | * @param array $instance |
| 1874 | 1874 | */ |
| 1875 | - public function widget( $args, $instance ) { |
|
| 1875 | + public function widget($args, $instance) { |
|
| 1876 | 1876 | |
| 1877 | 1877 | // get the filtered values |
| 1878 | - $argument_values = $this->argument_values( $instance ); |
|
| 1879 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 1880 | - $output = $this->output( $argument_values, $args ); |
|
| 1878 | + $argument_values = $this->argument_values($instance); |
|
| 1879 | + $argument_values = $this->string_to_bool($argument_values); |
|
| 1880 | + $output = $this->output($argument_values, $args); |
|
| 1881 | 1881 | |
| 1882 | - if ( $output ) { |
|
| 1882 | + if ($output) { |
|
| 1883 | 1883 | // Before widget |
| 1884 | 1884 | $before_widget = $args['before_widget']; |
| 1885 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 1886 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 1885 | + $before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this); |
|
| 1886 | + $before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this); |
|
| 1887 | 1887 | |
| 1888 | 1888 | // After widget |
| 1889 | 1889 | $after_widget = $args['after_widget']; |
| 1890 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 1891 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 1890 | + $after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this); |
|
| 1891 | + $after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this); |
|
| 1892 | 1892 | |
| 1893 | 1893 | echo $before_widget; |
| 1894 | 1894 | // elementor strips the widget wrapping div so we check for and add it back if needed |
| 1895 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1896 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 1895 | + if ($this->is_elementor_widget_output()) { |
|
| 1896 | + echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : ''; |
|
| 1897 | 1897 | } |
| 1898 | - echo $this->output_title( $args, $instance ); |
|
| 1898 | + echo $this->output_title($args, $instance); |
|
| 1899 | 1899 | echo $output; |
| 1900 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1901 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 1900 | + if ($this->is_elementor_widget_output()) { |
|
| 1901 | + echo !empty($this->options['widget_ops']['classname']) ? "</span>" : ''; |
|
| 1902 | 1902 | } |
| 1903 | 1903 | echo $after_widget; |
| 1904 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 1905 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 1904 | + } elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty |
|
| 1905 | + $output = $this->preview_placeholder_text("{{" . $this->base_id . "}}"); |
|
| 1906 | 1906 | echo $output; |
| 1907 | 1907 | } |
| 1908 | 1908 | } |
@@ -1915,7 +1915,7 @@ discard block |
||
| 1915 | 1915 | */ |
| 1916 | 1916 | public function is_elementor_widget_output() { |
| 1917 | 1917 | $result = false; |
| 1918 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 1918 | + if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') { |
|
| 1919 | 1919 | $result = true; |
| 1920 | 1920 | } |
| 1921 | 1921 | |
@@ -1930,7 +1930,7 @@ discard block |
||
| 1930 | 1930 | */ |
| 1931 | 1931 | public function is_elementor_preview() { |
| 1932 | 1932 | $result = false; |
| 1933 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 1933 | + if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) { |
|
| 1934 | 1934 | $result = true; |
| 1935 | 1935 | } |
| 1936 | 1936 | |
@@ -1945,7 +1945,7 @@ discard block |
||
| 1945 | 1945 | */ |
| 1946 | 1946 | public function is_divi_preview() { |
| 1947 | 1947 | $result = false; |
| 1948 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 1948 | + if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) { |
|
| 1949 | 1949 | $result = true; |
| 1950 | 1950 | } |
| 1951 | 1951 | |
@@ -1960,7 +1960,7 @@ discard block |
||
| 1960 | 1960 | */ |
| 1961 | 1961 | public function is_beaver_preview() { |
| 1962 | 1962 | $result = false; |
| 1963 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 1963 | + if (isset($_REQUEST['fl_builder'])) { |
|
| 1964 | 1964 | $result = true; |
| 1965 | 1965 | } |
| 1966 | 1966 | |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | */ |
| 1976 | 1976 | public function is_siteorigin_preview() { |
| 1977 | 1977 | $result = false; |
| 1978 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 1978 | + if (!empty($_REQUEST['siteorigin_panels_live_editor'])) { |
|
| 1979 | 1979 | $result = true; |
| 1980 | 1980 | } |
| 1981 | 1981 | |
@@ -1990,7 +1990,7 @@ discard block |
||
| 1990 | 1990 | */ |
| 1991 | 1991 | public function is_cornerstone_preview() { |
| 1992 | 1992 | $result = false; |
| 1993 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 1993 | + if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') { |
|
| 1994 | 1994 | $result = true; |
| 1995 | 1995 | } |
| 1996 | 1996 | |
@@ -2005,15 +2005,15 @@ discard block |
||
| 2005 | 2005 | */ |
| 2006 | 2006 | public function is_preview() { |
| 2007 | 2007 | $preview = false; |
| 2008 | - if ( $this->is_divi_preview() ) { |
|
| 2008 | + if ($this->is_divi_preview()) { |
|
| 2009 | 2009 | $preview = true; |
| 2010 | - } elseif ( $this->is_elementor_preview() ) { |
|
| 2010 | + } elseif ($this->is_elementor_preview()) { |
|
| 2011 | 2011 | $preview = true; |
| 2012 | - } elseif ( $this->is_beaver_preview() ) { |
|
| 2012 | + } elseif ($this->is_beaver_preview()) { |
|
| 2013 | 2013 | $preview = true; |
| 2014 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2014 | + } elseif ($this->is_siteorigin_preview()) { |
|
| 2015 | 2015 | $preview = true; |
| 2016 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2016 | + } elseif ($this->is_cornerstone_preview()) { |
|
| 2017 | 2017 | $preview = true; |
| 2018 | 2018 | } |
| 2019 | 2019 | |
@@ -2028,11 +2028,11 @@ discard block |
||
| 2028 | 2028 | * |
| 2029 | 2029 | * @return string |
| 2030 | 2030 | */ |
| 2031 | - public function output_title( $args, $instance = array() ) { |
|
| 2031 | + public function output_title($args, $instance = array()) { |
|
| 2032 | 2032 | $output = ''; |
| 2033 | - if ( ! empty( $instance['title'] ) ) { |
|
| 2033 | + if (!empty($instance['title'])) { |
|
| 2034 | 2034 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 2035 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2035 | + $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
|
| 2036 | 2036 | $output = $args['before_title'] . $title . $args['after_title']; |
| 2037 | 2037 | } |
| 2038 | 2038 | |
@@ -2044,7 +2044,7 @@ discard block |
||
| 2044 | 2044 | * |
| 2045 | 2045 | * @param array $instance The widget options. |
| 2046 | 2046 | */ |
| 2047 | - public function form( $instance ) { |
|
| 2047 | + public function form($instance) { |
|
| 2048 | 2048 | |
| 2049 | 2049 | // set widget instance |
| 2050 | 2050 | $this->instance = $instance; |
@@ -2052,12 +2052,12 @@ discard block |
||
| 2052 | 2052 | // set it as a SD widget |
| 2053 | 2053 | echo $this->widget_advanced_toggle(); |
| 2054 | 2054 | |
| 2055 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2055 | + echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>"; |
|
| 2056 | 2056 | $arguments = $this->get_arguments(); |
| 2057 | 2057 | |
| 2058 | - if ( is_array( $arguments ) ) { |
|
| 2059 | - foreach ( $arguments as $key => $args ) { |
|
| 2060 | - $this->widget_inputs( $args, $instance ); |
|
| 2058 | + if (is_array($arguments)) { |
|
| 2059 | + foreach ($arguments as $key => $args) { |
|
| 2060 | + $this->widget_inputs($args, $instance); |
|
| 2061 | 2061 | } |
| 2062 | 2062 | } |
| 2063 | 2063 | } |
@@ -2070,7 +2070,7 @@ discard block |
||
| 2070 | 2070 | public function widget_advanced_toggle() { |
| 2071 | 2071 | |
| 2072 | 2072 | $output = ''; |
| 2073 | - if ( $this->block_show_advanced() ) { |
|
| 2073 | + if ($this->block_show_advanced()) { |
|
| 2074 | 2074 | $val = 1; |
| 2075 | 2075 | } else { |
| 2076 | 2076 | $val = 0; |
@@ -2090,14 +2090,14 @@ discard block |
||
| 2090 | 2090 | * |
| 2091 | 2091 | * @return string $output |
| 2092 | 2092 | */ |
| 2093 | - public function convert_element_require( $input ) { |
|
| 2093 | + public function convert_element_require($input) { |
|
| 2094 | 2094 | |
| 2095 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2095 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
| 2096 | 2096 | |
| 2097 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2097 | + $output = esc_attr(str_replace(array("[%", "%]"), array( |
|
| 2098 | 2098 | "jQuery(form).find('[data-argument=\"", |
| 2099 | 2099 | "\"]').find('input,select').val()" |
| 2100 | - ), $input ) ); |
|
| 2100 | + ), $input)); |
|
| 2101 | 2101 | |
| 2102 | 2102 | return $output; |
| 2103 | 2103 | } |
@@ -2108,54 +2108,54 @@ discard block |
||
| 2108 | 2108 | * @param $args |
| 2109 | 2109 | * @param $instance |
| 2110 | 2110 | */ |
| 2111 | - public function widget_inputs( $args, $instance ) { |
|
| 2111 | + public function widget_inputs($args, $instance) { |
|
| 2112 | 2112 | |
| 2113 | 2113 | $class = ""; |
| 2114 | 2114 | $element_require = ""; |
| 2115 | 2115 | $custom_attributes = ""; |
| 2116 | 2116 | |
| 2117 | 2117 | // get value |
| 2118 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2119 | - $value = $instance[ $args['name'] ]; |
|
| 2120 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2121 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2118 | + if (isset($instance[$args['name']])) { |
|
| 2119 | + $value = $instance[$args['name']]; |
|
| 2120 | + } elseif (!isset($instance[$args['name']]) && !empty($args['default'])) { |
|
| 2121 | + $value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']); |
|
| 2122 | 2122 | } else { |
| 2123 | 2123 | $value = ''; |
| 2124 | 2124 | } |
| 2125 | 2125 | |
| 2126 | 2126 | // get placeholder |
| 2127 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 2128 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2127 | + if (!empty($args['placeholder'])) { |
|
| 2128 | + $placeholder = "placeholder='" . esc_html($args['placeholder']) . "'"; |
|
| 2129 | 2129 | } else { |
| 2130 | 2130 | $placeholder = ''; |
| 2131 | 2131 | } |
| 2132 | 2132 | |
| 2133 | 2133 | // get if advanced |
| 2134 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2134 | + if (isset($args['advanced']) && $args['advanced']) { |
|
| 2135 | 2135 | $class .= " sd-advanced-setting "; |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | 2138 | // element_require |
| 2139 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2139 | + if (isset($args['element_require']) && $args['element_require']) { |
|
| 2140 | 2140 | $element_require = $args['element_require']; |
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | // custom_attributes |
| 2144 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2145 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2144 | + if (isset($args['custom_attributes']) && $args['custom_attributes']) { |
|
| 2145 | + $custom_attributes = $this->array_to_attributes($args['custom_attributes'], true); |
|
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | 2148 | // before wrapper |
| 2149 | 2149 | ?> |
| 2150 | - <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
|
| 2151 | - data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
|
| 2152 | - data-element_require='<?php if ( $element_require ) { |
|
| 2153 | - echo $this->convert_element_require( $element_require ); |
|
| 2150 | + <p class="sd-argument <?php echo esc_attr($class); ?>" |
|
| 2151 | + data-argument='<?php echo esc_attr($args['name']); ?>' |
|
| 2152 | + data-element_require='<?php if ($element_require) { |
|
| 2153 | + echo $this->convert_element_require($element_require); |
|
| 2154 | 2154 | } ?>' |
| 2155 | 2155 | > |
| 2156 | 2156 | <?php |
| 2157 | 2157 | |
| 2158 | - switch ( $args['type'] ) { |
|
| 2158 | + switch ($args['type']) { |
|
| 2159 | 2159 | //array('text','password','number','email','tel','url','color') |
| 2160 | 2160 | case "text": |
| 2161 | 2161 | case "password": |
@@ -2166,46 +2166,46 @@ discard block |
||
| 2166 | 2166 | case "color": |
| 2167 | 2167 | ?> |
| 2168 | 2168 | <label |
| 2169 | - 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> |
|
| 2169 | + 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> |
|
| 2170 | 2170 | <input <?php echo $placeholder; ?> class="widefat" |
| 2171 | 2171 | <?php echo $custom_attributes; ?> |
| 2172 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2173 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
| 2174 | - type="<?php echo esc_attr( $args['type'] ); ?>" |
|
| 2175 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2172 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2173 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
| 2174 | + type="<?php echo esc_attr($args['type']); ?>" |
|
| 2175 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2176 | 2176 | <?php |
| 2177 | 2177 | |
| 2178 | 2178 | break; |
| 2179 | 2179 | case "select": |
| 2180 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2181 | - if ( $multiple ) { |
|
| 2182 | - if ( empty( $value ) ) { |
|
| 2180 | + $multiple = isset($args['multiple']) && $args['multiple'] ? true : false; |
|
| 2181 | + if ($multiple) { |
|
| 2182 | + if (empty($value)) { |
|
| 2183 | 2183 | $value = array(); |
| 2184 | 2184 | } |
| 2185 | 2185 | } |
| 2186 | 2186 | ?> |
| 2187 | 2187 | <label |
| 2188 | - 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> |
|
| 2188 | + 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> |
|
| 2189 | 2189 | <select <?php echo $placeholder; ?> class="widefat" |
| 2190 | 2190 | <?php echo $custom_attributes; ?> |
| 2191 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2192 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
|
| 2193 | - if ( $multiple ) { |
|
| 2191 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2192 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); |
|
| 2193 | + if ($multiple) { |
|
| 2194 | 2194 | echo "[]"; |
| 2195 | 2195 | } ?>" |
| 2196 | - <?php if ( $multiple ) { |
|
| 2196 | + <?php if ($multiple) { |
|
| 2197 | 2197 | echo "multiple"; |
| 2198 | 2198 | } //@todo not implemented yet due to gutenberg not supporting it |
| 2199 | 2199 | ?> |
| 2200 | 2200 | > |
| 2201 | 2201 | <?php |
| 2202 | 2202 | |
| 2203 | - if ( ! empty( $args['options'] ) ) { |
|
| 2204 | - foreach ( $args['options'] as $val => $label ) { |
|
| 2205 | - if ( $multiple ) { |
|
| 2206 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2203 | + if (!empty($args['options'])) { |
|
| 2204 | + foreach ($args['options'] as $val => $label) { |
|
| 2205 | + if ($multiple) { |
|
| 2206 | + $selected = in_array($val, $value) ? 'selected="selected"' : ''; |
|
| 2207 | 2207 | } else { |
| 2208 | - $selected = selected( $value, $val, false ); |
|
| 2208 | + $selected = selected($value, $val, false); |
|
| 2209 | 2209 | } |
| 2210 | 2210 | echo "<option value='$val' " . $selected . ">$label</option>"; |
| 2211 | 2211 | } |
@@ -2217,20 +2217,20 @@ discard block |
||
| 2217 | 2217 | case "checkbox": |
| 2218 | 2218 | ?> |
| 2219 | 2219 | <input <?php echo $placeholder; ?> |
| 2220 | - <?php checked( 1, $value, true ) ?> |
|
| 2220 | + <?php checked(1, $value, true) ?> |
|
| 2221 | 2221 | <?php echo $custom_attributes; ?> |
| 2222 | - class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2223 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" |
|
| 2222 | + class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2223 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox" |
|
| 2224 | 2224 | value="1"> |
| 2225 | 2225 | <label |
| 2226 | - 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> |
|
| 2226 | + 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> |
|
| 2227 | 2227 | <?php |
| 2228 | 2228 | break; |
| 2229 | 2229 | case "hidden": |
| 2230 | 2230 | ?> |
| 2231 | - <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2232 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
|
| 2233 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2231 | + <input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2232 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden" |
|
| 2233 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2234 | 2234 | <?php |
| 2235 | 2235 | break; |
| 2236 | 2236 | default: |
@@ -2252,14 +2252,14 @@ discard block |
||
| 2252 | 2252 | * @return string |
| 2253 | 2253 | * @todo, need to make its own tooltip script |
| 2254 | 2254 | */ |
| 2255 | - public function widget_field_desc( $args ) { |
|
| 2255 | + public function widget_field_desc($args) { |
|
| 2256 | 2256 | |
| 2257 | 2257 | $description = ''; |
| 2258 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2259 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2260 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 2258 | + if (isset($args['desc']) && $args['desc']) { |
|
| 2259 | + if (isset($args['desc_tip']) && $args['desc_tip']) { |
|
| 2260 | + $description = $this->desc_tip($args['desc']); |
|
| 2261 | 2261 | } else { |
| 2262 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2262 | + $description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>'; |
|
| 2263 | 2263 | } |
| 2264 | 2264 | } |
| 2265 | 2265 | |
@@ -2274,11 +2274,11 @@ discard block |
||
| 2274 | 2274 | * |
| 2275 | 2275 | * @return string |
| 2276 | 2276 | */ |
| 2277 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 2278 | - if ( $allow_html ) { |
|
| 2279 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 2277 | + function desc_tip($tip, $allow_html = false) { |
|
| 2278 | + if ($allow_html) { |
|
| 2279 | + $tip = $this->sanitize_tooltip($tip); |
|
| 2280 | 2280 | } else { |
| 2281 | - $tip = esc_attr( $tip ); |
|
| 2281 | + $tip = esc_attr($tip); |
|
| 2282 | 2282 | } |
| 2283 | 2283 | |
| 2284 | 2284 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -2291,8 +2291,8 @@ discard block |
||
| 2291 | 2291 | * |
| 2292 | 2292 | * @return string |
| 2293 | 2293 | */ |
| 2294 | - public function sanitize_tooltip( $var ) { |
|
| 2295 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2294 | + public function sanitize_tooltip($var) { |
|
| 2295 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
| 2296 | 2296 | 'br' => array(), |
| 2297 | 2297 | 'em' => array(), |
| 2298 | 2298 | 'strong' => array(), |
@@ -2302,7 +2302,7 @@ discard block |
||
| 2302 | 2302 | 'li' => array(), |
| 2303 | 2303 | 'ol' => array(), |
| 2304 | 2304 | 'p' => array(), |
| 2305 | - ) ) ); |
|
| 2305 | + ))); |
|
| 2306 | 2306 | } |
| 2307 | 2307 | |
| 2308 | 2308 | /** |
@@ -2314,23 +2314,23 @@ discard block |
||
| 2314 | 2314 | * @return array |
| 2315 | 2315 | * @todo we should add some sanitation here. |
| 2316 | 2316 | */ |
| 2317 | - public function update( $new_instance, $old_instance ) { |
|
| 2317 | + public function update($new_instance, $old_instance) { |
|
| 2318 | 2318 | |
| 2319 | 2319 | //save the widget |
| 2320 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2320 | + $instance = array_merge((array)$old_instance, (array)$new_instance); |
|
| 2321 | 2321 | |
| 2322 | 2322 | // set widget instance |
| 2323 | 2323 | $this->instance = $instance; |
| 2324 | 2324 | |
| 2325 | - if ( empty( $this->arguments ) ) { |
|
| 2325 | + if (empty($this->arguments)) { |
|
| 2326 | 2326 | $this->get_arguments(); |
| 2327 | 2327 | } |
| 2328 | 2328 | |
| 2329 | 2329 | // check for checkboxes |
| 2330 | - if ( ! empty( $this->arguments ) ) { |
|
| 2331 | - foreach ( $this->arguments as $argument ) { |
|
| 2332 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2333 | - $instance[ $argument['name'] ] = '0'; |
|
| 2330 | + if (!empty($this->arguments)) { |
|
| 2331 | + foreach ($this->arguments as $argument) { |
|
| 2332 | + if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) { |
|
| 2333 | + $instance[$argument['name']] = '0'; |
|
| 2334 | 2334 | } |
| 2335 | 2335 | } |
| 2336 | 2336 | } |
@@ -2348,7 +2348,7 @@ discard block |
||
| 2348 | 2348 | */ |
| 2349 | 2349 | public function is_block_content_call() { |
| 2350 | 2350 | $result = false; |
| 2351 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2351 | + if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') { |
|
| 2352 | 2352 | $result = true; |
| 2353 | 2353 | } |
| 2354 | 2354 | |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | <?php |
| 537 | 537 | if(! empty( $insert_shortcode_function )){ |
| 538 | 538 | echo $insert_shortcode_function; |
| 539 | - }else{ |
|
| 539 | + } else{ |
|
| 540 | 540 | |
| 541 | 541 | /** |
| 542 | 542 | * Function for super duper insert shortcode. |
@@ -1275,8 +1275,7 @@ discard block |
||
| 1275 | 1275 | $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
| 1276 | 1276 | if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
| 1277 | 1277 | // don't set default for an empty checkbox |
| 1278 | - } |
|
| 1279 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1278 | + } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1280 | 1279 | $argument_values[ $key ] = $args['default']; |
| 1281 | 1280 | } |
| 1282 | 1281 | } |
@@ -1649,7 +1648,7 @@ discard block |
||
| 1649 | 1648 | // If the user sets block-output array then build it |
| 1650 | 1649 | if ( ! empty( $this->options['block-output'] ) ) { |
| 1651 | 1650 | $this->block_element( $this->options['block-output'] ); |
| 1652 | - }else{ |
|
| 1651 | + } else{ |
|
| 1653 | 1652 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1654 | 1653 | ?> |
| 1655 | 1654 | el('div', { |
@@ -1,30 +1,30 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // MUST have WordPress. |
| 3 | -if ( !defined( 'WPINC' ) ) { |
|
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 3 | +if (!defined('WPINC')) { |
|
| 4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | class WPInv_Meta_Box_Details { |
| 8 | - public static function output( $post ) { |
|
| 8 | + public static function output($post) { |
|
| 9 | 9 | $currency_symbol = wpinv_currency_symbol(); |
| 10 | - $statuses = wpinv_get_invoice_statuses( true ); |
|
| 10 | + $statuses = wpinv_get_invoice_statuses(true); |
|
| 11 | 11 | |
| 12 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
| 13 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 12 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
| 13 | + $invoice = new WPInv_Invoice($post_id); |
|
| 14 | 14 | |
| 15 | - $status = $invoice->get_status( false ); // Current status |
|
| 15 | + $status = $invoice->get_status(false); // Current status |
|
| 16 | 16 | $discount = $invoice->get_discount(); |
| 17 | 17 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
| 18 | 18 | $invoice_number = $invoice->get_number(); |
| 19 | 19 | |
| 20 | 20 | $date_created = $invoice->get_created_date(); |
| 21 | - $datetime_created = strtotime( $date_created ); |
|
| 22 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
|
| 21 | + $datetime_created = strtotime($date_created); |
|
| 22 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : ''; |
|
| 23 | 23 | $date_completed = $invoice->get_completed_date(); |
| 24 | - $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a'; |
|
| 25 | - $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
|
| 26 | - $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
|
| 27 | - $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user’s email address.', 'invoicing' ); |
|
| 24 | + $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a'; |
|
| 25 | + $title['status'] = __('Invoice Status:', 'invoicing'); |
|
| 26 | + $title['number'] = __('Invoice Number:', 'invoicing'); |
|
| 27 | + $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user’s email address.', 'invoicing'); |
|
| 28 | 28 | |
| 29 | 29 | $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice); |
| 30 | 30 | $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice); |
@@ -34,36 +34,36 @@ discard block |
||
| 34 | 34 | <div class="gdmbx2-wrap form-table"> |
| 35 | 35 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
| 36 | 36 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
| 37 | - <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
|
| 38 | - <div class="gdmbx-td"><?php echo $date_created;?></div> |
|
| 37 | + <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div> |
|
| 38 | + <div class="gdmbx-td"><?php echo $date_created; ?></div> |
|
| 39 | 39 | </div> |
| 40 | - <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft', 'draft' ) ) ) ) { ?> |
|
| 40 | + <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft', 'draft')))) { ?> |
|
| 41 | 41 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
| 42 | - <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
|
| 42 | + <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div> |
|
| 43 | 43 | <div class="gdmbx-td"> |
| 44 | - <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd"> |
|
| 45 | - <p class="wpi-meta-row wpi-meta-desc"><?php _e( 'Leave blank to disable sending auto reminder for this invoice.', 'invoicing' );?></p> |
|
| 44 | + <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd"> |
|
| 45 | + <p class="wpi-meta-row wpi-meta-desc"><?php _e('Leave blank to disable sending auto reminder for this invoice.', 'invoicing'); ?></p> |
|
| 46 | 46 | </div> |
| 47 | 47 | </div> |
| 48 | 48 | <?php } ?> |
| 49 | - <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?> |
|
| 50 | - <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
|
| 49 | + <?php do_action('wpinv_meta_box_details_after_due_date', $post_id); ?> |
|
| 50 | + <?php if ($date_completed && $date_completed != 'n/a') { ?> |
|
| 51 | 51 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
| 52 | - <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
|
| 53 | - <div class="gdmbx-td"><?php echo $date_completed;?></div> |
|
| 52 | + <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div> |
|
| 53 | + <div class="gdmbx-td"><?php echo $date_completed; ?></div> |
|
| 54 | 54 | </div> |
| 55 | 55 | <?php } ?> |
| 56 | - <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?> |
|
| 56 | + <?php $is_viewed = wpinv_is_invoice_viewed($post_id); ?> |
|
| 57 | 57 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed"> |
| 58 | - <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div> |
|
| 59 | - <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div> |
|
| 58 | + <div class="gdmbx-th"><label><?php _e('Viewed by Customer:', 'invoicing'); ?></label></div> |
|
| 59 | + <div class="gdmbx-td"><?php (1 == $is_viewed) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?></div> |
|
| 60 | 60 | </div> |
| 61 | 61 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
| 62 | 62 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
| 63 | 63 | <div class="gdmbx-td"> |
| 64 | 64 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select wpi_select2"> |
| 65 | - <?php foreach ( $statuses as $value => $label ) { ?> |
|
| 66 | - <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
|
| 65 | + <?php foreach ($statuses as $value => $label) { ?> |
|
| 66 | + <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option> |
|
| 67 | 67 | <?php } ?> |
| 68 | 68 | </select> |
| 69 | 69 | </div> |
@@ -71,117 +71,117 @@ discard block |
||
| 71 | 71 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
| 72 | 72 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
| 73 | 73 | <div class="gdmbx-td"> |
| 74 | - <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly> |
|
| 74 | + <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly> |
|
| 75 | 75 | </div> |
| 76 | 76 | </div> |
| 77 | - <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); |
|
| 77 | + <?php do_action('wpinv_meta_box_details_inner', $post_id); |
|
| 78 | 78 | $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id); |
| 79 | 79 | ?> |
| 80 | - <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?> |
|
| 80 | + <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) && !$disable_discount || $discount_code) { ?> |
|
| 81 | 81 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
| 82 | - <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
|
| 82 | + <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div> |
|
| 83 | 83 | <div class="gdmbx-td"> |
| 84 | - <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid && !$disable_discount ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
| 84 | + <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid && !$disable_discount) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
| 85 | 85 | </div> |
| 86 | 86 | </div> |
| 87 | 87 | <?php } ?> |
| 88 | 88 | </div> |
| 89 | 89 | </div> |
| 90 | 90 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
| 91 | - <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label> |
|
| 91 | + <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label> |
|
| 92 | 92 | <select id="wpi_save_send" name="wpi_save_send" class="wpi_select2"> |
| 93 | - <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
|
| 94 | - <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
|
| 93 | + <option value="1"><?php _e('Yes', 'invoicing'); ?></option> |
|
| 94 | + <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option> |
|
| 95 | 95 | </select> |
| 96 | 96 | </p> |
| 97 | 97 | <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p> |
| 98 | 98 | </div> |
| 99 | -<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
|
| 99 | +<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?> |
|
| 100 | 100 | <?php |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - public static function resend_invoice( $post ) { |
|
| 103 | + public static function resend_invoice($post) { |
|
| 104 | 104 | global $wpi_mb_invoice; |
| 105 | 105 | |
| 106 | - if ( empty( $wpi_mb_invoice ) ) { |
|
| 106 | + if (empty($wpi_mb_invoice)) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $text = array( |
| 111 | - 'message' => esc_attr__( 'This will send a copy of the invoice to the customer’s email address.', 'invoicing' ), |
|
| 112 | - 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
|
| 111 | + 'message' => esc_attr__('This will send a copy of the invoice to the customer’s email address.', 'invoicing'), |
|
| 112 | + 'button_text' => __('Resend Invoice', 'invoicing'), |
|
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | 115 | $text = apply_filters('wpinv_resend_invoice_metabox_text', $text); |
| 116 | - do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
|
| 116 | + do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice); |
|
| 117 | 117 | |
| 118 | - if ( $email = $wpi_mb_invoice->get_email() ) { |
|
| 118 | + if ($email = $wpi_mb_invoice->get_email()) { |
|
| 119 | 119 | $email_actions = array(); |
| 120 | - $email_actions['email_url'] = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ); |
|
| 121 | - $email_actions['reminder_url'] = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
|
| 120 | + $email_actions['email_url'] = remove_query_arg('wpinv-message', add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))); |
|
| 121 | + $email_actions['reminder_url'] = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID)); |
|
| 122 | 122 | |
| 123 | - $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions ); |
|
| 123 | + $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions); |
|
| 124 | 124 | ?> |
| 125 | 125 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
| 126 | - <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
| 127 | - <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
|
| 128 | - <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
| 126 | + <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
| 127 | + <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?> |
|
| 128 | + <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
| 129 | 129 | <?php } ?> |
| 130 | 130 | <?php |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
|
| 133 | + do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public static function subscriptions( $post ) { |
|
| 137 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
| 136 | + public static function subscriptions($post) { |
|
| 137 | + $invoice = wpinv_get_invoice($post->ID); |
|
| 138 | 138 | |
| 139 | - if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
|
| 140 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 139 | + if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) { |
|
| 140 | + $subscription = wpinv_get_subscription($invoice); |
|
| 141 | 141 | |
| 142 | - if ( empty( $subscription ) ) { |
|
| 142 | + if (empty($subscription)) { |
|
| 143 | 143 | ?> |
| 144 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p> |
|
| 144 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing'), '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', '</a>'); ?></p> |
|
| 145 | 145 | <?php |
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency ); |
|
| 149 | - $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 150 | - $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
| 148 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency); |
|
| 149 | + $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency; |
|
| 150 | + $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)); |
|
| 151 | 151 | $payments = $subscription->get_child_payments(); |
| 152 | 152 | ?> |
| 153 | 153 | <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
| 154 | - <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?> |
|
| 154 | + <?php if (!empty($subscription) && !empty($subscription->id)) { ?> |
|
| 155 | 155 | <p class="wpi-meta-row wpi-sub-id"> |
| 156 | - <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p> |
|
| 156 | + <label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p> |
|
| 157 | 157 | <?php } ?> |
| 158 | 158 | <p class="wpi-meta-row wpi-bill-cycle"> |
| 159 | - <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?> |
|
| 159 | + <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?> |
|
| 160 | 160 | </p> |
| 161 | 161 | <p class="wpi-meta-row wpi-billed-times"> |
| 162 | - <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?> |
|
| 162 | + <label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); ?> |
|
| 163 | 163 | </p> |
| 164 | 164 | <p class="wpi-meta-row wpi-start-date"> |
| 165 | - <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?> |
|
| 165 | + <label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?> |
|
| 166 | 166 | </p> |
| 167 | 167 | <p class="wpi-meta-row wpi-end-date"> |
| 168 | - <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?> |
|
| 168 | + <label><?php echo ('trialling' == $subscription->status ? __('Trialling Until:', 'invoicing') : __('Expiration Date:', 'invoicing')); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?> |
|
| 169 | 169 | </p> |
| 170 | - <?php if ( $subscription->status ) { ?> |
|
| 170 | + <?php if ($subscription->status) { ?> |
|
| 171 | 171 | <p class="wpi-meta-row wpi-sub-status"> |
| 172 | - <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
| 172 | + <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
| 173 | 173 | </p> |
| 174 | 174 | <?php } ?> |
| 175 | - <?php if ( !empty( $payments ) ) { ?> |
|
| 176 | - <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
|
| 175 | + <?php if (!empty($payments)) { ?> |
|
| 176 | + <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p> |
|
| 177 | 177 | <ul id="wpi-sub-payments"> |
| 178 | - <?php foreach ( $payments as $payment ) { |
|
| 178 | + <?php foreach ($payments as $payment) { |
|
| 179 | 179 | $invoice_id = $payment->ID; |
| 180 | 180 | ?> |
| 181 | 181 | <li> |
| 182 | - <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
|
| 183 | - <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
|
| 184 | - <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
|
| 182 | + <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a> – |
|
| 183 | + <span><?php echo wpinv_get_invoice_date($invoice_id); ?> – </span> |
|
| 184 | + <span><?php echo wpinv_payment_total($invoice_id, true); ?></span> |
|
| 185 | 185 | </li> |
| 186 | 186 | <?php } ?> |
| 187 | 187 | </ul> |
@@ -189,50 +189,50 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - public static function renewals( $post ) { |
|
| 193 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
| 192 | + public static function renewals($post) { |
|
| 193 | + $invoice = wpinv_get_invoice($post->ID); |
|
| 194 | 194 | |
| 195 | - if ( wpinv_is_subscription_payment( $invoice ) ) { |
|
| 196 | - $parent_url = get_edit_post_link( $invoice->parent_invoice ); |
|
| 197 | - $parent_id = wpinv_get_invoice_number( $invoice->parent_invoice ); |
|
| 198 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 195 | + if (wpinv_is_subscription_payment($invoice)) { |
|
| 196 | + $parent_url = get_edit_post_link($invoice->parent_invoice); |
|
| 197 | + $parent_id = wpinv_get_invoice_number($invoice->parent_invoice); |
|
| 198 | + $subscription = wpinv_get_subscription($invoice); |
|
| 199 | 199 | ?> |
| 200 | - <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?> |
|
| 201 | - <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p> |
|
| 200 | + <?php if (!empty($subscription)) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?> |
|
| 201 | + <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p> |
|
| 202 | 202 | <?php |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - public static function payment_meta( $post ) { |
|
| 206 | + public static function payment_meta($post) { |
|
| 207 | 207 | global $wpi_mb_invoice; |
| 208 | 208 | |
| 209 | - $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false; |
|
| 210 | - if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) { |
|
| 209 | + $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false; |
|
| 210 | + if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) { |
|
| 211 | 211 | $set_dateway = true; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | ?> |
| 215 | 215 | <p class="wpi-meta-row"> |
| 216 | - <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?> |
|
| 217 | - <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label> |
|
| 216 | + <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?> |
|
| 217 | + <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label> |
|
| 218 | 218 | <select required="required" id="wpinv_gateway" class="wpi_select2" name="wpinv_gateway"> |
| 219 | - <?php foreach ( $gateways as $name => $gateway ) { |
|
| 220 | - if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) { |
|
| 219 | + <?php foreach ($gateways as $name => $gateway) { |
|
| 220 | + if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) { |
|
| 221 | 221 | continue; |
| 222 | 222 | } |
| 223 | 223 | ?> |
| 224 | - <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
| 224 | + <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
| 225 | 225 | <?php } ?> |
| 226 | 226 | </select> |
| 227 | 227 | <?php } else { |
| 228 | - echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_admin_label( $wpi_mb_invoice->gateway ) ); |
|
| 228 | + echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_admin_label($wpi_mb_invoice->gateway)); |
|
| 229 | 229 | } ?> |
| 230 | 230 | </p> |
| 231 | - <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?> |
|
| 232 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p> |
|
| 231 | + <?php if ($key = $wpi_mb_invoice->get_key()) { ?> |
|
| 232 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p> |
|
| 233 | 233 | <?php } ?> |
| 234 | - <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?> |
|
| 235 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p> |
|
| 234 | + <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?> |
|
| 235 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p> |
|
| 236 | 236 | <?php } ?> |
| 237 | 237 | <?php |
| 238 | 238 | } |
@@ -1,34 +1,34 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // MUST have WordPress. |
| 3 | -if ( !defined( 'WPINC' ) ) { |
|
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 3 | +if (!defined('WPINC')) { |
|
| 4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | class WPInv_Meta_Box_Billing_Details { |
| 8 | - public static function output( $post ) { |
|
| 8 | + public static function output($post) { |
|
| 9 | 9 | global $user_ID; |
| 10 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
| 11 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 10 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
| 11 | + $invoice = new WPInv_Invoice($post_id); |
|
| 12 | 12 | ?> |
| 13 | 13 | <div class="gdmbx2-wrap form-table"> |
| 14 | 14 | <div id="gdmbx2-metabox-wpinv_address" class="gdmbx2-metabox gdmbx-field-list wpinv-address gdmbx-row"> |
| 15 | 15 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-user-id table-layout"> |
| 16 | 16 | <div class="gdmbx-th"> |
| 17 | - <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label> |
|
| 17 | + <label for="post_author_override"><?php _e('Customer', 'invoicing'); ?></label> |
|
| 18 | 18 | </div> |
| 19 | 19 | <div class="gdmbx-td gdmbx-customer-div"> |
| 20 | - <?php wpinv_dropdown_users( array( |
|
| 20 | + <?php wpinv_dropdown_users(array( |
|
| 21 | 21 | 'name' => 'post_author_override', |
| 22 | 22 | 'selected' => empty($post->ID) ? $user_ID : $post->post_author, |
| 23 | 23 | 'include_selected' => true, |
| 24 | 24 | 'show' => 'display_name_with_email', |
| 25 | 25 | 'orderby' => 'user_email', |
| 26 | 26 | 'class' => 'gdmbx2-text-large wpi_select2' |
| 27 | - ) ); ?> |
|
| 27 | + )); ?> |
|
| 28 | 28 | </div> |
| 29 | 29 | </div> |
| 30 | 30 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-email table-layout" style="display:none"> |
| 31 | - <div class="gdmbx-th"><label for="wpinv_email"><?php _e( 'Email', 'invoicing' );?> <span class="required">*</span></label> |
|
| 31 | + <div class="gdmbx-th"><label for="wpinv_email"><?php _e('Email', 'invoicing'); ?> <span class="required">*</span></label> |
|
| 32 | 32 | </div> |
| 33 | 33 | <div class="gdmbx-td"> |
| 34 | 34 | <input type="hidden" id="wpinv_new_user" name="wpinv_new_user" value="" /> |
@@ -36,122 +36,122 @@ discard block |
||
| 36 | 36 | </div> |
| 37 | 37 | </div> |
| 38 | 38 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-btns table-layout"> |
| 39 | - <div class="gdmbx-th"><label><?php _e( 'Actions', 'invoicing' );?></label> |
|
| 39 | + <div class="gdmbx-th"><label><?php _e('Actions', 'invoicing'); ?></label> |
|
| 40 | 40 | </div> |
| 41 | - <?php if ( $invoice->has_status( array( 'auto-draft', 'draft', 'wpi-pending', 'wpi-quote-pending' ) ) ) { ?> |
|
| 41 | + <?php if ($invoice->has_status(array('auto-draft', 'draft', 'wpi-pending', 'wpi-quote-pending'))) { ?> |
|
| 42 | 42 | <div class="gdmbx-td"> |
| 43 | - <a id="wpinv-fill-user-details" class="button button-small button-secondary" title="<?php esc_attr_e( 'Fill User Details', 'invoicing' );?>" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-refresh"></i><?php _e( 'Fill User Details', 'invoicing' );?></a> |
|
| 44 | - <a class="wpinv-new-user button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-plus"></i><?php _e( 'Add New User', 'invoicing' );?></a> |
|
| 45 | - <a style="display:none" class="wpinv-new-cancel button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-close"></i><?php _e( 'Cancel', 'invoicing' );?> </a> |
|
| 43 | + <a id="wpinv-fill-user-details" class="button button-small button-secondary" title="<?php esc_attr_e('Fill User Details', 'invoicing'); ?>" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-refresh"></i><?php _e('Fill User Details', 'invoicing'); ?></a> |
|
| 44 | + <a class="wpinv-new-user button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-plus"></i><?php _e('Add New User', 'invoicing'); ?></a> |
|
| 45 | + <a style="display:none" class="wpinv-new-cancel button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-close"></i><?php _e('Cancel', 'invoicing'); ?> </a> |
|
| 46 | 46 | </div> |
| 47 | 47 | <?php } ?> |
| 48 | 48 | </div> |
| 49 | 49 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-first-name table-layout"> |
| 50 | - <div class="gdmbx-th"><label for="wpinv_first_name"><?php _e( 'First Name', 'invoicing' );?></label></div> |
|
| 50 | + <div class="gdmbx-th"><label for="wpinv_first_name"><?php _e('First Name', 'invoicing'); ?></label></div> |
|
| 51 | 51 | <div class="gdmbx-td"> |
| 52 | - <input type="text" class="gdmbx2-text-large" name="wpinv_first_name" id="wpinv_first_name" value="<?php echo esc_attr( $invoice->first_name );?>" /> |
|
| 52 | + <input type="text" class="gdmbx2-text-large" name="wpinv_first_name" id="wpinv_first_name" value="<?php echo esc_attr($invoice->first_name); ?>" /> |
|
| 53 | 53 | </div> |
| 54 | 54 | </div> |
| 55 | 55 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-last-name table-layout"> |
| 56 | - <div class="gdmbx-th"><label for="wpinv_last_name"><?php _e( 'Last Name', 'invoicing' );?></label></div> |
|
| 56 | + <div class="gdmbx-th"><label for="wpinv_last_name"><?php _e('Last Name', 'invoicing'); ?></label></div> |
|
| 57 | 57 | <div class="gdmbx-td"> |
| 58 | - <input type="text" class="gdmbx2-text-large" name="wpinv_last_name" id="wpinv_last_name" value="<?php echo esc_attr( $invoice->last_name );?>" /> |
|
| 58 | + <input type="text" class="gdmbx2-text-large" name="wpinv_last_name" id="wpinv_last_name" value="<?php echo esc_attr($invoice->last_name); ?>" /> |
|
| 59 | 59 | </div> |
| 60 | 60 | </div> |
| 61 | 61 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-company table-layout"> |
| 62 | - <div class="gdmbx-th"><label for="wpinv_company"><?php _e( 'Company', 'invoicing' );?></label></div> |
|
| 62 | + <div class="gdmbx-th"><label for="wpinv_company"><?php _e('Company', 'invoicing'); ?></label></div> |
|
| 63 | 63 | <div class="gdmbx-td"> |
| 64 | - <input type="text" class="gdmbx2-text-large" name="wpinv_company" id="wpinv_company" value="<?php echo esc_attr( $invoice->company );?>" /> |
|
| 64 | + <input type="text" class="gdmbx2-text-large" name="wpinv_company" id="wpinv_company" value="<?php echo esc_attr($invoice->company); ?>" /> |
|
| 65 | 65 | </div> |
| 66 | 66 | </div> |
| 67 | 67 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-vat-number table-layout"> |
| 68 | - <div class="gdmbx-th"><label for="wpinv_vat_number"><?php _e( 'Vat Number', 'invoicing' );?></label></div> |
|
| 68 | + <div class="gdmbx-th"><label for="wpinv_vat_number"><?php _e('Vat Number', 'invoicing'); ?></label></div> |
|
| 69 | 69 | <div class="gdmbx-td"> |
| 70 | - <input type="text" class="gdmbx2-text-large" name="wpinv_vat_number" id="wpinv_vat_number" value="<?php echo esc_attr( $invoice->vat_number );?>" /> |
|
| 70 | + <input type="text" class="gdmbx2-text-large" name="wpinv_vat_number" id="wpinv_vat_number" value="<?php echo esc_attr($invoice->vat_number); ?>" /> |
|
| 71 | 71 | </div> |
| 72 | 72 | </div> |
| 73 | 73 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-address table-layout"> |
| 74 | - <div class="gdmbx-th"><label for="wpinv_address"><?php _e( 'Address', 'invoicing' );?></label></div> |
|
| 74 | + <div class="gdmbx-th"><label for="wpinv_address"><?php _e('Address', 'invoicing'); ?></label></div> |
|
| 75 | 75 | <div class="gdmbx-td"> |
| 76 | - <input type="text" class="gdmbx2-text-large" name="wpinv_address" id="wpinv_address" value="<?php echo esc_attr( $invoice->address );?>" /> |
|
| 76 | + <input type="text" class="gdmbx2-text-large" name="wpinv_address" id="wpinv_address" value="<?php echo esc_attr($invoice->address); ?>" /> |
|
| 77 | 77 | </div> |
| 78 | 78 | </div> |
| 79 | 79 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-city table-layout"> |
| 80 | - <div class="gdmbx-th"><label for="wpinv_city"><?php _e( 'City', 'invoicing' );?></label></div> |
|
| 80 | + <div class="gdmbx-th"><label for="wpinv_city"><?php _e('City', 'invoicing'); ?></label></div> |
|
| 81 | 81 | <div class="gdmbx-td"> |
| 82 | - <input type="text" class="gdmbx2-text-large" name="wpinv_city" id="wpinv_city" value="<?php echo esc_attr( $invoice->city );?>" /> |
|
| 82 | + <input type="text" class="gdmbx2-text-large" name="wpinv_city" id="wpinv_city" value="<?php echo esc_attr($invoice->city); ?>" /> |
|
| 83 | 83 | </div> |
| 84 | 84 | </div> |
| 85 | 85 | <div class="gdmbx-row gdmbx-type-select gdmbx-wpinv-country table-layout"> |
| 86 | - <div class="gdmbx-th"><label for="wpinv_country"><?php _e( 'Country', 'invoicing' );?> <span class="wpi-loader"><i class="fa fa-refresh fa-spin"></i></span></label></div> |
|
| 86 | + <div class="gdmbx-th"><label for="wpinv_country"><?php _e('Country', 'invoicing'); ?> <span class="wpi-loader"><i class="fa fa-refresh fa-spin"></i></span></label></div> |
|
| 87 | 87 | <div class="gdmbx-td"> |
| 88 | 88 | <?php |
| 89 | - echo wpinv_html_select( array( |
|
| 90 | - 'options' => array_merge( array( '' => __( 'Choose a country', 'invoicing' ) ), wpinv_get_country_list() ), |
|
| 89 | + echo wpinv_html_select(array( |
|
| 90 | + 'options' => array_merge(array('' => __('Choose a country', 'invoicing')), wpinv_get_country_list()), |
|
| 91 | 91 | 'name' => 'wpinv_country', |
| 92 | 92 | 'id' => 'wpinv_country', |
| 93 | 93 | 'selected' => $invoice->country, |
| 94 | 94 | 'show_option_all' => false, |
| 95 | 95 | 'show_option_none' => false, |
| 96 | 96 | 'class' => 'gdmbx2-text-large wpi_select2', |
| 97 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 97 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
| 98 | 98 | 'required' => false, |
| 99 | - ) ); |
|
| 99 | + )); |
|
| 100 | 100 | ?> |
| 101 | 101 | </div> |
| 102 | 102 | </div> |
| 103 | 103 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-state table-layout"> |
| 104 | - <div class="gdmbx-th"><label for="wpinv_state"><?php _e( 'State', 'invoicing' );?></label></div> |
|
| 104 | + <div class="gdmbx-th"><label for="wpinv_state"><?php _e('State', 'invoicing'); ?></label></div> |
|
| 105 | 105 | <div class="gdmbx-td"> |
| 106 | 106 | <?php |
| 107 | - $states = wpinv_get_country_states( $invoice->country ); |
|
| 108 | - if( !empty( $states ) ) { |
|
| 109 | - echo wpinv_html_select( array( |
|
| 110 | - 'options' => array_merge( array( '' => __( 'Choose a state', 'invoicing' ) ), $states ), |
|
| 107 | + $states = wpinv_get_country_states($invoice->country); |
|
| 108 | + if (!empty($states)) { |
|
| 109 | + echo wpinv_html_select(array( |
|
| 110 | + 'options' => array_merge(array('' => __('Choose a state', 'invoicing')), $states), |
|
| 111 | 111 | 'name' => 'wpinv_state', |
| 112 | 112 | 'id' => 'wpinv_state', |
| 113 | 113 | 'selected' => $invoice->state, |
| 114 | 114 | 'show_option_all' => false, |
| 115 | 115 | 'show_option_none' => false, |
| 116 | 116 | 'class' => 'gdmbx2-text-large wpi_select2', |
| 117 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
| 117 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
| 118 | 118 | 'required' => false, |
| 119 | - ) ); |
|
| 119 | + )); |
|
| 120 | 120 | } else { |
| 121 | - echo wpinv_html_text( array( |
|
| 121 | + echo wpinv_html_text(array( |
|
| 122 | 122 | 'name' => 'wpinv_state', |
| 123 | - 'value' => ! empty( $invoice->state ) ? $invoice->state : '', |
|
| 123 | + 'value' => !empty($invoice->state) ? $invoice->state : '', |
|
| 124 | 124 | 'id' => 'wpinv_state', |
| 125 | 125 | 'class' => 'gdmbx2-text-large', |
| 126 | 126 | 'required' => false, |
| 127 | - ) ); |
|
| 127 | + )); |
|
| 128 | 128 | } |
| 129 | 129 | ?> |
| 130 | 130 | </div> |
| 131 | 131 | </div> |
| 132 | 132 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-zip table-layout"> |
| 133 | - <div class="gdmbx-th"><label for="wpinv_zip"><?php _e( 'Zipcode', 'invoicing' );?></label></div> |
|
| 133 | + <div class="gdmbx-th"><label for="wpinv_zip"><?php _e('Zipcode', 'invoicing'); ?></label></div> |
|
| 134 | 134 | <div class="gdmbx-td"> |
| 135 | - <input type="text" class="gdmbx2-text-large" name="wpinv_zip" id="wpinv_zip" value="<?php echo esc_attr( $invoice->zip );?>" /> |
|
| 135 | + <input type="text" class="gdmbx2-text-large" name="wpinv_zip" id="wpinv_zip" value="<?php echo esc_attr($invoice->zip); ?>" /> |
|
| 136 | 136 | </div> |
| 137 | 137 | </div> |
| 138 | 138 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-phone table-layout"> |
| 139 | - <div class="gdmbx-th"><label for="wpinv_phone"><?php _e( 'Phone', 'invoicing' );?></label></div> |
|
| 139 | + <div class="gdmbx-th"><label for="wpinv_phone"><?php _e('Phone', 'invoicing'); ?></label></div> |
|
| 140 | 140 | <div class="gdmbx-td"> |
| 141 | - <input type="text" class="gdmbx2-text-large" name="wpinv_phone" id="wpinv_phone" value="<?php echo esc_attr( $invoice->phone );?>" /> |
|
| 141 | + <input type="text" class="gdmbx2-text-large" name="wpinv_phone" id="wpinv_phone" value="<?php echo esc_attr($invoice->phone); ?>" /> |
|
| 142 | 142 | </div> |
| 143 | 143 | </div> |
| 144 | 144 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-ip table-layout"> |
| 145 | - <div class="gdmbx-th"><label for="wpinv_ip"><?php _e( 'IP Address', 'invoicing' );?><?php if ($invoice->ip) { ?> |
|
| 146 | - <a href="<?php echo admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $invoice->ip ); ?>" title="<?php esc_attr_e( 'View IP information', 'invoicing' );?>" target="_blank"><i class="fa fa-external-link" aria-hidden="true"></i></a> |
|
| 145 | + <div class="gdmbx-th"><label for="wpinv_ip"><?php _e('IP Address', 'invoicing'); ?><?php if ($invoice->ip) { ?> |
|
| 146 | + <a href="<?php echo admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $invoice->ip); ?>" title="<?php esc_attr_e('View IP information', 'invoicing'); ?>" target="_blank"><i class="fa fa-external-link" aria-hidden="true"></i></a> |
|
| 147 | 147 | <?php } ?></label></div> |
| 148 | 148 | <div class="gdmbx-td"> |
| 149 | - <input type="text" class="gdmbx2-text-large" value="<?php echo esc_attr( $invoice->ip );?>" readonly /> |
|
| 149 | + <input type="text" class="gdmbx2-text-large" value="<?php echo esc_attr($invoice->ip); ?>" readonly /> |
|
| 150 | 150 | </div> |
| 151 | 151 | </div> |
| 152 | 152 | </div> |
| 153 | 153 | </div> |
| 154 | -<?php wp_nonce_field( 'wpinv_save_invoice', 'wpinv_save_invoice' ) ;?> |
|
| 154 | +<?php wp_nonce_field('wpinv_save_invoice', 'wpinv_save_invoice'); ?> |
|
| 155 | 155 | <?php |
| 156 | 156 | } |
| 157 | 157 | } |