id !== 'dashboard' && $current_screen->id !== 'themes') { return; } if (is_network_admin()) { return; } if (!current_user_can('manage_options')) { return; } ?>

'templategalaxy', 'file' => 'templategalaxy.php', 'name' => __('TemplateGalaxy', 'bloghoot') ), array( 'slug' => 'advanced-import', 'file' => 'advanced-import.php', 'name' => __('Advanced Import', 'bloghoot') ) // Add more plugins here as needed ); // Include the necessary WordPress functions // Set up a transient to store the installation progress set_transient('install_and_activate_progress', array(), MINUTE_IN_SECONDS * 10); // Loop through each plugin foreach ($recommended_plugins as $plugin) { $plugin_slug = $plugin['slug']; $plugin_file = $plugin['file']; $plugin_name = $plugin['name']; // Check if the plugin is active if (is_plugin_active($plugin_slug . '/' . $plugin_file)) { bloghoot_update_install_and_activate_progress($plugin_name, 'Already Active'); continue; // Skip to the next plugin } // Check if the plugin is installed but not active if (bloghoot_is_plugin_installed($plugin_slug . '/' . $plugin_file)) { $activate = activate_plugin($plugin_slug . '/' . $plugin_file); if (is_wp_error($activate)) { bloghoot_update_install_and_activate_progress($plugin_name, 'Error'); continue; // Skip to the next plugin } bloghoot_update_install_and_activate_progress($plugin_name, 'Activated'); continue; // Skip to the next plugin } // Plugin is not installed or activated, proceed with installation bloghoot_update_install_and_activate_progress($plugin_name, 'Installing'); // Fetch plugin information $api = plugins_api('plugin_information', array( 'slug' => $plugin_slug, 'fields' => array('sections' => false), )); // Check if plugin information is fetched successfully if (is_wp_error($api)) { bloghoot_update_install_and_activate_progress($plugin_name, 'Error'); continue; // Skip to the next plugin } // Set up the plugin upgrader $upgrader = new Plugin_Upgrader(); $install = $upgrader->install($api->download_link); // Check if installation is successful if ($install) { // Activate the plugin $activate = activate_plugin($plugin_slug . '/' . $plugin_file); // Check if activation is successful if (is_wp_error($activate)) { bloghoot_update_install_and_activate_progress($plugin_name, 'Error'); continue; // Skip to the next plugin } bloghoot_update_install_and_activate_progress($plugin_name, 'Activated'); } else { bloghoot_update_install_and_activate_progress($plugin_name, 'Error'); } } // Delete the progress transient $redirect_url = admin_url('themes.php?page=advanced-import'); // Delete the progress transient delete_transient('install_and_activate_progress'); // Return JSON response wp_send_json_success(array('redirect_url' => $redirect_url)); } // Function to check if a plugin is installed but not active function bloghoot_is_plugin_installed($plugin_slug) { $plugins = get_plugins(); return isset($plugins[$plugin_slug]); } // Function to update the installation and activation progress function bloghoot_update_install_and_activate_progress($plugin_name, $status) { $progress = get_transient('install_and_activate_progress'); $progress[] = array( 'plugin' => $plugin_name, 'status' => $status, ); set_transient('install_and_activate_progress', $progress, MINUTE_IN_SECONDS * 10); } function bloghoot_dashboard_menu() { add_theme_page(esc_html__('About Bloghoot', 'bloghoot'), esc_html__('About Bloghoot', 'bloghoot'), 'edit_theme_options', 'about-bloghoot', 'bloghoot_theme_info_display'); } add_action('admin_menu', 'bloghoot_dashboard_menu'); function bloghoot_theme_info_display() { ?>