@@ -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; |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class WPInv_Plugin { |
| 15 | 15 | private static $instance; |
| 16 | 16 | |
| 17 | 17 | public static function run() { |
| 18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
| 18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
| 19 | 19 | self::$instance = new WPInv_Plugin; |
| 20 | 20 | self::$instance->includes(); |
| 21 | 21 | self::$instance->actions(); |
@@ -31,31 +31,31 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function define_constants() { |
| 34 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 35 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 34 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 35 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | private function actions() { |
| 39 | 39 | /* Internationalize the text strings used. */ |
| 40 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 40 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 41 | 41 | |
| 42 | 42 | /* Perform actions on admin initialization. */ |
| 43 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 44 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
| 45 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
| 46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 43 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 44 | + add_action('init', array(&$this, 'init'), 3); |
|
| 45 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
| 46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 47 | 47 | |
| 48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 48 | + if (class_exists('BuddyPress')) { |
|
| 49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 53 | 53 | |
| 54 | - if ( is_admin() ) { |
|
| 55 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 56 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 54 | + if (is_admin()) { |
|
| 55 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 56 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 57 | 57 | } else { |
| 58 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 58 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
| 67 | 67 | */ |
| 68 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 68 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 69 | 69 | |
| 70 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 70 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function plugins_loaded() { |
| 74 | 74 | /* Internationalize the text strings used. */ |
| 75 | 75 | $this->load_textdomain(); |
| 76 | 76 | |
| 77 | - do_action( 'wpinv_loaded' ); |
|
| 77 | + do_action('wpinv_loaded'); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -82,210 +82,210 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @since 1.0 |
| 84 | 84 | */ |
| 85 | - public function load_textdomain( $locale = NULL ) { |
|
| 86 | - if ( empty( $locale ) ) { |
|
| 87 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 85 | + public function load_textdomain($locale = NULL) { |
|
| 86 | + if (empty($locale)) { |
|
| 87 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 90 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 91 | 91 | |
| 92 | - unload_textdomain( 'invoicing' ); |
|
| 93 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 94 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 92 | + unload_textdomain('invoicing'); |
|
| 93 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 94 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Define language constants. |
| 98 | 98 | */ |
| 99 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 99 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function includes() { |
| 103 | 103 | global $wpinv_options; |
| 104 | 104 | |
| 105 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 105 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 106 | 106 | $wpinv_options = wpinv_get_settings(); |
| 107 | 107 | |
| 108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
| 109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
| 116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
| 122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
| 123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
| 124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
| 125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
| 126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
| 130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 132 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 133 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 135 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 136 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
| 137 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php' ); |
|
| 138 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 139 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
| 109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
| 116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
| 122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
| 123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
| 124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
| 125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
| 126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
| 130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
| 132 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
| 133 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
| 134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
| 135 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
| 136 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
| 137 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php'); |
|
| 138 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
| 139 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
| 140 | 140 | |
| 141 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
| 142 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 141 | + if (!class_exists('WPInv_EUVat')) { |
|
| 142 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 146 | - if ( !empty( $gateways ) ) { |
|
| 147 | - foreach ( $gateways as $gateway ) { |
|
| 148 | - if ( $gateway == 'manual' ) { |
|
| 145 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 146 | + if (!empty($gateways)) { |
|
| 147 | + foreach ($gateways as $gateway) { |
|
| 148 | + if ($gateway == 'manual') { |
|
| 149 | 149 | continue; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 153 | 153 | |
| 154 | - if ( file_exists( $gateway_file ) ) { |
|
| 155 | - require_once( $gateway_file ); |
|
| 154 | + if (file_exists($gateway_file)) { |
|
| 155 | + require_once($gateway_file); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
| 159 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
| 160 | 160 | |
| 161 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 162 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 163 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 164 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
| 161 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 162 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 163 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 164 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
| 165 | 165 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 166 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
| 167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
| 168 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 169 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
| 170 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 171 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 166 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
| 167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
| 168 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 169 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
| 170 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 171 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
| 172 | 172 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 173 | 173 | // load the user class only on the users.php page |
| 174 | 174 | global $pagenow; |
| 175 | - if($pagenow=='users.php'){ |
|
| 175 | + if ($pagenow == 'users.php') { |
|
| 176 | 176 | new WPInv_Admin_Users(); |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // include css inliner |
| 181 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 182 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 181 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 182 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 185 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public function init() { |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | public function admin_init() { |
| 192 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 192 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 195 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | public function activation_redirect() { |
| 199 | 199 | // Bail if no activation redirect |
| 200 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 200 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Delete the redirect transient |
| 205 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 205 | + delete_transient('_wpinv_activation_redirect'); |
|
| 206 | 206 | |
| 207 | 207 | // Bail if activating from network, or bulk |
| 208 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 208 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 209 | 209 | return; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 212 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 213 | 213 | exit; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | public function enqueue_scripts() { |
| 217 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 217 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 218 | 218 | |
| 219 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
| 220 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 219 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
| 220 | + wp_enqueue_style('wpinv_front_style'); |
|
| 221 | 221 | |
| 222 | 222 | // Register scripts |
| 223 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 224 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
| 223 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 224 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
| 225 | 225 | |
| 226 | 226 | $localize = array(); |
| 227 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 228 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 227 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 228 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 229 | 229 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 230 | 230 | $localize['currency_pos'] = wpinv_currency_position(); |
| 231 | 231 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 232 | 232 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 233 | 233 | $localize['decimals'] = wpinv_decimals(); |
| 234 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
| 234 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
| 235 | 235 | |
| 236 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 236 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 237 | 237 | |
| 238 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 238 | + wp_enqueue_script('jquery-blockui'); |
|
| 239 | 239 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 240 | 240 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 241 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 242 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 243 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 241 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 242 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 243 | + wp_dequeue_script('google-maps-api'); |
|
| 244 | 244 | } |
| 245 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 246 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 245 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 246 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 247 | 247 | } |
| 248 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 249 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 248 | + wp_enqueue_script('wpinv-front-script'); |
|
| 249 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function admin_enqueue_scripts() { |
| 253 | 253 | global $post, $pagenow; |
| 254 | 254 | |
| 255 | 255 | $post_type = wpinv_admin_post_type(); |
| 256 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 257 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 256 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 257 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
| 258 | 258 | |
| 259 | 259 | $jquery_ui_css = false; |
| 260 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 260 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 261 | 261 | $jquery_ui_css = true; |
| 262 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 262 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
| 263 | 263 | $jquery_ui_css = true; |
| 264 | 264 | } |
| 265 | - if ( $jquery_ui_css ) { |
|
| 266 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 267 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 265 | + if ($jquery_ui_css) { |
|
| 266 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 267 | + wp_enqueue_style('jquery-ui-css'); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 271 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 270 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 271 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 272 | 272 | |
| 273 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
| 274 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 273 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
| 274 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 275 | 275 | |
| 276 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
| 277 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 278 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 276 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
| 277 | + if ($page == 'wpinv-subscriptions') { |
|
| 278 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
| 282 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 281 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
| 282 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 286 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 285 | + wp_enqueue_style('wp-color-picker'); |
|
| 286 | + wp_enqueue_script('wp-color-picker'); |
|
| 287 | 287 | |
| 288 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 288 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 289 | 289 | |
| 290 | 290 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
| 291 | 291 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -296,17 +296,17 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
| 300 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 299 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
| 300 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 301 | 301 | |
| 302 | 302 | $localize = array(); |
| 303 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 304 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 305 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 306 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 307 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 308 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 309 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 303 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 304 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 305 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 306 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 307 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 308 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 309 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 310 | 310 | $localize['tax'] = wpinv_tax_amount(); |
| 311 | 311 | $localize['discount'] = wpinv_discount_amount(); |
| 312 | 312 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -314,69 +314,69 @@ discard block |
||
| 314 | 314 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 315 | 315 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 316 | 316 | $localize['decimals'] = wpinv_decimals(); |
| 317 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 318 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 319 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 320 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 321 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 322 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 323 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 324 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 325 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 326 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
| 327 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 328 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
| 329 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
| 330 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
| 317 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 318 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 319 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
| 320 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 321 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 322 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 323 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 324 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
| 325 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 326 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
| 327 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 328 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
| 329 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
| 330 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
| 331 | 331 | |
| 332 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 332 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
| 333 | 333 | |
| 334 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 334 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 335 | 335 | |
| 336 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 337 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 338 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 336 | + if ($page == 'wpinv-subscriptions') { |
|
| 337 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
| 338 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
| 339 | 339 | } |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - public function admin_body_class( $classes ) { |
|
| 342 | + public function admin_body_class($classes) { |
|
| 343 | 343 | global $pagenow, $post, $current_screen; |
| 344 | 344 | |
| 345 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 345 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
| 346 | 346 | $classes .= ' wpinv-cpt'; |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 349 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 350 | 350 | |
| 351 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
| 352 | - if ( $add_class ) { |
|
| 353 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
| 351 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
| 352 | + if ($add_class) { |
|
| 353 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | $settings_class = array(); |
| 357 | - if ( $page == 'wpinv-settings' ) { |
|
| 358 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 359 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 357 | + if ($page == 'wpinv-settings') { |
|
| 358 | + if (!empty($_REQUEST['tab'])) { |
|
| 359 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 363 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 362 | + if (!empty($_REQUEST['section'])) { |
|
| 363 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 366 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if ( !empty( $settings_class ) ) { |
|
| 370 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 369 | + if (!empty($settings_class)) { |
|
| 370 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $post_type = wpinv_admin_post_type(); |
| 374 | 374 | |
| 375 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 375 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 376 | 376 | return $classes .= ' wpinv'; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 379 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
| 380 | 380 | $classes .= ' wpi-editable-n'; |
| 381 | 381 | } |
| 382 | 382 | |
@@ -388,20 +388,20 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | public function wpinv_actions() { |
| 391 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 392 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 391 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 392 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - public function pre_get_posts( $wp_query ) { |
|
| 397 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 398 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 396 | + public function pre_get_posts($wp_query) { |
|
| 397 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 398 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | return $wp_query; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | public function bp_invoicing_init() { |
| 405 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 405 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | \ No newline at end of file |
@@ -795,7 +795,7 @@ |
||
| 795 | 795 | * Output the JS for building the dynamic Guntenberg block. |
| 796 | 796 | * |
| 797 | 797 | * @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. |
| 798 | - * @return mixed |
|
| 798 | + * @return string |
|
| 799 | 799 | */ |
| 800 | 800 | public function block() { |
| 801 | 801 | ob_start(); |
@@ -1,151 +1,151 @@ 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 | - * @ver 1.0.5 |
|
| 21 | - */ |
|
| 22 | - class WP_Super_Duper extends WP_Widget { |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - public $version = "1.0.5"; |
|
| 26 | - public $block_code; |
|
| 27 | - public $options; |
|
| 28 | - public $base_id; |
|
| 29 | - public $arguments = array(); |
|
| 30 | - public $instance = array(); |
|
| 31 | - private $class_name; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Take the array options and use them to build. |
|
| 35 | - */ |
|
| 36 | - public function __construct( $options ) { |
|
| 37 | - global $sd_widgets; |
|
| 38 | - |
|
| 39 | - $sd_widgets[ $options['base_id'] ] = array( 'name' => $options['name'], |
|
| 40 | - 'class_name' => $options['class_name'] |
|
| 41 | - ); |
|
| 42 | - $this->base_id = $options['base_id']; |
|
| 43 | - // lets filter the options before we do anything |
|
| 44 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 45 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 46 | - $options = $this->add_name_from_key( $options ); |
|
| 47 | - $this->options = $options; |
|
| 48 | - |
|
| 49 | - $this->base_id = $options['base_id']; |
|
| 50 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 51 | - |
|
| 52 | - // init parent |
|
| 53 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 54 | - |
|
| 55 | - if ( isset( $options['class_name'] ) ) { |
|
| 56 | - // register widget |
|
| 57 | - $this->class_name = $options['class_name']; |
|
| 58 | - |
|
| 59 | - // register shortcode |
|
| 60 | - $this->register_shortcode(); |
|
| 61 | - |
|
| 62 | - // register block |
|
| 63 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // add the CSS and JS we need ONCE |
|
| 67 | - global $sd_widget_scripts; |
|
| 68 | - |
|
| 69 | - if ( ! $sd_widget_scripts ) { |
|
| 70 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 71 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 72 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 73 | - |
|
| 74 | - $sd_widget_scripts = true; |
|
| 75 | - |
|
| 76 | - // add shortcode insert button once |
|
| 77 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 78 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Get widget settings. |
|
| 86 | - * |
|
| 87 | - * @since 1.0.0 |
|
| 88 | - */ |
|
| 89 | - public static function get_widget_settings() { |
|
| 90 | - global $sd_widgets; |
|
| 91 | - |
|
| 92 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 93 | - if ( ! $shortcode ) { |
|
| 94 | - wp_die(); |
|
| 95 | - } |
|
| 96 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 97 | - if ( ! $widget_args ) { |
|
| 98 | - wp_die(); |
|
| 99 | - } |
|
| 100 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 101 | - if ( ! $class_name ) { |
|
| 102 | - wp_die(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // invoke an instance method |
|
| 106 | - $widget = new $class_name; |
|
| 107 | - |
|
| 108 | - ob_start(); |
|
| 109 | - $widget->form( array() ); |
|
| 110 | - $form = ob_get_clean(); |
|
| 111 | - echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 112 | - echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 113 | - echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 114 | - ?> |
|
| 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 | + * @ver 1.0.5 |
|
| 21 | + */ |
|
| 22 | + class WP_Super_Duper extends WP_Widget { |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + public $version = "1.0.5"; |
|
| 26 | + public $block_code; |
|
| 27 | + public $options; |
|
| 28 | + public $base_id; |
|
| 29 | + public $arguments = array(); |
|
| 30 | + public $instance = array(); |
|
| 31 | + private $class_name; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Take the array options and use them to build. |
|
| 35 | + */ |
|
| 36 | + public function __construct( $options ) { |
|
| 37 | + global $sd_widgets; |
|
| 38 | + |
|
| 39 | + $sd_widgets[ $options['base_id'] ] = array( 'name' => $options['name'], |
|
| 40 | + 'class_name' => $options['class_name'] |
|
| 41 | + ); |
|
| 42 | + $this->base_id = $options['base_id']; |
|
| 43 | + // lets filter the options before we do anything |
|
| 44 | + $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 45 | + $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 46 | + $options = $this->add_name_from_key( $options ); |
|
| 47 | + $this->options = $options; |
|
| 48 | + |
|
| 49 | + $this->base_id = $options['base_id']; |
|
| 50 | + $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 51 | + |
|
| 52 | + // init parent |
|
| 53 | + parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 54 | + |
|
| 55 | + if ( isset( $options['class_name'] ) ) { |
|
| 56 | + // register widget |
|
| 57 | + $this->class_name = $options['class_name']; |
|
| 58 | + |
|
| 59 | + // register shortcode |
|
| 60 | + $this->register_shortcode(); |
|
| 61 | + |
|
| 62 | + // register block |
|
| 63 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // add the CSS and JS we need ONCE |
|
| 67 | + global $sd_widget_scripts; |
|
| 68 | + |
|
| 69 | + if ( ! $sd_widget_scripts ) { |
|
| 70 | + wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 71 | + wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 72 | + wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 73 | + |
|
| 74 | + $sd_widget_scripts = true; |
|
| 75 | + |
|
| 76 | + // add shortcode insert button once |
|
| 77 | + add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 78 | + add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Get widget settings. |
|
| 86 | + * |
|
| 87 | + * @since 1.0.0 |
|
| 88 | + */ |
|
| 89 | + public static function get_widget_settings() { |
|
| 90 | + global $sd_widgets; |
|
| 91 | + |
|
| 92 | + $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 93 | + if ( ! $shortcode ) { |
|
| 94 | + wp_die(); |
|
| 95 | + } |
|
| 96 | + $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 97 | + if ( ! $widget_args ) { |
|
| 98 | + wp_die(); |
|
| 99 | + } |
|
| 100 | + $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 101 | + if ( ! $class_name ) { |
|
| 102 | + wp_die(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // invoke an instance method |
|
| 106 | + $widget = new $class_name; |
|
| 107 | + |
|
| 108 | + ob_start(); |
|
| 109 | + $widget->form( array() ); |
|
| 110 | + $form = ob_get_clean(); |
|
| 111 | + echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 112 | + echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 113 | + echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 114 | + ?> |
|
| 115 | 115 | <?php |
| 116 | - wp_die(); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 121 | - * |
|
| 122 | - * @since 1.0.0 |
|
| 123 | - * |
|
| 124 | - * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 125 | - * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 126 | - */ |
|
| 127 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 128 | - global $sd_widgets, $shortcode_insert_button_once; |
|
| 129 | - if ( $shortcode_insert_button_once ) { |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - add_thickbox(); |
|
| 133 | - ?> |
|
| 116 | + wp_die(); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 121 | + * |
|
| 122 | + * @since 1.0.0 |
|
| 123 | + * |
|
| 124 | + * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 125 | + * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 126 | + */ |
|
| 127 | + public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 128 | + global $sd_widgets, $shortcode_insert_button_once; |
|
| 129 | + if ( $shortcode_insert_button_once ) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + add_thickbox(); |
|
| 133 | + ?> |
|
| 134 | 134 | <div id="super-duper-content" style="display:none;"> |
| 135 | 135 | |
| 136 | 136 | <div class="sd-shortcode-left-wrap"> |
| 137 | 137 | <?php |
| 138 | - asort( $sd_widgets ); |
|
| 139 | - if ( ! empty( $sd_widgets ) ) { |
|
| 140 | - echo '<select onchange="sd_get_shortcode_options(this);">'; |
|
| 141 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 142 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 143 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 144 | - } |
|
| 145 | - echo "</select>"; |
|
| 146 | - |
|
| 147 | - } |
|
| 148 | - ?> |
|
| 138 | + asort( $sd_widgets ); |
|
| 139 | + if ( ! empty( $sd_widgets ) ) { |
|
| 140 | + echo '<select onchange="sd_get_shortcode_options(this);">'; |
|
| 141 | + echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 142 | + foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 143 | + echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 144 | + } |
|
| 145 | + echo "</select>"; |
|
| 146 | + |
|
| 147 | + } |
|
| 148 | + ?> |
|
| 149 | 149 | <div class="sd-shortcode-settings"></div> |
| 150 | 150 | |
| 151 | 151 | </div> |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | </div> |
| 164 | 164 | |
| 165 | 165 | <?php |
| 166 | - // if Font Awesome is available then show a icon if not show a WP icon. |
|
| 167 | - $button_string = wp_style_is( 'font-awesome', 'enqueued' ) && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>'; |
|
| 168 | - ?> |
|
| 166 | + // if Font Awesome is available then show a icon if not show a WP icon. |
|
| 167 | + $button_string = wp_style_is( 'font-awesome', 'enqueued' ) && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>'; |
|
| 168 | + ?> |
|
| 169 | 169 | |
| 170 | 170 | <a href="#TB_inline?width=100%&height=550&inlineId=super-duper-content" |
| 171 | 171 | class="thickbox button super-duper-content-open" |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | <script> |
| 195 | 195 | |
| 196 | 196 | <?php |
| 197 | - if(! empty( $insert_shortcode_function )){ |
|
| 198 | - echo $insert_shortcode_function; |
|
| 199 | - }else{ |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Function for super duper insert shortcode. |
|
| 203 | - * |
|
| 204 | - * @since 1.0.0 |
|
| 205 | - */ |
|
| 206 | - ?> |
|
| 197 | + if(! empty( $insert_shortcode_function )){ |
|
| 198 | + echo $insert_shortcode_function; |
|
| 199 | + }else{ |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Function for super duper insert shortcode. |
|
| 203 | + * |
|
| 204 | + * @since 1.0.0 |
|
| 205 | + */ |
|
| 206 | + ?> |
|
| 207 | 207 | function sd_insert_shortcode() { |
| 208 | 208 | $shortcode = jQuery('#sd-shortcode-output').val(); |
| 209 | 209 | if ($shortcode) { |
@@ -333,12 +333,12 @@ discard block |
||
| 333 | 333 | } |
| 334 | 334 | </script> |
| 335 | 335 | <?php |
| 336 | - $shortcode_insert_button_once = true; |
|
| 337 | - } |
|
| 336 | + $shortcode_insert_button_once = true; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - public function widget_css() { |
|
| 340 | - ob_start(); |
|
| 341 | - ?> |
|
| 339 | + public function widget_css() { |
|
| 340 | + ob_start(); |
|
| 341 | + ?> |
|
| 342 | 342 | <style> |
| 343 | 343 | .sd-advanced-setting { |
| 344 | 344 | display: none; |
@@ -359,20 +359,20 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | </style> |
| 361 | 361 | <?php |
| 362 | - $output = ob_get_clean(); |
|
| 362 | + $output = ob_get_clean(); |
|
| 363 | 363 | |
| 364 | - /* |
|
| 364 | + /* |
|
| 365 | 365 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 366 | 366 | */ |
| 367 | - return str_replace( array( |
|
| 368 | - '<style>', |
|
| 369 | - '</style>' |
|
| 370 | - ), '', $output ); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - public function widget_js() { |
|
| 374 | - ob_start(); |
|
| 375 | - ?> |
|
| 367 | + return str_replace( array( |
|
| 368 | + '<style>', |
|
| 369 | + '</style>' |
|
| 370 | + ), '', $output ); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + public function widget_js() { |
|
| 374 | + ob_start(); |
|
| 375 | + ?> |
|
| 376 | 376 | <script> |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -527,279 +527,279 @@ discard block |
||
| 527 | 527 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
| 528 | 528 | </script> |
| 529 | 529 | <?php |
| 530 | - $output = ob_get_clean(); |
|
| 530 | + $output = ob_get_clean(); |
|
| 531 | 531 | |
| 532 | - /* |
|
| 532 | + /* |
|
| 533 | 533 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 534 | 534 | */ |
| 535 | - return str_replace( array( |
|
| 536 | - '<script>', |
|
| 537 | - '</script>' |
|
| 538 | - ), '', $output ); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Set the name from the argument key. |
|
| 544 | - * |
|
| 545 | - * @param $options |
|
| 546 | - * |
|
| 547 | - * @return mixed |
|
| 548 | - */ |
|
| 549 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 550 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 551 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 552 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 553 | - } |
|
| 554 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 555 | - foreach ( $options as $key => $val ) { |
|
| 556 | - $options[ $key ]['name'] = $key; |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - return $options; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Register the parent shortcode. |
|
| 565 | - * |
|
| 566 | - * @since 1.0.0 |
|
| 567 | - */ |
|
| 568 | - public function register_shortcode() { |
|
| 569 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 570 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 575 | - * |
|
| 576 | - * @since 1.0.0 |
|
| 577 | - */ |
|
| 578 | - public static function render_shortcode() { |
|
| 579 | - |
|
| 580 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 581 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 582 | - wp_die(); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - // we might need the $post value here so lets set it. |
|
| 586 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 587 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 588 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 589 | - global $post; |
|
| 590 | - $post = $post_obj; |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 595 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 596 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 597 | - $attributes = ''; |
|
| 598 | - if ( ! empty( $attributes_array ) ) { |
|
| 599 | - foreach ( $attributes_array as $key => $value ) { |
|
| 600 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 605 | - |
|
| 606 | - echo do_shortcode( $shortcode ); |
|
| 607 | - |
|
| 608 | - } |
|
| 609 | - wp_die(); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * Output the shortcode. |
|
| 614 | - * |
|
| 615 | - * @param array $args |
|
| 616 | - * @param string $content |
|
| 617 | - * |
|
| 618 | - * @return string |
|
| 619 | - */ |
|
| 620 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 621 | - $args = self::argument_values( $args ); |
|
| 622 | - |
|
| 623 | - // add extra argument so we know its a output to gutenberg |
|
| 624 | - //$args |
|
| 625 | - $args = $this->string_to_bool( $args ); |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 629 | - |
|
| 630 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 631 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 632 | - |
|
| 633 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 634 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 635 | - |
|
| 636 | - $shortcode_args = array(); |
|
| 637 | - $output = ''; |
|
| 638 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 639 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 640 | - if ( $main_content && ! $no_wrap ) { |
|
| 641 | - // wrap the shortcode in a dive with the same class as the widget |
|
| 642 | - $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
| 643 | - if ( ! empty( $args['title'] ) ) { |
|
| 644 | - // if its a shortcode and there is a title try to grab the title wrappers |
|
| 645 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 646 | - if ( empty( $instance ) ) { |
|
| 647 | - global $wp_registered_sidebars; |
|
| 648 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 649 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 650 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 651 | - $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 652 | - $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 653 | - break; |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 659 | - } |
|
| 660 | - $output .= $main_content; |
|
| 661 | - $output .= '</div>'; |
|
| 662 | - } elseif ( $main_content && $no_wrap ) { |
|
| 663 | - $output .= $main_content; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $output; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 671 | - * |
|
| 672 | - * @param $options |
|
| 673 | - * |
|
| 674 | - * @return mixed |
|
| 675 | - */ |
|
| 676 | - public function string_to_bool( $options ) { |
|
| 677 | - // convert bool strings to booleans |
|
| 678 | - foreach ( $options as $key => $val ) { |
|
| 679 | - if ( $val == 'false' ) { |
|
| 680 | - $options[ $key ] = false; |
|
| 681 | - } elseif ( $val == 'true' ) { |
|
| 682 | - $options[ $key ] = true; |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - return $options; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Get the argument values that are also filterable. |
|
| 691 | - * |
|
| 692 | - * @param $instance |
|
| 693 | - * |
|
| 694 | - * @return array |
|
| 695 | - */ |
|
| 696 | - public function argument_values( $instance ) { |
|
| 697 | - $argument_values = array(); |
|
| 698 | - |
|
| 699 | - // set widget instance |
|
| 700 | - $this->instance = $instance; |
|
| 701 | - |
|
| 702 | - if ( empty( $this->arguments ) ) { |
|
| 703 | - $this->arguments = $this->get_arguments(); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if ( ! empty( $this->arguments ) ) { |
|
| 707 | - foreach ( $this->arguments as $key => $args ) { |
|
| 708 | - // set the input name from the key |
|
| 709 | - $args['name'] = $key; |
|
| 710 | - // |
|
| 711 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 712 | - if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 713 | - $argument_values[ $key ] = $args['default']; |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - return $argument_values; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Set arguments in super duper. |
|
| 723 | - * |
|
| 724 | - * @since 1.0.0 |
|
| 725 | - * |
|
| 726 | - * @return array Set arguments. |
|
| 727 | - */ |
|
| 728 | - public function set_arguments() { |
|
| 729 | - return $this->arguments; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Get arguments in super duper. |
|
| 734 | - * |
|
| 735 | - * @since 1.0.0 |
|
| 736 | - * |
|
| 737 | - * @return array Get arguments. |
|
| 738 | - */ |
|
| 739 | - public function get_arguments() { |
|
| 740 | - if ( empty( $this->arguments ) ) { |
|
| 741 | - $this->arguments = $this->set_arguments(); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 745 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 746 | - |
|
| 747 | - return $this->arguments; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 752 | - * |
|
| 753 | - * @param array $args |
|
| 754 | - * @param array $widget_args |
|
| 755 | - * @param string $content |
|
| 756 | - */ |
|
| 757 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 758 | - |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 763 | - */ |
|
| 764 | - public function register_block() { |
|
| 765 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Check if we need to show advanced options. |
|
| 770 | - * |
|
| 771 | - * @return bool |
|
| 772 | - */ |
|
| 773 | - public function block_show_advanced() { |
|
| 774 | - |
|
| 775 | - $show = false; |
|
| 776 | - $arguments = $this->arguments; |
|
| 777 | - |
|
| 778 | - if ( empty( $arguments ) ) { |
|
| 779 | - $arguments = $this->get_arguments(); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - if ( ! empty( $arguments ) ) { |
|
| 783 | - foreach ( $arguments as $argument ) { |
|
| 784 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 785 | - $show = true; |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - return $show; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * Output the JS for building the dynamic Guntenberg block. |
|
| 796 | - * |
|
| 797 | - * @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. |
|
| 798 | - * @return mixed |
|
| 799 | - */ |
|
| 800 | - public function block() { |
|
| 801 | - ob_start(); |
|
| 802 | - ?> |
|
| 535 | + return str_replace( array( |
|
| 536 | + '<script>', |
|
| 537 | + '</script>' |
|
| 538 | + ), '', $output ); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Set the name from the argument key. |
|
| 544 | + * |
|
| 545 | + * @param $options |
|
| 546 | + * |
|
| 547 | + * @return mixed |
|
| 548 | + */ |
|
| 549 | + private function add_name_from_key( $options, $arguments = false ) { |
|
| 550 | + if ( ! empty( $options['arguments'] ) ) { |
|
| 551 | + foreach ( $options['arguments'] as $key => $val ) { |
|
| 552 | + $options['arguments'][ $key ]['name'] = $key; |
|
| 553 | + } |
|
| 554 | + } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 555 | + foreach ( $options as $key => $val ) { |
|
| 556 | + $options[ $key ]['name'] = $key; |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + return $options; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Register the parent shortcode. |
|
| 565 | + * |
|
| 566 | + * @since 1.0.0 |
|
| 567 | + */ |
|
| 568 | + public function register_shortcode() { |
|
| 569 | + add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 570 | + add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 575 | + * |
|
| 576 | + * @since 1.0.0 |
|
| 577 | + */ |
|
| 578 | + public static function render_shortcode() { |
|
| 579 | + |
|
| 580 | + check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 581 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 582 | + wp_die(); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + // we might need the $post value here so lets set it. |
|
| 586 | + if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 587 | + $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 588 | + if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 589 | + global $post; |
|
| 590 | + $post = $post_obj; |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 595 | + $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 596 | + $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 597 | + $attributes = ''; |
|
| 598 | + if ( ! empty( $attributes_array ) ) { |
|
| 599 | + foreach ( $attributes_array as $key => $value ) { |
|
| 600 | + $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 605 | + |
|
| 606 | + echo do_shortcode( $shortcode ); |
|
| 607 | + |
|
| 608 | + } |
|
| 609 | + wp_die(); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * Output the shortcode. |
|
| 614 | + * |
|
| 615 | + * @param array $args |
|
| 616 | + * @param string $content |
|
| 617 | + * |
|
| 618 | + * @return string |
|
| 619 | + */ |
|
| 620 | + public function shortcode_output( $args = array(), $content = '' ) { |
|
| 621 | + $args = self::argument_values( $args ); |
|
| 622 | + |
|
| 623 | + // add extra argument so we know its a output to gutenberg |
|
| 624 | + //$args |
|
| 625 | + $args = $this->string_to_bool( $args ); |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 629 | + |
|
| 630 | + $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 631 | + $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 632 | + |
|
| 633 | + $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 634 | + $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 635 | + |
|
| 636 | + $shortcode_args = array(); |
|
| 637 | + $output = ''; |
|
| 638 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 639 | + $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 640 | + if ( $main_content && ! $no_wrap ) { |
|
| 641 | + // wrap the shortcode in a dive with the same class as the widget |
|
| 642 | + $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
| 643 | + if ( ! empty( $args['title'] ) ) { |
|
| 644 | + // if its a shortcode and there is a title try to grab the title wrappers |
|
| 645 | + $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 646 | + if ( empty( $instance ) ) { |
|
| 647 | + global $wp_registered_sidebars; |
|
| 648 | + if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 649 | + foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 650 | + if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 651 | + $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 652 | + $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 653 | + break; |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + $output .= $this->output_title( $shortcode_args, $args ); |
|
| 659 | + } |
|
| 660 | + $output .= $main_content; |
|
| 661 | + $output .= '</div>'; |
|
| 662 | + } elseif ( $main_content && $no_wrap ) { |
|
| 663 | + $output .= $main_content; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $output; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 671 | + * |
|
| 672 | + * @param $options |
|
| 673 | + * |
|
| 674 | + * @return mixed |
|
| 675 | + */ |
|
| 676 | + public function string_to_bool( $options ) { |
|
| 677 | + // convert bool strings to booleans |
|
| 678 | + foreach ( $options as $key => $val ) { |
|
| 679 | + if ( $val == 'false' ) { |
|
| 680 | + $options[ $key ] = false; |
|
| 681 | + } elseif ( $val == 'true' ) { |
|
| 682 | + $options[ $key ] = true; |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + return $options; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Get the argument values that are also filterable. |
|
| 691 | + * |
|
| 692 | + * @param $instance |
|
| 693 | + * |
|
| 694 | + * @return array |
|
| 695 | + */ |
|
| 696 | + public function argument_values( $instance ) { |
|
| 697 | + $argument_values = array(); |
|
| 698 | + |
|
| 699 | + // set widget instance |
|
| 700 | + $this->instance = $instance; |
|
| 701 | + |
|
| 702 | + if ( empty( $this->arguments ) ) { |
|
| 703 | + $this->arguments = $this->get_arguments(); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if ( ! empty( $this->arguments ) ) { |
|
| 707 | + foreach ( $this->arguments as $key => $args ) { |
|
| 708 | + // set the input name from the key |
|
| 709 | + $args['name'] = $key; |
|
| 710 | + // |
|
| 711 | + $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 712 | + if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 713 | + $argument_values[ $key ] = $args['default']; |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + return $argument_values; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Set arguments in super duper. |
|
| 723 | + * |
|
| 724 | + * @since 1.0.0 |
|
| 725 | + * |
|
| 726 | + * @return array Set arguments. |
|
| 727 | + */ |
|
| 728 | + public function set_arguments() { |
|
| 729 | + return $this->arguments; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Get arguments in super duper. |
|
| 734 | + * |
|
| 735 | + * @since 1.0.0 |
|
| 736 | + * |
|
| 737 | + * @return array Get arguments. |
|
| 738 | + */ |
|
| 739 | + public function get_arguments() { |
|
| 740 | + if ( empty( $this->arguments ) ) { |
|
| 741 | + $this->arguments = $this->set_arguments(); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 745 | + $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 746 | + |
|
| 747 | + return $this->arguments; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 752 | + * |
|
| 753 | + * @param array $args |
|
| 754 | + * @param array $widget_args |
|
| 755 | + * @param string $content |
|
| 756 | + */ |
|
| 757 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 758 | + |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 763 | + */ |
|
| 764 | + public function register_block() { |
|
| 765 | + wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Check if we need to show advanced options. |
|
| 770 | + * |
|
| 771 | + * @return bool |
|
| 772 | + */ |
|
| 773 | + public function block_show_advanced() { |
|
| 774 | + |
|
| 775 | + $show = false; |
|
| 776 | + $arguments = $this->arguments; |
|
| 777 | + |
|
| 778 | + if ( empty( $arguments ) ) { |
|
| 779 | + $arguments = $this->get_arguments(); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + if ( ! empty( $arguments ) ) { |
|
| 783 | + foreach ( $arguments as $argument ) { |
|
| 784 | + if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 785 | + $show = true; |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + return $show; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * Output the JS for building the dynamic Guntenberg block. |
|
| 796 | + * |
|
| 797 | + * @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. |
|
| 798 | + * @return mixed |
|
| 799 | + */ |
|
| 800 | + public function block() { |
|
| 801 | + ob_start(); |
|
| 802 | + ?> |
|
| 803 | 803 | <script> |
| 804 | 804 | /** |
| 805 | 805 | * BLOCK: Basic |
@@ -838,76 +838,76 @@ discard block |
||
| 838 | 838 | 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/. |
| 839 | 839 | 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. |
| 840 | 840 | <?php if ( isset( $this->options['block-keywords'] ) ) { |
| 841 | - echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 842 | - }?> |
|
| 841 | + echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 842 | + }?> |
|
| 843 | 843 | |
| 844 | 844 | <?php |
| 845 | 845 | |
| 846 | - $show_advanced = $this->block_show_advanced(); |
|
| 847 | - |
|
| 848 | - $show_alignment = false; |
|
| 849 | - |
|
| 850 | - if ( ! empty( $this->arguments ) ) { |
|
| 851 | - echo "attributes : {"; |
|
| 852 | - |
|
| 853 | - if ( $show_advanced ) { |
|
| 854 | - echo "show_advanced: {"; |
|
| 855 | - echo " type: 'boolean',"; |
|
| 856 | - echo " default: false,"; |
|
| 857 | - echo "},"; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - // block wrap element |
|
| 861 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 862 | - echo "block_wrap: {"; |
|
| 863 | - echo " type: 'string',"; |
|
| 864 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 865 | - echo "},"; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - foreach ( $this->arguments as $key => $args ) { |
|
| 870 | - |
|
| 871 | - // set if we should show alignment |
|
| 872 | - if ( $key == 'alignment' ) { |
|
| 873 | - $show_alignment = true; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - $extra = ''; |
|
| 877 | - |
|
| 878 | - if ( $args['type'] == 'checkbox' ) { |
|
| 879 | - $type = 'boolean'; |
|
| 880 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 881 | - } elseif ( $args['type'] == 'number' ) { |
|
| 882 | - $type = 'number'; |
|
| 883 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 884 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 885 | - $type = 'array'; |
|
| 886 | - if ( is_array( $args['default'] ) ) { |
|
| 887 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 888 | - } else { |
|
| 889 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 890 | - } |
|
| 891 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 892 | - $type = 'array'; |
|
| 893 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 894 | - } else { |
|
| 895 | - $type = 'string'; |
|
| 896 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 897 | - } |
|
| 898 | - echo $key . " : {"; |
|
| 899 | - echo "type : '$type',"; |
|
| 900 | - echo "default : $default,"; |
|
| 901 | - echo "},"; |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 905 | - |
|
| 906 | - echo "},"; |
|
| 907 | - |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - ?> |
|
| 846 | + $show_advanced = $this->block_show_advanced(); |
|
| 847 | + |
|
| 848 | + $show_alignment = false; |
|
| 849 | + |
|
| 850 | + if ( ! empty( $this->arguments ) ) { |
|
| 851 | + echo "attributes : {"; |
|
| 852 | + |
|
| 853 | + if ( $show_advanced ) { |
|
| 854 | + echo "show_advanced: {"; |
|
| 855 | + echo " type: 'boolean',"; |
|
| 856 | + echo " default: false,"; |
|
| 857 | + echo "},"; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + // block wrap element |
|
| 861 | + if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 862 | + echo "block_wrap: {"; |
|
| 863 | + echo " type: 'string',"; |
|
| 864 | + echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 865 | + echo "},"; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + foreach ( $this->arguments as $key => $args ) { |
|
| 870 | + |
|
| 871 | + // set if we should show alignment |
|
| 872 | + if ( $key == 'alignment' ) { |
|
| 873 | + $show_alignment = true; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + $extra = ''; |
|
| 877 | + |
|
| 878 | + if ( $args['type'] == 'checkbox' ) { |
|
| 879 | + $type = 'boolean'; |
|
| 880 | + $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 881 | + } elseif ( $args['type'] == 'number' ) { |
|
| 882 | + $type = 'number'; |
|
| 883 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 884 | + } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 885 | + $type = 'array'; |
|
| 886 | + if ( is_array( $args['default'] ) ) { |
|
| 887 | + $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 888 | + } else { |
|
| 889 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 890 | + } |
|
| 891 | + } elseif ( $args['type'] == 'multiselect' ) { |
|
| 892 | + $type = 'array'; |
|
| 893 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 894 | + } else { |
|
| 895 | + $type = 'string'; |
|
| 896 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 897 | + } |
|
| 898 | + echo $key . " : {"; |
|
| 899 | + echo "type : '$type',"; |
|
| 900 | + echo "default : $default,"; |
|
| 901 | + echo "},"; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 905 | + |
|
| 906 | + echo "},"; |
|
| 907 | + |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + ?> |
|
| 911 | 911 | |
| 912 | 912 | // The "edit" property must be a valid function. |
| 913 | 913 | edit: function (props) { |
@@ -926,8 +926,8 @@ discard block |
||
| 926 | 926 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
| 927 | 927 | 'attributes': props.attributes, |
| 928 | 928 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
| 929 | - echo $post->ID; |
|
| 930 | - }?>, |
|
| 929 | + echo $post->ID; |
|
| 930 | + }?>, |
|
| 931 | 931 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
| 932 | 932 | }; |
| 933 | 933 | |
@@ -974,10 +974,10 @@ discard block |
||
| 974 | 974 | |
| 975 | 975 | <?php |
| 976 | 976 | |
| 977 | - if(! empty( $this->arguments )){ |
|
| 977 | + if(! empty( $this->arguments )){ |
|
| 978 | 978 | |
| 979 | - if ( $show_advanced ) { |
|
| 980 | - ?> |
|
| 979 | + if ( $show_advanced ) { |
|
| 980 | + ?> |
|
| 981 | 981 | el( |
| 982 | 982 | wp.components.ToggleControl, |
| 983 | 983 | { |
@@ -990,65 +990,65 @@ discard block |
||
| 990 | 990 | ), |
| 991 | 991 | <?php |
| 992 | 992 | |
| 993 | - } |
|
| 994 | - |
|
| 995 | - foreach($this->arguments as $key => $args){ |
|
| 996 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 997 | - $options = ''; |
|
| 998 | - $extra = ''; |
|
| 999 | - $require = ''; |
|
| 1000 | - $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 1001 | - $value = "props.attributes.$key"; |
|
| 1002 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1003 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 1004 | - $type = 'TextControl'; |
|
| 1005 | - } elseif ( $args['type'] == 'checkbox' ) { |
|
| 1006 | - $type = 'CheckboxControl'; |
|
| 1007 | - $extra .= "checked: props.attributes.$key,"; |
|
| 1008 | - $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 1009 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1010 | - $type = 'SelectControl'; |
|
| 1011 | - if ( ! empty( $args['options'] ) ) { |
|
| 1012 | - $options .= "options : ["; |
|
| 1013 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1014 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1015 | - } |
|
| 1016 | - $options .= "],"; |
|
| 1017 | - } |
|
| 1018 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1019 | - $extra .= ' multiple: true, '; |
|
| 1020 | - //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
| 1021 | - //$value = "['edit', 'delete']"; |
|
| 1022 | - } |
|
| 1023 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 1024 | - $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 1025 | - } else { |
|
| 1026 | - continue;// if we have not implemented the control then don't break the JS. |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - // add show only if advanced |
|
| 1030 | - if ( ! empty( $args['advanced'] ) ) { |
|
| 1031 | - echo "props.attributes.show_advanced && "; |
|
| 1032 | - } |
|
| 1033 | - // add setting require if defined |
|
| 1034 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 1035 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1036 | - } |
|
| 1037 | - ?> |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + foreach($this->arguments as $key => $args){ |
|
| 996 | + $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 997 | + $options = ''; |
|
| 998 | + $extra = ''; |
|
| 999 | + $require = ''; |
|
| 1000 | + $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 1001 | + $value = "props.attributes.$key"; |
|
| 1002 | + $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1003 | + if ( in_array( $args['type'], $text_type ) ) { |
|
| 1004 | + $type = 'TextControl'; |
|
| 1005 | + } elseif ( $args['type'] == 'checkbox' ) { |
|
| 1006 | + $type = 'CheckboxControl'; |
|
| 1007 | + $extra .= "checked: props.attributes.$key,"; |
|
| 1008 | + $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 1009 | + } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1010 | + $type = 'SelectControl'; |
|
| 1011 | + if ( ! empty( $args['options'] ) ) { |
|
| 1012 | + $options .= "options : ["; |
|
| 1013 | + foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1014 | + $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1015 | + } |
|
| 1016 | + $options .= "],"; |
|
| 1017 | + } |
|
| 1018 | + if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1019 | + $extra .= ' multiple: true, '; |
|
| 1020 | + //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
| 1021 | + //$value = "['edit', 'delete']"; |
|
| 1022 | + } |
|
| 1023 | + } elseif ( $args['type'] == 'alignment' ) { |
|
| 1024 | + $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 1025 | + } else { |
|
| 1026 | + continue;// if we have not implemented the control then don't break the JS. |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + // add show only if advanced |
|
| 1030 | + if ( ! empty( $args['advanced'] ) ) { |
|
| 1031 | + echo "props.attributes.show_advanced && "; |
|
| 1032 | + } |
|
| 1033 | + // add setting require if defined |
|
| 1034 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 1035 | + echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1036 | + } |
|
| 1037 | + ?> |
|
| 1038 | 1038 | el( |
| 1039 | 1039 | wp.components.<?php echo esc_attr( $type );?>, |
| 1040 | 1040 | { |
| 1041 | 1041 | label: '<?php echo esc_attr( $args['title'] );?>', |
| 1042 | 1042 | help: '<?php if ( isset( $args['desc'] ) ) { |
| 1043 | - echo esc_attr( $args['desc'] ); |
|
| 1044 | - }?>', |
|
| 1043 | + echo esc_attr( $args['desc'] ); |
|
| 1044 | + }?>', |
|
| 1045 | 1045 | value: <?php echo $value;?>, |
| 1046 | 1046 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
| 1047 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1048 | - }?> |
|
| 1047 | + echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1048 | + }?> |
|
| 1049 | 1049 | <?php if ( ! empty( $args['placeholder'] ) ) { |
| 1050 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1051 | - }?> |
|
| 1050 | + echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1051 | + }?> |
|
| 1052 | 1052 | <?php echo $options;?> |
| 1053 | 1053 | <?php echo $extra;?> |
| 1054 | 1054 | <?php echo $custom_attributes;?> |
@@ -1058,27 +1058,27 @@ discard block |
||
| 1058 | 1058 | } |
| 1059 | 1059 | ), |
| 1060 | 1060 | <?php |
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - ?> |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + ?> |
|
| 1064 | 1064 | |
| 1065 | 1065 | ), |
| 1066 | 1066 | |
| 1067 | 1067 | <?php |
| 1068 | - // If the user sets block-output array then build it |
|
| 1069 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1070 | - $this->block_element( $this->options['block-output'] ); |
|
| 1071 | - }else{ |
|
| 1072 | - // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1073 | - ?> |
|
| 1068 | + // If the user sets block-output array then build it |
|
| 1069 | + if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1070 | + $this->block_element( $this->options['block-output'] ); |
|
| 1071 | + }else{ |
|
| 1072 | + // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1073 | + ?> |
|
| 1074 | 1074 | el('div', { |
| 1075 | 1075 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
| 1076 | 1076 | className: props.className, |
| 1077 | 1077 | style: {'min-height': '30px'} |
| 1078 | 1078 | }) |
| 1079 | 1079 | <?php |
| 1080 | - } |
|
| 1081 | - ?> |
|
| 1080 | + } |
|
| 1081 | + ?> |
|
| 1082 | 1082 | ]; // end return |
| 1083 | 1083 | }, |
| 1084 | 1084 | |
@@ -1095,17 +1095,17 @@ discard block |
||
| 1095 | 1095 | var content = "[<?php echo $this->options['base_id'];?>"; |
| 1096 | 1096 | <?php |
| 1097 | 1097 | |
| 1098 | - if(! empty( $this->arguments )){ |
|
| 1099 | - foreach($this->arguments as $key => $args){ |
|
| 1100 | - ?> |
|
| 1098 | + if(! empty( $this->arguments )){ |
|
| 1099 | + foreach($this->arguments as $key => $args){ |
|
| 1100 | + ?> |
|
| 1101 | 1101 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
| 1102 | 1102 | content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
| 1103 | 1103 | } |
| 1104 | 1104 | <?php |
| 1105 | - } |
|
| 1106 | - } |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | 1107 | |
| 1108 | - ?> |
|
| 1108 | + ?> |
|
| 1109 | 1109 | content += "]"; |
| 1110 | 1110 | |
| 1111 | 1111 | |
@@ -1134,370 +1134,370 @@ discard block |
||
| 1134 | 1134 | })(); |
| 1135 | 1135 | </script> |
| 1136 | 1136 | <?php |
| 1137 | - $output = ob_get_clean(); |
|
| 1137 | + $output = ob_get_clean(); |
|
| 1138 | 1138 | |
| 1139 | - /* |
|
| 1139 | + /* |
|
| 1140 | 1140 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1141 | 1141 | */ |
| 1142 | 1142 | |
| 1143 | - return str_replace( array( |
|
| 1144 | - '<script>', |
|
| 1145 | - '</script>' |
|
| 1146 | - ), '', $output ); |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Convert an array of attributes to block string. |
|
| 1151 | - * |
|
| 1152 | - * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 1153 | - * |
|
| 1154 | - * @param $custom_attributes |
|
| 1155 | - * |
|
| 1156 | - * @return string |
|
| 1157 | - */ |
|
| 1158 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 1159 | - $attributes = ''; |
|
| 1160 | - if ( ! empty( $custom_attributes ) ) { |
|
| 1161 | - |
|
| 1162 | - if ( $html ) { |
|
| 1163 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1164 | - $attributes .= " $key='$val' "; |
|
| 1165 | - } |
|
| 1166 | - } else { |
|
| 1167 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1168 | - $attributes .= "'$key': '$val',"; |
|
| 1169 | - } |
|
| 1170 | - } |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - return $attributes; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * A self looping function to create the output for JS block elements. |
|
| 1178 | - * |
|
| 1179 | - * This is what is output in the WP Editor visual view. |
|
| 1180 | - * |
|
| 1181 | - * @param $args |
|
| 1182 | - */ |
|
| 1183 | - public function block_element( $args ) { |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - if ( ! empty( $args ) ) { |
|
| 1187 | - foreach ( $args as $element => $new_args ) { |
|
| 1188 | - |
|
| 1189 | - if ( is_array( $new_args ) ) { // its an element |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - if ( isset( $new_args['element'] ) ) { |
|
| 1193 | - |
|
| 1194 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 1195 | - echo str_replace( array( |
|
| 1196 | - "'+", |
|
| 1197 | - "+'" |
|
| 1198 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 1199 | - unset( $new_args['element_require'] ); |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 1203 | - |
|
| 1204 | - // get the attributes |
|
| 1205 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 1209 | - // do nothing |
|
| 1210 | - } else { |
|
| 1211 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - echo "},";// end attributes |
|
| 1216 | - |
|
| 1217 | - // get the content |
|
| 1218 | - $first_item = 0; |
|
| 1219 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1220 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 1221 | - |
|
| 1222 | - if ( $new_key === 'content' ) { |
|
| 1223 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - if ( is_array( $new_value ) ) { |
|
| 1227 | - |
|
| 1228 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 1229 | - echo str_replace( array( |
|
| 1230 | - "'+", |
|
| 1231 | - "+'" |
|
| 1232 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 1233 | - unset( $new_value['element_require'] ); |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 1237 | - $x = 1; |
|
| 1238 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 1239 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1240 | - $x ++; |
|
| 1241 | - } |
|
| 1242 | - } else { |
|
| 1243 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1244 | - } |
|
| 1245 | - } |
|
| 1246 | - $first_item ++; |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - echo ")";// end content |
|
| 1251 | - |
|
| 1252 | - echo ", \n"; |
|
| 1253 | - |
|
| 1254 | - } |
|
| 1255 | - } else { |
|
| 1256 | - |
|
| 1257 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 1258 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 1259 | - } elseif ( $element == 'style' ) { |
|
| 1260 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 1261 | - } else { |
|
| 1262 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * Replace block attributes placeholders with the proper naming. |
|
| 1272 | - * |
|
| 1273 | - * @param $string |
|
| 1274 | - * |
|
| 1275 | - * @return mixed |
|
| 1276 | - */ |
|
| 1277 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 1278 | - |
|
| 1279 | - if ( $no_wrap ) { |
|
| 1280 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 1281 | - } else { |
|
| 1282 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - return $string; |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - /** |
|
| 1289 | - * Outputs the content of the widget |
|
| 1290 | - * |
|
| 1291 | - * @param array $args |
|
| 1292 | - * @param array $instance |
|
| 1293 | - */ |
|
| 1294 | - public function widget( $args, $instance ) { |
|
| 1295 | - |
|
| 1296 | - // get the filtered values |
|
| 1297 | - $argument_values = $this->argument_values( $instance ); |
|
| 1298 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 1299 | - $output = $this->output( $argument_values, $args ); |
|
| 1300 | - |
|
| 1301 | - if ( $output ) { |
|
| 1302 | - // Before widget |
|
| 1303 | - $before_widget = $args['before_widget']; |
|
| 1304 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 1305 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 1306 | - |
|
| 1307 | - // After widget |
|
| 1308 | - $after_widget = $args['after_widget']; |
|
| 1309 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 1310 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 1311 | - |
|
| 1312 | - echo $before_widget; |
|
| 1313 | - // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 1314 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1315 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 1316 | - } |
|
| 1317 | - echo $this->output_title( $args, $instance ); |
|
| 1318 | - echo $output; |
|
| 1319 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1320 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 1321 | - } |
|
| 1322 | - echo $after_widget; |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - /** |
|
| 1327 | - * Tests if the current output is inside a elementor container. |
|
| 1328 | - * |
|
| 1329 | - * @since 1.0.4 |
|
| 1330 | - * @return bool |
|
| 1331 | - */ |
|
| 1332 | - public function is_elementor_widget_output() { |
|
| 1333 | - $result = false; |
|
| 1334 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 1335 | - $result = true; |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - return $result; |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * Tests if the current output is inside a elementor preview. |
|
| 1343 | - * |
|
| 1344 | - * @since 1.0.4 |
|
| 1345 | - * @return bool |
|
| 1346 | - */ |
|
| 1347 | - public function is_elementor_preview() { |
|
| 1348 | - $result = false; |
|
| 1349 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 1350 | - $result = true; |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - return $result; |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - /** |
|
| 1357 | - * Output the super title. |
|
| 1358 | - * |
|
| 1359 | - * @param $args |
|
| 1360 | - * @param array $instance |
|
| 1361 | - * |
|
| 1362 | - * @return string |
|
| 1363 | - */ |
|
| 1364 | - public function output_title( $args, $instance = array() ) { |
|
| 1365 | - $output = ''; |
|
| 1366 | - if ( ! empty( $instance['title'] ) ) { |
|
| 1367 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 1368 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 1369 | - $output = $args['before_title'] . $title . $args['after_title']; |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - return $output; |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - /** |
|
| 1376 | - * Outputs the options form inputs for the widget. |
|
| 1377 | - * |
|
| 1378 | - * @param array $instance The widget options. |
|
| 1379 | - */ |
|
| 1380 | - public function form( $instance ) { |
|
| 1381 | - |
|
| 1382 | - // set widget instance |
|
| 1383 | - $this->instance = $instance; |
|
| 1384 | - |
|
| 1385 | - // set it as a SD widget |
|
| 1386 | - echo $this->widget_advanced_toggle(); |
|
| 1387 | - |
|
| 1388 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 1389 | - $arguments = $this->get_arguments(); |
|
| 1390 | - |
|
| 1391 | - if ( is_array( $arguments ) ) { |
|
| 1392 | - foreach ( $arguments as $key => $args ) { |
|
| 1393 | - $this->widget_inputs( $args, $instance ); |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - /** |
|
| 1399 | - * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 1400 | - * |
|
| 1401 | - * @return string |
|
| 1402 | - */ |
|
| 1403 | - public function widget_advanced_toggle() { |
|
| 1404 | - |
|
| 1405 | - $output = ''; |
|
| 1406 | - if ( $this->block_show_advanced() ) { |
|
| 1407 | - $val = 1; |
|
| 1408 | - } else { |
|
| 1409 | - $val = 0; |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 1413 | - |
|
| 1414 | - return $output; |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * Convert require element. |
|
| 1419 | - * |
|
| 1420 | - * @since 1.0.0 |
|
| 1421 | - * |
|
| 1422 | - * @param string $input Input element. |
|
| 1423 | - * |
|
| 1424 | - * @return string $output |
|
| 1425 | - */ |
|
| 1426 | - public function convert_element_require( $input ) { |
|
| 1427 | - |
|
| 1428 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 1429 | - |
|
| 1430 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 1431 | - "jQuery(form).find('[data-argument=\"", |
|
| 1432 | - "\"]').find('input,select').val()" |
|
| 1433 | - ), $input ) ); |
|
| 1434 | - |
|
| 1435 | - return $output; |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - /** |
|
| 1439 | - * Builds the inputs for the widget options. |
|
| 1440 | - * |
|
| 1441 | - * @param $args |
|
| 1442 | - * @param $instance |
|
| 1443 | - */ |
|
| 1444 | - public function widget_inputs( $args, $instance ) { |
|
| 1445 | - |
|
| 1446 | - $class = ""; |
|
| 1447 | - $element_require = ""; |
|
| 1448 | - $custom_attributes = ""; |
|
| 1449 | - |
|
| 1450 | - // get value |
|
| 1451 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 1452 | - $value = $instance[ $args['name'] ]; |
|
| 1453 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 1454 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 1455 | - } else { |
|
| 1456 | - $value = ''; |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - // get placeholder |
|
| 1460 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 1461 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 1462 | - } else { |
|
| 1463 | - $placeholder = ''; |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - // get if advanced |
|
| 1467 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 1468 | - $class .= " sd-advanced-setting "; |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - // element_require |
|
| 1472 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 1473 | - $element_require = $args['element_require']; |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - // custom_attributes |
|
| 1477 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 1478 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - // before wrapper |
|
| 1482 | - ?> |
|
| 1143 | + return str_replace( array( |
|
| 1144 | + '<script>', |
|
| 1145 | + '</script>' |
|
| 1146 | + ), '', $output ); |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Convert an array of attributes to block string. |
|
| 1151 | + * |
|
| 1152 | + * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 1153 | + * |
|
| 1154 | + * @param $custom_attributes |
|
| 1155 | + * |
|
| 1156 | + * @return string |
|
| 1157 | + */ |
|
| 1158 | + public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 1159 | + $attributes = ''; |
|
| 1160 | + if ( ! empty( $custom_attributes ) ) { |
|
| 1161 | + |
|
| 1162 | + if ( $html ) { |
|
| 1163 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 1164 | + $attributes .= " $key='$val' "; |
|
| 1165 | + } |
|
| 1166 | + } else { |
|
| 1167 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 1168 | + $attributes .= "'$key': '$val',"; |
|
| 1169 | + } |
|
| 1170 | + } |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + return $attributes; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * A self looping function to create the output for JS block elements. |
|
| 1178 | + * |
|
| 1179 | + * This is what is output in the WP Editor visual view. |
|
| 1180 | + * |
|
| 1181 | + * @param $args |
|
| 1182 | + */ |
|
| 1183 | + public function block_element( $args ) { |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + if ( ! empty( $args ) ) { |
|
| 1187 | + foreach ( $args as $element => $new_args ) { |
|
| 1188 | + |
|
| 1189 | + if ( is_array( $new_args ) ) { // its an element |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + if ( isset( $new_args['element'] ) ) { |
|
| 1193 | + |
|
| 1194 | + if ( isset( $new_args['element_require'] ) ) { |
|
| 1195 | + echo str_replace( array( |
|
| 1196 | + "'+", |
|
| 1197 | + "+'" |
|
| 1198 | + ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 1199 | + unset( $new_args['element_require'] ); |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 1203 | + |
|
| 1204 | + // get the attributes |
|
| 1205 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 1209 | + // do nothing |
|
| 1210 | + } else { |
|
| 1211 | + echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + echo "},";// end attributes |
|
| 1216 | + |
|
| 1217 | + // get the content |
|
| 1218 | + $first_item = 0; |
|
| 1219 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 1220 | + if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 1221 | + |
|
| 1222 | + if ( $new_key === 'content' ) { |
|
| 1223 | + echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + if ( is_array( $new_value ) ) { |
|
| 1227 | + |
|
| 1228 | + if ( isset( $new_value['element_require'] ) ) { |
|
| 1229 | + echo str_replace( array( |
|
| 1230 | + "'+", |
|
| 1231 | + "+'" |
|
| 1232 | + ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 1233 | + unset( $new_value['element_require'] ); |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + if ( isset( $new_value['element_repeat'] ) ) { |
|
| 1237 | + $x = 1; |
|
| 1238 | + while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 1239 | + $this->block_element( array( '' => $new_value ) ); |
|
| 1240 | + $x ++; |
|
| 1241 | + } |
|
| 1242 | + } else { |
|
| 1243 | + $this->block_element( array( '' => $new_value ) ); |
|
| 1244 | + } |
|
| 1245 | + } |
|
| 1246 | + $first_item ++; |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + echo ")";// end content |
|
| 1251 | + |
|
| 1252 | + echo ", \n"; |
|
| 1253 | + |
|
| 1254 | + } |
|
| 1255 | + } else { |
|
| 1256 | + |
|
| 1257 | + if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 1258 | + echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 1259 | + } elseif ( $element == 'style' ) { |
|
| 1260 | + echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 1261 | + } else { |
|
| 1262 | + echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + /** |
|
| 1271 | + * Replace block attributes placeholders with the proper naming. |
|
| 1272 | + * |
|
| 1273 | + * @param $string |
|
| 1274 | + * |
|
| 1275 | + * @return mixed |
|
| 1276 | + */ |
|
| 1277 | + public function block_props_replace( $string, $no_wrap = false ) { |
|
| 1278 | + |
|
| 1279 | + if ( $no_wrap ) { |
|
| 1280 | + $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 1281 | + } else { |
|
| 1282 | + $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + return $string; |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + /** |
|
| 1289 | + * Outputs the content of the widget |
|
| 1290 | + * |
|
| 1291 | + * @param array $args |
|
| 1292 | + * @param array $instance |
|
| 1293 | + */ |
|
| 1294 | + public function widget( $args, $instance ) { |
|
| 1295 | + |
|
| 1296 | + // get the filtered values |
|
| 1297 | + $argument_values = $this->argument_values( $instance ); |
|
| 1298 | + $argument_values = $this->string_to_bool( $argument_values ); |
|
| 1299 | + $output = $this->output( $argument_values, $args ); |
|
| 1300 | + |
|
| 1301 | + if ( $output ) { |
|
| 1302 | + // Before widget |
|
| 1303 | + $before_widget = $args['before_widget']; |
|
| 1304 | + $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 1305 | + $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 1306 | + |
|
| 1307 | + // After widget |
|
| 1308 | + $after_widget = $args['after_widget']; |
|
| 1309 | + $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 1310 | + $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 1311 | + |
|
| 1312 | + echo $before_widget; |
|
| 1313 | + // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 1314 | + if ( $this->is_elementor_widget_output() ) { |
|
| 1315 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 1316 | + } |
|
| 1317 | + echo $this->output_title( $args, $instance ); |
|
| 1318 | + echo $output; |
|
| 1319 | + if ( $this->is_elementor_widget_output() ) { |
|
| 1320 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 1321 | + } |
|
| 1322 | + echo $after_widget; |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + /** |
|
| 1327 | + * Tests if the current output is inside a elementor container. |
|
| 1328 | + * |
|
| 1329 | + * @since 1.0.4 |
|
| 1330 | + * @return bool |
|
| 1331 | + */ |
|
| 1332 | + public function is_elementor_widget_output() { |
|
| 1333 | + $result = false; |
|
| 1334 | + if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 1335 | + $result = true; |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + return $result; |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * Tests if the current output is inside a elementor preview. |
|
| 1343 | + * |
|
| 1344 | + * @since 1.0.4 |
|
| 1345 | + * @return bool |
|
| 1346 | + */ |
|
| 1347 | + public function is_elementor_preview() { |
|
| 1348 | + $result = false; |
|
| 1349 | + if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 1350 | + $result = true; |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + return $result; |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + /** |
|
| 1357 | + * Output the super title. |
|
| 1358 | + * |
|
| 1359 | + * @param $args |
|
| 1360 | + * @param array $instance |
|
| 1361 | + * |
|
| 1362 | + * @return string |
|
| 1363 | + */ |
|
| 1364 | + public function output_title( $args, $instance = array() ) { |
|
| 1365 | + $output = ''; |
|
| 1366 | + if ( ! empty( $instance['title'] ) ) { |
|
| 1367 | + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 1368 | + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 1369 | + $output = $args['before_title'] . $title . $args['after_title']; |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + return $output; |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + /** |
|
| 1376 | + * Outputs the options form inputs for the widget. |
|
| 1377 | + * |
|
| 1378 | + * @param array $instance The widget options. |
|
| 1379 | + */ |
|
| 1380 | + public function form( $instance ) { |
|
| 1381 | + |
|
| 1382 | + // set widget instance |
|
| 1383 | + $this->instance = $instance; |
|
| 1384 | + |
|
| 1385 | + // set it as a SD widget |
|
| 1386 | + echo $this->widget_advanced_toggle(); |
|
| 1387 | + |
|
| 1388 | + echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 1389 | + $arguments = $this->get_arguments(); |
|
| 1390 | + |
|
| 1391 | + if ( is_array( $arguments ) ) { |
|
| 1392 | + foreach ( $arguments as $key => $args ) { |
|
| 1393 | + $this->widget_inputs( $args, $instance ); |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + /** |
|
| 1399 | + * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 1400 | + * |
|
| 1401 | + * @return string |
|
| 1402 | + */ |
|
| 1403 | + public function widget_advanced_toggle() { |
|
| 1404 | + |
|
| 1405 | + $output = ''; |
|
| 1406 | + if ( $this->block_show_advanced() ) { |
|
| 1407 | + $val = 1; |
|
| 1408 | + } else { |
|
| 1409 | + $val = 0; |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 1413 | + |
|
| 1414 | + return $output; |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * Convert require element. |
|
| 1419 | + * |
|
| 1420 | + * @since 1.0.0 |
|
| 1421 | + * |
|
| 1422 | + * @param string $input Input element. |
|
| 1423 | + * |
|
| 1424 | + * @return string $output |
|
| 1425 | + */ |
|
| 1426 | + public function convert_element_require( $input ) { |
|
| 1427 | + |
|
| 1428 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 1429 | + |
|
| 1430 | + $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 1431 | + "jQuery(form).find('[data-argument=\"", |
|
| 1432 | + "\"]').find('input,select').val()" |
|
| 1433 | + ), $input ) ); |
|
| 1434 | + |
|
| 1435 | + return $output; |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + /** |
|
| 1439 | + * Builds the inputs for the widget options. |
|
| 1440 | + * |
|
| 1441 | + * @param $args |
|
| 1442 | + * @param $instance |
|
| 1443 | + */ |
|
| 1444 | + public function widget_inputs( $args, $instance ) { |
|
| 1445 | + |
|
| 1446 | + $class = ""; |
|
| 1447 | + $element_require = ""; |
|
| 1448 | + $custom_attributes = ""; |
|
| 1449 | + |
|
| 1450 | + // get value |
|
| 1451 | + if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 1452 | + $value = $instance[ $args['name'] ]; |
|
| 1453 | + } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 1454 | + $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 1455 | + } else { |
|
| 1456 | + $value = ''; |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + // get placeholder |
|
| 1460 | + if ( ! empty( $args['placeholder'] ) ) { |
|
| 1461 | + $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 1462 | + } else { |
|
| 1463 | + $placeholder = ''; |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + // get if advanced |
|
| 1467 | + if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 1468 | + $class .= " sd-advanced-setting "; |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + // element_require |
|
| 1472 | + if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 1473 | + $element_require = $args['element_require']; |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + // custom_attributes |
|
| 1477 | + if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 1478 | + $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + // before wrapper |
|
| 1482 | + ?> |
|
| 1483 | 1483 | <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
| 1484 | 1484 | data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
| 1485 | 1485 | data-element_require='<?php if ( $element_require ) { |
| 1486 | - echo $this->convert_element_require( $element_require ); |
|
| 1487 | - } ?>' |
|
| 1486 | + echo $this->convert_element_require( $element_require ); |
|
| 1487 | + } ?>' |
|
| 1488 | 1488 | > |
| 1489 | 1489 | <?php |
| 1490 | 1490 | |
| 1491 | - switch ( $args['type'] ) { |
|
| 1492 | - //array('text','password','number','email','tel','url','color') |
|
| 1493 | - case "text": |
|
| 1494 | - case "password": |
|
| 1495 | - case "number": |
|
| 1496 | - case "email": |
|
| 1497 | - case "tel": |
|
| 1498 | - case "url": |
|
| 1499 | - case "color": |
|
| 1500 | - ?> |
|
| 1491 | + switch ( $args['type'] ) { |
|
| 1492 | + //array('text','password','number','email','tel','url','color') |
|
| 1493 | + case "text": |
|
| 1494 | + case "password": |
|
| 1495 | + case "number": |
|
| 1496 | + case "email": |
|
| 1497 | + case "tel": |
|
| 1498 | + case "url": |
|
| 1499 | + case "color": |
|
| 1500 | + ?> |
|
| 1501 | 1501 | <label |
| 1502 | 1502 | 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> |
| 1503 | 1503 | <input <?php echo $placeholder; ?> class="widefat" |
@@ -1508,47 +1508,47 @@ discard block |
||
| 1508 | 1508 | value="<?php echo esc_attr( $value ); ?>"> |
| 1509 | 1509 | <?php |
| 1510 | 1510 | |
| 1511 | - break; |
|
| 1512 | - case "select": |
|
| 1513 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 1514 | - if ( $multiple ) { |
|
| 1515 | - if ( empty( $value ) ) { |
|
| 1516 | - $value = array(); |
|
| 1517 | - } |
|
| 1518 | - } |
|
| 1519 | - ?> |
|
| 1511 | + break; |
|
| 1512 | + case "select": |
|
| 1513 | + $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 1514 | + if ( $multiple ) { |
|
| 1515 | + if ( empty( $value ) ) { |
|
| 1516 | + $value = array(); |
|
| 1517 | + } |
|
| 1518 | + } |
|
| 1519 | + ?> |
|
| 1520 | 1520 | <label |
| 1521 | 1521 | 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> |
| 1522 | 1522 | <select <?php echo $placeholder; ?> class="widefat" |
| 1523 | 1523 | <?php echo $custom_attributes; ?> |
| 1524 | 1524 | id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 1525 | 1525 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
| 1526 | - if ( $multiple ) { |
|
| 1527 | - echo "[]"; |
|
| 1528 | - } ?>" |
|
| 1526 | + if ( $multiple ) { |
|
| 1527 | + echo "[]"; |
|
| 1528 | + } ?>" |
|
| 1529 | 1529 | <?php if ( $multiple ) { |
| 1530 | - echo "multiple"; |
|
| 1531 | - } //@todo not implemented yet due to gutenberg not supporting it |
|
| 1532 | - ?> |
|
| 1530 | + echo "multiple"; |
|
| 1531 | + } //@todo not implemented yet due to gutenberg not supporting it |
|
| 1532 | + ?> |
|
| 1533 | 1533 | > |
| 1534 | 1534 | <?php |
| 1535 | 1535 | |
| 1536 | - if ( ! empty( $args['options'] ) ) { |
|
| 1537 | - foreach ( $args['options'] as $val => $label ) { |
|
| 1538 | - if ( $multiple ) { |
|
| 1539 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 1540 | - } else { |
|
| 1541 | - $selected = selected( $value, $val, false ); |
|
| 1542 | - } |
|
| 1543 | - echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 1546 | - ?> |
|
| 1536 | + if ( ! empty( $args['options'] ) ) { |
|
| 1537 | + foreach ( $args['options'] as $val => $label ) { |
|
| 1538 | + if ( $multiple ) { |
|
| 1539 | + $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 1540 | + } else { |
|
| 1541 | + $selected = selected( $value, $val, false ); |
|
| 1542 | + } |
|
| 1543 | + echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 1544 | + } |
|
| 1545 | + } |
|
| 1546 | + ?> |
|
| 1547 | 1547 | </select> |
| 1548 | 1548 | <?php |
| 1549 | - break; |
|
| 1550 | - case "checkbox": |
|
| 1551 | - ?> |
|
| 1549 | + break; |
|
| 1550 | + case "checkbox": |
|
| 1551 | + ?> |
|
| 1552 | 1552 | <input <?php echo $placeholder; ?> |
| 1553 | 1553 | <?php checked( 1, $value, true ) ?> |
| 1554 | 1554 | <?php echo $custom_attributes; ?> |
@@ -1558,136 +1558,136 @@ discard block |
||
| 1558 | 1558 | <label |
| 1559 | 1559 | 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> |
| 1560 | 1560 | <?php |
| 1561 | - break; |
|
| 1562 | - case "hidden": |
|
| 1563 | - ?> |
|
| 1561 | + break; |
|
| 1562 | + case "hidden": |
|
| 1563 | + ?> |
|
| 1564 | 1564 | <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 1565 | 1565 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
| 1566 | 1566 | value="<?php echo esc_attr( $value ); ?>"> |
| 1567 | 1567 | <?php |
| 1568 | - break; |
|
| 1569 | - default: |
|
| 1570 | - echo "No input type found!"; // @todo we need to add more input types. |
|
| 1571 | - } |
|
| 1568 | + break; |
|
| 1569 | + default: |
|
| 1570 | + echo "No input type found!"; // @todo we need to add more input types. |
|
| 1571 | + } |
|
| 1572 | 1572 | |
| 1573 | - // after wrapper |
|
| 1574 | - ?> |
|
| 1573 | + // after wrapper |
|
| 1574 | + ?> |
|
| 1575 | 1575 | </p> |
| 1576 | 1576 | <?php |
| 1577 | 1577 | |
| 1578 | - } |
|
| 1579 | - |
|
| 1580 | - /** |
|
| 1581 | - * Get the widget input description html. |
|
| 1582 | - * |
|
| 1583 | - * @param $args |
|
| 1584 | - * |
|
| 1585 | - * @return string |
|
| 1586 | - * @todo, need to make its own tooltip script |
|
| 1587 | - */ |
|
| 1588 | - public function widget_field_desc( $args ) { |
|
| 1589 | - |
|
| 1590 | - $description = ''; |
|
| 1591 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 1592 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 1593 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 1594 | - } else { |
|
| 1595 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 1596 | - } |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - return $description; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - /** |
|
| 1603 | - * Get the tool tip html. |
|
| 1604 | - * |
|
| 1605 | - * @param $tip |
|
| 1606 | - * @param bool $allow_html |
|
| 1607 | - * |
|
| 1608 | - * @return string |
|
| 1609 | - */ |
|
| 1610 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 1611 | - if ( $allow_html ) { |
|
| 1612 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 1613 | - } else { |
|
| 1614 | - $tip = esc_attr( $tip ); |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - /** |
|
| 1621 | - * Sanitize a string destined to be a tooltip. |
|
| 1622 | - * |
|
| 1623 | - * @param string $var |
|
| 1624 | - * |
|
| 1625 | - * @return string |
|
| 1626 | - */ |
|
| 1627 | - public function sanitize_tooltip( $var ) { |
|
| 1628 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 1629 | - 'br' => array(), |
|
| 1630 | - 'em' => array(), |
|
| 1631 | - 'strong' => array(), |
|
| 1632 | - 'small' => array(), |
|
| 1633 | - 'span' => array(), |
|
| 1634 | - 'ul' => array(), |
|
| 1635 | - 'li' => array(), |
|
| 1636 | - 'ol' => array(), |
|
| 1637 | - 'p' => array(), |
|
| 1638 | - ) ) ); |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - /** |
|
| 1642 | - * Processing widget options on save |
|
| 1643 | - * |
|
| 1644 | - * @param array $new_instance The new options |
|
| 1645 | - * @param array $old_instance The previous options |
|
| 1646 | - * |
|
| 1647 | - * @return array |
|
| 1648 | - * @todo we should add some sanitation here. |
|
| 1649 | - */ |
|
| 1650 | - public function update( $new_instance, $old_instance ) { |
|
| 1651 | - |
|
| 1652 | - //save the widget |
|
| 1653 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 1654 | - |
|
| 1655 | - // set widget instance |
|
| 1656 | - $this->instance = $instance; |
|
| 1657 | - |
|
| 1658 | - if ( empty( $this->arguments ) ) { |
|
| 1659 | - $this->get_arguments(); |
|
| 1660 | - } |
|
| 1661 | - |
|
| 1662 | - // check for checkboxes |
|
| 1663 | - if ( ! empty( $this->arguments ) ) { |
|
| 1664 | - foreach ( $this->arguments as $argument ) { |
|
| 1665 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 1666 | - $instance[ $argument['name'] ] = '0'; |
|
| 1667 | - } |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - |
|
| 1671 | - return $instance; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - /** |
|
| 1675 | - * Checks if the current call is a ajax call to get the block content. |
|
| 1676 | - * |
|
| 1677 | - * This can be used in your widget to return different content as the block content. |
|
| 1678 | - * |
|
| 1679 | - * @since 1.0.3 |
|
| 1680 | - * @return bool |
|
| 1681 | - */ |
|
| 1682 | - public function is_block_content_call() { |
|
| 1683 | - $result = false; |
|
| 1684 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 1685 | - $result = true; |
|
| 1686 | - } |
|
| 1687 | - |
|
| 1688 | - return $result; |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - } |
|
| 1578 | + } |
|
| 1579 | + |
|
| 1580 | + /** |
|
| 1581 | + * Get the widget input description html. |
|
| 1582 | + * |
|
| 1583 | + * @param $args |
|
| 1584 | + * |
|
| 1585 | + * @return string |
|
| 1586 | + * @todo, need to make its own tooltip script |
|
| 1587 | + */ |
|
| 1588 | + public function widget_field_desc( $args ) { |
|
| 1589 | + |
|
| 1590 | + $description = ''; |
|
| 1591 | + if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 1592 | + if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 1593 | + $description = $this->desc_tip( $args['desc'] ); |
|
| 1594 | + } else { |
|
| 1595 | + $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 1596 | + } |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + return $description; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + /** |
|
| 1603 | + * Get the tool tip html. |
|
| 1604 | + * |
|
| 1605 | + * @param $tip |
|
| 1606 | + * @param bool $allow_html |
|
| 1607 | + * |
|
| 1608 | + * @return string |
|
| 1609 | + */ |
|
| 1610 | + function desc_tip( $tip, $allow_html = false ) { |
|
| 1611 | + if ( $allow_html ) { |
|
| 1612 | + $tip = $this->sanitize_tooltip( $tip ); |
|
| 1613 | + } else { |
|
| 1614 | + $tip = esc_attr( $tip ); |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + /** |
|
| 1621 | + * Sanitize a string destined to be a tooltip. |
|
| 1622 | + * |
|
| 1623 | + * @param string $var |
|
| 1624 | + * |
|
| 1625 | + * @return string |
|
| 1626 | + */ |
|
| 1627 | + public function sanitize_tooltip( $var ) { |
|
| 1628 | + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 1629 | + 'br' => array(), |
|
| 1630 | + 'em' => array(), |
|
| 1631 | + 'strong' => array(), |
|
| 1632 | + 'small' => array(), |
|
| 1633 | + 'span' => array(), |
|
| 1634 | + 'ul' => array(), |
|
| 1635 | + 'li' => array(), |
|
| 1636 | + 'ol' => array(), |
|
| 1637 | + 'p' => array(), |
|
| 1638 | + ) ) ); |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + /** |
|
| 1642 | + * Processing widget options on save |
|
| 1643 | + * |
|
| 1644 | + * @param array $new_instance The new options |
|
| 1645 | + * @param array $old_instance The previous options |
|
| 1646 | + * |
|
| 1647 | + * @return array |
|
| 1648 | + * @todo we should add some sanitation here. |
|
| 1649 | + */ |
|
| 1650 | + public function update( $new_instance, $old_instance ) { |
|
| 1651 | + |
|
| 1652 | + //save the widget |
|
| 1653 | + $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 1654 | + |
|
| 1655 | + // set widget instance |
|
| 1656 | + $this->instance = $instance; |
|
| 1657 | + |
|
| 1658 | + if ( empty( $this->arguments ) ) { |
|
| 1659 | + $this->get_arguments(); |
|
| 1660 | + } |
|
| 1661 | + |
|
| 1662 | + // check for checkboxes |
|
| 1663 | + if ( ! empty( $this->arguments ) ) { |
|
| 1664 | + foreach ( $this->arguments as $argument ) { |
|
| 1665 | + if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 1666 | + $instance[ $argument['name'] ] = '0'; |
|
| 1667 | + } |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + |
|
| 1671 | + return $instance; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + /** |
|
| 1675 | + * Checks if the current call is a ajax call to get the block content. |
|
| 1676 | + * |
|
| 1677 | + * This can be used in your widget to return different content as the block content. |
|
| 1678 | + * |
|
| 1679 | + * @since 1.0.3 |
|
| 1680 | + * @return bool |
|
| 1681 | + */ |
|
| 1682 | + public function is_block_content_call() { |
|
| 1683 | + $result = false; |
|
| 1684 | + if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 1685 | + $result = true; |
|
| 1686 | + } |
|
| 1687 | + |
|
| 1688 | + return $result; |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + } |
|
| 1692 | 1692 | |
| 1693 | 1693 | } |
| 1694 | 1694 | \ 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 | /** |
@@ -33,26 +33,26 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * Take the array options and use them to build. |
| 35 | 35 | */ |
| 36 | - public function __construct( $options ) { |
|
| 36 | + public function __construct($options) { |
|
| 37 | 37 | global $sd_widgets; |
| 38 | 38 | |
| 39 | - $sd_widgets[ $options['base_id'] ] = array( 'name' => $options['name'], |
|
| 39 | + $sd_widgets[$options['base_id']] = array('name' => $options['name'], |
|
| 40 | 40 | 'class_name' => $options['class_name'] |
| 41 | 41 | ); |
| 42 | 42 | $this->base_id = $options['base_id']; |
| 43 | 43 | // lets filter the options before we do anything |
| 44 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 45 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 46 | - $options = $this->add_name_from_key( $options ); |
|
| 44 | + $options = apply_filters("wp_super_duper_options", $options); |
|
| 45 | + $options = apply_filters("wp_super_duper_options_{$this->base_id}", $options); |
|
| 46 | + $options = $this->add_name_from_key($options); |
|
| 47 | 47 | $this->options = $options; |
| 48 | 48 | |
| 49 | 49 | $this->base_id = $options['base_id']; |
| 50 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 50 | + $this->arguments = isset($options['arguments']) ? $options['arguments'] : array(); |
|
| 51 | 51 | |
| 52 | 52 | // init parent |
| 53 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 53 | + parent::__construct($options['base_id'], $options['name'], $options['widget_ops']); |
|
| 54 | 54 | |
| 55 | - if ( isset( $options['class_name'] ) ) { |
|
| 55 | + if (isset($options['class_name'])) { |
|
| 56 | 56 | // register widget |
| 57 | 57 | $this->class_name = $options['class_name']; |
| 58 | 58 | |
@@ -60,25 +60,25 @@ discard block |
||
| 60 | 60 | $this->register_shortcode(); |
| 61 | 61 | |
| 62 | 62 | // register block |
| 63 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 63 | + add_action('admin_enqueue_scripts', array($this, 'register_block')); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // add the CSS and JS we need ONCE |
| 67 | 67 | global $sd_widget_scripts; |
| 68 | 68 | |
| 69 | - if ( ! $sd_widget_scripts ) { |
|
| 70 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 71 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 72 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 69 | + if (!$sd_widget_scripts) { |
|
| 70 | + wp_add_inline_script('admin-widgets', $this->widget_js()); |
|
| 71 | + wp_add_inline_script('customize-controls', $this->widget_js()); |
|
| 72 | + wp_add_inline_style('widgets', $this->widget_css()); |
|
| 73 | 73 | |
| 74 | 74 | $sd_widget_scripts = true; |
| 75 | 75 | |
| 76 | 76 | // add shortcode insert button once |
| 77 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 78 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 77 | + add_action('media_buttons', array($this, 'shortcode_insert_button')); |
|
| 78 | + add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings')); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 81 | + do_action('wp_super_duper_widget_init', $options, $this); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | public static function get_widget_settings() { |
| 90 | 90 | global $sd_widgets; |
| 91 | 91 | |
| 92 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 93 | - if ( ! $shortcode ) { |
|
| 92 | + $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : ''; |
|
| 93 | + if (!$shortcode) { |
|
| 94 | 94 | wp_die(); |
| 95 | 95 | } |
| 96 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 97 | - if ( ! $widget_args ) { |
|
| 96 | + $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : ''; |
|
| 97 | + if (!$widget_args) { |
|
| 98 | 98 | wp_die(); |
| 99 | 99 | } |
| 100 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 101 | - if ( ! $class_name ) { |
|
| 100 | + $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 101 | + if (!$class_name) { |
|
| 102 | 102 | wp_die(); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $widget = new $class_name; |
| 107 | 107 | |
| 108 | 108 | ob_start(); |
| 109 | - $widget->form( array() ); |
|
| 109 | + $widget->form(array()); |
|
| 110 | 110 | $form = ob_get_clean(); |
| 111 | 111 | echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
| 112 | 112 | echo "<style>" . $widget->widget_css() . "</style>"; |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | * @param string $editor_id Optional. Shortcode editor id. Default null. |
| 125 | 125 | * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
| 126 | 126 | */ |
| 127 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 127 | + public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') { |
|
| 128 | 128 | global $sd_widgets, $shortcode_insert_button_once; |
| 129 | - if ( $shortcode_insert_button_once ) { |
|
| 129 | + if ($shortcode_insert_button_once) { |
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | add_thickbox(); |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | <div class="sd-shortcode-left-wrap"> |
| 137 | 137 | <?php |
| 138 | - asort( $sd_widgets ); |
|
| 139 | - if ( ! empty( $sd_widgets ) ) { |
|
| 138 | + asort($sd_widgets); |
|
| 139 | + if (!empty($sd_widgets)) { |
|
| 140 | 140 | echo '<select onchange="sd_get_shortcode_options(this);">'; |
| 141 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 142 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 143 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 141 | + echo "<option>" . __('Select shortcode') . "</option>"; |
|
| 142 | + foreach ($sd_widgets as $shortcode => $class) { |
|
| 143 | + echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>"; |
|
| 144 | 144 | } |
| 145 | 145 | echo "</select>"; |
| 146 | 146 | |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | <textarea id='sd-shortcode-output' disabled></textarea> |
| 155 | 155 | <div id='sd-shortcode-output-actions'> |
| 156 | 156 | <button class="button" |
| 157 | - onclick="sd_insert_shortcode()"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 157 | + onclick="sd_insert_shortcode()"><?php _e('Insert shortcode'); ?></button> |
|
| 158 | 158 | <button class="button" |
| 159 | - onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
|
| 159 | + onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button> |
|
| 160 | 160 | </div> |
| 161 | 161 | </div> |
| 162 | 162 | |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | <?php |
| 166 | 166 | // if Font Awesome is available then show a icon if not show a WP icon. |
| 167 | - $button_string = wp_style_is( 'font-awesome', 'enqueued' ) && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>'; |
|
| 167 | + $button_string = wp_style_is('font-awesome', 'enqueued') && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>'; |
|
| 168 | 168 | ?> |
| 169 | 169 | |
| 170 | 170 | <a href="#TB_inline?width=100%&height=550&inlineId=super-duper-content" |
| 171 | 171 | class="thickbox button super-duper-content-open" |
| 172 | - title="<?php _e( 'Add Shortcode' ); ?>"><?php echo $button_string; ?></a> |
|
| 172 | + title="<?php _e('Add Shortcode'); ?>"><?php echo $button_string; ?></a> |
|
| 173 | 173 | |
| 174 | 174 | <style> |
| 175 | 175 | .sd-shortcode-left-wrap { |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | <script> |
| 195 | 195 | |
| 196 | 196 | <?php |
| 197 | - if(! empty( $insert_shortcode_function )){ |
|
| 197 | + if (!empty($insert_shortcode_function)) { |
|
| 198 | 198 | echo $insert_shortcode_function; |
| 199 | - }else{ |
|
| 199 | + } else { |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * Function for super duper insert shortcode. |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | 'shortcode': $short_code, |
| 247 | 247 | 'attributes': 123, |
| 248 | 248 | 'post_id': 321, |
| 249 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 249 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 250 | 250 | }; |
| 251 | 251 | |
| 252 | 252 | jQuery.post(ajaxurl, data, function (response) { |
@@ -364,10 +364,10 @@ discard block |
||
| 364 | 364 | /* |
| 365 | 365 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 366 | 366 | */ |
| 367 | - return str_replace( array( |
|
| 367 | + return str_replace(array( |
|
| 368 | 368 | '<style>', |
| 369 | 369 | '</style>' |
| 370 | - ), '', $output ); |
|
| 370 | + ), '', $output); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | public function widget_js() { |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | }); |
| 525 | 525 | |
| 526 | 526 | } |
| 527 | - <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 527 | + <?php do_action('wp_super_duper_widget_js', $this); ?> |
|
| 528 | 528 | </script> |
| 529 | 529 | <?php |
| 530 | 530 | $output = ob_get_clean(); |
@@ -532,10 +532,10 @@ discard block |
||
| 532 | 532 | /* |
| 533 | 533 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 534 | 534 | */ |
| 535 | - return str_replace( array( |
|
| 535 | + return str_replace(array( |
|
| 536 | 536 | '<script>', |
| 537 | 537 | '</script>' |
| 538 | - ), '', $output ); |
|
| 538 | + ), '', $output); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | * |
| 547 | 547 | * @return mixed |
| 548 | 548 | */ |
| 549 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 550 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 551 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 552 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 549 | + private function add_name_from_key($options, $arguments = false) { |
|
| 550 | + if (!empty($options['arguments'])) { |
|
| 551 | + foreach ($options['arguments'] as $key => $val) { |
|
| 552 | + $options['arguments'][$key]['name'] = $key; |
|
| 553 | 553 | } |
| 554 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 555 | - foreach ( $options as $key => $val ) { |
|
| 556 | - $options[ $key ]['name'] = $key; |
|
| 554 | + } elseif ($arguments && is_array($options) && !empty($options)) { |
|
| 555 | + foreach ($options as $key => $val) { |
|
| 556 | + $options[$key]['name'] = $key; |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | |
@@ -566,8 +566,8 @@ discard block |
||
| 566 | 566 | * @since 1.0.0 |
| 567 | 567 | */ |
| 568 | 568 | public function register_shortcode() { |
| 569 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 570 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 569 | + add_shortcode($this->base_id, array($this, 'shortcode_output')); |
|
| 570 | + add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode')); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -577,33 +577,33 @@ discard block |
||
| 577 | 577 | */ |
| 578 | 578 | public static function render_shortcode() { |
| 579 | 579 | |
| 580 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 581 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 580 | + check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true); |
|
| 581 | + if (!current_user_can('manage_options')) { |
|
| 582 | 582 | wp_die(); |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | // we might need the $post value here so lets set it. |
| 586 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 587 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 588 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 586 | + if (isset($_POST['post_id']) && $_POST['post_id']) { |
|
| 587 | + $post_obj = get_post(absint($_POST['post_id'])); |
|
| 588 | + if (!empty($post_obj) && empty($post)) { |
|
| 589 | 589 | global $post; |
| 590 | 590 | $post = $post_obj; |
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 595 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 596 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 594 | + if (isset($_POST['shortcode']) && $_POST['shortcode']) { |
|
| 595 | + $shortcode_name = sanitize_title_with_dashes($_POST['shortcode']); |
|
| 596 | + $attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 597 | 597 | $attributes = ''; |
| 598 | - if ( ! empty( $attributes_array ) ) { |
|
| 599 | - foreach ( $attributes_array as $key => $value ) { |
|
| 600 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 598 | + if (!empty($attributes_array)) { |
|
| 599 | + foreach ($attributes_array as $key => $value) { |
|
| 600 | + $attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' "; |
|
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
| 605 | 605 | |
| 606 | - echo do_shortcode( $shortcode ); |
|
| 606 | + echo do_shortcode($shortcode); |
|
| 607 | 607 | |
| 608 | 608 | } |
| 609 | 609 | wp_die(); |
@@ -617,37 +617,37 @@ discard block |
||
| 617 | 617 | * |
| 618 | 618 | * @return string |
| 619 | 619 | */ |
| 620 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 621 | - $args = self::argument_values( $args ); |
|
| 620 | + public function shortcode_output($args = array(), $content = '') { |
|
| 621 | + $args = self::argument_values($args); |
|
| 622 | 622 | |
| 623 | 623 | // add extra argument so we know its a output to gutenberg |
| 624 | 624 | //$args |
| 625 | - $args = $this->string_to_bool( $args ); |
|
| 625 | + $args = $this->string_to_bool($args); |
|
| 626 | 626 | |
| 627 | 627 | |
| 628 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 628 | + $calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : ''; |
|
| 629 | 629 | |
| 630 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 631 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 630 | + $calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this); |
|
| 631 | + $calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this); |
|
| 632 | 632 | |
| 633 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 634 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 633 | + $attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this); |
|
| 634 | + $attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this); |
|
| 635 | 635 | |
| 636 | 636 | $shortcode_args = array(); |
| 637 | 637 | $output = ''; |
| 638 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 639 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 640 | - if ( $main_content && ! $no_wrap ) { |
|
| 638 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
| 639 | + $main_content = $this->output($args, $shortcode_args, $content); |
|
| 640 | + if ($main_content && !$no_wrap) { |
|
| 641 | 641 | // wrap the shortcode in a dive with the same class as the widget |
| 642 | 642 | $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
| 643 | - if ( ! empty( $args['title'] ) ) { |
|
| 643 | + if (!empty($args['title'])) { |
|
| 644 | 644 | // if its a shortcode and there is a title try to grab the title wrappers |
| 645 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 646 | - if ( empty( $instance ) ) { |
|
| 645 | + $shortcode_args = array('before_title' => '', 'after_title' => ''); |
|
| 646 | + if (empty($instance)) { |
|
| 647 | 647 | global $wp_registered_sidebars; |
| 648 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 649 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 650 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 648 | + if (!empty($wp_registered_sidebars)) { |
|
| 649 | + foreach ($wp_registered_sidebars as $sidebar) { |
|
| 650 | + if (!empty($sidebar['before_title'])) { |
|
| 651 | 651 | $shortcode_args['before_title'] = $sidebar['before_title']; |
| 652 | 652 | $shortcode_args['after_title'] = $sidebar['after_title']; |
| 653 | 653 | break; |
@@ -655,11 +655,11 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | } |
| 658 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 658 | + $output .= $this->output_title($shortcode_args, $args); |
|
| 659 | 659 | } |
| 660 | 660 | $output .= $main_content; |
| 661 | 661 | $output .= '</div>'; |
| 662 | - } elseif ( $main_content && $no_wrap ) { |
|
| 662 | + } elseif ($main_content && $no_wrap) { |
|
| 663 | 663 | $output .= $main_content; |
| 664 | 664 | } |
| 665 | 665 | |
@@ -673,13 +673,13 @@ discard block |
||
| 673 | 673 | * |
| 674 | 674 | * @return mixed |
| 675 | 675 | */ |
| 676 | - public function string_to_bool( $options ) { |
|
| 676 | + public function string_to_bool($options) { |
|
| 677 | 677 | // convert bool strings to booleans |
| 678 | - foreach ( $options as $key => $val ) { |
|
| 679 | - if ( $val == 'false' ) { |
|
| 680 | - $options[ $key ] = false; |
|
| 681 | - } elseif ( $val == 'true' ) { |
|
| 682 | - $options[ $key ] = true; |
|
| 678 | + foreach ($options as $key => $val) { |
|
| 679 | + if ($val == 'false') { |
|
| 680 | + $options[$key] = false; |
|
| 681 | + } elseif ($val == 'true') { |
|
| 682 | + $options[$key] = true; |
|
| 683 | 683 | } |
| 684 | 684 | } |
| 685 | 685 | |
@@ -693,24 +693,24 @@ discard block |
||
| 693 | 693 | * |
| 694 | 694 | * @return array |
| 695 | 695 | */ |
| 696 | - public function argument_values( $instance ) { |
|
| 696 | + public function argument_values($instance) { |
|
| 697 | 697 | $argument_values = array(); |
| 698 | 698 | |
| 699 | 699 | // set widget instance |
| 700 | 700 | $this->instance = $instance; |
| 701 | 701 | |
| 702 | - if ( empty( $this->arguments ) ) { |
|
| 702 | + if (empty($this->arguments)) { |
|
| 703 | 703 | $this->arguments = $this->get_arguments(); |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - if ( ! empty( $this->arguments ) ) { |
|
| 707 | - foreach ( $this->arguments as $key => $args ) { |
|
| 706 | + if (!empty($this->arguments)) { |
|
| 707 | + foreach ($this->arguments as $key => $args) { |
|
| 708 | 708 | // set the input name from the key |
| 709 | 709 | $args['name'] = $key; |
| 710 | 710 | // |
| 711 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 712 | - if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 713 | - $argument_values[ $key ] = $args['default']; |
|
| 711 | + $argument_values[$key] = isset($instance[$key]) ? $instance[$key] : ''; |
|
| 712 | + if ($argument_values[$key] == '' && isset($args['default'])) { |
|
| 713 | + $argument_values[$key] = $args['default']; |
|
| 714 | 714 | } |
| 715 | 715 | } |
| 716 | 716 | } |
@@ -737,12 +737,12 @@ discard block |
||
| 737 | 737 | * @return array Get arguments. |
| 738 | 738 | */ |
| 739 | 739 | public function get_arguments() { |
| 740 | - if ( empty( $this->arguments ) ) { |
|
| 740 | + if (empty($this->arguments)) { |
|
| 741 | 741 | $this->arguments = $this->set_arguments(); |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 745 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 744 | + $this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance); |
|
| 745 | + $this->arguments = $this->add_name_from_key($this->arguments, true); |
|
| 746 | 746 | |
| 747 | 747 | return $this->arguments; |
| 748 | 748 | } |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | * @param array $widget_args |
| 755 | 755 | * @param string $content |
| 756 | 756 | */ |
| 757 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 757 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 758 | 758 | |
| 759 | 759 | } |
| 760 | 760 | |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | * Add the dynamic block code inline when the wp-block in enqueued. |
| 763 | 763 | */ |
| 764 | 764 | public function register_block() { |
| 765 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 765 | + wp_add_inline_script('wp-blocks', $this->block()); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | /** |
@@ -775,13 +775,13 @@ discard block |
||
| 775 | 775 | $show = false; |
| 776 | 776 | $arguments = $this->arguments; |
| 777 | 777 | |
| 778 | - if ( empty( $arguments ) ) { |
|
| 778 | + if (empty($arguments)) { |
|
| 779 | 779 | $arguments = $this->get_arguments(); |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - if ( ! empty( $arguments ) ) { |
|
| 783 | - foreach ( $arguments as $argument ) { |
|
| 784 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 782 | + if (!empty($arguments)) { |
|
| 783 | + foreach ($arguments as $argument) { |
|
| 784 | + if (isset($argument['advanced']) && $argument['advanced']) { |
|
| 785 | 785 | $show = true; |
| 786 | 786 | } |
| 787 | 787 | } |
@@ -832,12 +832,12 @@ discard block |
||
| 832 | 832 | * @return {?WPBlock} The block, if it has been successfully |
| 833 | 833 | * registered; otherwise `undefined`. |
| 834 | 834 | */ |
| 835 | - 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. |
|
| 836 | - title: '<?php echo $this->options['name'];?>', // Block title. |
|
| 837 | - description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title. |
|
| 838 | - 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/. |
|
| 839 | - 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. |
|
| 840 | - <?php if ( isset( $this->options['block-keywords'] ) ) { |
|
| 835 | + 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. |
|
| 836 | + title: '<?php echo $this->options['name']; ?>', // Block title. |
|
| 837 | + description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title. |
|
| 838 | + 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/. |
|
| 839 | + 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. |
|
| 840 | + <?php if (isset($this->options['block-keywords'])) { |
|
| 841 | 841 | echo "keywords : " . $this->options['block-keywords'] . ","; |
| 842 | 842 | }?> |
| 843 | 843 | |
@@ -847,10 +847,10 @@ discard block |
||
| 847 | 847 | |
| 848 | 848 | $show_alignment = false; |
| 849 | 849 | |
| 850 | - if ( ! empty( $this->arguments ) ) { |
|
| 850 | + if (!empty($this->arguments)) { |
|
| 851 | 851 | echo "attributes : {"; |
| 852 | 852 | |
| 853 | - if ( $show_advanced ) { |
|
| 853 | + if ($show_advanced) { |
|
| 854 | 854 | echo "show_advanced: {"; |
| 855 | 855 | echo " type: 'boolean',"; |
| 856 | 856 | echo " default: false,"; |
@@ -858,42 +858,42 @@ discard block |
||
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | // block wrap element |
| 861 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 861 | + if (isset($this->options['block-wrap'])) { //@todo we should validate this? |
|
| 862 | 862 | echo "block_wrap: {"; |
| 863 | 863 | echo " type: 'string',"; |
| 864 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 864 | + echo " default: '" . esc_attr($this->options['block-wrap']) . "',"; |
|
| 865 | 865 | echo "},"; |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | |
| 869 | - foreach ( $this->arguments as $key => $args ) { |
|
| 869 | + foreach ($this->arguments as $key => $args) { |
|
| 870 | 870 | |
| 871 | 871 | // set if we should show alignment |
| 872 | - if ( $key == 'alignment' ) { |
|
| 872 | + if ($key == 'alignment') { |
|
| 873 | 873 | $show_alignment = true; |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | $extra = ''; |
| 877 | 877 | |
| 878 | - if ( $args['type'] == 'checkbox' ) { |
|
| 878 | + if ($args['type'] == 'checkbox') { |
|
| 879 | 879 | $type = 'boolean'; |
| 880 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 881 | - } elseif ( $args['type'] == 'number' ) { |
|
| 880 | + $default = isset($args['default']) && $args['default'] ? 'true' : 'false'; |
|
| 881 | + } elseif ($args['type'] == 'number') { |
|
| 882 | 882 | $type = 'number'; |
| 883 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 884 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 883 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 884 | + } elseif ($args['type'] == 'select' && !empty($args['multiple'])) { |
|
| 885 | 885 | $type = 'array'; |
| 886 | - if ( is_array( $args['default'] ) ) { |
|
| 887 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 886 | + if (is_array($args['default'])) { |
|
| 887 | + $default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]"; |
|
| 888 | 888 | } else { |
| 889 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 889 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 890 | 890 | } |
| 891 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 891 | + } elseif ($args['type'] == 'multiselect') { |
|
| 892 | 892 | $type = 'array'; |
| 893 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 893 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 894 | 894 | } else { |
| 895 | 895 | $type = 'string'; |
| 896 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 896 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 897 | 897 | } |
| 898 | 898 | echo $key . " : {"; |
| 899 | 899 | echo "type : '$type',"; |
@@ -923,12 +923,12 @@ discard block |
||
| 923 | 923 | is_fetching = true; |
| 924 | 924 | var data = { |
| 925 | 925 | 'action': 'super_duper_output_shortcode', |
| 926 | - 'shortcode': '<?php echo $this->options['base_id'];?>', |
|
| 926 | + 'shortcode': '<?php echo $this->options['base_id']; ?>', |
|
| 927 | 927 | 'attributes': props.attributes, |
| 928 | - 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
|
| 928 | + 'post_id': <?php global $post; if (isset($post->ID)) { |
|
| 929 | 929 | echo $post->ID; |
| 930 | 930 | }?>, |
| 931 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 931 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 932 | 932 | }; |
| 933 | 933 | |
| 934 | 934 | jQuery.post(ajaxurl, data, function (response) { |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | |
| 938 | 938 | // if the content is empty then we place some placeholder text |
| 939 | 939 | if (env == '') { |
| 940 | - env = "<div style='background:#0185ba33;padding: 10px;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>"; |
|
| 940 | + env = "<div style='background:#0185ba33;padding: 10px;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>"; |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | props.setAttributes({content: env}); |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | |
| 957 | 957 | el(wp.editor.BlockControls, {key: 'controls'}, |
| 958 | 958 | |
| 959 | - <?php if($show_alignment){?> |
|
| 959 | + <?php if ($show_alignment) {?> |
|
| 960 | 960 | el( |
| 961 | 961 | wp.editor.AlignmentToolbar, |
| 962 | 962 | { |
@@ -974,9 +974,9 @@ discard block |
||
| 974 | 974 | |
| 975 | 975 | <?php |
| 976 | 976 | |
| 977 | - if(! empty( $this->arguments )){ |
|
| 977 | + if (!empty($this->arguments)) { |
|
| 978 | 978 | |
| 979 | - if ( $show_advanced ) { |
|
| 979 | + if ($show_advanced) { |
|
| 980 | 980 | ?> |
| 981 | 981 | el( |
| 982 | 982 | wp.components.ToggleControl, |
@@ -992,68 +992,68 @@ discard block |
||
| 992 | 992 | |
| 993 | 993 | } |
| 994 | 994 | |
| 995 | - foreach($this->arguments as $key => $args){ |
|
| 996 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 995 | + foreach ($this->arguments as $key => $args) { |
|
| 996 | + $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : ''; |
|
| 997 | 997 | $options = ''; |
| 998 | 998 | $extra = ''; |
| 999 | 999 | $require = ''; |
| 1000 | 1000 | $onchange = "props.setAttributes({ $key: $key } )"; |
| 1001 | 1001 | $value = "props.attributes.$key"; |
| 1002 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1003 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 1002 | + $text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color'); |
|
| 1003 | + if (in_array($args['type'], $text_type)) { |
|
| 1004 | 1004 | $type = 'TextControl'; |
| 1005 | - } elseif ( $args['type'] == 'checkbox' ) { |
|
| 1005 | + } elseif ($args['type'] == 'checkbox') { |
|
| 1006 | 1006 | $type = 'CheckboxControl'; |
| 1007 | 1007 | $extra .= "checked: props.attributes.$key,"; |
| 1008 | 1008 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
| 1009 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1009 | + } elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') { |
|
| 1010 | 1010 | $type = 'SelectControl'; |
| 1011 | - if ( ! empty( $args['options'] ) ) { |
|
| 1011 | + if (!empty($args['options'])) { |
|
| 1012 | 1012 | $options .= "options : ["; |
| 1013 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1014 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1013 | + foreach ($args['options'] as $option_val => $option_label) { |
|
| 1014 | + $options .= "{ value : '" . esc_attr($option_val) . "', label : '" . esc_attr($option_label) . "' },"; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | $options .= "],"; |
| 1017 | 1017 | } |
| 1018 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1018 | + if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1019 | 1019 | $extra .= ' multiple: true, '; |
| 1020 | 1020 | //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
| 1021 | 1021 | //$value = "['edit', 'delete']"; |
| 1022 | 1022 | } |
| 1023 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 1023 | + } elseif ($args['type'] == 'alignment') { |
|
| 1024 | 1024 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
| 1025 | 1025 | } else { |
| 1026 | - continue;// if we have not implemented the control then don't break the JS. |
|
| 1026 | + continue; // if we have not implemented the control then don't break the JS. |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | // add show only if advanced |
| 1030 | - if ( ! empty( $args['advanced'] ) ) { |
|
| 1030 | + if (!empty($args['advanced'])) { |
|
| 1031 | 1031 | echo "props.attributes.show_advanced && "; |
| 1032 | 1032 | } |
| 1033 | 1033 | // add setting require if defined |
| 1034 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 1035 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1034 | + if (!empty($args['element_require'])) { |
|
| 1035 | + echo $this->block_props_replace($args['element_require'], true) . " && "; |
|
| 1036 | 1036 | } |
| 1037 | 1037 | ?> |
| 1038 | 1038 | el( |
| 1039 | - wp.components.<?php echo esc_attr( $type );?>, |
|
| 1039 | + wp.components.<?php echo esc_attr($type); ?>, |
|
| 1040 | 1040 | { |
| 1041 | - label: '<?php echo esc_attr( $args['title'] );?>', |
|
| 1042 | - help: '<?php if ( isset( $args['desc'] ) ) { |
|
| 1043 | - echo esc_attr( $args['desc'] ); |
|
| 1041 | + label: '<?php echo esc_attr($args['title']); ?>', |
|
| 1042 | + help: '<?php if (isset($args['desc'])) { |
|
| 1043 | + echo esc_attr($args['desc']); |
|
| 1044 | 1044 | }?>', |
| 1045 | - value: <?php echo $value;?>, |
|
| 1046 | - <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
|
| 1047 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1045 | + value: <?php echo $value; ?>, |
|
| 1046 | + <?php if ($type == 'TextControl' && $args['type'] != 'text') { |
|
| 1047 | + echo "type: '" . esc_attr($args['type']) . "',"; |
|
| 1048 | 1048 | }?> |
| 1049 | - <?php if ( ! empty( $args['placeholder'] ) ) { |
|
| 1050 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1049 | + <?php if (!empty($args['placeholder'])) { |
|
| 1050 | + echo "placeholder: '" . esc_attr($args['placeholder']) . "',"; |
|
| 1051 | 1051 | }?> |
| 1052 | - <?php echo $options;?> |
|
| 1053 | - <?php echo $extra;?> |
|
| 1054 | - <?php echo $custom_attributes;?> |
|
| 1055 | - onChange: function ( <?php echo $key;?> ) { |
|
| 1056 | - <?php echo $onchange;?> |
|
| 1052 | + <?php echo $options; ?> |
|
| 1053 | + <?php echo $extra; ?> |
|
| 1054 | + <?php echo $custom_attributes; ?> |
|
| 1055 | + onChange: function ( <?php echo $key; ?> ) { |
|
| 1056 | + <?php echo $onchange; ?> |
|
| 1057 | 1057 | } |
| 1058 | 1058 | } |
| 1059 | 1059 | ), |
@@ -1066,9 +1066,9 @@ discard block |
||
| 1066 | 1066 | |
| 1067 | 1067 | <?php |
| 1068 | 1068 | // If the user sets block-output array then build it |
| 1069 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1070 | - $this->block_element( $this->options['block-output'] ); |
|
| 1071 | - }else{ |
|
| 1069 | + if (!empty($this->options['block-output'])) { |
|
| 1070 | + $this->block_element($this->options['block-output']); |
|
| 1071 | + } else { |
|
| 1072 | 1072 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1073 | 1073 | ?> |
| 1074 | 1074 | el('div', { |
@@ -1092,14 +1092,14 @@ discard block |
||
| 1092 | 1092 | var align = ''; |
| 1093 | 1093 | |
| 1094 | 1094 | // build the shortcode. |
| 1095 | - var content = "[<?php echo $this->options['base_id'];?>"; |
|
| 1095 | + var content = "[<?php echo $this->options['base_id']; ?>"; |
|
| 1096 | 1096 | <?php |
| 1097 | 1097 | |
| 1098 | - if(! empty( $this->arguments )){ |
|
| 1099 | - foreach($this->arguments as $key => $args){ |
|
| 1098 | + if (!empty($this->arguments)) { |
|
| 1099 | + foreach ($this->arguments as $key => $args) { |
|
| 1100 | 1100 | ?> |
| 1101 | - if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
|
| 1102 | - content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
|
| 1101 | + if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) { |
|
| 1102 | + content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' "; |
|
| 1103 | 1103 | } |
| 1104 | 1104 | <?php |
| 1105 | 1105 | } |
@@ -1140,10 +1140,10 @@ discard block |
||
| 1140 | 1140 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1141 | 1141 | */ |
| 1142 | 1142 | |
| 1143 | - return str_replace( array( |
|
| 1143 | + return str_replace(array( |
|
| 1144 | 1144 | '<script>', |
| 1145 | 1145 | '</script>' |
| 1146 | - ), '', $output ); |
|
| 1146 | + ), '', $output); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | /** |
@@ -1155,16 +1155,16 @@ discard block |
||
| 1155 | 1155 | * |
| 1156 | 1156 | * @return string |
| 1157 | 1157 | */ |
| 1158 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 1158 | + public function array_to_attributes($custom_attributes, $html = false) { |
|
| 1159 | 1159 | $attributes = ''; |
| 1160 | - if ( ! empty( $custom_attributes ) ) { |
|
| 1160 | + if (!empty($custom_attributes)) { |
|
| 1161 | 1161 | |
| 1162 | - if ( $html ) { |
|
| 1163 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1162 | + if ($html) { |
|
| 1163 | + foreach ($custom_attributes as $key => $val) { |
|
| 1164 | 1164 | $attributes .= " $key='$val' "; |
| 1165 | 1165 | } |
| 1166 | 1166 | } else { |
| 1167 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1167 | + foreach ($custom_attributes as $key => $val) { |
|
| 1168 | 1168 | $attributes .= "'$key': '$val',"; |
| 1169 | 1169 | } |
| 1170 | 1170 | } |
@@ -1180,86 +1180,86 @@ discard block |
||
| 1180 | 1180 | * |
| 1181 | 1181 | * @param $args |
| 1182 | 1182 | */ |
| 1183 | - public function block_element( $args ) { |
|
| 1183 | + public function block_element($args) { |
|
| 1184 | 1184 | |
| 1185 | 1185 | |
| 1186 | - if ( ! empty( $args ) ) { |
|
| 1187 | - foreach ( $args as $element => $new_args ) { |
|
| 1186 | + if (!empty($args)) { |
|
| 1187 | + foreach ($args as $element => $new_args) { |
|
| 1188 | 1188 | |
| 1189 | - if ( is_array( $new_args ) ) { // its an element |
|
| 1189 | + if (is_array($new_args)) { // its an element |
|
| 1190 | 1190 | |
| 1191 | 1191 | |
| 1192 | - if ( isset( $new_args['element'] ) ) { |
|
| 1192 | + if (isset($new_args['element'])) { |
|
| 1193 | 1193 | |
| 1194 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 1195 | - echo str_replace( array( |
|
| 1194 | + if (isset($new_args['element_require'])) { |
|
| 1195 | + echo str_replace(array( |
|
| 1196 | 1196 | "'+", |
| 1197 | 1197 | "+'" |
| 1198 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 1199 | - unset( $new_args['element_require'] ); |
|
| 1198 | + ), '', $this->block_props_replace($new_args['element_require'])) . " && "; |
|
| 1199 | + unset($new_args['element_require']); |
|
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | echo "\n el( '" . $new_args['element'] . "', {"; |
| 1203 | 1203 | |
| 1204 | 1204 | // get the attributes |
| 1205 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1205 | + foreach ($new_args as $new_key => $new_value) { |
|
| 1206 | 1206 | |
| 1207 | 1207 | |
| 1208 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 1208 | + if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) { |
|
| 1209 | 1209 | // do nothing |
| 1210 | 1210 | } else { |
| 1211 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 1211 | + echo $this->block_element(array($new_key => $new_value)); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | - echo "},";// end attributes |
|
| 1215 | + echo "},"; // end attributes |
|
| 1216 | 1216 | |
| 1217 | 1217 | // get the content |
| 1218 | 1218 | $first_item = 0; |
| 1219 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1220 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 1219 | + foreach ($new_args as $new_key => $new_value) { |
|
| 1220 | + if ($new_key === 'content' || is_array($new_value)) { |
|
| 1221 | 1221 | |
| 1222 | - if ( $new_key === 'content' ) { |
|
| 1223 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
| 1222 | + if ($new_key === 'content') { |
|
| 1223 | + echo "'" . $this->block_props_replace($new_value) . "'"; |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | - if ( is_array( $new_value ) ) { |
|
| 1226 | + if (is_array($new_value)) { |
|
| 1227 | 1227 | |
| 1228 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 1229 | - echo str_replace( array( |
|
| 1228 | + if (isset($new_value['element_require'])) { |
|
| 1229 | + echo str_replace(array( |
|
| 1230 | 1230 | "'+", |
| 1231 | 1231 | "+'" |
| 1232 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 1233 | - unset( $new_value['element_require'] ); |
|
| 1232 | + ), '', $this->block_props_replace($new_value['element_require'])) . " && "; |
|
| 1233 | + unset($new_value['element_require']); |
|
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 1236 | + if (isset($new_value['element_repeat'])) { |
|
| 1237 | 1237 | $x = 1; |
| 1238 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 1239 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1240 | - $x ++; |
|
| 1238 | + while ($x <= absint($new_value['element_repeat'])) { |
|
| 1239 | + $this->block_element(array('' => $new_value)); |
|
| 1240 | + $x++; |
|
| 1241 | 1241 | } |
| 1242 | 1242 | } else { |
| 1243 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1243 | + $this->block_element(array('' => $new_value)); |
|
| 1244 | 1244 | } |
| 1245 | 1245 | } |
| 1246 | - $first_item ++; |
|
| 1246 | + $first_item++; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | - echo ")";// end content |
|
| 1250 | + echo ")"; // end content |
|
| 1251 | 1251 | |
| 1252 | 1252 | echo ", \n"; |
| 1253 | 1253 | |
| 1254 | 1254 | } |
| 1255 | 1255 | } else { |
| 1256 | 1256 | |
| 1257 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 1258 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 1259 | - } elseif ( $element == 'style' ) { |
|
| 1260 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 1257 | + if (substr($element, 0, 3) === "if_") { |
|
| 1258 | + echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ","; |
|
| 1259 | + } elseif ($element == 'style') { |
|
| 1260 | + echo $element . ": " . $this->block_props_replace($new_args) . ","; |
|
| 1261 | 1261 | } else { |
| 1262 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 1262 | + echo $element . ": '" . $this->block_props_replace($new_args) . "',"; |
|
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | } |
@@ -1274,12 +1274,12 @@ discard block |
||
| 1274 | 1274 | * |
| 1275 | 1275 | * @return mixed |
| 1276 | 1276 | */ |
| 1277 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 1277 | + public function block_props_replace($string, $no_wrap = false) { |
|
| 1278 | 1278 | |
| 1279 | - if ( $no_wrap ) { |
|
| 1280 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 1279 | + if ($no_wrap) { |
|
| 1280 | + $string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string); |
|
| 1281 | 1281 | } else { |
| 1282 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 1282 | + $string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string); |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | return $string; |
@@ -1291,33 +1291,33 @@ discard block |
||
| 1291 | 1291 | * @param array $args |
| 1292 | 1292 | * @param array $instance |
| 1293 | 1293 | */ |
| 1294 | - public function widget( $args, $instance ) { |
|
| 1294 | + public function widget($args, $instance) { |
|
| 1295 | 1295 | |
| 1296 | 1296 | // get the filtered values |
| 1297 | - $argument_values = $this->argument_values( $instance ); |
|
| 1298 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 1299 | - $output = $this->output( $argument_values, $args ); |
|
| 1297 | + $argument_values = $this->argument_values($instance); |
|
| 1298 | + $argument_values = $this->string_to_bool($argument_values); |
|
| 1299 | + $output = $this->output($argument_values, $args); |
|
| 1300 | 1300 | |
| 1301 | - if ( $output ) { |
|
| 1301 | + if ($output) { |
|
| 1302 | 1302 | // Before widget |
| 1303 | 1303 | $before_widget = $args['before_widget']; |
| 1304 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 1305 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 1304 | + $before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this); |
|
| 1305 | + $before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this); |
|
| 1306 | 1306 | |
| 1307 | 1307 | // After widget |
| 1308 | 1308 | $after_widget = $args['after_widget']; |
| 1309 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 1310 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 1309 | + $after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this); |
|
| 1310 | + $after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this); |
|
| 1311 | 1311 | |
| 1312 | 1312 | echo $before_widget; |
| 1313 | 1313 | // elementor strips the widget wrapping div so we check for and add it back if needed |
| 1314 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1315 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 1314 | + if ($this->is_elementor_widget_output()) { |
|
| 1315 | + echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : ''; |
|
| 1316 | 1316 | } |
| 1317 | - echo $this->output_title( $args, $instance ); |
|
| 1317 | + echo $this->output_title($args, $instance); |
|
| 1318 | 1318 | echo $output; |
| 1319 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1320 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 1319 | + if ($this->is_elementor_widget_output()) { |
|
| 1320 | + echo !empty($this->options['widget_ops']['classname']) ? "</span>" : ''; |
|
| 1321 | 1321 | } |
| 1322 | 1322 | echo $after_widget; |
| 1323 | 1323 | } |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | */ |
| 1332 | 1332 | public function is_elementor_widget_output() { |
| 1333 | 1333 | $result = false; |
| 1334 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 1334 | + if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') { |
|
| 1335 | 1335 | $result = true; |
| 1336 | 1336 | } |
| 1337 | 1337 | |
@@ -1346,7 +1346,7 @@ discard block |
||
| 1346 | 1346 | */ |
| 1347 | 1347 | public function is_elementor_preview() { |
| 1348 | 1348 | $result = false; |
| 1349 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 1349 | + if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) { |
|
| 1350 | 1350 | $result = true; |
| 1351 | 1351 | } |
| 1352 | 1352 | |
@@ -1361,11 +1361,11 @@ discard block |
||
| 1361 | 1361 | * |
| 1362 | 1362 | * @return string |
| 1363 | 1363 | */ |
| 1364 | - public function output_title( $args, $instance = array() ) { |
|
| 1364 | + public function output_title($args, $instance = array()) { |
|
| 1365 | 1365 | $output = ''; |
| 1366 | - if ( ! empty( $instance['title'] ) ) { |
|
| 1366 | + if (!empty($instance['title'])) { |
|
| 1367 | 1367 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 1368 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 1368 | + $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
|
| 1369 | 1369 | $output = $args['before_title'] . $title . $args['after_title']; |
| 1370 | 1370 | } |
| 1371 | 1371 | |
@@ -1377,7 +1377,7 @@ discard block |
||
| 1377 | 1377 | * |
| 1378 | 1378 | * @param array $instance The widget options. |
| 1379 | 1379 | */ |
| 1380 | - public function form( $instance ) { |
|
| 1380 | + public function form($instance) { |
|
| 1381 | 1381 | |
| 1382 | 1382 | // set widget instance |
| 1383 | 1383 | $this->instance = $instance; |
@@ -1385,12 +1385,12 @@ discard block |
||
| 1385 | 1385 | // set it as a SD widget |
| 1386 | 1386 | echo $this->widget_advanced_toggle(); |
| 1387 | 1387 | |
| 1388 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 1388 | + echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>"; |
|
| 1389 | 1389 | $arguments = $this->get_arguments(); |
| 1390 | 1390 | |
| 1391 | - if ( is_array( $arguments ) ) { |
|
| 1392 | - foreach ( $arguments as $key => $args ) { |
|
| 1393 | - $this->widget_inputs( $args, $instance ); |
|
| 1391 | + if (is_array($arguments)) { |
|
| 1392 | + foreach ($arguments as $key => $args) { |
|
| 1393 | + $this->widget_inputs($args, $instance); |
|
| 1394 | 1394 | } |
| 1395 | 1395 | } |
| 1396 | 1396 | } |
@@ -1403,7 +1403,7 @@ discard block |
||
| 1403 | 1403 | public function widget_advanced_toggle() { |
| 1404 | 1404 | |
| 1405 | 1405 | $output = ''; |
| 1406 | - if ( $this->block_show_advanced() ) { |
|
| 1406 | + if ($this->block_show_advanced()) { |
|
| 1407 | 1407 | $val = 1; |
| 1408 | 1408 | } else { |
| 1409 | 1409 | $val = 0; |
@@ -1423,14 +1423,14 @@ discard block |
||
| 1423 | 1423 | * |
| 1424 | 1424 | * @return string $output |
| 1425 | 1425 | */ |
| 1426 | - public function convert_element_require( $input ) { |
|
| 1426 | + public function convert_element_require($input) { |
|
| 1427 | 1427 | |
| 1428 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 1428 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
| 1429 | 1429 | |
| 1430 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 1430 | + $output = esc_attr(str_replace(array("[%", "%]"), array( |
|
| 1431 | 1431 | "jQuery(form).find('[data-argument=\"", |
| 1432 | 1432 | "\"]').find('input,select').val()" |
| 1433 | - ), $input ) ); |
|
| 1433 | + ), $input)); |
|
| 1434 | 1434 | |
| 1435 | 1435 | return $output; |
| 1436 | 1436 | } |
@@ -1441,54 +1441,54 @@ discard block |
||
| 1441 | 1441 | * @param $args |
| 1442 | 1442 | * @param $instance |
| 1443 | 1443 | */ |
| 1444 | - public function widget_inputs( $args, $instance ) { |
|
| 1444 | + public function widget_inputs($args, $instance) { |
|
| 1445 | 1445 | |
| 1446 | 1446 | $class = ""; |
| 1447 | 1447 | $element_require = ""; |
| 1448 | 1448 | $custom_attributes = ""; |
| 1449 | 1449 | |
| 1450 | 1450 | // get value |
| 1451 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 1452 | - $value = $instance[ $args['name'] ]; |
|
| 1453 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 1454 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 1451 | + if (isset($instance[$args['name']])) { |
|
| 1452 | + $value = $instance[$args['name']]; |
|
| 1453 | + } elseif (!isset($instance[$args['name']]) && !empty($args['default'])) { |
|
| 1454 | + $value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']); |
|
| 1455 | 1455 | } else { |
| 1456 | 1456 | $value = ''; |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | // get placeholder |
| 1460 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 1461 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 1460 | + if (!empty($args['placeholder'])) { |
|
| 1461 | + $placeholder = "placeholder='" . esc_html($args['placeholder']) . "'"; |
|
| 1462 | 1462 | } else { |
| 1463 | 1463 | $placeholder = ''; |
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | // get if advanced |
| 1467 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 1467 | + if (isset($args['advanced']) && $args['advanced']) { |
|
| 1468 | 1468 | $class .= " sd-advanced-setting "; |
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | 1471 | // element_require |
| 1472 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 1472 | + if (isset($args['element_require']) && $args['element_require']) { |
|
| 1473 | 1473 | $element_require = $args['element_require']; |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | // custom_attributes |
| 1477 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 1478 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 1477 | + if (isset($args['custom_attributes']) && $args['custom_attributes']) { |
|
| 1478 | + $custom_attributes = $this->array_to_attributes($args['custom_attributes'], true); |
|
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | // before wrapper |
| 1482 | 1482 | ?> |
| 1483 | - <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
|
| 1484 | - data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
|
| 1485 | - data-element_require='<?php if ( $element_require ) { |
|
| 1486 | - echo $this->convert_element_require( $element_require ); |
|
| 1483 | + <p class="sd-argument <?php echo esc_attr($class); ?>" |
|
| 1484 | + data-argument='<?php echo esc_attr($args['name']); ?>' |
|
| 1485 | + data-element_require='<?php if ($element_require) { |
|
| 1486 | + echo $this->convert_element_require($element_require); |
|
| 1487 | 1487 | } ?>' |
| 1488 | 1488 | > |
| 1489 | 1489 | <?php |
| 1490 | 1490 | |
| 1491 | - switch ( $args['type'] ) { |
|
| 1491 | + switch ($args['type']) { |
|
| 1492 | 1492 | //array('text','password','number','email','tel','url','color') |
| 1493 | 1493 | case "text": |
| 1494 | 1494 | case "password": |
@@ -1499,46 +1499,46 @@ discard block |
||
| 1499 | 1499 | case "color": |
| 1500 | 1500 | ?> |
| 1501 | 1501 | <label |
| 1502 | - 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> |
|
| 1502 | + 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> |
|
| 1503 | 1503 | <input <?php echo $placeholder; ?> class="widefat" |
| 1504 | 1504 | <?php echo $custom_attributes; ?> |
| 1505 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 1506 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
| 1507 | - type="<?php echo esc_attr( $args['type'] ); ?>" |
|
| 1508 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 1505 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 1506 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
| 1507 | + type="<?php echo esc_attr($args['type']); ?>" |
|
| 1508 | + value="<?php echo esc_attr($value); ?>"> |
|
| 1509 | 1509 | <?php |
| 1510 | 1510 | |
| 1511 | 1511 | break; |
| 1512 | 1512 | case "select": |
| 1513 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 1514 | - if ( $multiple ) { |
|
| 1515 | - if ( empty( $value ) ) { |
|
| 1513 | + $multiple = isset($args['multiple']) && $args['multiple'] ? true : false; |
|
| 1514 | + if ($multiple) { |
|
| 1515 | + if (empty($value)) { |
|
| 1516 | 1516 | $value = array(); |
| 1517 | 1517 | } |
| 1518 | 1518 | } |
| 1519 | 1519 | ?> |
| 1520 | 1520 | <label |
| 1521 | - 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> |
|
| 1521 | + 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> |
|
| 1522 | 1522 | <select <?php echo $placeholder; ?> class="widefat" |
| 1523 | 1523 | <?php echo $custom_attributes; ?> |
| 1524 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 1525 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
|
| 1526 | - if ( $multiple ) { |
|
| 1524 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 1525 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); |
|
| 1526 | + if ($multiple) { |
|
| 1527 | 1527 | echo "[]"; |
| 1528 | 1528 | } ?>" |
| 1529 | - <?php if ( $multiple ) { |
|
| 1529 | + <?php if ($multiple) { |
|
| 1530 | 1530 | echo "multiple"; |
| 1531 | 1531 | } //@todo not implemented yet due to gutenberg not supporting it |
| 1532 | 1532 | ?> |
| 1533 | 1533 | > |
| 1534 | 1534 | <?php |
| 1535 | 1535 | |
| 1536 | - if ( ! empty( $args['options'] ) ) { |
|
| 1537 | - foreach ( $args['options'] as $val => $label ) { |
|
| 1538 | - if ( $multiple ) { |
|
| 1539 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 1536 | + if (!empty($args['options'])) { |
|
| 1537 | + foreach ($args['options'] as $val => $label) { |
|
| 1538 | + if ($multiple) { |
|
| 1539 | + $selected = in_array($val, $value) ? 'selected="selected"' : ''; |
|
| 1540 | 1540 | } else { |
| 1541 | - $selected = selected( $value, $val, false ); |
|
| 1541 | + $selected = selected($value, $val, false); |
|
| 1542 | 1542 | } |
| 1543 | 1543 | echo "<option value='$val' " . $selected . ">$label</option>"; |
| 1544 | 1544 | } |
@@ -1550,20 +1550,20 @@ discard block |
||
| 1550 | 1550 | case "checkbox": |
| 1551 | 1551 | ?> |
| 1552 | 1552 | <input <?php echo $placeholder; ?> |
| 1553 | - <?php checked( 1, $value, true ) ?> |
|
| 1553 | + <?php checked(1, $value, true) ?> |
|
| 1554 | 1554 | <?php echo $custom_attributes; ?> |
| 1555 | - class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 1556 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" |
|
| 1555 | + class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 1556 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox" |
|
| 1557 | 1557 | value="1"> |
| 1558 | 1558 | <label |
| 1559 | - 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> |
|
| 1559 | + 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> |
|
| 1560 | 1560 | <?php |
| 1561 | 1561 | break; |
| 1562 | 1562 | case "hidden": |
| 1563 | 1563 | ?> |
| 1564 | - <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 1565 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
|
| 1566 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 1564 | + <input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 1565 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden" |
|
| 1566 | + value="<?php echo esc_attr($value); ?>"> |
|
| 1567 | 1567 | <?php |
| 1568 | 1568 | break; |
| 1569 | 1569 | default: |
@@ -1585,14 +1585,14 @@ discard block |
||
| 1585 | 1585 | * @return string |
| 1586 | 1586 | * @todo, need to make its own tooltip script |
| 1587 | 1587 | */ |
| 1588 | - public function widget_field_desc( $args ) { |
|
| 1588 | + public function widget_field_desc($args) { |
|
| 1589 | 1589 | |
| 1590 | 1590 | $description = ''; |
| 1591 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 1592 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 1593 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 1591 | + if (isset($args['desc']) && $args['desc']) { |
|
| 1592 | + if (isset($args['desc_tip']) && $args['desc_tip']) { |
|
| 1593 | + $description = $this->desc_tip($args['desc']); |
|
| 1594 | 1594 | } else { |
| 1595 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 1595 | + $description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>'; |
|
| 1596 | 1596 | } |
| 1597 | 1597 | } |
| 1598 | 1598 | |
@@ -1607,11 +1607,11 @@ discard block |
||
| 1607 | 1607 | * |
| 1608 | 1608 | * @return string |
| 1609 | 1609 | */ |
| 1610 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 1611 | - if ( $allow_html ) { |
|
| 1612 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 1610 | + function desc_tip($tip, $allow_html = false) { |
|
| 1611 | + if ($allow_html) { |
|
| 1612 | + $tip = $this->sanitize_tooltip($tip); |
|
| 1613 | 1613 | } else { |
| 1614 | - $tip = esc_attr( $tip ); |
|
| 1614 | + $tip = esc_attr($tip); |
|
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | 1617 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -1624,8 +1624,8 @@ discard block |
||
| 1624 | 1624 | * |
| 1625 | 1625 | * @return string |
| 1626 | 1626 | */ |
| 1627 | - public function sanitize_tooltip( $var ) { |
|
| 1628 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 1627 | + public function sanitize_tooltip($var) { |
|
| 1628 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
| 1629 | 1629 | 'br' => array(), |
| 1630 | 1630 | 'em' => array(), |
| 1631 | 1631 | 'strong' => array(), |
@@ -1635,7 +1635,7 @@ discard block |
||
| 1635 | 1635 | 'li' => array(), |
| 1636 | 1636 | 'ol' => array(), |
| 1637 | 1637 | 'p' => array(), |
| 1638 | - ) ) ); |
|
| 1638 | + ))); |
|
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | /** |
@@ -1647,23 +1647,23 @@ discard block |
||
| 1647 | 1647 | * @return array |
| 1648 | 1648 | * @todo we should add some sanitation here. |
| 1649 | 1649 | */ |
| 1650 | - public function update( $new_instance, $old_instance ) { |
|
| 1650 | + public function update($new_instance, $old_instance) { |
|
| 1651 | 1651 | |
| 1652 | 1652 | //save the widget |
| 1653 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 1653 | + $instance = array_merge((array)$old_instance, (array)$new_instance); |
|
| 1654 | 1654 | |
| 1655 | 1655 | // set widget instance |
| 1656 | 1656 | $this->instance = $instance; |
| 1657 | 1657 | |
| 1658 | - if ( empty( $this->arguments ) ) { |
|
| 1658 | + if (empty($this->arguments)) { |
|
| 1659 | 1659 | $this->get_arguments(); |
| 1660 | 1660 | } |
| 1661 | 1661 | |
| 1662 | 1662 | // check for checkboxes |
| 1663 | - if ( ! empty( $this->arguments ) ) { |
|
| 1664 | - foreach ( $this->arguments as $argument ) { |
|
| 1665 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 1666 | - $instance[ $argument['name'] ] = '0'; |
|
| 1663 | + if (!empty($this->arguments)) { |
|
| 1664 | + foreach ($this->arguments as $argument) { |
|
| 1665 | + if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) { |
|
| 1666 | + $instance[$argument['name']] = '0'; |
|
| 1667 | 1667 | } |
| 1668 | 1668 | } |
| 1669 | 1669 | } |
@@ -1681,7 +1681,7 @@ discard block |
||
| 1681 | 1681 | */ |
| 1682 | 1682 | public function is_block_content_call() { |
| 1683 | 1683 | $result = false; |
| 1684 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 1684 | + if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') { |
|
| 1685 | 1685 | $result = true; |
| 1686 | 1686 | } |
| 1687 | 1687 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | <?php |
| 197 | 197 | if(! empty( $insert_shortcode_function )){ |
| 198 | 198 | echo $insert_shortcode_function; |
| 199 | - }else{ |
|
| 199 | + } else{ |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * Function for super duper insert shortcode. |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | // If the user sets block-output array then build it |
| 1069 | 1069 | if ( ! empty( $this->options['block-output'] ) ) { |
| 1070 | 1070 | $this->block_element( $this->options['block-output'] ); |
| 1071 | - }else{ |
|
| 1071 | + } else{ |
|
| 1072 | 1072 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1073 | 1073 | ?> |
| 1074 | 1074 | el('div', { |
@@ -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 | } |