← All changes
|
vendor-prefixed/src/Pages/RecommendedPluginsPage.php
+79
-79
4.4.1
→
4.4.6
View file →
| @@ -13,9 +13,9 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | class RecommendedPluginsPage |
| 15 | 15 | { |
| 16 | 16 | protected static ?self $instance = null; |
| 17 | - public static function get_instance() : self | |
| 17 | + public static function get_instance(): self | |
| 18 | 18 | { |
| 19 | 19 | if (null === self::$instance) { |
| 20 | 20 | self::$instance = new self(); |
| 21 | 21 | } |
| @@ -22,15 +22,15 @@ | ||
| 22 | 22 | return self::$instance; |
| 23 | 23 | } |
| 24 | 24 | protected function __construct() |
| 25 | 25 | { |
| 26 | - \add_action('wp_ajax_yay_recommended_get_plugin_data', [$this, 'ajax_get_plugin_data'], 9); | |
| 27 | - \add_action('wp_ajax_yay_recommended_activate_plugin', [$this, 'ajax_activate_plugin'], 9); | |
| 28 | - \add_action('wp_ajax_yay_recommended_upgrade_plugin', [$this, 'ajax_upgrade_plugin'], 9); | |
| 26 | + add_action('wp_ajax_yay_recommended_get_plugin_data', [$this, 'ajax_get_plugin_data'], 9); | |
| 27 | + add_action('wp_ajax_yay_recommended_activate_plugin', [$this, 'ajax_activate_plugin'], 9); | |
| 28 | + add_action('wp_ajax_yay_recommended_upgrade_plugin', [$this, 'ajax_upgrade_plugin'], 9); | |
| 29 | 29 | } |
| 30 | - public static function render() : void | |
| 30 | + public static function render(): void | |
| 31 | 31 | { |
| 32 | - if (\function_exists('WC')) { | |
| 32 | + if (function_exists('YayMailScoped\WC')) { | |
| 33 | 33 | $featured_tab = '<li class="plugin-install-tab plugin-install-featured" data-tab="featured"><a href="#">Featured</a></li>'; |
| 34 | 34 | $woo_tab = '<li class="plugin-install-tab plugin-install-woocommerce" data-tab="woocommerce"><a href="#" class="current" aria-current="page">WooCommerce</a></li>'; |
| 35 | 35 | } else { |
| 36 | 36 | $featured_tab = '<li class="plugin-install-tab plugin-install-featured" data-tab="featured"><a href="#" class="current" aria-current="page">Featured</a></li>'; |
| @@ -44,17 +44,17 @@ | ||
| 44 | 44 | <div class="yay-recommended-plugins-layout"> |
| 45 | 45 | <div class="yay-recommended-plugins-layout-header"> |
| 46 | 46 | <div class="wp-filter yay-recommended-plugins-header"> |
| 47 | 47 | <h2 class="yay-recommended-plugins-header-title"><?php |
| 48 | - \esc_attr_e('Recommended Plugins', 'yaycommerce'); | |
| 48 | + esc_attr_e('Recommended Plugins', 'yaycommerce'); | |
| 49 | 49 | ?></h2> |
| 50 | 50 | <ul class="filter-links"> |
| 51 | 51 | <?php |
| 52 | - echo \wp_kses_post($featured_tab); | |
| 52 | + echo wp_kses_post($featured_tab); | |
| 53 | 53 | ?> |
| 54 | 54 | <li class="plugin-install-tab plugin-install-all" data-tab="all"><a href="#">All</a></li> |
| 55 | 55 | <?php |
| 56 | - echo \wp_kses_post($woo_tab); | |
| 56 | + echo wp_kses_post($woo_tab); | |
| 57 | 57 | ?> |
| 58 | 58 | <li class="plugin-install-tab plugin-install-management" data-tab="management"><a href="#">Management</a></li> |
| 59 | 59 | <li class="plugin-install-tab plugin-install-marketing" data-tab="marketing"><a href="#">Marketing</a></li> |
| 60 | 60 | </ul> |
| @@ -66,22 +66,22 @@ | ||
| 66 | 66 | </div> |
| 67 | 67 | </div> |
| 68 | 68 | <?php |
| 69 | 69 | } |
| 70 | - public static function load_data() : void | |
| 70 | + public static function load_data(): void | |
| 71 | 71 | { |
| 72 | - \add_action('admin_enqueue_scripts', [self::class, 'enqueue_scripts']); | |
| 72 | + add_action('admin_enqueue_scripts', [self::class, 'enqueue_scripts']); | |
| 73 | 73 | } |
| 74 | - public static function enqueue_scripts() : void | |
| 74 | + public static function enqueue_scripts(): void | |
| 75 | 75 | { |
| 76 | - $assets_url = \plugin_dir_url(__FILE__) . '../../assets/'; | |
| 77 | - \wp_enqueue_script('plugin-install'); | |
| 78 | - \wp_enqueue_script('thickbox'); | |
| 79 | - \wp_enqueue_style('thickbox'); | |
| 80 | - \wp_enqueue_style('yaycommerce-other-plugins', $assets_url . 'css/other-plugins.css', [], '1.0'); | |
| 81 | - \wp_register_script('yaycommerce-other-plugins', $assets_url . 'js/other-plugins.js', ['jquery'], '1.0', \true); | |
| 82 | - \wp_localize_script('yaycommerce-other-plugins', 'yayRecommended', ['nonce' => \wp_create_nonce('yay_recommended_nonce'), 'admin_ajax' => \admin_url('admin-ajax.php'), 'woo_active' => \function_exists('WC')]); | |
| 83 | - \wp_enqueue_script('yaycommerce-other-plugins'); | |
| 76 | + $assets_url = plugin_dir_url(__FILE__) . '../../assets/'; | |
| 77 | + wp_enqueue_script('plugin-install'); | |
| 78 | + wp_enqueue_script('thickbox'); | |
| 79 | + wp_enqueue_style('thickbox'); | |
| 80 | + wp_enqueue_style('yaycommerce-other-plugins', $assets_url . 'css/other-plugins.css', [], '1.0'); | |
| 81 | + wp_register_script('yaycommerce-other-plugins', $assets_url . 'js/other-plugins.js', ['jquery'], '1.0', \true); | |
| 82 | + wp_localize_script('yaycommerce-other-plugins', 'yayRecommended', ['nonce' => wp_create_nonce('yay_recommended_nonce'), 'admin_ajax' => admin_url('admin-ajax.php'), 'woo_active' => function_exists('YayMailScoped\WC')]); | |
| 83 | + wp_enqueue_script('yaycommerce-other-plugins'); | |
| 84 | 84 | } |
| 85 | 85 | /** |
| 86 | 86 | * Return the plugins to display. Filterable via yay_recommended_plugins_excluded. |
| 87 | 87 | * |
| @@ -86,74 +86,74 @@ | ||
| 86 | 86 | * Return the plugins to display. Filterable via yay_recommended_plugins_excluded. |
| 87 | 87 | * |
| 88 | 88 | * @return array<string, array> |
| 89 | 89 | */ |
| 90 | - public static function get_other_plugins() : array | |
| 90 | + public static function get_other_plugins(): array | |
| 91 | 91 | { |
| 92 | 92 | return include __DIR__ . '/../../views/recommended-plugins-data.php'; |
| 93 | 93 | } |
| 94 | - public function ajax_get_plugin_data() : void | |
| 94 | + public function ajax_get_plugin_data(): void | |
| 95 | 95 | { |
| 96 | 96 | try { |
| 97 | - if (!\current_user_can('install_plugins')) { | |
| 98 | - \wp_send_json_error(['mess' => \__('Permission denied', 'yaycommerce')]); | |
| 97 | + if (!current_user_can('install_plugins')) { | |
| 98 | + wp_send_json_error(['mess' => __('Permission denied', 'yaycommerce')]); | |
| 99 | 99 | } |
| 100 | 100 | if (!isset($_POST['tab'])) { |
| 101 | - \wp_send_json_error(['mess' => 'Missing tab']); | |
| 101 | + wp_send_json_error(['mess' => 'Missing tab']); | |
| 102 | 102 | } |
| 103 | - $nonce = isset($_POST['nonce']) ? \sanitize_text_field($_POST['nonce']) : ''; | |
| 104 | - if (!\wp_verify_nonce($nonce, 'yay_recommended_nonce')) { | |
| 105 | - \wp_send_json_error(['mess' => \__('Nonce is invalid', 'yaycommerce')]); | |
| 103 | + $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; | |
| 104 | + if (!wp_verify_nonce($nonce, 'yay_recommended_nonce')) { | |
| 105 | + wp_send_json_error(['mess' => __('Nonce is invalid', 'yaycommerce')]); | |
| 106 | 106 | } |
| 107 | 107 | require_once \ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 108 | - $tab = \sanitize_text_field($_POST['tab']); | |
| 109 | - $recommended_data = \apply_filters('yay_recommended_plugins_excluded', self::get_other_plugins()); | |
| 108 | + $tab = sanitize_text_field($_POST['tab']); | |
| 109 | + $recommended_data = apply_filters('yay_recommended_plugins_excluded', self::get_other_plugins()); | |
| 110 | 110 | $recommended_plugins = []; |
| 111 | 111 | foreach ($recommended_data as $key => $plugin) { |
| 112 | - if (\in_array($tab, $plugin['type'], \true) || 'all' === $tab) { | |
| 112 | + if (in_array($tab, $plugin['type'], \true) || 'all' === $tab) { | |
| 113 | 113 | $recommended_plugins[$key] = $plugin; |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | - \ob_start(); | |
| 116 | + ob_start(); | |
| 117 | 117 | include __DIR__ . '/../../views/recommended-plugins-page.php'; |
| 118 | - $html = \ob_get_clean(); | |
| 119 | - \wp_send_json_success(['mess' => \__('Get data success', 'yaycommerce'), 'html' => $html]); | |
| 118 | + $html = ob_get_clean(); | |
| 119 | + wp_send_json_success(['mess' => __('Get data success', 'yaycommerce'), 'html' => $html]); | |
| 120 | 120 | } catch (\Exception $ex) { |
| 121 | - \wp_send_json_error(['mess' => \__('Error exception.', 'yaycommerce'), ['error' => $ex]]); | |
| 121 | + wp_send_json_error(['mess' => __('Error exception.', 'yaycommerce'), ['error' => $ex]]); | |
| 122 | 122 | } catch (\Error $ex) { |
| 123 | - \wp_send_json_error(['mess' => \__('Error.', 'yaycommerce'), ['error' => $ex]]); | |
| 123 | + wp_send_json_error(['mess' => __('Error.', 'yaycommerce'), ['error' => $ex]]); | |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | - public function ajax_activate_plugin() : void | |
| 126 | + public function ajax_activate_plugin(): void | |
| 127 | 127 | { |
| 128 | 128 | try { |
| 129 | - if (!\current_user_can('activate_plugins')) { | |
| 130 | - \wp_send_json_error(['mess' => \__('Permission denied', 'yaycommerce')]); | |
| 129 | + if (!current_user_can('activate_plugins')) { | |
| 130 | + wp_send_json_error(['mess' => __('Permission denied', 'yaycommerce')]); | |
| 131 | 131 | } |
| 132 | 132 | if (!isset($_POST['file'])) { |
| 133 | - \wp_send_json_error(['mess' => 'Missing file']); | |
| 133 | + wp_send_json_error(['mess' => 'Missing file']); | |
| 134 | 134 | } |
| 135 | - $nonce = isset($_POST['nonce']) ? \sanitize_text_field($_POST['nonce']) : ''; | |
| 136 | - if (!\wp_verify_nonce($nonce, 'yay_recommended_nonce')) { | |
| 137 | - \wp_send_json_error(['mess' => \__('Nonce is invalid', 'yaycommerce')]); | |
| 135 | + $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; | |
| 136 | + if (!wp_verify_nonce($nonce, 'yay_recommended_nonce')) { | |
| 137 | + wp_send_json_error(['mess' => __('Nonce is invalid', 'yaycommerce')]); | |
| 138 | 138 | } |
| 139 | - $file = \sanitize_text_field($_POST['file']); | |
| 140 | - $result = \activate_plugin($file); | |
| 141 | - if (\is_wp_error($result)) { | |
| 142 | - \wp_send_json_error(['mess' => $result->get_error_message()]); | |
| 139 | + $file = sanitize_text_field($_POST['file']); | |
| 140 | + $result = activate_plugin($file); | |
| 141 | + if (is_wp_error($result)) { | |
| 142 | + wp_send_json_error(['mess' => $result->get_error_message()]); | |
| 143 | 143 | } |
| 144 | - \wp_send_json_success(['mess' => \__('Activate success', 'yaycommerce')]); | |
| 144 | + wp_send_json_success(['mess' => __('Activate success', 'yaycommerce')]); | |
| 145 | 145 | } catch (\Exception $ex) { |
| 146 | - \wp_send_json_error(['mess' => \__('Error exception.', 'yaycommerce'), ['error' => $ex]]); | |
| 146 | + wp_send_json_error(['mess' => __('Error exception.', 'yaycommerce'), ['error' => $ex]]); | |
| 147 | 147 | } catch (\Error $ex) { |
| 148 | - \wp_send_json_error(['mess' => \__('Error.', 'yaycommerce'), ['error' => $ex]]); | |
| 148 | + wp_send_json_error(['mess' => __('Error.', 'yaycommerce'), ['error' => $ex]]); | |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | - public function ajax_upgrade_plugin() : void | |
| 151 | + public function ajax_upgrade_plugin(): void | |
| 152 | 152 | { |
| 153 | 153 | try { |
| 154 | - if (!\current_user_can('install_plugins')) { | |
| 155 | - \wp_send_json_error(['mess' => \__('Permission denied', 'yaycommerce')]); | |
| 154 | + if (!current_user_can('install_plugins')) { | |
| 155 | + wp_send_json_error(['mess' => __('Permission denied', 'yaycommerce')]); | |
| 156 | 156 | } |
| 157 | 157 | require_once \ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 158 | 158 | require_once \ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 159 | 159 | require_once \ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; |
| @@ -158,57 +158,57 @@ | ||
| 158 | 158 | require_once \ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 159 | 159 | require_once \ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; |
| 160 | 160 | require_once \ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; |
| 161 | 161 | if (!isset($_POST['plugin'])) { |
| 162 | - \wp_send_json_error(['mess' => 'Missing plugin']); | |
| 162 | + wp_send_json_error(['mess' => 'Missing plugin']); | |
| 163 | 163 | } |
| 164 | - $nonce = isset($_POST['nonce']) ? \sanitize_text_field($_POST['nonce']) : ''; | |
| 165 | - if (!\wp_verify_nonce($nonce, 'yay_recommended_nonce')) { | |
| 166 | - \wp_send_json_error(['mess' => \__('Nonce is invalid', 'yaycommerce')]); | |
| 164 | + $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; | |
| 165 | + if (!wp_verify_nonce($nonce, 'yay_recommended_nonce')) { | |
| 166 | + wp_send_json_error(['mess' => __('Nonce is invalid', 'yaycommerce')]); | |
| 167 | 167 | } |
| 168 | - $plugin = \sanitize_text_field($_POST['plugin']); | |
| 169 | - $type = isset($_POST['type']) ? \sanitize_text_field($_POST['type']) : 'install'; | |
| 168 | + $plugin = sanitize_text_field($_POST['plugin']); | |
| 169 | + $type = isset($_POST['type']) ? sanitize_text_field($_POST['type']) : 'install'; | |
| 170 | 170 | $skin = new \WP_Ajax_Upgrader_Skin(); |
| 171 | 171 | $upgrader = new \Plugin_Upgrader($skin); |
| 172 | 172 | if ('install' === $type) { |
| 173 | 173 | $result = $upgrader->install($plugin); |
| 174 | - if (\is_wp_error($result)) { | |
| 175 | - \wp_send_json_error(['mess' => $result->get_error_message()]); | |
| 174 | + if (is_wp_error($result)) { | |
| 175 | + wp_send_json_error(['mess' => $result->get_error_message()]); | |
| 176 | 176 | } |
| 177 | 177 | $args = ['slug' => $upgrader->result['destination_name'], 'fields' => ['short_description' => \true, 'icons' => \true, 'banners' => \false, 'reviews' => \false, 'sections' => \false]]; |
| 178 | - $plugin_data = \plugins_api('plugin_information', $args); | |
| 179 | - if ($plugin_data && !\is_wp_error($plugin_data)) { | |
| 180 | - $install_status = \install_plugin_install_status($plugin_data); | |
| 181 | - $active_plugin = \activate_plugin($install_status['file']); | |
| 182 | - if (\is_wp_error($active_plugin)) { | |
| 183 | - \wp_send_json_error(['mess' => $active_plugin->get_error_message()]); | |
| 178 | + $plugin_data = plugins_api('plugin_information', $args); | |
| 179 | + if ($plugin_data && !is_wp_error($plugin_data)) { | |
| 180 | + $install_status = install_plugin_install_status($plugin_data); | |
| 181 | + $active_plugin = activate_plugin($install_status['file']); | |
| 182 | + if (is_wp_error($active_plugin)) { | |
| 183 | + wp_send_json_error(['mess' => $active_plugin->get_error_message()]); | |
| 184 | 184 | } |
| 185 | - \wp_send_json_success(['mess' => \__('Install success', 'yaycommerce')]); | |
| 185 | + wp_send_json_success(['mess' => __('Install success', 'yaycommerce')]); | |
| 186 | 186 | } else { |
| 187 | - \wp_send_json_error(['mess' => 'Error']); | |
| 187 | + wp_send_json_error(['mess' => 'Error']); | |
| 188 | 188 | } |
| 189 | 189 | } else { |
| 190 | - $is_active = \is_plugin_active($plugin); | |
| 190 | + $is_active = is_plugin_active($plugin); | |
| 191 | 191 | $result = $upgrader->upgrade($plugin); |
| 192 | - if (\is_wp_error($result)) { | |
| 193 | - \wp_send_json_error(['mess' => $result->get_error_message()]); | |
| 192 | + if (is_wp_error($result)) { | |
| 193 | + wp_send_json_error(['mess' => $result->get_error_message()]); | |
| 194 | 194 | } |
| 195 | - \activate_plugin($plugin); | |
| 196 | - \wp_send_json_success(['mess' => \__('Update success', 'yaycommerce'), 'active' => $is_active]); | |
| 195 | + activate_plugin($plugin); | |
| 196 | + wp_send_json_success(['mess' => __('Update success', 'yaycommerce'), 'active' => $is_active]); | |
| 197 | 197 | } |
| 198 | 198 | } catch (\Exception $ex) { |
| 199 | - \wp_send_json_error(['mess' => \__('Error exception.', 'yaycommerce'), ['error' => $ex]]); | |
| 199 | + wp_send_json_error(['mess' => __('Error exception.', 'yaycommerce'), ['error' => $ex]]); | |
| 200 | 200 | } catch (\Error $ex) { |
| 201 | - \wp_send_json_error(['mess' => \__('Error.', 'yaycommerce'), ['error' => $ex]]); | |
| 201 | + wp_send_json_error(['mess' => __('Error.', 'yaycommerce'), ['error' => $ex]]); | |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | - public function check_pro_version_exists(array $plugin_detail) : ?string | |
| 204 | + public function check_pro_version_exists(array $plugin_detail): ?string | |
| 205 | 205 | { |
| 206 | - $all_plugins = \get_plugins(); | |
| 206 | + $all_plugins = get_plugins(); | |
| 207 | 207 | $slug = $plugin_detail['slug'] ?? ''; |
| 208 | 208 | $map = ['filebird' => ['filebird-pro/filebird.php'], 'yaymail' => ['yaymail-pro/yaymail.php', 'email-customizer-for-woocommerce/yaymail.php'], 'yaycurrency' => ['yaycurrency-pro/yay-currency.php', 'multi-currency-switcher/yay-currency.php'], 'yaysmtp' => ['yaysmtp-pro/yay-smtp.php'], 'yayswatches' => ['yayswatches-pro/yay-swatches.php'], 'yayextra' => ['yayextra-pro/yayextra.php'], 'yaypricing' => ['yaypricing-pro/yaypricing.php', 'dynamic-pricing-discounts/yaypricing.php'], 'yay-customer-reviews-woocommerce' => ['yayreviews-pro/yay-customer-reviews-woocommerce.php'], 'yay-wholesale-b2b' => ['yay-wholesale-b2b-pro/yay-wholesale-b2b.php'], 'yayboost-sales-booster-for-woocommerce' => ['yayboost-pro/yayboost-sales-booster-for-woocommerce.php'], 'cf7-multi-step' => ['contact-form-7-multi-step-pro/contact-form-7-multi-step.php'], 'cf7-database' => ['contact-form-7-database-pro/cf7-database.php'], 'wp-whatsapp' => ['whatsapp-for-wordpress/whatsapp.php']]; |
| 209 | 209 | foreach ($map[$slug] ?? [] as $basename) { |
| 210 | - if (\array_key_exists($basename, $all_plugins)) { | |
| 210 | + if (array_key_exists($basename, $all_plugins)) { | |
| 211 | 211 | return $basename; |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | return null; |