Featured'; $woo_tab = '
  • WooCommerce
  • '; } else { $featured_tab = ''; $woo_tab = '
  • WooCommerce
  • '; } ?>
    wp_create_nonce('yay_recommended_nonce'), 'admin_ajax' => admin_url('admin-ajax.php'), 'woo_active' => function_exists('YayMailScoped\WC')]); wp_enqueue_script('yaycommerce-other-plugins'); } /** * Return the plugins to display. Filterable via yay_recommended_plugins_excluded. * * @return array */ public static function get_other_plugins(): array { return include __DIR__ . '/../../views/recommended-plugins-data.php'; } public function ajax_get_plugin_data(): void { try { if (!current_user_can('install_plugins')) { wp_send_json_error(['mess' => __('Permission denied', 'yaycommerce')]); } if (!isset($_POST['tab'])) { wp_send_json_error(['mess' => 'Missing tab']); } $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; if (!wp_verify_nonce($nonce, 'yay_recommended_nonce')) { wp_send_json_error(['mess' => __('Nonce is invalid', 'yaycommerce')]); } require_once \ABSPATH . 'wp-admin/includes/plugin-install.php'; $tab = sanitize_text_field($_POST['tab']); $recommended_data = apply_filters('yay_recommended_plugins_excluded', self::get_other_plugins()); $recommended_plugins = []; foreach ($recommended_data as $key => $plugin) { if (in_array($tab, $plugin['type'], \true) || 'all' === $tab) { $recommended_plugins[$key] = $plugin; } } ob_start(); include __DIR__ . '/../../views/recommended-plugins-page.php'; $html = ob_get_clean(); wp_send_json_success(['mess' => __('Get data success', 'yaycommerce'), 'html' => $html]); } catch (\Exception $ex) { wp_send_json_error(['mess' => __('Error exception.', 'yaycommerce'), ['error' => $ex]]); } catch (\Error $ex) { wp_send_json_error(['mess' => __('Error.', 'yaycommerce'), ['error' => $ex]]); } } public function ajax_activate_plugin(): void { try { if (!current_user_can('activate_plugins')) { wp_send_json_error(['mess' => __('Permission denied', 'yaycommerce')]); } if (!isset($_POST['file'])) { wp_send_json_error(['mess' => 'Missing file']); } $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; if (!wp_verify_nonce($nonce, 'yay_recommended_nonce')) { wp_send_json_error(['mess' => __('Nonce is invalid', 'yaycommerce')]); } $file = sanitize_text_field($_POST['file']); $result = activate_plugin($file); if (is_wp_error($result)) { wp_send_json_error(['mess' => $result->get_error_message()]); } wp_send_json_success(['mess' => __('Activate success', 'yaycommerce')]); } catch (\Exception $ex) { wp_send_json_error(['mess' => __('Error exception.', 'yaycommerce'), ['error' => $ex]]); } catch (\Error $ex) { wp_send_json_error(['mess' => __('Error.', 'yaycommerce'), ['error' => $ex]]); } } public function ajax_upgrade_plugin(): void { try { if (!current_user_can('install_plugins')) { wp_send_json_error(['mess' => __('Permission denied', 'yaycommerce')]); } require_once \ABSPATH . 'wp-admin/includes/plugin-install.php'; require_once \ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once \ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; require_once \ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; if (!isset($_POST['plugin'])) { wp_send_json_error(['mess' => 'Missing plugin']); } $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; if (!wp_verify_nonce($nonce, 'yay_recommended_nonce')) { wp_send_json_error(['mess' => __('Nonce is invalid', 'yaycommerce')]); } $plugin = sanitize_text_field($_POST['plugin']); $type = isset($_POST['type']) ? sanitize_text_field($_POST['type']) : 'install'; $skin = new \WP_Ajax_Upgrader_Skin(); $upgrader = new \Plugin_Upgrader($skin); if ('install' === $type) { $result = $upgrader->install($plugin); if (is_wp_error($result)) { wp_send_json_error(['mess' => $result->get_error_message()]); } $args = ['slug' => $upgrader->result['destination_name'], 'fields' => ['short_description' => \true, 'icons' => \true, 'banners' => \false, 'reviews' => \false, 'sections' => \false]]; $plugin_data = plugins_api('plugin_information', $args); if ($plugin_data && !is_wp_error($plugin_data)) { $install_status = install_plugin_install_status($plugin_data); $active_plugin = activate_plugin($install_status['file']); if (is_wp_error($active_plugin)) { wp_send_json_error(['mess' => $active_plugin->get_error_message()]); } wp_send_json_success(['mess' => __('Install success', 'yaycommerce')]); } else { wp_send_json_error(['mess' => 'Error']); } } else { $is_active = is_plugin_active($plugin); $result = $upgrader->upgrade($plugin); if (is_wp_error($result)) { wp_send_json_error(['mess' => $result->get_error_message()]); } activate_plugin($plugin); wp_send_json_success(['mess' => __('Update success', 'yaycommerce'), 'active' => $is_active]); } } catch (\Exception $ex) { wp_send_json_error(['mess' => __('Error exception.', 'yaycommerce'), ['error' => $ex]]); } catch (\Error $ex) { wp_send_json_error(['mess' => __('Error.', 'yaycommerce'), ['error' => $ex]]); } } public function check_pro_version_exists(array $plugin_detail): ?string { $all_plugins = get_plugins(); $slug = $plugin_detail['slug'] ?? ''; $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']]; foreach ($map[$slug] ?? [] as $basename) { if (array_key_exists($basename, $all_plugins)) { return $basename; } } return null; } }