compatibility
2 years ago
controls
2 years ago
pa-display-conditions
2 years ago
templates
2 years ago
acf-helper.php
2 years ago
addons-cross-cp.php
2 years ago
addons-integration.php
2 years ago
assets-manager.php
2 years ago
class-pa-core.php
2 years ago
class-premium-template-tags.php
2 years ago
helper-functions.php
2 years ago
live-editor-modal.php
2 years ago
module-base.php
2 years ago
pa-nav-menu-walker.php
2 years ago
helper-functions.php
1203 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PA Helper Functions. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes; |
| 7 | |
| 8 | // Premium Addons Pro Classes. |
| 9 | use PremiumAddonsPro\Includes\White_Label\Helper; |
| 10 | |
| 11 | // Elementor Classes. |
| 12 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 13 | use Elementor\Plugin; |
| 14 | use Elementor\Controls_Manager; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Class Helper_Functions. |
| 22 | */ |
| 23 | class Helper_Functions { |
| 24 | |
| 25 | /** |
| 26 | * A list of safe tage for `validate_html_tag` method. |
| 27 | */ |
| 28 | const ALLOWED_HTML_WRAPPER_TAGS = array( |
| 29 | 'article', |
| 30 | 'aside', |
| 31 | 'div', |
| 32 | 'footer', |
| 33 | 'h1', |
| 34 | 'h2', |
| 35 | 'h3', |
| 36 | 'h4', |
| 37 | 'h5', |
| 38 | 'h6', |
| 39 | 'header', |
| 40 | 'main', |
| 41 | 'nav', |
| 42 | 'p', |
| 43 | 'section', |
| 44 | 'span', |
| 45 | ); |
| 46 | |
| 47 | /** |
| 48 | * Google maps prefixes |
| 49 | * |
| 50 | * @var google_localize |
| 51 | */ |
| 52 | private static $google_localize = null; |
| 53 | |
| 54 | /** |
| 55 | * WP lang prefixes |
| 56 | * |
| 57 | * @var lang_locales |
| 58 | */ |
| 59 | private static $lang_locales = null; |
| 60 | |
| 61 | /** |
| 62 | * Script debug enabled |
| 63 | * |
| 64 | * @var script_debug |
| 65 | */ |
| 66 | private static $script_debug = null; |
| 67 | |
| 68 | /** |
| 69 | * JS scripts directory |
| 70 | * |
| 71 | * @var js_dir |
| 72 | */ |
| 73 | private static $js_dir = null; |
| 74 | |
| 75 | /** |
| 76 | * CSS fiels directory |
| 77 | * |
| 78 | * @var js_dir |
| 79 | */ |
| 80 | private static $css_dir = null; |
| 81 | |
| 82 | /** |
| 83 | * JS Suffix |
| 84 | * |
| 85 | * @var js_suffix |
| 86 | */ |
| 87 | private static $assets_suffix = null; |
| 88 | |
| 89 | /** |
| 90 | * Check if white labeling - Free version author field is set |
| 91 | * |
| 92 | * @since 1.0.0 |
| 93 | * @access public |
| 94 | * |
| 95 | * @return string |
| 96 | */ |
| 97 | public static function author() { |
| 98 | |
| 99 | $author_free = 'Leap13'; |
| 100 | |
| 101 | if ( self::check_papro_version() ) { |
| 102 | |
| 103 | $white_label = Helper::get_white_labeling_settings(); |
| 104 | |
| 105 | $author_free = $white_label['premium-wht-lbl-name']; |
| 106 | |
| 107 | } |
| 108 | |
| 109 | return '' !== $author_free ? $author_free : 'Leap13'; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Check if white labeling - Free version name field is set |
| 114 | * |
| 115 | * @since 1.0.0 |
| 116 | * @access public |
| 117 | * |
| 118 | * @return string |
| 119 | */ |
| 120 | public static function name() { |
| 121 | |
| 122 | $name_free = 'Premium Addons for Elementor'; |
| 123 | |
| 124 | if ( self::check_papro_version() ) { |
| 125 | |
| 126 | $white_label = Helper::get_white_labeling_settings(); |
| 127 | |
| 128 | $name_free = $white_label['premium-wht-lbl-plugin-name']; |
| 129 | |
| 130 | } |
| 131 | |
| 132 | return '' !== $name_free ? $name_free : 'Premium Addons for Elementor'; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Check if white labeling - Hide row meta option is checked |
| 137 | * |
| 138 | * @since 1.0.0 |
| 139 | * @return boolean |
| 140 | */ |
| 141 | public static function is_hide_row_meta() { |
| 142 | |
| 143 | if ( self::check_papro_version() ) { |
| 144 | |
| 145 | $white_label = Helper::get_white_labeling_settings(); |
| 146 | |
| 147 | $hide_meta = $white_label['premium-wht-lbl-row']; |
| 148 | |
| 149 | } |
| 150 | |
| 151 | return isset( $hide_meta ) ? $hide_meta : false; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Check if white labeling - Hide plugin logo option is checked |
| 156 | * |
| 157 | * @since 1.0.0 |
| 158 | * @access public |
| 159 | * |
| 160 | * @return boolean |
| 161 | */ |
| 162 | public static function is_hide_logo() { |
| 163 | |
| 164 | if ( self::check_papro_version() ) { |
| 165 | |
| 166 | if ( isset( get_option( 'pa_wht_lbl_save_settings' )['premium-wht-lbl-logo'] ) ) { |
| 167 | |
| 168 | $hide_logo = get_option( 'pa_wht_lbl_save_settings' )['premium-wht-lbl-logo']; |
| 169 | |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return isset( $hide_logo ) ? $hide_logo : false; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Get White Labeling - Widgets Category string |
| 178 | * |
| 179 | * @since 1.0.0 |
| 180 | * @access public |
| 181 | * |
| 182 | * @return string |
| 183 | */ |
| 184 | public static function get_category() { |
| 185 | |
| 186 | $category = __( 'Premium Addons', 'premium-addons-for-elementor' ); |
| 187 | |
| 188 | if ( self::check_papro_version() ) { |
| 189 | |
| 190 | $white_label = Helper::get_white_labeling_settings(); |
| 191 | |
| 192 | $category = $white_label['premium-wht-lbl-short-name']; |
| 193 | |
| 194 | } |
| 195 | |
| 196 | return '' !== $category ? $category : __( 'Premium Addons', 'premium-addons-for-elementor' ); |
| 197 | |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Get White Labeling - Widgets Prefix string |
| 202 | * |
| 203 | * @since 1.0.0 |
| 204 | * @access public |
| 205 | * |
| 206 | * @return string |
| 207 | */ |
| 208 | public static function get_prefix() { |
| 209 | |
| 210 | $prefix = __( 'Premium', 'premium-addons-for-elementor' ); |
| 211 | |
| 212 | if ( self::check_papro_version() ) { |
| 213 | |
| 214 | $white_label = Helper::get_white_labeling_settings(); |
| 215 | |
| 216 | $prefix = $white_label['premium-wht-lbl-prefix']; |
| 217 | |
| 218 | } |
| 219 | |
| 220 | return '' !== $prefix ? $prefix : __( 'Premium', 'premium-addons-for-elementor' ); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Check if white labeling - Future notification checked |
| 225 | * |
| 226 | * @since 1.0.0 |
| 227 | * @return boolean |
| 228 | */ |
| 229 | public static function check_hide_notifications() { |
| 230 | |
| 231 | if ( self::check_papro_version() ) { |
| 232 | |
| 233 | $white_label = Helper::get_white_labeling_settings(); |
| 234 | |
| 235 | $hide_notification = isset( $white_label['premium-wht-lbl-not'] ) ? $white_label['premium-wht-lbl-not'] : false; |
| 236 | |
| 237 | } |
| 238 | |
| 239 | return isset( $hide_notification ) ? $hide_notification : false; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Get White Labeling - Widgets Badge string |
| 244 | * |
| 245 | * @since 1.0.0 |
| 246 | * @access public |
| 247 | * |
| 248 | * @return string |
| 249 | */ |
| 250 | public static function get_badge() { |
| 251 | |
| 252 | $badge = 'PA'; |
| 253 | |
| 254 | if ( self::check_papro_version() ) { |
| 255 | |
| 256 | $white_label = Helper::get_white_labeling_settings(); |
| 257 | |
| 258 | $badge = $white_label['premium-wht-lbl-badge']; |
| 259 | |
| 260 | } |
| 261 | |
| 262 | return '' !== $badge ? $badge : 'PA'; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Get Google Maps localization prefixes |
| 267 | * |
| 268 | * @since 1.0.0 |
| 269 | * @access public |
| 270 | * |
| 271 | * @return array |
| 272 | */ |
| 273 | public static function get_google_maps_prefixes() { |
| 274 | |
| 275 | if ( null === self::$google_localize ) { |
| 276 | |
| 277 | self::$google_localize = array( |
| 278 | 'ar' => __( 'Arabic', 'premium-addons-for-elementor' ), |
| 279 | 'eu' => __( 'Basque', 'premium-addons-for-elementor' ), |
| 280 | 'bg' => __( 'Bulgarian', 'premium-addons-for-elementor' ), |
| 281 | 'bn' => __( 'Bengali', 'premium-addons-for-elementor' ), |
| 282 | 'ca' => __( 'Catalan', 'premium-addons-for-elementor' ), |
| 283 | 'cs' => __( 'Czech', 'premium-addons-for-elementor' ), |
| 284 | 'da' => __( 'Danish', 'premium-addons-for-elementor' ), |
| 285 | 'de' => __( 'German', 'premium-addons-for-elementor' ), |
| 286 | 'el' => __( 'Greek', 'premium-addons-for-elementor' ), |
| 287 | 'en' => __( 'English', 'premium-addons-for-elementor' ), |
| 288 | 'en-AU' => __( 'English (australian)', 'premium-addons-for-elementor' ), |
| 289 | 'en-GB' => __( 'English (great britain)', 'premium-addons-for-elementor' ), |
| 290 | 'es' => __( 'Spanish', 'premium-addons-for-elementor' ), |
| 291 | 'fa' => __( 'Farsi', 'premium-addons-for-elementor' ), |
| 292 | 'fi' => __( 'Finnish', 'premium-addons-for-elementor' ), |
| 293 | 'fil' => __( 'Filipino', 'premium-addons-for-elementor' ), |
| 294 | 'fr' => __( 'French', 'premium-addons-for-elementor' ), |
| 295 | 'gl' => __( 'Galician', 'premium-addons-for-elementor' ), |
| 296 | 'gu' => __( 'Gujarati', 'premium-addons-for-elementor' ), |
| 297 | 'hi' => __( 'Hindi', 'premium-addons-for-elementor' ), |
| 298 | 'hr' => __( 'Croatian', 'premium-addons-for-elementor' ), |
| 299 | 'hu' => __( 'Hungarian', 'premium-addons-for-elementor' ), |
| 300 | 'id' => __( 'Indonesian', 'premium-addons-for-elementor' ), |
| 301 | 'it' => __( 'Italian', 'premium-addons-for-elementor' ), |
| 302 | 'iw' => __( 'Hebrew', 'premium-addons-for-elementor' ), |
| 303 | 'ja' => __( 'Japanese', 'premium-addons-for-elementor' ), |
| 304 | 'kn' => __( 'Kannada', 'premium-addons-for-elementor' ), |
| 305 | 'ko' => __( 'Korean', 'premium-addons-for-elementor' ), |
| 306 | 'lt' => __( 'Lithuanian', 'premium-addons-for-elementor' ), |
| 307 | 'lv' => __( 'Latvian', 'premium-addons-for-elementor' ), |
| 308 | 'ml' => __( 'Malayalam', 'premium-addons-for-elementor' ), |
| 309 | 'mr' => __( 'Marathi', 'premium-addons-for-elementor' ), |
| 310 | 'nl' => __( 'Dutch', 'premium-addons-for-elementor' ), |
| 311 | 'no' => __( 'Norwegian', 'premium-addons-for-elementor' ), |
| 312 | 'pl' => __( 'Polish', 'premium-addons-for-elementor' ), |
| 313 | 'pt' => __( 'Portuguese', 'premium-addons-for-elementor' ), |
| 314 | 'pt-BR' => __( 'Portuguese (brazil)', 'premium-addons-for-elementor' ), |
| 315 | 'pt-PT' => __( 'Portuguese (portugal)', 'premium-addons-for-elementor' ), |
| 316 | 'ro' => __( 'Romanian', 'premium-addons-for-elementor' ), |
| 317 | 'ru' => __( 'Russian', 'premium-addons-for-elementor' ), |
| 318 | 'sk' => __( 'Slovak', 'premium-addons-for-elementor' ), |
| 319 | 'sl' => __( 'Slovenian', 'premium-addons-for-elementor' ), |
| 320 | 'sr' => __( 'Serbian', 'premium-addons-for-elementor' ), |
| 321 | 'sv' => __( 'Swedish', 'premium-addons-for-elementor' ), |
| 322 | 'tl' => __( 'Tagalog', 'premium-addons-for-elementor' ), |
| 323 | 'ta' => __( 'Tamil', 'premium-addons-for-elementor' ), |
| 324 | 'te' => __( 'Telugu', 'premium-addons-for-elementor' ), |
| 325 | 'th' => __( 'Thai', 'premium-addons-for-elementor' ), |
| 326 | 'tr' => __( 'Turkish', 'premium-addons-for-elementor' ), |
| 327 | 'uk' => __( 'Ukrainian', 'premium-addons-for-elementor' ), |
| 328 | 'vi' => __( 'Vietnamese', 'premium-addons-for-elementor' ), |
| 329 | 'zh-CN' => __( 'Chinese (simplified)', 'premium-addons-for-elementor' ), |
| 330 | 'zh-TW' => __( 'Chinese (traditional)', 'premium-addons-for-elementor' ), |
| 331 | ); |
| 332 | } |
| 333 | |
| 334 | return self::$google_localize; |
| 335 | |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Checks if a plugin is installed |
| 340 | * |
| 341 | * @since 1.0.0 |
| 342 | * @access public |
| 343 | * |
| 344 | * @param string $plugin_path plugin path. |
| 345 | * |
| 346 | * @return boolean |
| 347 | */ |
| 348 | public static function is_plugin_installed( $plugin_path ) { |
| 349 | |
| 350 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 351 | |
| 352 | $plugins = get_plugins(); |
| 353 | |
| 354 | return isset( $plugins[ $plugin_path ] ); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Check Plugin Active |
| 359 | * |
| 360 | * @since 4.2.5 |
| 361 | * @access public |
| 362 | * |
| 363 | * @param string $slug plugin slug. |
| 364 | * |
| 365 | * @return boolean $is_active plugin active. |
| 366 | */ |
| 367 | public static function check_plugin_active( $slug = '' ) { |
| 368 | |
| 369 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 370 | |
| 371 | $is_active = in_array( $slug, (array) get_option( 'active_plugins', array() ), true ); |
| 372 | |
| 373 | return $is_active; |
| 374 | |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Check if script debug mode enabled. |
| 379 | * |
| 380 | * @since 3.11.1 |
| 381 | * @access public |
| 382 | * |
| 383 | * @return boolean is debug mode enabled |
| 384 | */ |
| 385 | public static function is_debug_enabled() { |
| 386 | |
| 387 | if ( null === self::$script_debug ) { |
| 388 | |
| 389 | self::$script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; |
| 390 | } |
| 391 | |
| 392 | return self::$script_debug; |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Get scripts dir. |
| 397 | * |
| 398 | * @access public |
| 399 | * |
| 400 | * @return string JS scripts directory. |
| 401 | */ |
| 402 | public static function get_scripts_dir() { |
| 403 | |
| 404 | if ( null === self::$js_dir ) { |
| 405 | |
| 406 | self::$js_dir = self::is_debug_enabled() ? 'js' : 'min-js'; |
| 407 | } |
| 408 | |
| 409 | return self::$js_dir; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Get styles dir. |
| 414 | * |
| 415 | * @access public |
| 416 | * |
| 417 | * @return string CSS files directory. |
| 418 | */ |
| 419 | public static function get_styles_dir() { |
| 420 | |
| 421 | if ( null === self::$css_dir ) { |
| 422 | |
| 423 | self::$css_dir = self::is_debug_enabled() ? 'css' : 'min-css'; |
| 424 | } |
| 425 | |
| 426 | return self::$css_dir; |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Get assets suffix. |
| 431 | * |
| 432 | * @access public |
| 433 | * |
| 434 | * @return string JS scripts suffix. |
| 435 | */ |
| 436 | public static function get_assets_suffix() { |
| 437 | |
| 438 | if ( null === self::$assets_suffix ) { |
| 439 | |
| 440 | self::$assets_suffix = self::is_debug_enabled() ? '' : '.min'; |
| 441 | } |
| 442 | |
| 443 | return self::$assets_suffix; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Get Installed Theme |
| 448 | * |
| 449 | * Returns the active theme slug |
| 450 | * |
| 451 | * @access public |
| 452 | * |
| 453 | * @return string theme slug |
| 454 | */ |
| 455 | public static function get_installed_theme() { |
| 456 | |
| 457 | $theme = wp_get_theme(); |
| 458 | |
| 459 | if ( $theme->parent() ) { |
| 460 | |
| 461 | $theme_name = sanitize_key( $theme->parent()->get( 'Name' ) ); |
| 462 | |
| 463 | return $theme_name; |
| 464 | |
| 465 | } |
| 466 | |
| 467 | $theme_name = $theme->get( 'Name' ); |
| 468 | |
| 469 | $theme_name = sanitize_key( $theme_name ); |
| 470 | |
| 471 | return $theme_name; |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * Get Vimeo Video Data |
| 476 | * |
| 477 | * Get video data using Vimeo API |
| 478 | * |
| 479 | * @since 3.11.4 |
| 480 | * @access public |
| 481 | * |
| 482 | * @param string $video_id video ID. |
| 483 | */ |
| 484 | public static function get_vimeo_video_data( $video_id ) { |
| 485 | |
| 486 | $vimeo_data = wp_remote_get( 'http://www.vimeo.com/api/v2/video/' . intval( $video_id ) . '.php' ); |
| 487 | |
| 488 | if ( is_wp_error( $vimeo_data ) ) { |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | if ( isset( $vimeo_data['response']['code'] ) ) { |
| 493 | |
| 494 | if ( 200 === $vimeo_data['response']['code'] ) { |
| 495 | |
| 496 | $response = maybe_unserialize( $vimeo_data['body'] ); |
| 497 | $thumbnail = isset( $response[0]['thumbnail_large'] ) ? $response[0]['thumbnail_large'] : false; |
| 498 | |
| 499 | $data = array( |
| 500 | 'src' => $thumbnail, |
| 501 | 'url' => $response[0]['user_url'], |
| 502 | 'portrait' => $response[0]['user_portrait_huge'], |
| 503 | 'title' => $response[0]['title'], |
| 504 | 'user' => $response[0]['user_name'], |
| 505 | ); |
| 506 | |
| 507 | return $data; |
| 508 | |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | return false; |
| 513 | |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Get Video Thumbnail |
| 518 | * |
| 519 | * Get thumbnail URL for embed or self hosted |
| 520 | * |
| 521 | * @since 3.7.0 |
| 522 | * @access public |
| 523 | * |
| 524 | * @param string $video_id video ID. |
| 525 | * @param string $type embed type. |
| 526 | * @param string $size youtube thumbnail size. |
| 527 | */ |
| 528 | public static function get_video_thumbnail( $video_id, $type, $size = '' ) { |
| 529 | |
| 530 | $thumbnail_src = 'transparent'; |
| 531 | |
| 532 | if ( 'youtube' === $type ) { |
| 533 | if ( '' === $size ) { |
| 534 | $size = 'maxresdefault'; |
| 535 | } |
| 536 | $thumbnail_src = sprintf( 'https://i.ytimg.com/vi/%s/%s.jpg', $video_id, $size ); |
| 537 | |
| 538 | } elseif ( 'vimeo' === $type ) { |
| 539 | |
| 540 | $vimeo = self::get_vimeo_video_data( $video_id ); |
| 541 | |
| 542 | $thumbnail_src = $vimeo['src']; |
| 543 | |
| 544 | } elseif ( 'dailymotion' === $type ) { |
| 545 | $video_data = rplg_urlopen( 'https://api.dailymotion.com/video/' . $video_id . '?fields=thumbnail_url' ); |
| 546 | |
| 547 | if ( isset( $video_data['code'] ) ) { |
| 548 | if ( 404 === $video_data['code'] ) { |
| 549 | return $thumbnail_src; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | $thumbnail_src = rplg_json_decode( $video_data['data'] )->thumbnail_url; |
| 554 | } |
| 555 | |
| 556 | return $thumbnail_src; |
| 557 | |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Transient Expire |
| 562 | * |
| 563 | * Gets expire time of transient. |
| 564 | * |
| 565 | * @since 3.20.8 |
| 566 | * @access public |
| 567 | * |
| 568 | * @param string $period transient expiration period. |
| 569 | * |
| 570 | * @return string $expire_time expire time in seconds. |
| 571 | */ |
| 572 | public static function transient_expire( $period ) { |
| 573 | |
| 574 | $expire_time = 24 * HOUR_IN_SECONDS; |
| 575 | |
| 576 | switch ( $period ) { |
| 577 | case 'minute': |
| 578 | $expire_time = MINUTE_IN_SECONDS; |
| 579 | break; |
| 580 | case 'minutes': |
| 581 | $expire_time = 5 * MINUTE_IN_SECONDS; |
| 582 | break; |
| 583 | case 'hour': |
| 584 | $expire_time = 60 * MINUTE_IN_SECONDS; |
| 585 | break; |
| 586 | case 'week': |
| 587 | $expire_time = 7 * DAY_IN_SECONDS; |
| 588 | break; |
| 589 | case 'month': |
| 590 | $expire_time = 30 * DAY_IN_SECONDS; |
| 591 | break; |
| 592 | case 'year': |
| 593 | $expire_time = 365 * DAY_IN_SECONDS; |
| 594 | break; |
| 595 | default: |
| 596 | $expire_time = 24 * HOUR_IN_SECONDS; |
| 597 | } |
| 598 | |
| 599 | return $expire_time; |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * Get Campaign Link |
| 604 | * |
| 605 | * @since 3.20.9 |
| 606 | * @access public |
| 607 | * |
| 608 | * @param string $link page link. |
| 609 | * @param string $source source. |
| 610 | * @param string $medium media. |
| 611 | * @param string $campaign campaign name. |
| 612 | * |
| 613 | * @return string $link campaign URL |
| 614 | */ |
| 615 | public static function get_campaign_link( $link, $source, $medium, $campaign = '' ) { |
| 616 | |
| 617 | $theme = self::get_installed_theme(); |
| 618 | |
| 619 | $url = add_query_arg( |
| 620 | array( |
| 621 | 'utm_source' => $source, |
| 622 | 'utm_medium' => $medium, |
| 623 | 'utm_campaign' => $campaign, |
| 624 | 'utm_term' => $theme, |
| 625 | ), |
| 626 | $link |
| 627 | ); |
| 628 | |
| 629 | return $url; |
| 630 | |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Get Elementor UI Theme |
| 635 | * |
| 636 | * Detects user setting for UI theme |
| 637 | * |
| 638 | * @since 3.21.1 |
| 639 | * @access public |
| 640 | * |
| 641 | * @return string $theme UI Theme |
| 642 | */ |
| 643 | public static function get_elementor_ui_theme() { |
| 644 | |
| 645 | $theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); |
| 646 | |
| 647 | return $theme; |
| 648 | |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Check PAPRO Version |
| 653 | * |
| 654 | * Check if PAPRO version is updated |
| 655 | * |
| 656 | * @since 3.21.6 |
| 657 | * @access public |
| 658 | * |
| 659 | * @return boolen $is_updated |
| 660 | */ |
| 661 | public static function check_papro_version() { |
| 662 | |
| 663 | if ( ! defined( 'PREMIUM_PRO_ADDONS_VERSION' ) ) { |
| 664 | return false; |
| 665 | } |
| 666 | |
| 667 | $is_updated = get_option( 'papro_updated', true ); |
| 668 | |
| 669 | return $is_updated; |
| 670 | |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Valide HTML Tag |
| 675 | * |
| 676 | * Validates an HTML tag against a safe allowed list. |
| 677 | * |
| 678 | * @param string $tag HTML tag. |
| 679 | * |
| 680 | * @return string |
| 681 | */ |
| 682 | public static function validate_html_tag( $tag ) { |
| 683 | return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS, true ) ? $tag : 'div'; |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Get Image Data |
| 688 | * |
| 689 | * Returns image data based on image id. |
| 690 | * |
| 691 | * @since 0.0.1 |
| 692 | * @access public |
| 693 | * |
| 694 | * @param int $image_id Image ID. |
| 695 | * @param string $image_url Image URL. |
| 696 | * @param array $image_size Image sizes array. |
| 697 | * |
| 698 | * @return array $data image data. |
| 699 | */ |
| 700 | public static function get_image_data( $image_id, $image_url, $image_size ) { |
| 701 | |
| 702 | if ( ! $image_id && ! $image_url ) { |
| 703 | return false; |
| 704 | } |
| 705 | |
| 706 | $data = array(); |
| 707 | |
| 708 | $image_url = esc_url_raw( $image_url ); |
| 709 | |
| 710 | if ( ! empty( $image_id ) ) { // Existing attachment. |
| 711 | |
| 712 | $attachment = get_post( $image_id ); |
| 713 | |
| 714 | if ( is_object( $attachment ) ) { |
| 715 | $data['id'] = $image_id; |
| 716 | $data['url'] = $image_url; |
| 717 | |
| 718 | $data['image'] = wp_get_attachment_image( $attachment->ID, $image_size, true ); |
| 719 | $data['image_size'] = $image_size; |
| 720 | $data['caption'] = $attachment->post_excerpt; |
| 721 | $data['title'] = $attachment->post_title; |
| 722 | $data['description'] = $attachment->post_content; |
| 723 | |
| 724 | } |
| 725 | } else { // Placeholder image, most likely. |
| 726 | |
| 727 | if ( empty( $image_url ) ) { |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | $data['id'] = false; |
| 732 | $data['url'] = $image_url; |
| 733 | $data['image'] = '<img src="' . $image_url . '" alt="" title="" />'; |
| 734 | $data['image_size'] = $image_size; |
| 735 | $data['caption'] = ''; |
| 736 | $data['title'] = ''; |
| 737 | $data['description'] = ''; |
| 738 | } |
| 739 | |
| 740 | return $data; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Get Final Result. |
| 745 | * |
| 746 | * @access public |
| 747 | * @since 4.4.8 |
| 748 | * |
| 749 | * @param bool $condition_result result. |
| 750 | * @param string $operator operator. |
| 751 | * |
| 752 | * @return bool |
| 753 | */ |
| 754 | public static function get_final_result( $condition_result, $operator ) { |
| 755 | |
| 756 | if ( 'is' === $operator ) { |
| 757 | return true === $condition_result; |
| 758 | } else { |
| 759 | return true !== $condition_result; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Get Local Time ( WordPress TimeZone Setting ). |
| 765 | * |
| 766 | * @access public |
| 767 | * @since 4.4.8 |
| 768 | * |
| 769 | * @param string $format format. |
| 770 | */ |
| 771 | public static function get_local_time( $format ) { |
| 772 | |
| 773 | $local_time_zone = isset( $_COOKIE['localTimeZone'] ) && ! empty( $_COOKIE['localTimeZone'] ) ? |
| 774 | str_replace( 'GMT ', 'GMT+', sanitize_text_field( wp_unslash( $_COOKIE['localTimeZone'] ) ) ) |
| 775 | : date_default_timezone_get(); |
| 776 | |
| 777 | $today = new \DateTime( 'now', new \DateTimeZone( $local_time_zone ) ); |
| 778 | |
| 779 | return $today->format( $format ); |
| 780 | } |
| 781 | |
| 782 | /** |
| 783 | * Get Site Server Time ( WordPress TimeZone Setting ). |
| 784 | * |
| 785 | * @access public |
| 786 | * @since 4.4.8 |
| 787 | * |
| 788 | * @param string $format format. |
| 789 | */ |
| 790 | public static function get_site_server_time( $format ) { |
| 791 | |
| 792 | $today = gmdate( $format, strtotime( 'now' ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ); |
| 793 | |
| 794 | return $today; |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Get All Breakpoints. |
| 799 | * |
| 800 | * @param string $type result return type. |
| 801 | * |
| 802 | * @access public |
| 803 | * @since 4.6.1 |
| 804 | * |
| 805 | * @return array $devices enabled breakpoints. |
| 806 | */ |
| 807 | public static function get_all_breakpoints( $type = 'assoc' ) { |
| 808 | |
| 809 | $devices = array( |
| 810 | 'desktop' => __( 'Desktop', 'elementor' ), |
| 811 | 'tablet' => __( 'Tablet', 'elementor' ), |
| 812 | 'mobile' => __( 'Mobile', 'elementor' ), |
| 813 | ); |
| 814 | |
| 815 | $method_available = method_exists( Plugin::$instance->breakpoints, 'has_custom_breakpoints' ); |
| 816 | |
| 817 | if ( ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.4.0', '>' ) ) && $method_available ) { |
| 818 | |
| 819 | if ( Plugin::$instance->breakpoints->has_custom_breakpoints() ) { |
| 820 | $devices = array_merge( |
| 821 | $devices, |
| 822 | array( |
| 823 | 'widescreen' => __( 'Widescreen', 'elementor' ), |
| 824 | 'laptop' => __( 'Laptop', 'elementor' ), |
| 825 | 'tablet_extra' => __( 'Tablet Extra', 'elementor' ), |
| 826 | 'mobile_extra' => __( 'Mobile Extra', 'elementor' ), |
| 827 | ) |
| 828 | ); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | if ( 'keys' === $type ) { |
| 833 | $devices = array_keys( $devices ); |
| 834 | } |
| 835 | |
| 836 | return $devices; |
| 837 | |
| 838 | } |
| 839 | |
| 840 | /** |
| 841 | * Get WordPress language prefixes. |
| 842 | * |
| 843 | * @since 4.4.8 |
| 844 | * @access public |
| 845 | * |
| 846 | * @return array |
| 847 | */ |
| 848 | public static function get_lang_prefixes() { |
| 849 | |
| 850 | if ( null === self::$lang_locales ) { |
| 851 | |
| 852 | $langs = require_once PREMIUM_ADDONS_PATH . 'includes/pa-display-conditions/lang-locale.php'; |
| 853 | |
| 854 | foreach ( $langs as $lang => $props ) { |
| 855 | /* translators: %s: Language Name */ |
| 856 | $val = ucwords( $props['name'] ); |
| 857 | self::$lang_locales[ $lang ] = $val; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | return self::$lang_locales; |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * Get Woocommerce Categories. |
| 866 | * |
| 867 | * @access public |
| 868 | * @since 4.4.8 |
| 869 | * |
| 870 | * @param string $id array key. |
| 871 | * |
| 872 | * @return array |
| 873 | */ |
| 874 | public static function get_woo_categories( $id = 'slug' ) { |
| 875 | |
| 876 | $product_cat = array(); |
| 877 | |
| 878 | $cat_args = array( |
| 879 | 'orderby' => 'name', |
| 880 | 'order' => 'asc', |
| 881 | 'hide_empty' => false, |
| 882 | ); |
| 883 | |
| 884 | $product_categories = get_terms( 'product_cat', $cat_args ); |
| 885 | |
| 886 | if ( ! empty( $product_categories ) ) { |
| 887 | |
| 888 | foreach ( $product_categories as $key => $category ) { |
| 889 | |
| 890 | $cat_id = 'slug' === $id ? $category->slug : $category->term_id; |
| 891 | $product_cat[ $cat_id ] = $category->name; |
| 892 | |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | return $product_cat; |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Check Elementor Experiment |
| 901 | * |
| 902 | * Check if an Elementor experiment is enabled. |
| 903 | * |
| 904 | * @since 4.8.6 |
| 905 | * @access public |
| 906 | * |
| 907 | * @param string $experiment feature ID. |
| 908 | * |
| 909 | * @return boolean $is_enabled is feature enabled. |
| 910 | */ |
| 911 | public static function check_elementor_experiment( $experiment ) { |
| 912 | |
| 913 | $experiments_manager = Plugin::$instance->experiments; |
| 914 | |
| 915 | $is_enabled = $experiments_manager->is_feature_active( $experiment ); |
| 916 | |
| 917 | return $is_enabled; |
| 918 | |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Is Edit Mode. |
| 923 | * |
| 924 | * @access public |
| 925 | * @since 4.6.1 |
| 926 | * |
| 927 | * @return boolean |
| 928 | */ |
| 929 | public static function is_edit_mode() { |
| 930 | return isset( $_REQUEST['elementor-preview'] ) && ! empty( $_REQUEST['elementor-preview'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * Generate Unique ID |
| 935 | * |
| 936 | * Generates a unique ID for the current page. |
| 937 | * |
| 938 | * @since 4.6.9 |
| 939 | * @access public |
| 940 | * |
| 941 | * @param string $id page ID. |
| 942 | * |
| 943 | * @return string unique ID. |
| 944 | */ |
| 945 | public static function generate_unique_id( $id ) { |
| 946 | return substr( md5( $id ), 0, 9 ); |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * Get Safe Path |
| 951 | * |
| 952 | * @since 4.6.9 |
| 953 | * @access public |
| 954 | * |
| 955 | * @param string $file_path unsafe file path. |
| 956 | * |
| 957 | * @return string safe file path. |
| 958 | */ |
| 959 | public static function get_safe_path( $file_path ) { |
| 960 | |
| 961 | $path = str_replace( array( '//', '\\\\' ), array( '/', '\\' ), $file_path ); |
| 962 | |
| 963 | return str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $path ); |
| 964 | |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * Check if the current post type should include addons. |
| 969 | * |
| 970 | * @param string $id current post ID. |
| 971 | * |
| 972 | * @since 4.9.18 |
| 973 | * @access public |
| 974 | */ |
| 975 | public static function check_post_type( $id ) { |
| 976 | |
| 977 | if ( ! $id ) { |
| 978 | return false; |
| 979 | } |
| 980 | |
| 981 | $template_name = get_post_meta( $id, '_elementor_template_type', true ); |
| 982 | |
| 983 | $template_list = array( |
| 984 | 'header', |
| 985 | 'footer', |
| 986 | 'single', |
| 987 | 'post', |
| 988 | 'page', |
| 989 | 'archive', |
| 990 | 'search-results', |
| 991 | 'error-404', |
| 992 | 'product', |
| 993 | 'product-archive', |
| 994 | 'section', |
| 995 | ); |
| 996 | |
| 997 | return in_array( $template_name, $template_list ); |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * Get Draw SVG Notice |
| 1002 | * |
| 1003 | * @since 4.9.26 |
| 1004 | * @access public |
| 1005 | * |
| 1006 | * @param object $elem element object. |
| 1007 | * @param string $search search query. |
| 1008 | * @param array $conditions control conditions |
| 1009 | */ |
| 1010 | public static function get_draw_svg_notice( $elem, $search, $conditions, $index = 0 ) { |
| 1011 | |
| 1012 | $url = add_query_arg( |
| 1013 | array( |
| 1014 | 'page' => sprintf( 'premium-addons&search=%s#tab=elements', $search ), |
| 1015 | ), |
| 1016 | esc_url( admin_url( 'admin.php' ) ) |
| 1017 | ); |
| 1018 | |
| 1019 | $elem->add_control( |
| 1020 | 'draw_svg_notice_' . $index, |
| 1021 | array( |
| 1022 | 'type' => Controls_Manager::RAW_HTML, |
| 1023 | 'raw' => __( 'You need first to enable SVG Draw option checkbox from ', 'premium-addons-for-elementor' ) . '<a href="' . esc_url( $url ) . '" target="_blank">' . __( 'here.', 'premium-addons-for-elementor' ) . '</a>', |
| 1024 | 'classes' => 'editor-pa-control-notice', |
| 1025 | 'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning', |
| 1026 | 'condition' => $conditions, |
| 1027 | ) |
| 1028 | ); |
| 1029 | |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * Checks if Elementor PRO 3.8 or higher is activated && if the Loop expirement is activated. |
| 1034 | * |
| 1035 | * @since 4.9.45 |
| 1036 | * @access public |
| 1037 | * |
| 1038 | * @return bool |
| 1039 | */ |
| 1040 | public static function is_loop_exp_enabled() { |
| 1041 | |
| 1042 | if ( defined( 'ELEMENTOR_PRO_VERSION' ) && version_compare( ELEMENTOR_PRO_VERSION, '3.8', '>=' ) ) { |
| 1043 | $is_loop_enabled = self::check_elementor_experiment( 'loop' ); |
| 1044 | |
| 1045 | if ( $is_loop_enabled ) { |
| 1046 | return true; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * Get Element Classes. |
| 1055 | * |
| 1056 | * @access private |
| 1057 | * @since 2.8.22 |
| 1058 | * |
| 1059 | * @param array $devices devices to hide on. |
| 1060 | * |
| 1061 | * @return array |
| 1062 | */ |
| 1063 | public static function get_element_classes( $devices, $default = array() ) { |
| 1064 | |
| 1065 | $classes = $default; |
| 1066 | |
| 1067 | if ( count( $devices ) ) { |
| 1068 | foreach ( $devices as $index => $device ) { |
| 1069 | array_push( $classes, 'elementor-hidden-' . $device ); |
| 1070 | } |
| 1071 | |
| 1072 | array_push( $classes, 'premium-addons-element' ); |
| 1073 | } |
| 1074 | |
| 1075 | return $classes; |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * Round Numbers In A Reading-friendly Format. |
| 1080 | * |
| 1081 | * @param integer $num followers number. |
| 1082 | */ |
| 1083 | public static function premium_format_numbers( $num ) { |
| 1084 | $num = intval( $num ); |
| 1085 | $result = ''; |
| 1086 | |
| 1087 | if ( $num >= 1000000000 ) { |
| 1088 | $tmp = round( ( $num / 1000000 ), 1 ); |
| 1089 | $result = $tmp . 'B'; |
| 1090 | return $result; |
| 1091 | } |
| 1092 | |
| 1093 | if ( $num >= 1000000 ) { |
| 1094 | $tmp = round( ( $num / 1000000 ), 1 ); |
| 1095 | $result = $tmp . 'M'; |
| 1096 | return $result; |
| 1097 | } |
| 1098 | |
| 1099 | if ( $num >= 1000 ) { |
| 1100 | $tmp = round( ( $num / 1000 ), 1 ); |
| 1101 | $result = $tmp . 'K'; |
| 1102 | |
| 1103 | return $result; |
| 1104 | } |
| 1105 | |
| 1106 | return round( $num, 1 ); |
| 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * Get Contact Form Body |
| 1111 | * |
| 1112 | * @since 4.10.2 |
| 1113 | * @access public |
| 1114 | * |
| 1115 | * @param string $preset form preset. |
| 1116 | * |
| 1117 | * @return void |
| 1118 | */ |
| 1119 | public static function get_cf_form_body( $preset ) { |
| 1120 | |
| 1121 | $forms_array = array( |
| 1122 | |
| 1123 | 'preset1' => '<div class="premium-cf-full"><label class="premium-cf-label">Email</label> |
| 1124 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1125 | [submit "Subscribe"]', |
| 1126 | |
| 1127 | 'preset2' => '<div class="premium-cf-full"><label class="premium-cf-label">Name</label> |
| 1128 | [text* text-1 class:premium-cf-field placeholder "John Smith"]</div> |
| 1129 | |
| 1130 | <div class="premium-cf-full"><label class="premium-cf-label">Email</label> |
| 1131 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1132 | |
| 1133 | [submit "Send"]', |
| 1134 | |
| 1135 | 'preset3' => '<div class="premium-cf-full"><label class="premium-cf-label">Name</label> |
| 1136 | [text* text-1 class:premium-cf-field placeholder "John Smith"]</div> |
| 1137 | |
| 1138 | <div class="premium-cf-full"><label class="premium-cf-label">Email</label> |
| 1139 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1140 | |
| 1141 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1142 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1143 | |
| 1144 | [submit "Send"]', |
| 1145 | |
| 1146 | 'preset4' => '<div class="premium-cf-half"><label class="premium-cf-label">Name</label> |
| 1147 | [text* text-1 class:premium-cf-field placeholder "John Smith"]</div> |
| 1148 | |
| 1149 | <div class="premium-cf-half"><label class="premium-cf-label">Email</label> |
| 1150 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1151 | |
| 1152 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1153 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1154 | |
| 1155 | [submit "Send"]', |
| 1156 | |
| 1157 | 'preset5' => '<div class="premium-cf-half"><label class="premium-cf-label">First Name</label> |
| 1158 | [text* text-1 class:premium-cf-field placeholder "John"]</div> |
| 1159 | |
| 1160 | <div class="premium-cf-half"><label class="premium-cf-label">Last Name</label> |
| 1161 | [text* text-2 class:premium-cf-field placeholder "Smith"]</div> |
| 1162 | |
| 1163 | <div class="premium-cf-half"><label class="premium-cf-label">Email</label> |
| 1164 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1165 | |
| 1166 | <div class="premium-cf-half"><label class="premium-cf-label">Phone</label> |
| 1167 | [tel* tel-1 class:premium-cf-field placeholder "+13137262547"]</div> |
| 1168 | |
| 1169 | <div class="premium-cf-full"><label class="premium-cf-label">Gender</label> |
| 1170 | [select menu-1 "Male" "Female"]</div> |
| 1171 | |
| 1172 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1173 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1174 | [submit "Send"]', |
| 1175 | |
| 1176 | 'preset6' => '<div class="premium-cf-half"><label class="premium-cf-label">First Name</label> |
| 1177 | [text* text-1 class:premium-cf-field placeholder "John"]</div> |
| 1178 | |
| 1179 | <div class="premium-cf-half"><label class="premium-cf-label">Last Name</label> |
| 1180 | [text* text-2 class:premium-cf-field placeholder "Smith"]</div> |
| 1181 | |
| 1182 | <div class="premium-cf-half"><label class="premium-cf-label">Email</label> |
| 1183 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1184 | |
| 1185 | <div class="premium-cf-half"><label class="premium-cf-label">Phone</label> |
| 1186 | [tel* tel-1 class:premium-cf-field placeholder "+13137262547"]</div> |
| 1187 | |
| 1188 | <div class="premium-cf-full"><label class="premium-cf-label">Company Size</label> |
| 1189 | [radio radio-1 default:1 "1-10 employees" "11-30 employees" "30-50 employees" "Above 50 employee"] |
| 1190 | </div> |
| 1191 | |
| 1192 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1193 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1194 | [submit "Send"]', |
| 1195 | |
| 1196 | ); |
| 1197 | |
| 1198 | return $forms_array[ $preset ]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1199 | |
| 1200 | } |
| 1201 | |
| 1202 | } |
| 1203 |