esc_html__( 'WooCommerce', 'artist-art-gallery' ), 'slug' => 'woocommerce', 'required' => false, ), array( 'name' => esc_html__( 'Stackable - Gutenberg Blocks', 'artist-art-gallery' ), 'slug' => 'stackable-ultimate-gutenberg-blocks', 'required' => false, ), array( 'name' => esc_html__( 'YITH WooCommerce Wishlist', 'artist-art-gallery' ), 'slug' => 'yith-woocommerce-wishlist', 'required' => false, ), array( 'name' => esc_html__( 'WordClever – AI Content Writer', 'artist-art-gallery' ), 'slug' => 'wordclever-ai-content-writer', 'required' => false, ) ); /* * Array of configuration settings. Amend each line as needed. * * TGMPA will start providing localized text strings soon. If you already have translations of our standard * strings available, please help us make TGMPA even better by giving us access to these translations or by * sending in a pull-request with .po file(s) with the translations. * * Only uncomment the strings in the config array if you want to customize the strings. */ $config = array( 'id' => 'artist-art-gallery', // Unique ID for hashing notices for multiple instances of TGMPA. 'default_path' => '', // Default absolute path to bundled plugins. 'menu' => 'tgmpa-install-plugins', // Menu slug. 'has_notices' => true, // Show admin notices or not. 'dismissable' => true, // If false, a user cannot dismiss the nag message. 'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag. 'is_automatic' => false, // Automatically activate plugins after installation or not. 'message' => '', // Message to output right before the plugins table. ); tgmpa( $plugins, $config ); } // WordClever – AI Content Writer plugin activation add_action('wp_ajax_install_and_activate_required_plugin', 'install_and_activate_required_plugin'); function install_and_activate_required_plugin() { // Verify nonce for security if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'install_activate_nonce')) { wp_send_json_error(['message' => 'Nonce verification failed.']); } // Include necessary WordPress files include_once ABSPATH . 'wp-admin/includes/plugin.php'; include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/misc.php'; include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $artist_art_gallery_upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); // Define required plugins $plugins = [ [ 'slug' => 'woocommerce', 'file' => 'woocommerce/woocommerce.php', 'url' => 'https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip', ], [ 'slug' => 'wordclever-ai-content-writer', 'file' => 'wordclever-ai-content-writer/wordclever.php', 'url' => 'https://downloads.wordpress.org/plugin/wordclever-ai-content-writer.latest-stable.zip', ], [ 'slug' => 'yith-woocommerce-wishlist', 'file' => 'yith-woocommerce-wishlist/init.php', 'url' => 'https://downloads.wordpress.org/plugin/yith-woocommerce-wishlist.latest-stable.zip', ], [ 'slug' => 'stackable-ultimate-gutenberg-blocks', 'file' => 'stackable-ultimate-gutenberg-blocks/plugin.php', 'url' => 'https://downloads.wordpress.org/plugin/stackable-ultimate-gutenberg-blocks.latest-stable.zip', ] ]; $artist_art_gallery_installed_plugins = get_plugins(); foreach ($plugins as $plugin) { // Install if not present if (!isset($artist_art_gallery_installed_plugins[$plugin['file']])) { $artist_art_gallery_install_result = $artist_art_gallery_upgrader->install($plugin['url']); if (is_wp_error($artist_art_gallery_install_result)) { wp_send_json_error(['message' => "Failed to install {$plugin['slug']}"]); } } // Activate if not active if (!is_plugin_active($plugin['file'])) { $artist_art_gallery_activate_result = activate_plugin($plugin['file']); if (is_wp_error($artist_art_gallery_activate_result)) { wp_send_json_error([ 'message' => "Failed to activate {$plugin['slug']}", 'error' => $$artist_art_gallery_activate_result->get_error_message(), ]); } } } // Success response wp_send_json_success(['message' => 'WooCommerce and WordClever plugins are activated successfully.']); }