当前位置: 首页>>代码示例>>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;未经允许,请勿转载。