modules
5 days ago
woocommerce
5 days ago
utilities.php
5 days ago
wpr-custom-meta-keys.php
5 days ago
utilities.php
1478 lines
| 1 | <?php |
| 2 | namespace WprAddons\Classes; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | exit; // Exit if accessed directly |
| 6 | } |
| 7 | |
| 8 | class Utilities { |
| 9 | |
| 10 | /** |
| 11 | ** Get Plugin Name |
| 12 | */ |
| 13 | public static function get_plugin_name($full = false) { |
| 14 | return class_exists('\WprAddonsPro\Admin\Wpr_White_Label') ? \WprAddonsPro\Admin\Wpr_White_Label::get_plugin_name($full) : 'Royal Addons'; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | ** Get Available Modules |
| 19 | */ |
| 20 | public static function get_registered_modules() { |
| 21 | return [ |
| 22 | 'Post Grid/Slider/Carousel' => ['grid', 'https://royal-elementor-addons.com/elementor-grid-widget-examples/', '#filter:category-blog-grid', ''], |
| 23 | 'WooCommerce Grid/Slider/Carousel' => ['woo-grid', 'https://royal-elementor-addons.com/elementor-grid-widget-examples/', '#filter:category-woo-grid', ''], |
| 24 | 'Image Grid/Slider/Carousel' => ['media-grid', 'https://royal-elementor-addons.com/elementor-grid-widget-examples/', '#filter:category-gallery-grid', ''], |
| 25 | 'Magazine Grid/Slider' => ['magazine-grid', 'https://royal-elementor-addons.com/elementor-grid-widget-examples/', '#filter:category-magazine-grid', ''], |
| 26 | 'Posts/Story Timeline' => ['posts-timeline', 'https://royal-elementor-addons.com/elementor-timeline-widget/', '', ''], |
| 27 | 'Advanced Slider' => ['advanced-slider', 'https://royal-elementor-addons.com/elementor-advanced-slider-widget/', '', ''], |
| 28 | 'Off-Canvas Content' => ['offcanvas', 'https://royal-elementor-addons.com/elementor-offcanvas-menu-widget/', '', 'new'], |
| 29 | 'Testimonial' => ['testimonial', 'https://royal-elementor-addons.com/elementor-testimonials-slider-widget/', '', ''], |
| 30 | 'Nav Menu' => ['nav-menu', 'http://royal-elementor-addons.com/elementor-menu-widget/', '', ''], |
| 31 | 'Mega Menu' => ['mega-menu', 'https://royal-elementor-addons.com/elementor-mega-menu-widget/', '', 'new'], |
| 32 | 'Form Builder' => ['form-builder', 'https://royal-elementor-addons.com/elementor-form-builder-widget/', '', 'new'], |
| 33 | 'Onepage Navigation' => ['onepage-nav', 'https://royal-elementor-addons.com/elementor-one-page-navigation-widget/', '', ''], |
| 34 | 'Instagram Feed' => ['instagram-feed', 'https://royal-elementor-addons.com/elementor-instagram-feed-widget/', '', 'new'], |
| 35 | 'Data Table' => ['data-table', 'https://royal-elementor-addons.com/elementor-data-table-widget/', '', ''], |
| 36 | 'Pricing Table' => ['pricing-table', 'https://royal-elementor-addons.com/elementor-pricing-table-widget/', '', ''], |
| 37 | 'Content Toggle' => ['content-toggle', 'https://royal-elementor-addons.com/elementor-content-toggle-widget/', '', ''], |
| 38 | 'Charts' => ['charts', 'https://royal-elementor-addons.com/elementor-charts-widget/', '', ''], |
| 39 | 'Countdown' => ['countdown', 'https://royal-elementor-addons.com/elementor-countdown-widget/', '', ''], |
| 40 | 'Progress Bar' => ['progress-bar', 'https://royal-elementor-addons.com/elementor-progress-bar-widget/', '', ''], |
| 41 | 'Tabs' => ['tabs', 'https://royal-elementor-addons.com/elementor-tabs-widget/', '', ''], |
| 42 | 'Dual Color Heading' => ['dual-color-heading', 'https://royal-elementor-addons.com/elementor-dual-color-heading-widget/', '', ''], |
| 43 | 'Image Accordion' => ['image-accordion', 'https://royal-elementor-addons.com/elementor-image-accordion-widget/', '', ''], |
| 44 | 'Advanced Accordion' => ['advanced-accordion', 'https://royal-elementor-addons.com/elementor-advanced-accordion-widget/', '', ''], |
| 45 | 'Advanced Text' => ['advanced-text', 'https://royal-elementor-addons.com/elementor-advanced-text-widget/', '', ''], |
| 46 | 'Flip Carousel' => ['flip-carousel', 'https://royal-elementor-addons.com/elementor-flip-carousel-widget/', '', ''], |
| 47 | 'Flip Box' => ['flip-box', 'https://royal-elementor-addons.com/elementor-flip-box-widget/', '', ''], |
| 48 | 'Promo Box' => ['promo-box', 'https://royal-elementor-addons.com/elementor-promo-box-widget/', '', ''], |
| 49 | 'Feature List' => ['feature-list', 'https://royal-elementor-addons.com/elementor-feature-list-widget/', '', ''], |
| 50 | 'Before After' => ['before-after', 'https://royal-elementor-addons.com/elementor-before-after-widget/', '', ''], |
| 51 | 'Image Hotspots' => ['image-hotspots', 'https://royal-elementor-addons.com/elementor-image-hotspot-widget/', '', ''], |
| 52 | 'Form Styler' => ['forms', 'https://royal-elementor-addons.com/elementor-forms-widget/', '', ''], |
| 53 | 'MailChimp' => ['mailchimp', 'https://royal-elementor-addons.com/elementor-mailchimp-subscription-widget/', '', ''], |
| 54 | 'Content Ticker' => ['content-ticker', 'https://royal-elementor-addons.com/elementor-content-ticker-widget/', '', ''], |
| 55 | 'Button' => ['button', 'https://royal-elementor-addons.com/elementor-button-widget/', '', ''], |
| 56 | 'Dual Button' => ['dual-button', 'https://royal-elementor-addons.com/elementor-button-widget/', '#dualbuttonsection', ''], |
| 57 | 'Team Member' => ['team-member', 'https://royal-elementor-addons.com/elementor-team-member-widget/', '', ''], |
| 58 | 'Google Maps' => ['google-maps', 'http://royal-elementor-addons.com/elementor-google-maps-widget/', '', ''], |
| 59 | 'Price List' => ['price-list', 'https://royal-elementor-addons.com/elementor-price-list-widget/', '', ''], |
| 60 | 'Business Hours' => ['business-hours', 'https://royal-elementor-addons.com/elementor-business-hours-widget/', '', ''], |
| 61 | 'Sharing Buttons' => ['sharing-buttons', 'https://royal-elementor-addons.com/elementor-social-sharing-buttons-widget/', '', ''], |
| 62 | 'Search Form (Ajax)' => ['search', 'https://royal-elementor-addons.com/elementor-search-widget/', '', ''], |
| 63 | 'Back to Top' => ['back-to-top', 'https://royal-elementor-addons.com/elementor-back-to-top-widget/', '', ''], |
| 64 | 'Phone Call' => ['phone-call', 'https://royal-elementor-addons.com/elementor-phone-call-widget/', '', ''], |
| 65 | 'Lottie Animations' => ['lottie-animations', 'https://royal-elementor-addons.com/elementor-lottie-animation-widget/', '', ''], |
| 66 | 'Site Logo' => ['logo', '', '', ''], |
| 67 | 'Popup Trigger' => ['popup-trigger', '', '', ''], |
| 68 | 'Taxonomy List' => ['taxonomy-list', '', '', ''], |
| 69 | 'Page List' => ['page-list', '', '', ''], |
| 70 | 'Template' => ['elementor-template', '', '', ''], |
| 71 | 'Reading Progress Bar' => ['reading-progress-bar', 'https://royal-elementor-addons.com/elementor-reading-progress-bar-widget/', '', ''], |
| 72 | 'Twitter Feed' => ['twitter-feed', 'https://royal-elementor-addons.com/elementor-twitter-feed-widget/', '', ''], |
| 73 | 'Image Scroll' => ['image-scroll', 'https://royal-elementor-addons.com/image-scroll/', '', ''], |
| 74 | 'Date' => ['date', 'https://royal-elementor-addons.com/elementor-date-widget/', '', ''], |
| 75 | 'Video Playlist' => ['video-playlist', 'https://royal-elementor-addons.com/video-playlist/', '', 'new'], |
| 76 | 'Password Protected Content' => ['password-protected-content', 'https://royal-elementor-addons.com/password-protected-content/', '', 'new'], |
| 77 | 'Icon Box' => ['icon-box', '', '', 'new'], |
| 78 | 'Separator' => ['separator', '', '', 'new'], |
| 79 | // 'Random Image' => ['random-image', '', '', 'new'], |
| 80 | 'Circle Menu' => ['circle-menu', 'https://royal-elementor-addons.com/circle-menu/', '', 'new'], |
| 81 | 'Unfold' => ['unfold', 'https://royal-elementor-addons.com/unfold-widget/', '', 'new'], |
| 82 | ]; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | ** Get Enabled Modules |
| 87 | */ |
| 88 | public static function get_available_modules( $modules ) { |
| 89 | foreach ( $modules as $title => $data ) { |
| 90 | $slug = $data[0]; |
| 91 | if ( 'on' !== get_option('wpr-element-'. $slug, 'on') ) { |
| 92 | unset($modules[$title]); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return $modules; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | ** Get Theme Builder Modules |
| 101 | */ |
| 102 | public static function get_theme_builder_modules() { |
| 103 | return [ |
| 104 | 'Post Title' => ['post-title', '', '', ''], |
| 105 | 'Post Media' => ['post-media', '', '', ''], |
| 106 | 'Post Content' => ['post-content', '', '', ''], |
| 107 | 'Post Info' => ['post-info', '', '', ''], |
| 108 | 'Post Navigation' => ['post-navigation', '', '', ''], |
| 109 | 'Post Comments' => ['post-comments', '', '', ''], |
| 110 | 'Author Box' => ['author-box', '', '', ''], |
| 111 | 'Archive Title' => ['archive-title', '', '', ''], |
| 112 | ]; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | ** Get WooCommerce Builder Modules |
| 117 | */ |
| 118 | public static function get_woocommerce_builder_modules() { |
| 119 | return [ |
| 120 | 'Product Title' => ['product-title', '', '', ''], |
| 121 | 'Product Media' => ['product-media', '', '', ''], |
| 122 | 'Product Price' => ['product-price', '', '', ''], |
| 123 | 'Product Add to Cart' => ['product-add-to-cart', '', '', ''], |
| 124 | 'Product Tabs' => ['product-tabs', '', '', ''], |
| 125 | 'Product Excerpt' => ['product-excerpt', '', '', ''], |
| 126 | 'Product Description' => ['product-description', '', '', ''], |
| 127 | 'Product Rating' => ['product-rating', '', '', ''], |
| 128 | 'Product Meta' => ['product-meta', '', '', ''], |
| 129 | 'Product Sales Badge' => ['product-sales-badge', '', '', ''], |
| 130 | 'Product Stock' => ['product-stock', '', '', ''], |
| 131 | 'Product Additional Info' => ['product-additional-information', '', '', ''], |
| 132 | 'Product Notice' => ['product-notice', '', '', ''], |
| 133 | 'Product Mini Cart' => ['product-mini-cart', '', '', ''], |
| 134 | 'Page: Cart' => ['page-cart', '', '', ''], |
| 135 | 'Page: Checkout ' => ['page-checkout', '', '', ''], |
| 136 | ]; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | ** Get Shop Page URL |
| 141 | */ |
| 142 | public static function get_shop_url( $settings ) { |
| 143 | global $wp; |
| 144 | |
| 145 | if ( '' == get_option('permalink_structure' ) ) { |
| 146 | $url = remove_query_arg(array('page', 'paged'), add_query_arg($wp->query_string, '', home_url($wp->request))); |
| 147 | } else { |
| 148 | $url = preg_replace('%\/page/[0-9]+%', '', home_url(trailingslashit($wp->request))); |
| 149 | } |
| 150 | |
| 151 | // WPR Filters |
| 152 | $url = add_query_arg( 'wprfilters', '', $url ); |
| 153 | |
| 154 | // Min/Max. |
| 155 | if ( isset( $_GET['min_price'] ) ) { |
| 156 | $url = add_query_arg( 'min_price', wc_clean( wp_unslash( $_GET['min_price'] ) ), $url ); |
| 157 | } |
| 158 | |
| 159 | if ( isset( $_GET['max_price'] ) ) { |
| 160 | $url = add_query_arg( 'max_price', wc_clean( wp_unslash( $_GET['max_price'] ) ), $url ); |
| 161 | } |
| 162 | |
| 163 | // Search |
| 164 | if ( isset( $_GET['psearch'] ) ) { |
| 165 | $url = add_query_arg( 'psearch', wp_unslash( $_GET['psearch'] ), $url ); |
| 166 | } |
| 167 | |
| 168 | // Rating |
| 169 | if ( isset( $_GET['filter_rating'] ) ) { |
| 170 | $url = add_query_arg( 'filter_rating', wp_unslash( $_GET['filter_rating'] ), $url ); |
| 171 | } |
| 172 | |
| 173 | // Categories |
| 174 | if ( isset( $_GET['filter_product_cat'] ) ) { |
| 175 | $url = add_query_arg( 'filter_product_cat', wp_unslash( $_GET['filter_product_cat'] ), $url ); |
| 176 | } |
| 177 | |
| 178 | // Tags |
| 179 | if ( isset( $_GET['filter_product_tag'] ) ) { |
| 180 | $url = add_query_arg( 'filter_product_tag', wp_unslash( $_GET['filter_product_tag'] ), $url ); |
| 181 | } |
| 182 | |
| 183 | // All current filters. |
| 184 | if ( $_chosen_attributes = WC()->query->get_layered_nav_chosen_attributes() ) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure, WordPress.CodeAnalysis.AssignmentInCondition.Found |
| 185 | foreach ( $_chosen_attributes as $name => $data ) { |
| 186 | $filter_name = wc_attribute_taxonomy_slug( $name ); |
| 187 | if ( ! empty( $data['terms'] ) ) { |
| 188 | $url = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $url ); |
| 189 | } |
| 190 | |
| 191 | if ( !empty($settings) ) { |
| 192 | if ( 'or' === $settings['tax_query_type'] || isset($_GET['query_type_' . $filter_name]) ) { |
| 193 | $url = add_query_arg( 'query_type_' . $filter_name, 'or', $url ); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // Sorting |
| 200 | if ( isset( $_GET['orderby'] ) ) { |
| 201 | $url = add_query_arg( 'orderby', wp_unslash( $_GET['orderby'] ), $url ); |
| 202 | } |
| 203 | |
| 204 | // Fix URL |
| 205 | // $url = str_replace( '%2C', ',', $url ); |
| 206 | |
| 207 | return $url; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /** |
| 212 | ** Get Available Custom Post Types or Taxonomies |
| 213 | */ |
| 214 | public static function get_custom_types_of( $query, $exclude_defaults = true ) { |
| 215 | // Taxonomies |
| 216 | if ( 'tax' === $query ) { |
| 217 | $custom_types = get_taxonomies( [ 'show_in_nav_menus' => true ], 'objects' ); |
| 218 | |
| 219 | // Post Types |
| 220 | } else { |
| 221 | $custom_types = get_post_types( [ 'show_in_nav_menus' => true ], 'objects' ); |
| 222 | } |
| 223 | |
| 224 | $custom_type_list = []; |
| 225 | |
| 226 | foreach ( $custom_types as $key => $value ) { |
| 227 | if ( $exclude_defaults ) { |
| 228 | if ( $key != 'post' && $key != 'page' && $key != 'category' && $key != 'post_tag' ) { |
| 229 | $custom_type_list[ $key ] = $value->label; |
| 230 | } |
| 231 | } else { |
| 232 | $custom_type_list[ $key ] = $value->label; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | return $custom_type_list; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | /** |
| 241 | ** Get Available WooCommerce Taxonomies |
| 242 | */ |
| 243 | public static function get_woo_taxonomies() { |
| 244 | $taxonomy_list = []; |
| 245 | |
| 246 | foreach ( get_object_taxonomies( 'product' ) as $taxonomy_data ) { |
| 247 | $taxonomy = get_taxonomy( $taxonomy_data ); |
| 248 | if( $taxonomy->show_ui ) { |
| 249 | $taxonomy_list[ $taxonomy_data ] = $taxonomy->label; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return $taxonomy_list; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | /** |
| 258 | ** Get All Users |
| 259 | */ |
| 260 | public static function get_users() { |
| 261 | $users = []; |
| 262 | |
| 263 | if ( is_admin() ) { |
| 264 | foreach ( get_users() as $key => $user ) { |
| 265 | $users[$user->data->ID] = $user->data->user_nicename; |
| 266 | } |
| 267 | |
| 268 | wp_reset_postdata(); |
| 269 | } |
| 270 | |
| 271 | return $users; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | /** |
| 276 | ** Get User Roles |
| 277 | */ |
| 278 | public static function get_user_roles() { |
| 279 | if ( ! function_exists( 'get_editable_roles' ) ) { |
| 280 | require_once ABSPATH . 'wp-admin/includes/user.php'; |
| 281 | } |
| 282 | |
| 283 | $r = []; |
| 284 | |
| 285 | $editable_roles = array_reverse( get_editable_roles() ); |
| 286 | |
| 287 | $r['guest'] = esc_html__( 'Guest', 'wpr-addons' ); |
| 288 | |
| 289 | foreach ( $editable_roles as $role => $details ) { |
| 290 | $r[ $role ] = translate_user_role( $details['name'] ); |
| 291 | } |
| 292 | |
| 293 | return $r; |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /** |
| 298 | ** Get Terms of Taxonomy |
| 299 | */ |
| 300 | public static function get_terms_by_taxonomy( $slug ) { |
| 301 | if ( ( 'product_cat' === $slug || 'product_tag' === $slug ) && ! class_exists( 'WooCommerce' ) ) { |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | $query = get_terms( $slug, [ 'hide_empty' => false, 'posts_per_page' => -1 ] ); |
| 306 | $taxonomies = []; |
| 307 | |
| 308 | foreach ( $query as $tax ) { |
| 309 | $taxonomies[$tax->term_id] = $tax->name; |
| 310 | } |
| 311 | |
| 312 | wp_reset_postdata(); |
| 313 | |
| 314 | return $taxonomies; |
| 315 | } |
| 316 | |
| 317 | |
| 318 | /** |
| 319 | ** Get Posts of Post Type |
| 320 | */ |
| 321 | public static function get_posts_by_post_type( $slug ) { |
| 322 | $posts = []; |
| 323 | |
| 324 | if ( is_admin() ) { |
| 325 | $query = get_posts( [ 'post_type' => $slug, 'posts_per_page' => -1 ] ); |
| 326 | |
| 327 | foreach ( $query as $post ) { |
| 328 | $posts[$post->ID] = $post->post_title; |
| 329 | } |
| 330 | |
| 331 | wp_reset_postdata(); |
| 332 | } |
| 333 | |
| 334 | return $posts; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | /** |
| 339 | ** Get Library Template ID |
| 340 | */ |
| 341 | public static function get_template_id( $slug ) { |
| 342 | |
| 343 | $template = get_page_by_path( $slug, OBJECT, 'wpr_templates' ); |
| 344 | |
| 345 | return isset( $template->ID ) ? $template->ID : false; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | ** Check Single Conditions Array |
| 350 | */ |
| 351 | public static function check_id_in_path($path, $id) { |
| 352 | // Step 1: Remove any prefix up to and including the last slash if present |
| 353 | $last_slash_position = strrpos($path, '/'); |
| 354 | $numeric_part = $last_slash_position !== false ? substr($path, $last_slash_position + 1) : $path; |
| 355 | |
| 356 | // Step 2: Extract numbers (assuming they are separated by commas or spaces) |
| 357 | preg_match_all('/\d+/', $numeric_part, $matches); |
| 358 | |
| 359 | // The numbers are now in $matches[0] as an array |
| 360 | $ids = $matches[0]; |
| 361 | |
| 362 | // Step 3: Check if the specific $id is in the array of IDs |
| 363 | return in_array($id, $ids); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | ** Get Library Template Slug |
| 368 | */ |
| 369 | public static function get_template_slug( $data, $page, $post_id = '' ) { |
| 370 | if ( is_null($data) ) { |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | $template = NULL; |
| 375 | |
| 376 | // Find a Custom Condition |
| 377 | foreach( $data as $id => $conditions ) { |
| 378 | if ( in_array( $page .'/'. $post_id, $conditions) ) { |
| 379 | $template = $id; |
| 380 | } elseif ( in_array( $page .'/all', $conditions) && !in_array( $page .'/'. $post_id, $conditions) ) { |
| 381 | $template = $id; |
| 382 | } elseif ( in_array( $page, $conditions) && !in_array( $page .'/'. $post_id, $conditions) ) { |
| 383 | $template = $id; |
| 384 | } elseif ( array_filter($conditions, function($condition) use ($page) { return strpos($condition, $page) !== false; }) ) { |
| 385 | // Handles Taxonomy Conditions for Single Post/Product (check CPT) |
| 386 | $has_additional_slash = array_filter($conditions, function($condition) use ($page) { |
| 387 | $page_position = strpos($condition, $page . '/'); |
| 388 | return $page_position !== false && strpos($condition, '/', $page_position + strlen($page) + 1) !== false; |
| 389 | }); |
| 390 | |
| 391 | if ($has_additional_slash) { |
| 392 | // Extract the taxonomy name and term ID from the condition |
| 393 | foreach ($conditions as $condition) { |
| 394 | $parts = explode('/', $condition); |
| 395 | if (count($parts) >= 3) { |
| 396 | $taxonomy_name = $parts[2]; |
| 397 | $term_id = $parts[3]; |
| 398 | |
| 399 | // Check if the $post_id has the term of the specified taxonomy |
| 400 | if (has_term($term_id, $taxonomy_name, $post_id)) { |
| 401 | $template = $id; |
| 402 | break; |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) { |
| 410 | foreach ( $conditions as $key => $value ) { |
| 411 | if ( Utilities::check_id_in_path( $value, $post_id ) ) { |
| 412 | $template = $id; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | // If a Custom NOT Found, use Global |
| 419 | if ( is_null($template) ) { |
| 420 | foreach( $data as $id => $conditions ) { |
| 421 | if ( in_array( 'global', $conditions) ) { |
| 422 | $template = $id; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | if ( !empty($template) ) { |
| 428 | // tmp remove after 2 months |
| 429 | $templates_loop = new \WP_Query([ |
| 430 | 'post_type' => 'wpr_templates', |
| 431 | 'name' => $template, |
| 432 | 'posts_per_page' => 1, |
| 433 | ]); |
| 434 | |
| 435 | if ( ! $templates_loop->have_posts() ) { |
| 436 | if ( defined('ICL_LANGUAGE_CODE') ) { |
| 437 | $original_post = get_page_by_path($template, OBJECT, 'wpr_templates'); |
| 438 | if ( $original_post ) { |
| 439 | $original_post_id = $original_post->ID; |
| 440 | $language_code = ICL_LANGUAGE_CODE; |
| 441 | |
| 442 | $translated_post_id = icl_object_id($original_post_id, 'wpr_templates', false, $language_code); |
| 443 | |
| 444 | if ( $translated_post_id ) { |
| 445 | $translated_post = get_post($translated_post_id); |
| 446 | $translated_slug = $translated_post->post_name; |
| 447 | |
| 448 | if ( $translated_slug ) { |
| 449 | $template = $translated_slug; |
| 450 | } else { |
| 451 | $template = null; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | } else { |
| 456 | $template = null; |
| 457 | } |
| 458 | } else { |
| 459 | $template = $template; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | return $template; |
| 464 | } |
| 465 | |
| 466 | |
| 467 | /** |
| 468 | ** Get Elementor Template Type |
| 469 | */ |
| 470 | public static function get_elementor_template_type( $id ) { |
| 471 | $post_meta = get_post_meta($id); |
| 472 | $template_type = isset($post_meta['_elementor_template_type'][0]) ? $post_meta['_elementor_template_type'][0] : false; |
| 473 | |
| 474 | return $template_type; |
| 475 | } |
| 476 | |
| 477 | |
| 478 | /** |
| 479 | ** Get Royal Template Type |
| 480 | */ |
| 481 | public static function get_wpr_template_type( $id ) { |
| 482 | $post_meta = get_post_meta($id); |
| 483 | $template_type = isset($post_meta['_wpr_template_type'][0]) ? $post_meta['_wpr_template_type'][0] : false; |
| 484 | |
| 485 | return $template_type; |
| 486 | } |
| 487 | |
| 488 | |
| 489 | /** |
| 490 | ** Theme Builder Show Widgets on Spacific Pages |
| 491 | */ |
| 492 | public static function show_theme_buider_widget_on( $type ) { |
| 493 | global $post; |
| 494 | $display = false; |
| 495 | |
| 496 | if ( Utilities::is_theme_builder_template() ) { |
| 497 | $template_type = Utilities::get_wpr_template_type(get_the_ID()); |
| 498 | |
| 499 | if ( $type === $template_type ) { |
| 500 | $display = true; |
| 501 | } |
| 502 | |
| 503 | $conditions = json_decode(get_option('wpr_single_conditions')); |
| 504 | $front_page = Utilities::get_template_slug($conditions, 'single/front_page', get_the_ID()); |
| 505 | $page_404 = Utilities::get_template_slug($conditions, 'single/page_404', get_the_ID()); |
| 506 | |
| 507 | if ( $post->post_name == $front_page || $post->post_name == $page_404 ) { |
| 508 | $display = false; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | return $display; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | /** |
| 517 | ** Render Elementor Template |
| 518 | */ |
| 519 | public static function render_elementor_template( $slug, $template_id = null ) { |
| 520 | if ( empty( $template_id ) ) { |
| 521 | $template_id = Utilities::get_template_id( $slug ); |
| 522 | } |
| 523 | $type = get_post_meta(get_the_ID(), '_wpr_template_type', true) || get_post_meta($template_id, '_elementor_template_type', true); |
| 524 | $has_css = 'internal' === get_option( 'elementor_css_print_method' ) || '' !== $type; |
| 525 | $get_elementor_content = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id, $has_css); |
| 526 | |
| 527 | if ( '' === $get_elementor_content ) { |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | // Render Elementor Template Content |
| 532 | echo ''. $get_elementor_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 533 | } |
| 534 | |
| 535 | |
| 536 | /** |
| 537 | ** Enqueue a nested/inner Elementor template's widget assets and CSS. |
| 538 | ** Ensures icon fonts and widget-specific styles are loaded when a |
| 539 | ** template is rendered inside another widget (Offcanvas, Tabs, etc.). |
| 540 | */ |
| 541 | public static function enqueue_inner_template_assets( $template_id ) { |
| 542 | if ( empty( $template_id ) || ! class_exists( '\Elementor\Plugin' ) ) { |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | $elementor = \Elementor\Plugin::instance(); |
| 547 | |
| 548 | // Ensure Elementor frontend style handle exists for nested/AJAX renders. |
| 549 | // if ( isset( $elementor->frontend ) && ! wp_style_is( 'elementor-frontend', 'registered' ) ) { |
| 550 | // $elementor->frontend->register_styles(); |
| 551 | // } |
| 552 | |
| 553 | // if ( wp_style_is( 'elementor-frontend', 'registered' ) && ! wp_style_is( 'elementor-frontend', 'enqueued' ) ) { |
| 554 | // wp_enqueue_style( 'elementor-frontend' ); |
| 555 | // } |
| 556 | |
| 557 | // Enable widget-level asset dependencies (icon fonts, widget CSS files) |
| 558 | // stored in the template's post meta by Elementor's asset system. |
| 559 | if ( class_exists( '\Elementor\Core\Base\Elements_Iteration_Actions\Assets' ) ) { |
| 560 | $page_assets = get_post_meta( $template_id, \Elementor\Core\Base\Elements_Iteration_Actions\Assets::ASSETS_META_KEY, true ); |
| 561 | if ( ! empty( $page_assets ) && isset( $elementor->assets_loader ) ) { |
| 562 | $elementor->assets_loader->enable_assets( $page_assets ); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | // Enqueue the template's own Post CSS file. |
| 567 | if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) { |
| 568 | $css_file = new \Elementor\Core\Files\CSS\Post( $template_id ); |
| 569 | $css_file->enqueue(); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | |
| 574 | /** |
| 575 | ** Theme Builder Template Check |
| 576 | */ |
| 577 | public static function is_theme_builder_template() { |
| 578 | $current_page = get_post(get_the_ID()); |
| 579 | |
| 580 | if ( $current_page ) { |
| 581 | return strpos($current_page->post_name, 'user-archive') !== false || strpos($current_page->post_name, 'user-single') !== false || strpos($current_page->post_name, 'user-product') !== false; |
| 582 | } else { |
| 583 | return false; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | |
| 588 | /** |
| 589 | ** Blog Archive Page Check |
| 590 | */ |
| 591 | public static function is_blog_archive() { |
| 592 | $result = false; |
| 593 | $front_page = get_option( 'page_on_front' ); |
| 594 | $posts_page = get_option( 'page_for_posts' ); |
| 595 | |
| 596 | if ( is_home() && '0' === $front_page && '0' === $posts_page || (intval($posts_page) === get_queried_object_id() && !is_404()) ) { |
| 597 | $result = true; |
| 598 | } |
| 599 | |
| 600 | return $result; |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | ** Disable Extra Image Sizes |
| 605 | */ |
| 606 | public static function disable_extra_image_sizes( $new_sizes, $image_meta, $attachment_id ) { |
| 607 | $all_attachments = get_option( 'st_attachments', array() ); |
| 608 | |
| 609 | // If the cron job is already scheduled, bail. |
| 610 | if ( in_array( $attachment_id, $all_attachments, true ) ) { |
| 611 | return $new_sizes; |
| 612 | } |
| 613 | |
| 614 | $all_attachments[] = $attachment_id; |
| 615 | |
| 616 | update_option( 'st_attachments', $all_attachments, 'no' ); |
| 617 | |
| 618 | // Return blank array of sizes to not generate any sizes in this request. |
| 619 | return array(); |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | ** Regenerate Extra Image Sizes |
| 624 | */ |
| 625 | public static function regenerate_extra_image_sizes() { |
| 626 | $all_attachments = get_option( 'st_attachments', array() ); |
| 627 | |
| 628 | if ( empty( $all_attachments ) ) { |
| 629 | return; |
| 630 | } |
| 631 | |
| 632 | foreach ( $all_attachments as $attachment_id ) { |
| 633 | $file = get_attached_file( $attachment_id ); |
| 634 | if ( false !== $file ) { |
| 635 | wp_generate_attachment_metadata( $attachment_id, $file ); |
| 636 | } |
| 637 | } |
| 638 | update_option( 'st_attachments', array(), 'no' ); |
| 639 | } |
| 640 | |
| 641 | // Get Post Sharing Icon |
| 642 | public static function get_post_sharing_icon( $args = [] ) { |
| 643 | |
| 644 | $args['url'] = esc_url($args['url']); |
| 645 | |
| 646 | if ( 'facebook-f' === $args['network'] ) { |
| 647 | $sharing_url = 'https://www.facebook.com/sharer.php?u='. $args['url']; |
| 648 | $network_title = esc_html__( 'Facebook', 'wpr-addons' ); |
| 649 | } elseif ( 'twitter' === $args['network'] ) { |
| 650 | $sharing_url = 'https://twitter.com/intent/tweet?url='. $args['url']; |
| 651 | $network_title = esc_html__( 'Twitter', 'wpr-addons' ); |
| 652 | } elseif ( 'linkedin-in' === $args['network'] ) { |
| 653 | $sharing_url = 'https://www.linkedin.com/shareArticle?mini=true&url='. $args['url'] .'&title='. $args['title'] .'&summary='. $args['text'] .'&source='. $args['url']; |
| 654 | $network_title = esc_html__( 'LinkedIn', 'wpr-addons' ); |
| 655 | } elseif ( 'pinterest-p' === $args['network'] ) { |
| 656 | // $sharing_url = 'https://www.pinterest.com/pin/find/?url='. $args['url']; |
| 657 | $sharing_url = 'https://www.pinterest.com/pin/create/button/?url='. $args['url'] .'&media='. $args['image']; |
| 658 | $network_title = esc_html__( 'Pinterest', 'wpr-addons' ); |
| 659 | } elseif ( 'reddit' === $args['network'] ) { |
| 660 | $sharing_url = 'https://reddit.com/submit?url='. $args['url'] .'&title='. $args['title']; |
| 661 | $network_title = esc_html__( 'Reddit', 'wpr-addons' ); |
| 662 | } elseif ( 'tumblr' === $args['network'] ) { |
| 663 | $sharing_url = 'https://tumblr.com/share/link?url='. $args['url']; |
| 664 | $network_title = esc_html__( 'Tumblr', 'wpr-addons' ); |
| 665 | } elseif ( 'digg' === $args['network'] ) { |
| 666 | $sharing_url = 'https://digg.com/submit?url='. $args['url']; |
| 667 | $network_title = esc_html__( 'Digg', 'wpr-addons' ); |
| 668 | } elseif ( 'xing' === $args['network'] ) { |
| 669 | $sharing_url = 'https://www.xing.com/app/user?op=share&url='. $args['url']; |
| 670 | $network_title = esc_html__( 'Xing', 'wpr-addons' ); |
| 671 | } elseif ( 'stumbleupon' === $args['network'] ) { |
| 672 | $sharing_url = 'https://www.stumbleupon.com/submit?url='. $args['url']; |
| 673 | $network_title = esc_html__( 'StumpleUpon', 'wpr-addons' ); |
| 674 | } elseif ( 'vk' === $args['network'] ) { |
| 675 | $sharing_url = 'https://vkontakte.ru/share.php?url='. $args['url'] .'&title='. $args['title'] .'&description='. wp_trim_words( $args['text'], 250 ) .'&image='. $args['image'] .'/'; |
| 676 | $network_title = esc_html__( 'vKontakte', 'wpr-addons' ); |
| 677 | } elseif ( 'odnoklassniki' === $args['network'] ) { |
| 678 | $sharing_url = 'http://odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st._surl='. $args['url']; |
| 679 | $network_title = esc_html__( 'OdnoKlassniki', 'wpr-addons' ); |
| 680 | } elseif ( 'get-pocket' === $args['network'] ) { |
| 681 | $sharing_url = 'https://getpocket.com/edit?url='. $args['url']; |
| 682 | $network_title = esc_html__( 'Pocket', 'wpr-addons' ); |
| 683 | } elseif ( 'skype' === $args['network'] ) { |
| 684 | $sharing_url = 'https://web.skype.com/share?url='. $args['url']; |
| 685 | $network_title = esc_html__( 'Skype', 'wpr-addons' ); |
| 686 | } elseif ( 'whatsapp' === $args['network'] ) { |
| 687 | if ( 'yes' === $args['show_whatsapp_title'] && 'yes' == $args['show_whatsapp_excerpt'] ) { |
| 688 | $sharing_url = 'https://api.whatsapp.com/send?text=*'. $args['title'] .'*%0a'. wp_strip_all_tags($args['text']) .'%0a'. $args['url']; |
| 689 | } else if ( 'yes' === $args['show_whatsapp_title'] ) { |
| 690 | $sharing_url = 'https://api.whatsapp.com/send?text=*'. $args['title'] .'*%0a'. $args['url']; |
| 691 | } else if ( 'yes' === $args['show_whatsapp_excerpt'] ) { |
| 692 | $sharing_url = 'https://api.whatsapp.com/send?text=*'. wp_strip_all_tags($args['text']) .'%0a'. $args['url']; |
| 693 | } else { |
| 694 | $sharing_url = 'https://api.whatsapp.com/send?text='. $args['url']; |
| 695 | } |
| 696 | $network_title = esc_html__( 'WhatsApp', 'wpr-addons' ); |
| 697 | } elseif ( 'telegram' === $args['network'] ) { |
| 698 | $sharing_url = 'https://telegram.me/share/url?url='. $args['url'] .'&text='. $args['text']; |
| 699 | $network_title = esc_html__( 'Telegram', 'wpr-addons' ); |
| 700 | } elseif ( 'delicious' === $args['network'] ) { |
| 701 | $sharing_url = 'https://del.icio.us/save?url='. $args['url'] .'&title={title}'; |
| 702 | $network_title = esc_html__( 'Delicious', 'wpr-addons' ); |
| 703 | } elseif ( 'envelope' === $args['network'] ) { |
| 704 | $sharing_url = 'mailto:?subject='. $args['title'] .'&body='. $args['url']; |
| 705 | $network_title = esc_html__( 'Email', 'wpr-addons' ); |
| 706 | } elseif ( 'print' === $args['network'] ) { |
| 707 | $sharing_url = 'javascript:window.print()'; |
| 708 | $network_title = esc_html__( 'Print', 'wpr-addons' ); |
| 709 | } else { |
| 710 | $sharing_url = ''; |
| 711 | $network_title = ''; |
| 712 | } |
| 713 | |
| 714 | $sharing_url = 'print' === $args['network'] ? $sharing_url : $sharing_url; |
| 715 | |
| 716 | $output = ''; |
| 717 | |
| 718 | if ( '' !== $network_title ) { |
| 719 | $output .= '<a href="'. $sharing_url .'" class="wpr-sharing-icon wpr-sharing-'. esc_attr( $args['network'] ) .'" title="" target="_blank">'; |
| 720 | // Tooltip |
| 721 | $output .= 'yes' === $args['tooltip'] ? '<span class="wpr-sharing-tooltip wpr-tooltip">'. esc_html( $network_title ) .'</span>' : ''; |
| 722 | |
| 723 | // Category |
| 724 | if ( 'envelope' === $args['network'] || 'print' === $args['network'] ) { |
| 725 | $category = 'fas'; |
| 726 | } else { |
| 727 | $category = 'fab'; |
| 728 | } |
| 729 | |
| 730 | // Icon |
| 731 | if ( 'yes' === $args['icons'] ) { |
| 732 | $output .= '<i class="'. esc_attr($category) .' fa-'. esc_attr( $args['network'] ) .'"></i>'; |
| 733 | } |
| 734 | |
| 735 | // Label |
| 736 | if ( isset( $args['labels'] ) && 'yes' === $args['labels'] ) { |
| 737 | $label = isset( $args['custom_label'] ) && '' !== $args['custom_label'] ? $args['custom_label'] : $network_title; |
| 738 | $output .= '<span class="wpr-sharing-label">'. esc_html( $label ) .'</span>'; |
| 739 | } |
| 740 | $output .= '</a>'; |
| 741 | } |
| 742 | |
| 743 | return $output; |
| 744 | } |
| 745 | |
| 746 | |
| 747 | /** |
| 748 | ** Filter oEmbed Results |
| 749 | */ |
| 750 | public static function filter_oembed_results( $html ) { |
| 751 | // Filter |
| 752 | preg_match( '/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $html, $matches ); |
| 753 | |
| 754 | // Return URL |
| 755 | return $matches[1] .'&auto_play=true'; |
| 756 | } |
| 757 | |
| 758 | |
| 759 | /** |
| 760 | ** Get Post Custom Meta Keys |
| 761 | */ |
| 762 | public static function get_custom_meta_keys() { // needs ajaxifying |
| 763 | $data = []; |
| 764 | $options = []; |
| 765 | $merged_meta_keys = []; |
| 766 | $post_types = Utilities::get_custom_types_of( 'post', false ); |
| 767 | |
| 768 | foreach ( $post_types as $post_type_slug => $post_type_name ) { |
| 769 | $data[ $post_type_slug ] = []; |
| 770 | $posts = get_posts( [ 'post_type' => $post_type_slug, 'posts_per_page' => -1 ] ); |
| 771 | |
| 772 | foreach ( $posts as $key => $post ) { |
| 773 | $meta_keys = get_post_custom_keys( $post->ID ); |
| 774 | |
| 775 | if ( ! empty($meta_keys) ) { |
| 776 | for ( $i = 0; $i < count( $meta_keys ); $i++ ) { |
| 777 | if ( '_' !== substr( $meta_keys[$i], 0, 1 ) ) { |
| 778 | array_push( $data[$post_type_slug], $meta_keys[$i] ); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | $data[ $post_type_slug ] = array_unique( $data[ $post_type_slug ] ); |
| 785 | } |
| 786 | |
| 787 | foreach ( $data as $array ) { |
| 788 | $merged_meta_keys = array_unique( array_merge( $merged_meta_keys, $array ) ); |
| 789 | } |
| 790 | |
| 791 | // Rekey |
| 792 | $merged_meta_keys = array_values($merged_meta_keys); |
| 793 | |
| 794 | for ( $i = 0; $i < count( $merged_meta_keys ); $i++ ) { |
| 795 | $options[ $merged_meta_keys[$i] ] = $merged_meta_keys[$i]; |
| 796 | } |
| 797 | |
| 798 | return [ $data, $options ]; |
| 799 | } |
| 800 | |
| 801 | |
| 802 | /** |
| 803 | ** Get Taxonomy Custom Meta Keys |
| 804 | */ |
| 805 | public static function get_custom_meta_keys_tax() { // needs ajaxifying |
| 806 | $data = []; |
| 807 | $options = []; |
| 808 | $merged_meta_keys = []; |
| 809 | $tax_types = Utilities::get_custom_types_of( 'tax', false ); |
| 810 | |
| 811 | foreach ( $tax_types as $taxonomy_slug => $post_type_name ) { |
| 812 | $data[ $taxonomy_slug ] = []; |
| 813 | $taxonomies = get_terms( $taxonomy_slug ); |
| 814 | |
| 815 | foreach ( $taxonomies as $key => $tax ) { |
| 816 | $meta_keys = get_term_meta( $tax->term_id ); |
| 817 | $meta_keys = array_keys($meta_keys); |
| 818 | |
| 819 | if ( ! empty($meta_keys) ) { |
| 820 | for ( $i = 0; $i < count( $meta_keys ); $i++ ) { |
| 821 | if ( '_' !== substr( $meta_keys[$i], 0, 1 ) ) { |
| 822 | array_push( $data[$taxonomy_slug], $meta_keys[$i] ); |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | $data[ $taxonomy_slug ] = array_unique( $data[ $taxonomy_slug ] ); |
| 829 | } |
| 830 | |
| 831 | foreach ( $data as $array ) { |
| 832 | $merged_meta_keys = array_unique( array_merge( $merged_meta_keys, $array ) ); |
| 833 | } |
| 834 | |
| 835 | // Rekey |
| 836 | $merged_meta_keys = array_values($merged_meta_keys); |
| 837 | |
| 838 | for ( $i = 0; $i < count( $merged_meta_keys ); $i++ ) { |
| 839 | $options[ $merged_meta_keys[$i] ] = $merged_meta_keys[$i]; |
| 840 | } |
| 841 | |
| 842 | return [ $data, $options ]; |
| 843 | } |
| 844 | |
| 845 | |
| 846 | /** |
| 847 | ** Get SVG Icons Array |
| 848 | */ |
| 849 | public static function get_svg_icons_array( $stack, $fa_icons ) { |
| 850 | $svg_icons = []; |
| 851 | |
| 852 | if ( 'arrows' === $stack ) { |
| 853 | $svg_icons['svg-angle-1-left'] = esc_html__( 'Angle', 'wpr-addons' ); |
| 854 | $svg_icons['svg-angle-2-left'] = esc_html__( 'Angle Bold', 'wpr-addons' ); |
| 855 | $svg_icons['svg-angle-3-left'] = esc_html__( 'Angle Bold Round', 'wpr-addons' ); |
| 856 | $svg_icons['svg-angle-4-left'] = esc_html__( 'Angle Plane', 'wpr-addons' ); |
| 857 | $svg_icons['svg-arrow-1-left'] = esc_html__( 'Arrow', 'wpr-addons' ); |
| 858 | $svg_icons['svg-arrow-2-left'] = esc_html__( 'Arrow Bold', 'wpr-addons' ); |
| 859 | $svg_icons['svg-arrow-3-left'] = esc_html__( 'Arrow Bold Round', 'wpr-addons' ); |
| 860 | $svg_icons['svg-arrow-4-left'] = esc_html__( 'Arrow Caret', 'wpr-addons' ); |
| 861 | |
| 862 | } elseif ( 'blockquote' === $stack ) { |
| 863 | $svg_icons['svg-blockquote-1'] = esc_html__( 'Blockquote Round', 'wpr-addons' ); |
| 864 | $svg_icons['svg-blockquote-2'] = esc_html__( 'Blockquote ST', 'wpr-addons' ); |
| 865 | $svg_icons['svg-blockquote-3'] = esc_html__( 'Blockquote BS', 'wpr-addons' ); |
| 866 | $svg_icons['svg-blockquote-4'] = esc_html__( 'Blockquote Edges', 'wpr-addons' ); |
| 867 | $svg_icons['svg-blockquote-5'] = esc_html__( 'Blockquote Quad', 'wpr-addons' ); |
| 868 | |
| 869 | } elseif ( 'sharing' === $stack ) { |
| 870 | // $svg_icons['svg-sharing-1'] = esc_html__( 'sharing 1', 'wpr-addons' ); |
| 871 | // $svg_icons['svg-sharing-2'] = esc_html__( 'sharing 2', 'wpr-addons' ); |
| 872 | } |
| 873 | |
| 874 | // Merge FontAwesome and SVG icons |
| 875 | return array_merge( $fa_icons, $svg_icons ); |
| 876 | } |
| 877 | |
| 878 | |
| 879 | /** |
| 880 | ** Get SVG Icon |
| 881 | */ |
| 882 | public static function get_svg_icon( $icon, $dir ) { |
| 883 | $style_attr = ''; |
| 884 | |
| 885 | // Rotate Right |
| 886 | if ( 'right' === $dir ) { |
| 887 | $style_attr = 'style="transform: rotate(180deg); -webkit-transform: rotate(180deg);" '; |
| 888 | } |
| 889 | |
| 890 | $icons = [ |
| 891 | // Arrows |
| 892 | 'svg-angle-1-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 283.4 512" style="enable-background:new 0 0 283.4 512;" xml:space="preserve"><g><polygon class="st0" points="54.5,256.3 283.4,485.1 256.1,512.5 0,256.3 0,256.3 27.2,229 256.1,0 283.4,27.4 "/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 893 | 'svg-angle-2-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 303.3 512" style="enable-background:new 0 0 303.3 512;" xml:space="preserve"><g><polygon class="st0" points="94.7,256 303.3,464.6 256,512 47.3,303.4 0,256 47.3,208.6 256,0 303.3,47.4 "/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 894 | 'svg-angle-3-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 291.4 512" style="enable-background:new 0 0 291.4 512;" xml:space="preserve"><g><path class="st0" d="M281.1,451.5c13.8,13.8,13.8,36.3,0,50.1c-13.8,13.8-36.3,13.8-50.1,0L10.4,281C3.5,274.1,0,265.1,0,256c0-9.1,3.5-18.1,10.4-25L231,10.4c13.8-13.8,36.3-13.8,50.1,0c6.9,6.9,10.4,16,10.4,25s-3.5,18.1-10.4,25L85.5,256L281.1,451.5z"/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 895 | 'svg-angle-4-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 259.6 512" style="enable-background:new 0 0 259.6 512;" xml:space="preserve"><g><path class="st0" d="M256.6,18.1L126.2,256.1l130.6,237.6c3.6,5.6,3.9,10.8,0.2,14.9c-0.2,0.2-0.2,0.3-0.3,0.3s-0.3,0.3-0.3,0.3c-3.9,3.9-10.3,3.6-14.2-0.3L2.9,263.6c-2-2.1-3.1-4.7-2.9-7.5c0-2.8,1-5.6,3.1-7.7L242,3.1c4.1-4.1,10.6-4.1,14.6,0l0,0C260.7,7.3,260.5,10.9,256.6,18.1z"/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 896 | 'svg-arrow-1-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 338.4" style="enable-background:new 0 0 512 338.4;" xml:space="preserve"><g><polygon class="st0" points="511.4,183.1 53.4,183.1 188.9,318.7 169.2,338.4 0,169.2 169.2,0 188.9,19.7 53.4,155.3 511.4,155.3 "/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 897 | 'svg-arrow-2-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 320.6" style="enable-background:new 0 0 512 320.6;" xml:space="preserve"><g><polygon class="st0" points="512,184.4 92.7,184.4 194.7,286.4 160.5,320.6 34.3,194.4 34.3,194.4 0,160.2 160.4,0 194.5,34.2 92.7,136 512,136 "/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 898 | 'svg-arrow-3-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 499.6 320.6" style="enable-background:new 0 0 499.6 320.6;" xml:space="preserve"><g><path class="st0" d="M499.6,159.3c0.3,7-2.4,13.2-7,17.9c-4.3,4.3-10.4,7-16.9,7H81.6l95.6,95.6c9.3,9.3,9.3,24.4,0,33.8c-4.6,4.6-10.8,7-16.9,7c-6.1,0-12.3-2.4-16.9-7L6.9,177.2c-9.3-9.3-9.3-24.4,0-33.8l16.9-16.9l0,0L143.3,6.9c9.3-9.3,24.4-9.3,33.8,0c4.6,4.6,7,10.8,7,16.9s-2.4,12.3-7,16.9l-95.6,95.6h393.7C488.3,136.3,499.1,146.4,499.6,159.3z"/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 899 | 'svg-arrow-4-left' => '<svg '. $style_attr .'version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 499.6 201.3" style="enable-background:new 0 0 499.6 201.3;" xml:space="preserve"><g><polygon class="st0" points="0,101.1 126,0 126,81.6 499.6,81.6 499.6,120.8 126,120.8 126,201.3 "/></g></svg>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 900 | |
| 901 | // Blockquote |
| 902 | 'svg-blockquote-1' => '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 406.1" style="enable-background:new 0 0 512 406.1;" xml:space="preserve"><g><g id="Layer_2_1_" class="st0"><path class="st1" d="M510.6,301.8c0,57.6-46.7,104.3-104.3,104.3c-12.6,0-24.7-2.3-36-6.4c-28.3-9.1-64.7-29.1-82.8-76.3C218.9,145.3,477.7,0.1,477.7,0.1l6.4,12.3c0,0-152.4,85.7-132.8,200.8C421.8,170.3,510.1,220.2,510.6,301.8z"/><path class="st1" d="M234.6,301.8c0,57.6-46.7,104.3-104.3,104.3c-12.6,0-24.7-2.3-36-6.4c-28.3-9.1-64.7-29.1-82.8-76.3C-57.1,145.3,201.8,0.1,201.8,0.1l6.4,12.3c0,0-152.4,85.7-132.8,200.8C145.9,170.3,234.1,220.2,234.6,301.8z"/></g></g></svg>', |
| 903 | 'svg-blockquote-2' => '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 415.9" style="enable-background:new 0 0 512 415.9;" xml:space="preserve"><g><g class="st0"><polygon class="st1" points="512,0 303.1,208 303.1,415.9 512,415.9 "/><polygon class="st1" points="208.9,0 0,208 0,415.9 208.9,415.9 "/></g></g></svg>', |
| 904 | 'svg-blockquote-3' => '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 369.3" style="enable-background:new 0 0 512 369.3;" xml:space="preserve"><g><g class="st0"><polygon class="st1" points="240.7,0 240.7,240.5 88.1,369.3 88.1,328.3 131.4,240.5 0.3,240.5 0.3,0 "/><polygon class="st1" points="512,43.3 512,238.6 388.1,343.2 388.1,310 423.2,238.6 316.7,238.6 316.7,43.3 "/></g></g></svg>', |
| 905 | 'svg-blockquote-4' => '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 369.3" style="enable-background:new 0 0 512 369.3;" xml:space="preserve"><g><g class="st0"><g><path class="st1" d="M469.1,299.1c-62,79.7-148.7,69.8-148.7,69.8v-86.5c0,0,42.6-0.6,77.5-35.4c20.3-20.3,22.7-65.6,22.8-81.4h-101V-10.9H512v176.6C512.2,184.7,509.4,247.2,469.1,299.1z"/></g><g><path class="st1" d="M149.3,299.1c-62,79.7-148.7,69.8-148.7,69.8v-86.5c0,0,42.6-0.6,77.5-35.4c20.3-20.3,22.7-65.6,22.8-81.4H0V-10.9h192.2v176.6C192.4,184.7,189.7,247.2,149.3,299.1z"/></g></g></g></svg>', |
| 906 | 'svg-blockquote-5' => '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 422.1" style="enable-background:new 0 0 512 422.1;" xml:space="preserve"><g><g class="st0"><polygon class="st1" points="237,0 237,223.7 169.3,422.1 25.7,422.1 53.4,223.7 0,223.7 0,0 "/><polygon class="st1" points="512,0 512,223.7 444.3,422.1 300.7,422.1 328.4,223.7 275,223.7 275,0 "/></g></g></svg>', |
| 907 | |
| 908 | // Sharing |
| 909 | 'svg-sharing-1' => '<?xml version="1.0" ?><svg style="enable-background:new 0 0 48 48;" version="1.1" viewBox="0 0 48 48" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Icons"><g id="Icons_15_"><g><path d="M25.03766,20.73608v-3.7207c0-0.3799,0.4135-0.6034,0.7263-0.4023l9.3855,5.9218 c0.3017,0.19,0.3017,0.6146,0,0.8045l-5.1844,3.2738l-1.8659,1.1843l-2.3352,1.4749c-0.3129,0.2011-0.7263-0.0335-0.7263-0.4022 v-3.2403v-0.4916" style="fill:#5F83CF;"/><path d="M29.96506,26.61318l-1.8659,1.1843l-2.3352,1.4749c-0.3128,0.2011-0.7263-0.0335-0.7263-0.4022 v-3.2403v-0.4916c-2.5759,0.1057-5.718-0.3578-7.8439,0.6112c-1.9663,0.8963-3.5457,2.5639-4.2666,4.6015 c-0.1282,0.3623-0.2296,0.7341-0.3029,1.1114v-2.9721c0-1.128,0.2449-2.2513,0.7168-3.2759 c0.4588-0.9961,1.1271-1.8927,1.948-2.6196c0.8249-0.7306,1.8013-1.2869,2.8523-1.6189 c1.5111-0.4774,3.1532-0.4118,4.7155-0.3096c0.7252,0.0475,1.4538,0.0698,2.1808,0.0698" style="fill:#5F83CF;"/></g></g></g></svg>', |
| 910 | 'svg-sharing-2' => '<?xml version="1.0" ?><svg style="enable-background:new 0 0 48 48;" version="1.1" viewBox="0 0 48 48" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Icons"><g id="Icons_16_"><g><path d="M27.775,21.64385L27.775,21.64385l1-0.01h1v1.65l2.17-1.38l0.1-0.06l2.95-1.87l-5.22-3.29v0.87 v0.77h-1l-1-0.02l0,0" style="fill:#5F83CF;"/><path d="M28.775,18.32385c-0.33,0-0.67-0.01-1-0.02c-0.22-0.01-0.43-0.02-0.65-0.04 c-1.3358-0.0496-2.5105-0.0408-3.55,0.24c-0.5,0.16-0.97,0.38-1.41,0.67c-0.26,0.16-0.51,0.34-0.74,0.55 c-0.62,0.54-1.12,1.22-1.47,1.97c-0.35,0.77-0.54,1.62-0.54,2.47v2.24c0.06-0.29,0.13-0.57,0.23-0.84 c0.54-1.53,1.73-2.79,3.22-3.47c1.34-0.61,3.21-0.47,4.91-0.45c0.35,0,0.68,0,1-0.01" style="fill:#5F83CF;"/><path d="M31.945,23.63175l-1.8884,1.1873v3.8702c0,0.5422-0.5142,0.991-1.1499,0.991H16.0432 c-0.6357,0-1.1498-0.4488-1.1498-0.991v-8.7689c0-0.5515,0.5142-1.0002,1.1498-1.0002h3.5525h0.0037 c0.0561-0.0748,0.1739-0.2057,0.2393-0.2618c0.6731-0.5983,1.4864-1.0657,2.3465-1.3368 c0.0467-0.0187,0.0935-0.0281,0.1402-0.0374h-6.2821c-1.6734,0-3.0383,1.1872-3.0383,2.6362v8.7689 c0,1.449,1.3649,2.6269,3.0383,2.6269h12.8634c1.6734,0,3.0383-1.1779,3.0383-2.6269V23.63175z" style="fill:#F2F2F2;"/></g></g></g></svg>', |
| 911 | |
| 912 | ]; |
| 913 | |
| 914 | return $icons[$icon]; |
| 915 | } |
| 916 | |
| 917 | |
| 918 | /** |
| 919 | ** Get WPR Icon |
| 920 | */ |
| 921 | public static function get_wpr_icon( $icon, $dir ) { |
| 922 | if ( !empty($icon) ) { |
| 923 | if ( false !== strpos( $icon, 'svg-' ) ) { |
| 924 | return Utilities::get_svg_icon( $icon, $dir ); |
| 925 | |
| 926 | } elseif ( false !== strpos( $icon, 'fa-' ) ) { |
| 927 | $dir = '' !== $dir ? '-'. $dir : ''; |
| 928 | return wp_kses('<i class="'. esc_attr($icon . $dir) .'"></i>', [ |
| 929 | 'i' => [ |
| 930 | 'class' => [] |
| 931 | ] |
| 932 | ]); |
| 933 | } else { |
| 934 | return ''; |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | |
| 940 | /** |
| 941 | ** Mailchimp AJAX Subscribe |
| 942 | */ |
| 943 | public static function ajax_mailchimp_subscribe() { |
| 944 | // API Key |
| 945 | $api_key = !empty(get_option('wpr_mailchimp_api_key')) && false != get_option('wpr_mailchimp_api_key') ? get_option('wpr_mailchimp_api_key') : ''; // GOGA |
| 946 | |
| 947 | $api_key_sufix = explode( '-', $api_key )[1]; |
| 948 | |
| 949 | // List ID |
| 950 | $list_id = isset($_POST['listId']) ? sanitize_text_field(wp_unslash($_POST['listId'])) : ''; |
| 951 | |
| 952 | // Get Available Fileds (PHPCS - fields are sanitized later on input) |
| 953 | $available_fields = isset($_POST['fields']) ? $_POST['fields'] : []; // phpcs:ignore |
| 954 | wp_parse_str( $available_fields, $fields ); |
| 955 | |
| 956 | // Merge Additional Fields |
| 957 | $merge_fields = array( |
| 958 | 'FNAME' => !empty( $fields['wpr_mailchimp_firstname'] ) ? sanitize_text_field($fields['wpr_mailchimp_firstname']) : '', |
| 959 | 'LNAME' => !empty( $fields['wpr_mailchimp_lastname'] ) ? sanitize_text_field($fields['wpr_mailchimp_lastname']) : '', |
| 960 | 'PHONE' => !empty ( $fields['wpr_mailchimp_phone_number'] ) ? sanitize_text_field($fields['wpr_mailchimp_phone_number']) : '', |
| 961 | ); |
| 962 | |
| 963 | // API URL |
| 964 | $api_url = 'https://'. $api_key_sufix .'.api.mailchimp.com/3.0/lists/'. $list_id .'/members/'. md5(strtolower(sanitize_text_field($fields['wpr_mailchimp_email']))); |
| 965 | |
| 966 | // API Args |
| 967 | $api_args = [ |
| 968 | 'method' => 'PUT', |
| 969 | 'headers' => [ |
| 970 | 'Content-Type' => 'application/json', |
| 971 | 'Authorization' => 'apikey '. $api_key, |
| 972 | ], |
| 973 | 'body' => json_encode([ |
| 974 | 'email_address' => sanitize_text_field($fields[ 'wpr_mailchimp_email' ]), |
| 975 | 'status' => 'subscribed', |
| 976 | 'merge_fields' => $merge_fields, |
| 977 | ]), |
| 978 | ]; |
| 979 | |
| 980 | // Send Request |
| 981 | $request = wp_remote_post( $api_url, $api_args ); |
| 982 | |
| 983 | if ( ! is_wp_error($request) ) { |
| 984 | $request = json_decode( wp_remote_retrieve_body($request) ); |
| 985 | |
| 986 | // Set Status |
| 987 | if ( ! empty($request) ) { |
| 988 | if ($request->status == 'subscribed') { |
| 989 | wp_send_json([ 'status' => 'subscribed' ]); |
| 990 | } else { |
| 991 | wp_send_json([ 'status' => $request->title ]); |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | /** |
| 998 | ** Password Protected Content - Verify Password |
| 999 | */ |
| 1000 | public static function ajax_ppc_verify_password() { |
| 1001 | check_ajax_referer( 'wpr_ppc_verify', 'nonce' ); |
| 1002 | |
| 1003 | $widget_id = isset( $_POST['widget_id'] ) ? sanitize_text_field( wp_unslash( $_POST['widget_id'] ) ) : ''; |
| 1004 | $password = isset( $_POST['password'] ) ? sanitize_text_field( wp_unslash( $_POST['password'] ) ) : ''; |
| 1005 | $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0; |
| 1006 | |
| 1007 | if ( empty( $widget_id ) || empty( $password ) || empty( $post_id ) ) { |
| 1008 | wp_send_json_error( [ 'message' => esc_html__( 'Invalid request.', 'wpr-addons' ) ] ); |
| 1009 | } |
| 1010 | |
| 1011 | // Get Elementor data for the post |
| 1012 | $elementor_data = get_post_meta( $post_id, '_elementor_data', true ); |
| 1013 | if ( empty( $elementor_data ) ) { |
| 1014 | wp_send_json_error( [ 'message' => esc_html__( 'Invalid request.', 'wpr-addons' ) ] ); |
| 1015 | } |
| 1016 | |
| 1017 | $elements = json_decode( $elementor_data, true ); |
| 1018 | if ( ! is_array( $elements ) ) { |
| 1019 | wp_send_json_error( [ 'message' => esc_html__( 'Invalid request.', 'wpr-addons' ) ] ); |
| 1020 | } |
| 1021 | |
| 1022 | // Find widget in Elementor elements tree |
| 1023 | $widget_data = self::find_widget_in_elements( $elements, $widget_id ); |
| 1024 | if ( ! $widget_data || empty( $widget_data['settings']['set_password'] ) ) { |
| 1025 | wp_send_json_error( [ 'message' => esc_html__( 'Invalid request.', 'wpr-addons' ) ] ); |
| 1026 | } |
| 1027 | |
| 1028 | $stored_password = $widget_data['settings']['set_password']; |
| 1029 | |
| 1030 | if ( $password !== $stored_password ) { |
| 1031 | wp_send_json_error( [ 'message' => esc_html__( 'Incorrect password. Please try again.', 'wpr-addons' ) ] ); |
| 1032 | } |
| 1033 | |
| 1034 | // Set cookie |
| 1035 | $cookie_name = 'wpr_ppc_' . md5( $stored_password . $widget_id ); |
| 1036 | $secure = is_ssl(); |
| 1037 | setcookie( $cookie_name, md5( $stored_password ), time() + DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN, $secure, true ); |
| 1038 | |
| 1039 | // Render protected content |
| 1040 | $settings = $widget_data['settings']; |
| 1041 | $content_html = ''; |
| 1042 | |
| 1043 | if ( isset( $settings['content_type'] ) && 'template' === $settings['content_type'] && ! empty( $settings['protected_template'] ) ) { |
| 1044 | $template_id = $settings['protected_template']; |
| 1045 | |
| 1046 | if ( defined( 'ICL_LANGUAGE_CODE' ) ) { |
| 1047 | $default_language_code = apply_filters( 'wpml_default_language', null ); |
| 1048 | if ( ICL_LANGUAGE_CODE !== $default_language_code ) { |
| 1049 | $template_id = icl_object_id( $template_id, 'elementor_library', false, ICL_LANGUAGE_CODE ); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | $type = get_post_meta( $post_id, '_wpr_template_type', true ) || get_post_meta( $template_id, '_elementor_template_type', true ); |
| 1054 | $has_css = 'internal' === get_option( 'elementor_css_print_method' ) || '' !== $type; |
| 1055 | $content_html = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id, $has_css ); |
| 1056 | } else { |
| 1057 | $content_html = isset( $settings['protected_content'] ) ? $settings['protected_content'] : ''; |
| 1058 | } |
| 1059 | |
| 1060 | wp_send_json_success( [ |
| 1061 | 'message' => esc_html__( 'Password verified.', 'wpr-addons' ), |
| 1062 | 'content' => $content_html, |
| 1063 | ] ); |
| 1064 | } |
| 1065 | |
| 1066 | /** |
| 1067 | ** Password Protected Content - Find Widget in Elements Tree |
| 1068 | */ |
| 1069 | public static function find_widget_in_elements( $elements, $widget_id ) { |
| 1070 | foreach ( $elements as $element ) { |
| 1071 | if ( isset( $element['id'] ) && $element['id'] === $widget_id ) { |
| 1072 | return $element; |
| 1073 | } |
| 1074 | |
| 1075 | if ( ! empty( $element['elements'] ) ) { |
| 1076 | $found = self::find_widget_in_elements( $element['elements'], $widget_id ); |
| 1077 | if ( $found ) { |
| 1078 | return $found; |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | return false; |
| 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | ** Mailchimp - Get Lists |
| 1088 | */ |
| 1089 | public static function get_mailchimp_lists() { |
| 1090 | $api_key = get_option('wpr_mailchimp_api_key', ''); |
| 1091 | |
| 1092 | $mailchimp_list = [ |
| 1093 | 'def' => esc_html__( 'Select List', 'wpr-addons' ) |
| 1094 | ]; |
| 1095 | |
| 1096 | if ( '' === $api_key ) { |
| 1097 | return $mailchimp_list; |
| 1098 | } else { |
| 1099 | $url = 'https://'. substr( $api_key, strpos( $api_key, '-' ) + 1 ) .'.api.mailchimp.com/3.0/lists/'; |
| 1100 | $args = [ 'headers' => [ 'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key ) ] ]; |
| 1101 | |
| 1102 | $response = wp_remote_get( $url, $args ); |
| 1103 | |
| 1104 | if ( !is_wp_error($response) ) { |
| 1105 | $body = json_decode($response['body']); |
| 1106 | |
| 1107 | if ( ! empty( $body->lists ) ) { |
| 1108 | foreach ( $body->lists as $list ) { |
| 1109 | $mailchimp_list[$list->id] = $list->name .' ('. $list->stats->member_count .')'; |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | return $mailchimp_list; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | // Needs further logic |
| 1119 | public static function get_mailchimp_groups() { |
| 1120 | $groups_array = ['def' => 'Select Group']; |
| 1121 | foreach (self::get_mailchimp_lists() as $key => $value ) { |
| 1122 | if ( 'def' === $key ) { |
| 1123 | continue; |
| 1124 | } |
| 1125 | $audience = $key; // How to get settin |
| 1126 | $api_key = get_option('wpr_mailchimp_api_key'); |
| 1127 | $url = 'https://'. substr( $api_key, strpos( $api_key, '-' ) + 1 ) .'.api.mailchimp.com/3.0/lists/'.$audience.'/interest-categories'; |
| 1128 | $args = [ 'headers' => [ 'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key ) ] ]; |
| 1129 | |
| 1130 | $response = wp_remote_get( $url, $args ); |
| 1131 | |
| 1132 | foreach ( json_decode($response['body'])->categories as $key => $value ) { |
| 1133 | $group_name = $value->title; |
| 1134 | $group_id = $value->id; |
| 1135 | $url = 'https://'. substr( $api_key, strpos( $api_key, '-' ) + 1 ) .'.api.mailchimp.com/3.0/lists/'.$audience.'/interest-categories/'. $value->id .'/interests'; |
| 1136 | $args = [ 'headers' => [ 'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key ) ] ]; |
| 1137 | |
| 1138 | $response = wp_remote_get( $url, $args ); |
| 1139 | |
| 1140 | foreach (json_decode($response['body'])->interests as $key => $value ) { |
| 1141 | // var_dump($group_name, $group_id); |
| 1142 | // var_dump($group_name, $group_id, $value->id, $value->name); |
| 1143 | $groups_array[$value->id] = $value->name; |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | return $groups_array; |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | ** WPR Animation Timings |
| 1153 | */ |
| 1154 | public static function wpr_animation_timings() { |
| 1155 | $timing_functions = [ |
| 1156 | 'ease-default' => 'Default', |
| 1157 | 'linear' => 'Linear', |
| 1158 | 'ease-in' => 'Ease In', |
| 1159 | 'ease-out' => 'Ease Out', |
| 1160 | 'pro-eio' => 'EI Out (Pro)', |
| 1161 | 'pro-eiqd' => 'EI Quad (Pro)', |
| 1162 | 'pro-eicb' => 'EI Cubic (Pro)', |
| 1163 | 'pro-eiqrt' => 'EI Quart (Pro)', |
| 1164 | 'pro-eiqnt' => 'EI Quint (Pro)', |
| 1165 | 'pro-eisn' => 'EI Sine (Pro)', |
| 1166 | 'pro-eiex' => 'EI Expo (Pro)', |
| 1167 | 'pro-eicr' => 'EI Circ (Pro)', |
| 1168 | 'pro-eibk' => 'EI Back (Pro)', |
| 1169 | 'pro-eoqd' => 'EO Quad (Pro)', |
| 1170 | 'pro-eocb' => 'EO Cubic (Pro)', |
| 1171 | 'pro-eoqrt' => 'EO Quart (Pro)', |
| 1172 | 'pro-eoqnt' => 'EO Quint (Pro)', |
| 1173 | 'pro-eosn' => 'EO Sine (Pro)', |
| 1174 | 'pro-eoex' => 'EO Expo (Pro)', |
| 1175 | 'pro-eocr' => 'EO Circ (Pro)', |
| 1176 | 'pro-eobk' => 'EO Back (Pro)', |
| 1177 | 'pro-eioqd' => 'EIO Quad (Pro)', |
| 1178 | 'pro-eiocb' => 'EIO Cubic (Pro)', |
| 1179 | 'pro-eioqrt' => 'EIO Quart (Pro)', |
| 1180 | 'pro-eioqnt' => 'EIO Quint (Pro)', |
| 1181 | 'pro-eiosn' => 'EIO Sine (Pro)', |
| 1182 | 'pro-eioex' => 'EIO Expo (Pro)', |
| 1183 | 'pro-eiocr' => 'EIO Circ (Pro)', |
| 1184 | 'pro-eiobk' => 'EIO Back (Pro)', |
| 1185 | ]; |
| 1186 | |
| 1187 | if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) { |
| 1188 | $timing_functions = \WprAddonsPro\Includes\Controls\WPR_Control_Animations_Pro::wpr_animation_timings(); |
| 1189 | } |
| 1190 | |
| 1191 | return $timing_functions; |
| 1192 | } |
| 1193 | |
| 1194 | public static function wpr_animation_timing_pro_conditions() { |
| 1195 | return ['pro-eio','pro-eiqd','pro-eicb','pro-eiqrt','pro-eiqnt','pro-eisn','pro-eiex','pro-eicr','pro-eibk','pro-eoqd','pro-eocb','pro-eoqrt','pro-eoqnt','pro-eosn','pro-eoex','pro-eocr','pro-eobk','pro-eioqd','pro-eiocb','pro-eioqrt','pro-eioqnt','pro-eiosn','pro-eioex','pro-eiocr','pro-eiobk']; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | ** WPR Library Button |
| 1200 | */ |
| 1201 | public static function wpr_library_buttons( $module, $controls_manager, $tutorial_url = '' ) { |
| 1202 | if ( empty(get_option('wpr_wl_plugin_links')) ) { |
| 1203 | if ( '' !== $tutorial_url ) { |
| 1204 | $tutorial_link = '<a href="'. esc_url($tutorial_url) .'" target="_blank">'. esc_html__( 'Watch Video Tutorial ', 'wpr-addons' ) .'<span class="dashicons dashicons-video-alt3"></span></a>'; |
| 1205 | } else { |
| 1206 | $tutorial_link = ''; |
| 1207 | } |
| 1208 | |
| 1209 | $module->add_control( |
| 1210 | 'wpr_library_buttons', |
| 1211 | [ |
| 1212 | 'raw' => '<div class='. $module->get_name() .'><a href="#" target="_blank" data-theme="'. esc_attr(get_template()) .'">'. esc_html__( 'Widget Preview', 'wpr-addons' ) .'</a> <a href="#">'. esc_html__( 'Predefined Styles', 'wpr-addons' ) .'</a></div>'. $tutorial_link, |
| 1213 | 'type' => $controls_manager, |
| 1214 | ] |
| 1215 | ); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | /** |
| 1220 | ** Upgrade to Pro Notice |
| 1221 | */ |
| 1222 | public static function upgrade_pro_notice( $module, $controls_manager, $widget, $option, $condition = [] ) { |
| 1223 | if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) { |
| 1224 | return; |
| 1225 | } |
| 1226 | |
| 1227 | $url = 'https://royal-elementor-addons.com/?ref=rea-plugin-panel-'. $widget .'-upgrade-pro#purchasepro'; |
| 1228 | |
| 1229 | $module->add_control( |
| 1230 | $option .'_pro_notice', |
| 1231 | [ |
| 1232 | 'raw' => 'This option is available<br> in the <strong><a href="'. $url .'" target="_blank">Pro version</a></strong> and above.', |
| 1233 | // 'raw' => 'This option is available<br> in the <strong><a href="'. admin_url('admin.php?page=wpr-addons-pricing') .'" target="_blank">Pro version</a></strong>', |
| 1234 | 'type' => $controls_manager, |
| 1235 | 'content_classes' => 'wpr-pro-notice', |
| 1236 | 'condition' => [ |
| 1237 | $option => $condition, |
| 1238 | ] |
| 1239 | ] |
| 1240 | ); |
| 1241 | } |
| 1242 | |
| 1243 | public static function upgrade_expert_notice( $module, $controls_manager, $widget, $option, $condition = [] ) { |
| 1244 | if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->is_plan( 'expert' ) ) { |
| 1245 | return; |
| 1246 | } |
| 1247 | |
| 1248 | $url = 'https://royal-elementor-addons.com/?ref=rea-plugin-panel-'. $widget .'-upgrade-expert#purchasepro'; |
| 1249 | |
| 1250 | $module->add_control( |
| 1251 | $option .'_expert_notice', |
| 1252 | [ |
| 1253 | 'raw' => 'This option is available<br> in the <strong><a href="'. $url .'" target="_blank">Expert version</a></strong>', |
| 1254 | // 'raw' => 'This option is available<br> in the <strong><a href="'. admin_url('admin.php?page=wpr-addons-pricing') .'" target="_blank">Pro version</a></strong>', |
| 1255 | 'type' => $controls_manager, |
| 1256 | 'content_classes' => 'wpr-pro-notice', |
| 1257 | 'condition' => [ |
| 1258 | $option => $condition, |
| 1259 | ] |
| 1260 | ] |
| 1261 | ); |
| 1262 | } |
| 1263 | |
| 1264 | /** |
| 1265 | ** Request Feature Section |
| 1266 | */ |
| 1267 | public static function wpr_add_section_request_feature( $module, $raw_html, $tab ) { |
| 1268 | $module->start_controls_section( |
| 1269 | 'section_request_new_feature', |
| 1270 | [ |
| 1271 | 'label' => __( 'Request Feature', 'wpr-addons' ), |
| 1272 | 'tab' => $tab, |
| 1273 | ] |
| 1274 | ); |
| 1275 | |
| 1276 | $module->add_control( |
| 1277 | 'request_new_feature', |
| 1278 | [ |
| 1279 | 'type' => $raw_html, |
| 1280 | 'raw' => __( 'Missing an Option, have a New Widget or any kind of Feature Idea? Please share it with us and lets discuss. <a href="https://royaladdons.frill.co/b/6m4d5qm4/feature-ideas" target="_blank">Request New Feature <span class="dashicons dashicons-star-empty"></span></a>', 'wpr-addons' ), |
| 1281 | ] |
| 1282 | ); |
| 1283 | |
| 1284 | $module->end_controls_section(); // End Controls Section |
| 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | ** Pro Features List Section |
| 1289 | */ |
| 1290 | public static function pro_features_list_section( $module, $section, $type, $widget, $features ) { |
| 1291 | if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) { |
| 1292 | return; |
| 1293 | } |
| 1294 | |
| 1295 | if ( '' === $section ) { |
| 1296 | $module->start_controls_section( |
| 1297 | 'pro_features_section', |
| 1298 | [ |
| 1299 | 'label' => 'Pro Features <span class="dashicons dashicons-star-filled"></span>', |
| 1300 | ] |
| 1301 | ); |
| 1302 | } else { |
| 1303 | $module->start_controls_section( |
| 1304 | 'pro_features_section', |
| 1305 | [ |
| 1306 | 'label' => 'Pro Features <span class="dashicons dashicons-star-filled"></span>', |
| 1307 | 'tab' => $section, |
| 1308 | ] |
| 1309 | ); |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | $list_html = ''; |
| 1314 | |
| 1315 | for ($i=0; $i < count($features); $i++) { |
| 1316 | $list_html .= '<li>'. $features[$i] .'</li>'; |
| 1317 | } |
| 1318 | |
| 1319 | $module->add_control( |
| 1320 | 'pro_features_list', |
| 1321 | [ |
| 1322 | 'type' => $type, |
| 1323 | 'raw' => '<ul>'. $list_html .'</ul> |
| 1324 | <a href="https://royal-elementor-addons.com/?ref=rea-plugin-panel-pro-sec-'. $widget .'-upgrade-pro#purchasepro" target="_blank">Get Pro version</a>', |
| 1325 | 'content_classes' => 'wpr-pro-features-list', |
| 1326 | ] |
| 1327 | ); |
| 1328 | |
| 1329 | $module->end_controls_section(); |
| 1330 | } |
| 1331 | |
| 1332 | // Add two new functions for handling cookies |
| 1333 | public function get_wishlist_from_cookie() { |
| 1334 | if (isset($_COOKIE['wpr_wishlist'])) { |
| 1335 | return json_decode(stripslashes($_COOKIE['wpr_wishlist']), true); |
| 1336 | } else if ( isset($_COOKIE['wpr_wishlist_'. get_current_blog_id() .'']) ) { |
| 1337 | return json_decode(stripslashes($_COOKIE['wpr_wishlist_'. get_current_blog_id() .'']), true); |
| 1338 | } |
| 1339 | return array(); |
| 1340 | } |
| 1341 | |
| 1342 | // Client IP for form submission |
| 1343 | public static function get_client_ip() { |
| 1344 | $server_ip_keys = [ |
| 1345 | 'HTTP_CLIENT_IP', |
| 1346 | 'HTTP_X_FORWARDED_FOR', |
| 1347 | 'HTTP_X_FORWARDED', |
| 1348 | 'HTTP_X_CLUSTER_CLIENT_IP', |
| 1349 | 'HTTP_FORWARDED_FOR', |
| 1350 | 'HTTP_FORWARDED', |
| 1351 | 'REMOTE_ADDR', |
| 1352 | ]; |
| 1353 | |
| 1354 | foreach ( $server_ip_keys as $key ) { |
| 1355 | $value = self::_unstable_get_super_global_value( $_SERVER, $key ); |
| 1356 | if ( $value && filter_var( $value, FILTER_VALIDATE_IP ) ) { |
| 1357 | return $value; |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | // Fallback local ip. |
| 1362 | return '127.0.0.1'; |
| 1363 | } |
| 1364 | |
| 1365 | // For get_client_ip |
| 1366 | public static function _unstable_get_super_global_value( $super_global, $key ) { |
| 1367 | if ( ! isset( $super_global[ $key ] ) ) { |
| 1368 | return null; |
| 1369 | } |
| 1370 | |
| 1371 | if ( $_FILES === $super_global ) { |
| 1372 | $super_global[ $key ]['name'] = sanitize_file_name( $super_global[ $key ]['name'] ); |
| 1373 | return $super_global[ $key ]; |
| 1374 | } |
| 1375 | |
| 1376 | return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) ); |
| 1377 | } |
| 1378 | |
| 1379 | /** |
| 1380 | ** Check for New Free Users |
| 1381 | */ |
| 1382 | public static function is_new_free_user() { |
| 1383 | return (!defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code()) && (intval(get_option('royal_elementor_addons_activation_time')) > 1649247746); |
| 1384 | } |
| 1385 | |
| 1386 | // public static function is_new_free_user2() { |
| 1387 | // return (!defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code()) && (intval(get_option('royal_elementor_addons_activation_time')) > 1670317149); |
| 1388 | // } |
| 1389 | |
| 1390 | // public static function is_old_pro_user_or_expert() { |
| 1391 | // return wpr_fs()->is_plan( 'expert' ) || (wpr_fs()->is_plan( 'pro' ) && (intval(get_option('royal_elementor_addons_pro_activation_time')) < 1680264265)); |
| 1392 | // } |
| 1393 | |
| 1394 | // public static function is_new_pro_user() { |
| 1395 | // return wpr_fs()->is_plan( 'pro' ) && (intval(get_option('royal_elementor_addons_pro_activation_time')) > 1680264265); |
| 1396 | // } |
| 1397 | |
| 1398 | /** |
| 1399 | ** HTML Tags Whitelist |
| 1400 | */ |
| 1401 | public static function validate_html_tags_wl( $setting, $default, $tags_whitelist ) { |
| 1402 | $value = $setting; |
| 1403 | |
| 1404 | if ( ! in_array(strtolower($value), $tags_whitelist) ) { |
| 1405 | $value = $default; |
| 1406 | } |
| 1407 | |
| 1408 | return $value; |
| 1409 | } |
| 1410 | |
| 1411 | public static function get_all_breakpoints( $type = 'assoc' ) { |
| 1412 | $devices = array( |
| 1413 | 'desktop' => __( 'Desktop', 'elementor' ), |
| 1414 | ); |
| 1415 | |
| 1416 | if ( |
| 1417 | class_exists( '\Elementor\Plugin' ) && |
| 1418 | isset( \Elementor\Plugin::$instance->breakpoints ) && |
| 1419 | method_exists( \Elementor\Plugin::$instance->breakpoints, 'get_active_breakpoints' ) |
| 1420 | ) { |
| 1421 | $active_breakpoints = \Elementor\Plugin::$instance->breakpoints->get_active_breakpoints(); |
| 1422 | |
| 1423 | if ( is_array( $active_breakpoints ) ) { |
| 1424 | foreach ( $active_breakpoints as $key => $breakpoint ) { |
| 1425 | if ( 'desktop' === $key ) { |
| 1426 | continue; |
| 1427 | } |
| 1428 | |
| 1429 | $label = ''; |
| 1430 | |
| 1431 | if ( is_object( $breakpoint ) && method_exists( $breakpoint, 'get_label' ) ) { |
| 1432 | $label = $breakpoint->get_label(); |
| 1433 | } |
| 1434 | |
| 1435 | if ( '' === $label ) { |
| 1436 | $label = ucwords( str_replace( '_', ' ', $key ) ); |
| 1437 | } |
| 1438 | |
| 1439 | $devices[ $key ] = $label; |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | if ( ! isset( $devices['tablet'] ) ) { |
| 1445 | $devices['tablet'] = __( 'Tablet', 'elementor' ); |
| 1446 | } |
| 1447 | |
| 1448 | if ( ! isset( $devices['mobile'] ) ) { |
| 1449 | $devices['mobile'] = __( 'Mobile', 'elementor' ); |
| 1450 | } |
| 1451 | |
| 1452 | $order = array( |
| 1453 | 'widescreen', |
| 1454 | 'desktop', |
| 1455 | 'laptop', |
| 1456 | 'tablet_extra', |
| 1457 | 'tablet', |
| 1458 | 'mobile_extra', |
| 1459 | 'mobile', |
| 1460 | ); |
| 1461 | |
| 1462 | $ordered_devices = array(); |
| 1463 | |
| 1464 | foreach ( $order as $breakpoint_key ) { |
| 1465 | if ( isset( $devices[ $breakpoint_key ] ) ) { |
| 1466 | $ordered_devices[ $breakpoint_key ] = $devices[ $breakpoint_key ]; |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | foreach ( $devices as $breakpoint_key => $label ) { |
| 1471 | if ( ! isset( $ordered_devices[ $breakpoint_key ] ) ) { |
| 1472 | $ordered_devices[ $breakpoint_key ] = $label; |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | return ( 'keys' === $type ) ? array_keys( $ordered_devices ) : $ordered_devices; |
| 1477 | } |
| 1478 | } |