| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package Tag Groups |
| 5 |
* |
| 6 |
* @author Christoph Amthor |
| 7 |
* @copyright 2019 Christoph Amthor (@ Chatty Mango, chattymango.com) |
| 8 |
* @license GPL-3.0+ |
| 9 |
*/ |
| 10 |
|
| 11 |
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps, PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
| 12 |
if (! class_exists('TagGroups_Enqueue')) { |
| 13 |
|
| 14 |
/** |
| 15 |
* |
| 16 |
*/ |
| 17 |
class TagGroups_Enqueue |
| 18 |
{ |
| 19 |
/** |
| 20 |
* Add js and css to frontend |
| 21 |
* |
| 22 |
* @param void |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public function wp_enqueue_scripts() |
| 26 |
{ |
| 27 |
|
| 28 |
if (is_admin()) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
global $post; |
| 33 |
|
| 34 |
$tag_group_shortcode_enqueue_always = TagGroups_Options::get_option('tag_group_shortcode_enqueue_always', 1); |
| 35 |
|
| 36 |
/* enqueue frontend scripts and styling only if shortcode in use */ |
| 37 |
|
| 38 |
if ( |
| 39 |
$tag_group_shortcode_enqueue_always || |
| 40 |
! is_a($post, 'WP_Post') || |
| 41 |
has_shortcode($post->post_content, 'tag_groups_cloud') || |
| 42 |
has_shortcode($post->post_content, 'tag_groups_accordion') || |
| 43 |
has_shortcode($post->post_content, 'tag_groups_alphabet_tabs') || |
| 44 |
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
| 45 |
// has_shortcode($post->post_content, 'tag_groups_tabs') || |
| 46 |
strpos($post->post_content, '<!-- wp:chatty-mango/tag-groups-cloud-tabs') !== false || |
| 47 |
strpos($post->post_content, '<!-- wp:chatty-mango/tag-groups-cloud-accordion') !== false || |
| 48 |
strpos($post->post_content, '<!-- wp:chatty-mango/tag-groups-alphabet-tabs') !== false |
| 49 |
) { |
| 50 |
if (TagGroups_Options::get_option('tag_group_enqueue_jquery', 1)) { |
| 51 |
wp_enqueue_script('jquery'); |
| 52 |
|
| 53 |
wp_enqueue_script('jquery-ui-core'); |
| 54 |
|
| 55 |
wp_enqueue_script('jquery-ui-tabs'); |
| 56 |
|
| 57 |
wp_enqueue_script('jquery-ui-accordion'); |
| 58 |
} |
| 59 |
|
| 60 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 61 |
wp_register_script('tag-groups-js-frontend', TAG_GROUPS_PLUGIN_URL . '/assets/js/frontend.js', array(), TAG_GROUPS_VERSION); |
| 62 |
} else { |
| 63 |
wp_register_script('tag-groups-js-frontend', TAG_GROUPS_PLUGIN_URL . '/assets/js/frontend.min.js', array(), TAG_GROUPS_VERSION); |
| 64 |
} |
| 65 |
|
| 66 |
wp_enqueue_script('tag-groups-js-frontend'); |
| 67 |
|
| 68 |
$this->load_theme_css(); |
| 69 |
|
| 70 |
wp_enqueue_style('tag-groups-css-frontend-structure'); |
| 71 |
|
| 72 |
wp_enqueue_style('tag-groups-css-frontend-theme'); |
| 73 |
|
| 74 |
$this->enqueue_frontend_css(); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
/** |
| 79 |
* Equeue features that appear in lists and don't need jQuery UI |
| 80 |
*/ |
| 81 |
if ( |
| 82 |
$tag_group_shortcode_enqueue_always || |
| 83 |
! is_a($post, 'WP_Post') || |
| 84 |
has_shortcode($post->post_content, 'tag_groups_tag_list') || |
| 85 |
has_shortcode($post->post_content, 'tag_groups_alphabetical_index') || |
| 86 |
strpos($post->post_content, '<!-- wp:chatty-mango/tag-groups-tag-list') !== false || |
| 87 |
strpos($post->post_content, '<!-- wp:chatty-mango/tag-groups-alphabetical-tag-index') !== false |
| 88 |
) { |
| 89 |
$this->enqueue_frontend_css(); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Add css to backend |
| 95 |
* |
| 96 |
* @param string $where |
| 97 |
* @return void |
| 98 |
*/ |
| 99 |
public function admin_enqueue_scripts($where) |
| 100 |
{ |
| 101 |
|
| 102 |
if (strpos($where, 'tag-groups-settings') !== false) { |
| 103 |
wp_enqueue_script('jquery'); |
| 104 |
|
| 105 |
wp_enqueue_script('jquery-ui-core'); |
| 106 |
|
| 107 |
wp_enqueue_script('jquery-ui-accordion'); |
| 108 |
|
| 109 |
wp_enqueue_script('jquery-ui-tabs'); |
| 110 |
|
| 111 |
wp_enqueue_script('jquery-ui-tooltip'); |
| 112 |
|
| 113 |
wp_register_style('tag-groups-css-backend-structure', TAG_GROUPS_PLUGIN_URL . '/assets/css/jquery-ui.structure.min.css', array(), TAG_GROUPS_VERSION); |
| 114 |
|
| 115 |
wp_enqueue_style('tag-groups-css-backend-structure'); |
| 116 |
|
| 117 |
wp_register_style('tag-groups-css-backend-theme', TAG_GROUPS_PLUGIN_URL . '/assets/css/base/jquery-ui.theme.min.css', array(), TAG_GROUPS_VERSION); |
| 118 |
|
| 119 |
wp_enqueue_style('tag-groups-css-backend-theme'); |
| 120 |
|
| 121 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 122 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.css', array(), TAG_GROUPS_VERSION); |
| 123 |
} else { |
| 124 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.min.css', array(), TAG_GROUPS_VERSION); |
| 125 |
} |
| 126 |
|
| 127 |
wp_enqueue_style('tag-groups-css-backend-tgb'); |
| 128 |
|
| 129 |
wp_register_script('tag-groups-sumoselect-js', TAG_GROUPS_PLUGIN_URL . '/assets/js/jquery.sumoselect.min.js', array(), TAG_GROUPS_VERSION); |
| 130 |
|
| 131 |
wp_enqueue_script('tag-groups-sumoselect-js'); |
| 132 |
|
| 133 |
$banners_style_path = '/publishpress/wordpress-banners/assets/css/style.css'; |
| 134 |
$banners_vendor_url = '/vendor'; |
| 135 |
|
| 136 |
if (defined('TAG_GROUPS_LIB_VENDOR_PATH') && file_exists(TAG_GROUPS_LIB_VENDOR_PATH . $banners_style_path)) { |
| 137 |
$banners_vendor_url = '/lib/vendor'; |
| 138 |
} |
| 139 |
|
| 140 |
wp_enqueue_style('pp-wordpress-banners-style', TAG_GROUPS_PLUGIN_URL . $banners_vendor_url . $banners_style_path, false, TAG_GROUPS_VERSION); |
| 141 |
|
| 142 |
|
| 143 |
$this->load_sumoselect_css(); |
| 144 |
} elseif (strpos($where, '_page_tag-groups') !== false) { |
| 145 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 146 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.css', array(), TAG_GROUPS_VERSION); |
| 147 |
} else { |
| 148 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.min.css', array(), TAG_GROUPS_VERSION); |
| 149 |
} |
| 150 |
|
| 151 |
wp_enqueue_style('tag-groups-css-backend-tgb'); |
| 152 |
|
| 153 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 154 |
wp_register_script('tag-groups-js-backend', TAG_GROUPS_PLUGIN_URL . '/assets/js/backend.js', array(), TAG_GROUPS_VERSION); |
| 155 |
} else { |
| 156 |
wp_register_script('tag-groups-js-backend', TAG_GROUPS_PLUGIN_URL . '/assets/js/backend.min.js', array(), TAG_GROUPS_VERSION); |
| 157 |
} |
| 158 |
|
| 159 |
wp_enqueue_script('tag-groups-js-backend'); |
| 160 |
|
| 161 |
wp_enqueue_script('jquery-ui-sortable'); |
| 162 |
|
| 163 |
wp_enqueue_script('jquery-ui-core'); |
| 164 |
|
| 165 |
wp_enqueue_script('jquery-ui-accordion'); |
| 166 |
|
| 167 |
wp_enqueue_script('jquery-ui-tooltip'); |
| 168 |
} elseif (strpos($where, 'edit-tags.php') !== false || strpos($where, 'term.php') !== false || strpos($where, 'edit.php') !== false) { |
| 169 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 170 |
wp_register_script('tag-groups-sumoselect-js', TAG_GROUPS_PLUGIN_URL . '/assets/js/jquery.sumoselect.js', array(), TAG_GROUPS_VERSION); |
| 171 |
} else { |
| 172 |
wp_register_script('tag-groups-sumoselect-js', TAG_GROUPS_PLUGIN_URL . '/assets/js/jquery.sumoselect.min.js', array(), TAG_GROUPS_VERSION); |
| 173 |
} |
| 174 |
|
| 175 |
wp_enqueue_script('tag-groups-sumoselect-js'); |
| 176 |
|
| 177 |
$this->load_sumoselect_css(); |
| 178 |
|
| 179 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 180 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.css', array(), TAG_GROUPS_VERSION); |
| 181 |
} else { |
| 182 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.min.css', array(), TAG_GROUPS_VERSION); |
| 183 |
} |
| 184 |
|
| 185 |
wp_enqueue_style('tag-groups-css-backend-tgb'); |
| 186 |
} elseif (strpos($where, 'post-new.php') !== false || strpos($where, 'post.php') !== false) { |
| 187 |
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
| 188 |
// use following line to enable gutenberg on Appearance > Widgets |
| 189 |
// } elseif ( strpos( $where, 'post-new.php' ) !== false || strpos( $where, 'post.php' ) !== false || strpos( $where, 'widgets.php' ) !== false ) { |
| 190 |
|
| 191 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 192 |
wp_register_style('tag-groups-react-select-css', TAG_GROUPS_PLUGIN_URL . '/assets/css/react-select.css', array(), TAG_GROUPS_VERSION); |
| 193 |
} else { |
| 194 |
wp_register_style('tag-groups-react-select-css', TAG_GROUPS_PLUGIN_URL . '/assets/css/react-select.min.css', array(), TAG_GROUPS_VERSION); |
| 195 |
} |
| 196 |
|
| 197 |
wp_enqueue_style('tag-groups-react-select-css'); |
| 198 |
|
| 199 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 200 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.css', array(), TAG_GROUPS_VERSION); |
| 201 |
} else { |
| 202 |
wp_register_style('tag-groups-css-backend-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend.min.css', array(), TAG_GROUPS_VERSION); |
| 203 |
} |
| 204 |
|
| 205 |
wp_enqueue_style('tag-groups-css-backend-tgb'); |
| 206 |
} |
| 207 |
|
| 208 |
/* If we have RTL, we load an additional file for support */ |
| 209 |
if (wp_style_is('tag-groups-css-backend-tgb', 'enqueued') && is_rtl()) { |
| 210 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 211 |
wp_register_style('tag-groups-css-backend-rtl-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend-rtl.css', array(), TAG_GROUPS_VERSION); |
| 212 |
} else { |
| 213 |
wp_register_style('tag-groups-css-backend-rtl-tgb', TAG_GROUPS_PLUGIN_URL . '/assets/css/backend-rtl.min.css', array(), TAG_GROUPS_VERSION); |
| 214 |
} |
| 215 |
|
| 216 |
wp_enqueue_style('tag-groups-css-backend-rtl-tgb'); |
| 217 |
} |
| 218 |
|
| 219 |
if (TagGroups_Gutenberg::is_gutenberg_active()) { |
| 220 |
$this->admin_enqueue_scripts_for_gutenberg(); |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Adds js and css to the Gutenberg editor page |
| 226 |
* |
| 227 |
* |
| 228 |
* @param void |
| 229 |
* @return void |
| 230 |
*/ |
| 231 |
public function admin_enqueue_scripts_for_gutenberg() |
| 232 |
{ |
| 233 |
|
| 234 |
/** enqueue frontend scripts and styling only if shortcode in use */ |
| 235 |
|
| 236 |
$screen = get_current_screen(); |
| 237 |
|
| 238 |
if (is_object($screen) && property_exists($screen, 'base') && 'post' != $screen->base && 'site-editor' != $screen->base) { |
| 239 |
// use following line to enable gutenberg on Appearance > Widgets |
| 240 |
// if ( is_object( $screen ) && property_exists( $screen, 'base' ) && 'post' != $screen->base && 'widgets' != $screen->base ) { |
| 241 |
|
| 242 |
return; |
| 243 |
} |
| 244 |
|
| 245 |
wp_enqueue_script('jquery'); |
| 246 |
|
| 247 |
wp_enqueue_script('jquery-ui-core'); |
| 248 |
|
| 249 |
wp_enqueue_script('jquery-ui-tabs'); |
| 250 |
|
| 251 |
wp_enqueue_script('jquery-ui-accordion'); |
| 252 |
|
| 253 |
wp_enqueue_script('jquery-ui-tooltip'); |
| 254 |
|
| 255 |
$this->load_theme_css(); |
| 256 |
|
| 257 |
if (! is_admin()) { |
| 258 |
$this->enqueue_frontend_css(); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* load the JS |
| 263 |
*/ |
| 264 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 265 |
wp_register_script('tag-groups-js-frontend', TAG_GROUPS_PLUGIN_URL . '/assets/js/frontend.js', array(), TAG_GROUPS_VERSION); |
| 266 |
} else { |
| 267 |
wp_register_script('tag-groups-js-frontend', TAG_GROUPS_PLUGIN_URL . '/assets/js/frontend.min.js', array(), TAG_GROUPS_VERSION); |
| 268 |
} |
| 269 |
|
| 270 |
wp_enqueue_script('tag-groups-js-frontend'); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* enqueue CSS for free features |
| 275 |
* |
| 276 |
* @return void |
| 277 |
*/ |
| 278 |
private function enqueue_frontend_css() |
| 279 |
{ |
| 280 |
|
| 281 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 282 |
wp_register_style('tag-groups-css-frontend', TAG_GROUPS_PLUGIN_URL . '/assets/css/frontend.css', array(), TAG_GROUPS_VERSION); |
| 283 |
} else { |
| 284 |
wp_register_style('tag-groups-css-frontend', TAG_GROUPS_PLUGIN_URL . '/assets/css/frontend.min.css', array(), TAG_GROUPS_VERSION); |
| 285 |
} |
| 286 |
|
| 287 |
wp_enqueue_style('tag-groups-css-frontend'); |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
/** |
| 292 |
* Load the CSS of the theme |
| 293 |
* |
| 294 |
* @return void |
| 295 |
*/ |
| 296 |
public function load_theme_css() |
| 297 |
{ |
| 298 |
|
| 299 |
$theme = TagGroups_Options::get_option('tag_group_theme', TAG_GROUPS_STANDARD_THEME); |
| 300 |
|
| 301 |
if ('' == $theme) { |
| 302 |
return; |
| 303 |
} |
| 304 |
|
| 305 |
wp_register_style('tag-groups-css-frontend-structure', TAG_GROUPS_PLUGIN_URL . '/assets/css/jquery-ui.structure.min.css', array(), TAG_GROUPS_VERSION); |
| 306 |
|
| 307 |
$default_themes = explode(',', TAG_GROUPS_BUILT_IN_THEMES); |
| 308 |
|
| 309 |
if (in_array($theme, $default_themes)) { |
| 310 |
wp_register_style('tag-groups-css-frontend-theme', TAG_GROUPS_PLUGIN_URL . '/assets/css/' . $theme . '/jquery-ui.theme.min.css', array(), TAG_GROUPS_VERSION); |
| 311 |
} else { |
| 312 |
|
| 313 |
/** |
| 314 |
* Load minimized css if available |
| 315 |
*/ |
| 316 |
if (file_exists(WP_CONTENT_DIR . '/uploads/' . $theme . '/jquery-ui.theme.min.css')) { |
| 317 |
wp_register_style('tag-groups-css-frontend-theme', get_bloginfo('wpurl') . '/wp-content/uploads/' . $theme . '/jquery-ui.theme.min.css', array(), TAG_GROUPS_VERSION); |
| 318 |
} elseif (file_exists(WP_CONTENT_DIR . '/uploads/' . $theme . '/jquery-ui.theme.css')) { |
| 319 |
wp_register_style('tag-groups-css-frontend-theme', get_bloginfo('wpurl') . '/wp-content/uploads/' . $theme . '/jquery-ui.theme.css', array(), TAG_GROUPS_VERSION); |
| 320 |
} else { |
| 321 |
|
| 322 |
/** |
| 323 |
* Fallback: Is this a custom theme of an old version or did we revert to old plugin version? |
| 324 |
*/ |
| 325 |
if (file_exists(WP_CONTENT_DIR . '/uploads/' . $theme)) { |
| 326 |
$dh = opendir(WP_CONTENT_DIR . '/uploads/' . $theme); |
| 327 |
|
| 328 |
if (! empty($dh)) { |
| 329 |
while (false !== ( $filename = @readdir($dh) )) { |
| 330 |
if (preg_match("/jquery-ui-\d+\.\d+\.\d+\.custom\.(min\.)?css/i", $filename)) { |
| 331 |
wp_register_style('tag-groups-css-frontend-theme', get_bloginfo('wpurl') . '/wp-content/uploads/' . $theme . '/' . $filename, array(), TAG_GROUPS_VERSION); |
| 332 |
|
| 333 |
break; |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
} else { |
| 338 |
TagGroups_Error::log('[Tag Groups] Error finding %s/uploads/%s', WP_CONTENT_DIR, $theme); |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
wp_enqueue_style('tag-groups-css-frontend-structure'); |
| 344 |
|
| 345 |
wp_enqueue_style('tag-groups-css-frontend-theme'); |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
/** |
| 350 |
* Load the Sumoselect CSS for the text direction |
| 351 |
* |
| 352 |
* @return void |
| 353 |
*/ |
| 354 |
public function load_sumoselect_css() |
| 355 |
{ |
| 356 |
|
| 357 |
$direction = is_rtl() ? '-rtl' : ''; |
| 358 |
|
| 359 |
if (defined('WP_DEBUG') && WP_DEBUG) { |
| 360 |
wp_register_style('tag-groups-sumoselect-css', TAG_GROUPS_PLUGIN_URL . '/assets/css/sumoselect' . $direction . '.css', array(), TAG_GROUPS_VERSION); |
| 361 |
} else { |
| 362 |
wp_register_style('tag-groups-sumoselect-css', TAG_GROUPS_PLUGIN_URL . '/assets/css/sumoselect' . $direction . '.min.css', array(), TAG_GROUPS_VERSION); |
| 363 |
} |
| 364 |
|
| 365 |
wp_enqueue_style('tag-groups-sumoselect-css'); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
} |
| 370 |
|