| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * Plugin Name: King Addons | |
| 5 | - * Description: 4,000+ ready Elementor sections, 650+ templates, 70+ FREE widgets for Elementor, and features like Live Search, Popups, Carousels, Image Hotspots, and Parallax Backgrounds. | |
| 4 | + * Plugin Name: King Addons for Elementor | |
| 5 | + * Description: Elementor addons, 4,000+ Templates & Sections, 80+ Widgets, AI Tools, Mega Menu, Popup Builder, WooCommerce, Templates & Sections. Lightweight & fast Elementor toolkit. | |
| 6 | 6 | * Author URI: https://kingaddons.com/ |
| 7 | 7 | * Author: KingAddons.com |
| 8 | - * Version: 51.1.44 | |
| 8 | + * Version: 51.1.83 | |
| 9 | 9 | * Text Domain: king-addons |
| 10 | 10 | * Requires at least: 6.0 |
| 11 | 11 | * Requires PHP: 7.4 |
| 12 | 12 | * License: GPLv3 |
| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | // Load plugin textdomain immediately to prevent early translation loading notices. |
| 22 | 22 | load_plugin_textdomain('king-addons'); |
| 23 | 23 | |
| 24 | 24 | /** PLUGIN VERSION */ |
| 25 | -const KING_ADDONS_VERSION = '51.1.44'; | |
| 25 | +const KING_ADDONS_VERSION = '51.1.83'; | |
| 26 | 26 | |
| 27 | 27 | /** DEFINES */ |
| 28 | 28 | define('KING_ADDONS_PATH', plugin_dir_path(__FILE__)); |
| 29 | 29 | define('KING_ADDONS_URL', plugins_url('/', __FILE__)); |
| @@ -32,8 +32,11 @@ | ||
| 32 | 32 | const KING_ADDONS_ASSETS_UNIQUE_KEY = 'king-addons'; |
| 33 | 33 | |
| 34 | 34 | require_once(KING_ADDONS_PATH . 'includes/helpers/Global/global-constants.php'); |
| 35 | 35 | |
| 36 | +// Shared AI provider abstraction (OpenAI / OpenRouter), used by admin and extensions. | |
| 37 | +require_once(KING_ADDONS_PATH . 'includes/AI_Provider.php'); | |
| 38 | + | |
| 36 | 39 | if (!function_exists('king_addons_freemius')) { |
| 37 | 40 | // Create a helper function for easy SDK access. |
| 38 | 41 | function king_addons_freemius() |
| 39 | 42 | { |
| @@ -49,14 +52,14 @@ | ||
| 49 | 52 | 'slug' => 'king-addons', |
| 50 | 53 | 'premium_slug' => 'king-addons-pro', |
| 51 | 54 | 'type' => 'plugin', |
| 52 | 55 | 'public_key' => 'pk_eac3624cbc14c1846cf1ab9abbd68', |
| 53 | - 'is_premium' => false, // temp | |
| 56 | + 'is_premium' => false, | |
| 54 | 57 | 'premium_suffix' => 'pro', |
| 55 | 58 | // If your plugin is a serviceware, set this option to false. |
| 56 | 59 | 'has_premium_version' => true, |
| 57 | 60 | 'has_addons' => false, |
| 58 | - 'has_paid_plans' => false, // temp | |
| 61 | + 'has_paid_plans' => true, | |
| 59 | 62 | 'has_affiliation' => 'selected', |
| 60 | 63 | 'menu' => array( |
| 61 | 64 | 'slug' => 'king-addons', |
| 62 | 65 | 'first-path' => 'plugins.php', |
| @@ -103,8 +106,82 @@ | ||
| 103 | 106 | return (bool) $fs->can_use_premium_code(); |
| 104 | 107 | } |
| 105 | 108 | } |
| 106 | 109 | |
| 110 | +/** | |
| 111 | + * Whether the WooCommerce Builder top-level menu is registered. | |
| 112 | + * | |
| 113 | + * Wishlist and other store screens hang off that menu when it exists, | |
| 114 | + * and fall back to King Addons when it does not. | |
| 115 | + * | |
| 116 | + * @return bool | |
| 117 | + */ | |
| 118 | +if (!function_exists('king_addons_woo_builder_menu_is_active')) { | |
| 119 | + function king_addons_woo_builder_menu_is_active(): bool | |
| 120 | + { | |
| 121 | + $options = get_option('king_addons_options', []); | |
| 122 | + $enabled = !isset($options['ext_woo-builder']) || $options['ext_woo-builder'] === 'enabled'; | |
| 123 | + | |
| 124 | + return $enabled | |
| 125 | + && (defined('KING_ADDONS_EXT_WOO_BUILDER') ? (bool) KING_ADDONS_EXT_WOO_BUILDER : true) | |
| 126 | + && class_exists('WooCommerce') | |
| 127 | + && function_exists('WC'); | |
| 128 | + } | |
| 129 | +} | |
| 130 | + | |
| 131 | +/** | |
| 132 | + * Parent slug for WooCommerce-related admin screens. | |
| 133 | + * | |
| 134 | + * Page slugs stay the same; only the WP menu parent changes. | |
| 135 | + * | |
| 136 | + * @return string | |
| 137 | + */ | |
| 138 | +if (!function_exists('king_addons_woo_admin_parent_slug')) { | |
| 139 | + function king_addons_woo_admin_parent_slug(): string | |
| 140 | + { | |
| 141 | + return king_addons_woo_builder_menu_is_active() ? 'king-addons-woo-builder' : 'king-addons'; | |
| 142 | + } | |
| 143 | +} | |
| 144 | + | |
| 145 | +/** | |
| 146 | + * Whether the current admin screen belongs to King Addons. | |
| 147 | + * | |
| 148 | + * Screen IDs follow the WP parent menu title, so Woo screens under | |
| 149 | + * WooCommerce Builder become `woocommerce-builder_page_*`. Page slugs | |
| 150 | + * still start with `king-addons`. | |
| 151 | + * | |
| 152 | + * @param string|null $current_screen Optional screen id; current screen if omitted. | |
| 153 | + * @return bool | |
| 154 | + */ | |
| 155 | +if (!function_exists('king_addons_is_plugin_admin_screen')) { | |
| 156 | + function king_addons_is_plugin_admin_screen(?string $current_screen = null): bool | |
| 157 | + { | |
| 158 | + $page = isset($_GET['page']) ? sanitize_key(wp_unslash($_GET['page'])) : ''; | |
| 159 | + if ($page !== '' && strpos($page, 'king-addons') === 0) { | |
| 160 | + return true; | |
| 161 | + } | |
| 162 | + | |
| 163 | + if ($current_screen === null) { | |
| 164 | + $screen = function_exists('get_current_screen') ? get_current_screen() : null; | |
| 165 | + if (!$screen || empty($screen->id)) { | |
| 166 | + return false; | |
| 167 | + } | |
| 168 | + $current_screen = (string) $screen->id; | |
| 169 | + } | |
| 170 | + | |
| 171 | + $legacy_screens = [ | |
| 172 | + 'edit-king-addons-el-hf', | |
| 173 | + 'edit-king-addons-fb-sub', | |
| 174 | + 'header-footer_page_king-addons-el-hf-settings', | |
| 175 | + ]; | |
| 176 | + | |
| 177 | + return (strpos($current_screen, 'king-addons_') === 0) | |
| 178 | + || (strpos($current_screen, 'toplevel_page_king-addons') === 0) | |
| 179 | + || (strpos($current_screen, 'woocommerce-builder_page_') === 0) | |
| 180 | + || in_array($current_screen, $legacy_screens, true); | |
| 181 | + } | |
| 182 | +} | |
| 183 | + | |
| 107 | 184 | if (!function_exists('king_addons_doActivation')) { |
| 108 | 185 | function king_addons_doActivation() |
| 109 | 186 | { |
| 110 | 187 | add_option('king_addons_plugin_activated', true); |
| @@ -227,34 +304,128 @@ | ||
| 227 | 304 | if (isset($_GET['page']) && $_GET['page'] === 'king-addons-account') { |
| 228 | 305 | return; |
| 229 | 306 | } |
| 230 | 307 | |
| 231 | - $screen = function_exists('get_current_screen') ? get_current_screen() : null; | |
| 232 | - if (!$screen || empty($screen->id)) { | |
| 308 | + if (king_addons_is_plugin_admin_screen()) { | |
| 309 | + // Remove all notices | |
| 310 | + remove_all_actions('user_admin_notices'); | |
| 311 | + remove_all_actions('admin_notices'); | |
| 312 | + } | |
| 313 | + } | |
| 314 | + | |
| 315 | + add_action('in_admin_header', 'king_addons_hideAnotherNotices', 99); | |
| 316 | +} | |
| 317 | + | |
| 318 | +/** | |
| 319 | + * Custom admin footer text on King Addons pages | |
| 320 | + * Shows rating request similar to WooCommerce | |
| 321 | + * | |
| 322 | + * @param string $footer_text Default footer text. | |
| 323 | + * @return string Modified footer text. | |
| 324 | + * @since 51.2.0 | |
| 325 | + */ | |
| 326 | +if (!function_exists('king_addons_admin_footer_text')) { | |
| 327 | + function king_addons_admin_footer_text($footer_text) | |
| 328 | + { | |
| 329 | + if (!current_user_can('manage_options')) { | |
| 330 | + return $footer_text; | |
| 331 | + } | |
| 332 | + | |
| 333 | + if (!king_addons_is_plugin_admin_screen()) { | |
| 334 | + return $footer_text; | |
| 335 | + } | |
| 336 | + | |
| 337 | + // Check if user has already rated | |
| 338 | + if (!get_option('king_addons_admin_footer_text_rated')) { | |
| 339 | + $footer_text = sprintf( | |
| 340 | + /* translators: 1: King Addons 2: five stars */ | |
| 341 | + __('If you like %1$s please leave us a %2$s rating. A huge thanks in advance!', 'king-addons'), | |
| 342 | + sprintf('<strong>%s</strong>', esc_html__('King Addons', 'king-addons')), | |
| 343 | + '<a href="https://wordpress.org/support/plugin/king-addons/reviews?rate=5#new-post" target="_blank" class="king-addons-rating-link" aria-label="' . esc_attr__('five star', 'king-addons') . '" data-rated="' . esc_attr__('Thanks :)', 'king-addons') . '">★★★★★</a>' | |
| 344 | + ); | |
| 345 | + } else { | |
| 346 | + $footer_text = __('Thank you for using King Addons!', 'king-addons'); | |
| 347 | + } | |
| 348 | + | |
| 349 | + return '<span id="footer-thankyou">' . $footer_text . '</span>'; | |
| 350 | + } | |
| 351 | + | |
| 352 | + add_filter('admin_footer_text', 'king_addons_admin_footer_text', 1); | |
| 353 | +} | |
| 354 | + | |
| 355 | +/** | |
| 356 | + * Enqueue script for rating link click handler | |
| 357 | + * | |
| 358 | + * @return void | |
| 359 | + * @since 51.2.0 | |
| 360 | + */ | |
| 361 | +if (!function_exists('king_addons_rating_script')) { | |
| 362 | + function king_addons_rating_script() | |
| 363 | + { | |
| 364 | + if (!current_user_can('manage_options')) { | |
| 233 | 365 | return; |
| 234 | 366 | } |
| 235 | 367 | |
| 236 | - $current_screen = (string) $screen->id; | |
| 368 | + // Only on King Addons pages and only if not already rated | |
| 369 | + if (!king_addons_is_plugin_admin_screen() || get_option('king_addons_admin_footer_text_rated')) { | |
| 370 | + return; | |
| 371 | + } | |
| 237 | 372 | |
| 238 | - // Legacy explicit screens that do not follow the generic prefixes. | |
| 239 | - $legacy_screens = [ | |
| 240 | - 'edit-king-addons-el-hf', | |
| 241 | - 'edit-king-addons-fb-sub', | |
| 242 | - 'header-footer_page_king-addons-el-hf-settings', | |
| 243 | - ]; | |
| 373 | + $script = " | |
| 374 | + (function() { | |
| 375 | + 'use strict'; | |
| 376 | + var ratingLink = document.querySelector('a.king-addons-rating-link'); | |
| 377 | + if (ratingLink) { | |
| 378 | + ratingLink.addEventListener('click', function(e) { | |
| 379 | + var link = e.currentTarget; | |
| 380 | + var formData = new FormData(); | |
| 381 | + formData.append('action', 'king_addons_rated'); | |
| 382 | + formData.append('nonce', '" . esc_js(wp_create_nonce('king_addons_rated')) . "'); | |
| 383 | + | |
| 384 | + fetch('" . esc_js(admin_url('admin-ajax.php')) . "', { | |
| 385 | + method: 'POST', | |
| 386 | + body: formData, | |
| 387 | + credentials: 'same-origin' | |
| 388 | + }); | |
| 389 | + | |
| 390 | + var parent = link.parentElement; | |
| 391 | + if (parent) { | |
| 392 | + parent.textContent = link.getAttribute('data-rated'); | |
| 393 | + } | |
| 394 | + }); | |
| 395 | + } | |
| 396 | + })(); | |
| 397 | + "; | |
| 244 | 398 | |
| 245 | - $is_king_addons_screen = (strpos($current_screen, 'king-addons_') === 0) | |
| 246 | - || (strpos($current_screen, 'toplevel_page_king-addons') === 0) | |
| 247 | - || in_array($current_screen, $legacy_screens, true); | |
| 399 | + $handle = 'king-addons-admin-footer-rating'; | |
| 400 | + wp_register_script($handle, '', [], KING_ADDONS_VERSION, true); | |
| 401 | + wp_enqueue_script($handle); | |
| 402 | + wp_add_inline_script($handle, $script); | |
| 403 | + } | |
| 248 | 404 | |
| 249 | - if ($is_king_addons_screen) { | |
| 250 | - // Remove all notices | |
| 251 | - remove_all_actions('user_admin_notices'); | |
| 252 | - remove_all_actions('admin_notices'); | |
| 405 | + add_action('admin_enqueue_scripts', 'king_addons_rating_script'); | |
| 406 | +} | |
| 407 | + | |
| 408 | +/** | |
| 409 | + * AJAX handler for saving rated status | |
| 410 | + * | |
| 411 | + * @return void | |
| 412 | + * @since 51.2.0 | |
| 413 | + */ | |
| 414 | +if (!function_exists('king_addons_rated_callback')) { | |
| 415 | + function king_addons_rated_callback() | |
| 416 | + { | |
| 417 | + if (!current_user_can('manage_options')) { | |
| 418 | + wp_die(-1, 403); | |
| 253 | 419 | } |
| 420 | + | |
| 421 | + check_ajax_referer('king_addons_rated', 'nonce'); | |
| 422 | + | |
| 423 | + update_option('king_addons_admin_footer_text_rated', 1); | |
| 424 | + wp_die(); | |
| 254 | 425 | } |
| 255 | 426 | |
| 256 | - add_action('in_admin_header', 'king_addons_hideAnotherNotices', 99); | |
| 427 | + add_action('wp_ajax_king_addons_rated', 'king_addons_rated_callback'); | |
| 257 | 428 | } |
| 258 | 429 | |
| 259 | 430 | /** |
| 260 | 431 | * Apply theme detection script to Account page |
| @@ -274,9 +445,9 @@ | ||
| 274 | 445 | // Get user's theme preference |
| 275 | 446 | $theme_mode = get_user_meta(get_current_user_id(), 'king_addons_theme_mode', true); |
| 276 | 447 | $allowed_theme_modes = ['dark', 'light', 'auto']; |
| 277 | 448 | if (!in_array($theme_mode, $allowed_theme_modes, true)) { |
| 278 | - $theme_mode = 'dark'; // Default to dark theme | |
| 449 | + $theme_mode = 'auto'; | |
| 279 | 450 | } |
| 280 | 451 | ?> |
| 281 | 452 | <script> |
| 282 | 453 | (function() { |