當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TGM_Bulk_Installer::bulk_upgrade方法代碼示例

本文整理匯總了PHP中TGM_Bulk_Installer::bulk_upgrade方法的典型用法代碼示例。如果您正苦於以下問題:PHP TGM_Bulk_Installer::bulk_upgrade方法的具體用法?PHP TGM_Bulk_Installer::bulk_upgrade怎麽用?PHP TGM_Bulk_Installer::bulk_upgrade使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TGM_Bulk_Installer的用法示例。


在下文中一共展示了TGM_Bulk_Installer::bulk_upgrade方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: process_bulk_actions


//.........這裏部分代碼省略.........
         // Store all information in arrays since we are processing a bulk installation.
         $names = array();
         $sources = array();
         // Needed for installs.
         $file_paths = array();
         // Needed for upgrades.
         $to_inject = array();
         // Information to inject into the update_plugins transient.
         // Prepare the data for validated plugins for the install/upgrade.
         foreach ($plugins_to_install as $slug) {
             $name = $this->tgmpa->plugins[$slug]['name'];
             $source = $this->tgmpa->get_download_url($slug);
             if (!empty($name) && !empty($source)) {
                 $names[] = $name;
                 switch ($install_type) {
                     case 'install':
                         $sources[] = $source;
                         break;
                     case 'update':
                         $file_paths[] = $this->tgmpa->plugins[$slug]['file_path'];
                         $to_inject[$slug] = $this->tgmpa->plugins[$slug];
                         $to_inject[$slug]['source'] = $source;
                         break;
                 }
             }
         }
         unset($slug, $name, $source);
         // Create a new instance of TGM_Bulk_Installer.
         $installer = new TGM_Bulk_Installer(new TGM_Bulk_Installer_Skin(array('url' => esc_url_raw($this->tgmpa->get_tgmpa_url()), 'nonce' => 'bulk-' . $this->_args['plural'], 'names' => $names, 'install_type' => $install_type)));
         // Wrap the install process with the appropriate HTML.
         echo '<div class="tgmpa wrap">', '<h2>', esc_html(get_admin_page_title()), '</h2>';
         // Process the bulk installation submissions.
         add_filter('upgrader_source_selection', array($this->tgmpa, 'maybe_adjust_source_dir'), 1, 3);
         if ('tgmpa-bulk-update' === $this->current_action()) {
             // Inject our info into the update transient.
             $this->tgmpa->inject_update_info($to_inject);
             $installer->bulk_upgrade($file_paths);
         } else {
             $installer->bulk_install($sources);
         }
         remove_filter('upgrader_source_selection', array($this->tgmpa, 'maybe_adjust_source_dir'), 1, 3);
         echo '</div>';
         return true;
     }
     // Bulk activation process.
     if ('tgmpa-bulk-activate' === $this->current_action()) {
         check_admin_referer('bulk-' . $this->_args['plural']);
         // Did user actually select any plugins to activate ?
         if (empty($_POST['plugin'])) {
             echo '<div id="message" class="error"><p>', esc_html__('No plugins were selected to be activated. No action taken.', 'omega'), '</p></div>';
             return false;
         }
         // Grab plugin data from $_POST.
         $plugins = array();
         if (isset($_POST['plugin'])) {
             $plugins = array_map('urldecode', (array) $_POST['plugin']);
             $plugins = array_map(array($this->tgmpa, 'sanitize_key'), $plugins);
         }
         $plugins_to_activate = array();
         $plugin_names = array();
         // Grab the file paths for the selected & inactive plugins from the registration array.
         foreach ($plugins as $slug) {
             if ($this->tgmpa->can_plugin_activate($slug)) {
                 $plugins_to_activate[] = $this->tgmpa->plugins[$slug]['file_path'];
                 $plugin_names[] = $this->tgmpa->plugins[$slug]['name'];
             }
         }
         unset($slug);
         // Return early if there are no plugins to activate.
         if (empty($plugins_to_activate)) {
             echo '<div id="message" class="error"><p>', esc_html__('No plugins are available to be activated at this time.', 'omega'), '</p></div>';
             return false;
         }
         // Now we are good to go - let's start activating plugins.
         $activate = activate_plugins($plugins_to_activate);
         if (is_wp_error($activate)) {
             echo '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>';
         } else {
             $count = count($plugin_names);
             // Count so we can use _n function.
             $plugin_names = array_map(array('TGM_Utils', 'wrap_in_strong'), $plugin_names);
             $last_plugin = array_pop($plugin_names);
             // Pop off last name to prep for readability.
             $imploded = empty($plugin_names) ? $last_plugin : implode(', ', $plugin_names) . ' ' . esc_html_x('and', 'plugin A *and* plugin B', 'omega') . ' ' . $last_plugin;
             printf('<div id="message" class="updated"><p>%1$s %2$s.</p></div>', esc_html(_n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'omega')), $imploded);
             // Update recently activated plugins option.
             $recent = (array) get_option('recently_activated');
             foreach ($plugins_to_activate as $plugin => $time) {
                 if (isset($recent[$plugin])) {
                     unset($recent[$plugin]);
                 }
             }
             update_option('recently_activated', $recent);
         }
         unset($_POST);
         // Reset the $_POST variable in case user wants to perform one action after another.
         return true;
     }
     return false;
 }
開發者ID:narabikke,項目名稱:wordpress,代碼行數:101,代碼來源:class-tgm-plugin-activation.php


注:本文中的TGM_Bulk_Installer::bulk_upgrade方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。