public static function execute($params) { // Set progress Ai1wm_Status::info(__('Activating plugins...', AI1WM_PLUGIN_NAME)); // Open the archive file for reading $archive = new Ai1wm_Extractor(ai1wm_archive_path($params)); // Include WordPress files $include_files = array_keys(_get_dropins()); // Include mu-plugins files $include_files = array_merge($include_files, array(AI1WM_MUPLUGINS_NAME)); // Unpack WordPress files and mu-plugins files $archive->extract_by_files_array(WP_CONTENT_DIR, $include_files); // Close the archive file $archive->close(); // Set progress Ai1wm_Status::info(__('Done activating plugins...', AI1WM_PLUGIN_NAME)); return $params; }
public static function execute($params) { // Set shutdown handler @register_shutdown_function('Ai1wm_Import_Done::shutdown'); // Check multisite.json file if (true === is_file(ai1wm_multisite_path($params))) { // Read multisite.json file $handle = fopen(ai1wm_multisite_path($params), 'r'); if ($handle === false) { throw new Ai1wm_Import_Exception(__('Unable to read multisite.json file', AI1WM_PLUGIN_NAME)); } // Parse multisite.json file $multisite = fread($handle, filesize(ai1wm_multisite_path($params))); $multisite = json_decode($multisite); // Close handle fclose($handle); // Activate plugins if (isset($multisite->Plugins) && ($active_sitewide_plugins = $multisite->Plugins)) { activate_plugins($active_sitewide_plugins, null, is_multisite()); } } // Open the archive file for reading $archive = new Ai1wm_Extractor(ai1wm_archive_path($params)); // Include WordPress files $include_files = array_keys(_get_dropins()); // Include mu-plugins files $include_files = array_merge($include_files, array(AI1WM_MUPLUGINS_NAME)); // Unpack WordPress files and mu-plugins files $archive->extract_by_files_array(WP_CONTENT_DIR, $include_files); // Close the archive file $archive->close(); // Load must-use plugins foreach (wp_get_mu_plugins() as $mu_plugin) { include_once $mu_plugin; } return $params; }
/** * Check the wp-content directory and retrieve all drop-ins with any plugin data. * * @since 3.0.0 * @return array Key is the file path and the value is an array of the plugin data. */ function get_dropins() { $dropins = array(); $plugin_files = array(); $_dropins = _get_dropins(); // These exist in the wp-content directory if ($plugins_dir = @opendir(WP_CONTENT_DIR)) { while (($file = readdir($plugins_dir)) !== false) { if (isset($_dropins[$file])) { $plugin_files[] = $file; } } } else { return $dropins; } @closedir($plugins_dir); if (empty($plugin_files)) { return $dropins; } foreach ($plugin_files as $plugin_file) { if (!is_readable(WP_CONTENT_DIR . "/{$plugin_file}")) { continue; } $plugin_data = get_plugin_data(WP_CONTENT_DIR . "/{$plugin_file}", false, false); //Do not apply markup/translate as it'll be cached. if (empty($plugin_data['Name'])) { $plugin_data['Name'] = $plugin_file; } $dropins[$plugin_file] = $plugin_data; } uksort($dropins, 'strnatcasecmp'); return $dropins; }
/** * @global string $status * @global int $page * @global string $s * @global array $totals * @param array $item */ public function single_row($item) { global $status, $page, $s, $totals; list($plugin_file, $plugin_data) = $item; $context = $status; $screen = $this->screen; // Pre-order. $actions = array('deactivate' => '', 'activate' => '', 'details' => '', 'edit' => '', 'delete' => ''); if ('mustuse' == $context) { $is_active = true; } elseif ('dropins' == $context) { $dropins = _get_dropins(); $plugin_name = $plugin_file; if ($plugin_file != $plugin_data['Name']) { $plugin_name .= '<br/>' . $plugin_data['Name']; } if (true === $dropins[$plugin_file][1]) { // Doesn't require a constant $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } elseif (defined($dropins[$plugin_file][1]) && constant($dropins[$plugin_file][1])) { // Constant is true $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } else { $is_active = false; $description = '<p><strong>' . $dropins[$plugin_file][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf(__('Requires <code>%s</code> in <code>wp-config.php</code>.'), "define('" . $dropins[$plugin_file][1] . "', true);") . '</p>'; } if ($plugin_data['Description']) { $description .= '<p>' . $plugin_data['Description'] . '</p>'; } } else { if ($screen->in_admin('network')) { $is_active = is_plugin_active_for_network($plugin_file); } else { $is_active = is_plugin_active($plugin_file); } if ($screen->in_admin('network')) { if ($is_active) { if (current_user_can('manage_network_plugins')) { $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; } } else { if (current_user_can('manage_network_plugins')) { $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; } if (current_user_can('delete_plugins') && !is_plugin_active($plugin_file)) { $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; } } } else { if ($is_active) { $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; } else { $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; if (!is_multisite() && current_user_can('delete_plugins')) { $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; } } // end if $is_active } // end if $screen->in_admin( 'network' ) if ((!is_multisite() || $screen->in_admin('network')) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file)) { $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; } } // end if $context $prefix = $screen->in_admin('network') ? 'network_admin_' : ''; /** * Filter the action links displayed for each plugin in the Plugins list table. * * The dynamic portion of the hook name, `$prefix`, refers to the context the * action links are displayed in. The 'network_admin_' prefix is used if the * current screen is the Network plugins list table. The prefix is empty ('') * if the current screen is the site plugins list table. * * The default action links for the Network plugins list table include * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'. * * The default action links for the site plugins list table include * 'Activate', 'Deactivate', and 'Edit', for a network site, and * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site. * * @since 2.5.0 * * @param array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters($prefix . 'plugin_action_links', array_filter($actions), $plugin_file, $plugin_data, $context); /** * Filter the list of action links displayed for a specific plugin. * * The first dynamic portion of the hook name, $prefix, refers to the context * the action links are displayed in. The 'network_admin_' prefix is used if the * current screen is the Network plugins list table. The prefix is empty ('') * if the current screen is the site plugins list table. * * The second dynamic portion of the hook name, $plugin_file, refers to the path * to the plugin file, relative to the plugins directory. * * @since 2.7.0 * * @param array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters($prefix . "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context); $class = $is_active ? 'active' : 'inactive'; $checkbox_id = "checkbox_" . md5($plugin_data['Name']); if (in_array($status, array('mustuse', 'dropins'))) { $checkbox = ''; } else { $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf(__('Select %s'), $plugin_data['Name']) . "</label>" . "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' id='" . $checkbox_id . "' />"; } if ('dropins' != $context) { $description = '<p>' . ($plugin_data['Description'] ? $plugin_data['Description'] : ' ') . '</p>'; $plugin_name = $plugin_data['Name']; } $id = sanitize_title($plugin_name); if (!empty($totals['upgrade']) && !empty($plugin_data['update'])) { $class .= ' update'; } echo "<tr id='{$id}' class='{$class}'>"; list($columns, $hidden) = $this->get_column_info(); foreach ($columns as $column_name => $column_display_name) { $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } switch ($column_name) { case 'cb': echo "<th scope='row' class='check-column'>{$checkbox}</th>"; break; case 'name': echo "<td class='plugin-title'{$style}><strong>{$plugin_name}</strong>"; echo $this->row_actions($actions, true); echo "</td>"; break; case 'description': echo "<td class='column-description desc'{$style}>\r\n\t\t\t\t\t\t<div class='plugin-description'>{$description}</div>\r\n\t\t\t\t\t\t<div class='{$class} second plugin-version-author-uri'>"; $plugin_meta = array(); if (!empty($plugin_data['Version'])) { $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']); } if (!empty($plugin_data['Author'])) { $author = $plugin_data['Author']; if (!empty($plugin_data['AuthorURI'])) { $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; } $plugin_meta[] = sprintf(__('By %s'), $author); } // Details link using API info, if available if (isset($plugin_data['slug']) && current_user_can('install_plugins')) { $plugin_meta[] = sprintf('<a href="%s" class="thickbox" aria-label="%s" data-title="%s">%s</a>', esc_url(network_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . '&TB_iframe=true&width=600&height=550')), esc_attr(sprintf(__('More information about %s'), $plugin_name)), esc_attr($plugin_name), __('View details')); } elseif (!empty($plugin_data['PluginURI'])) { $plugin_meta[] = sprintf('<a href="%s">%s</a>', esc_url($plugin_data['PluginURI']), __('Visit plugin site')); } /** * Filter the array of row meta for each plugin in the Plugins list table. * * @since 2.8.0 * * @param array $plugin_meta An array of the plugin's metadata, * including the version, author, * author URI, and plugin URI. * @param string $plugin_file Path to the plugin file, relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $status Status of the plugin. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use', * 'Drop-ins', 'Search'. */ $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status); echo implode(' | ', $plugin_meta); echo "</div></td>"; break; default: echo "<td class='{$column_name} column-{$column_name}'{$style}>"; /** * Fires inside each custom column of the Plugins list table. * * @since 3.1.0 * * @param string $column_name Name of the column. * @param string $plugin_file Path to the plugin file. * @param array $plugin_data An array of plugin data. */ do_action('manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data); echo "</td>"; } } echo "</tr>"; /** * Fires after each row in the Plugins list table. * * @since 2.3.0 * * @param string $plugin_file Path to the plugin file, relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $status Status of the plugin. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use', * 'Drop-ins', 'Search'. */ do_action('after_plugin_row', $plugin_file, $plugin_data, $status); /** * Fires after each specific row in the Plugins list table. * * The dynamic portion of the hook name, `$plugin_file`, refers to the path * to the plugin file, relative to the plugins directory. * * @since 2.7.0 * * @param string $plugin_file Path to the plugin file, relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $status Status of the plugin. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use', * 'Drop-ins', 'Search'. */ do_action("after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status); }
function single_row($plugin_file, $plugin_data) { global $status, $page, $s; $context = $status; $screen = get_current_screen(); // preorder $actions = array('network_deactivate' => '', 'deactivate' => '', 'network_only' => '', 'activate' => '', 'network_activate' => '', 'edit' => '', 'delete' => ''); if ('mustuse' == $context) { $is_active = true; } elseif ('dropins' == $context) { $dropins = _get_dropins(); $plugin_name = $plugin_file; if ($plugin_file != $plugin_data['Name']) { $plugin_name .= '<br/>' . $plugin_data['Name']; } if (true === $dropins[$plugin_file][1]) { // Doesn't require a constant $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } elseif (constant($dropins[$plugin_file][1])) { // Constant is true $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } else { $is_active = false; $description = '<p><strong>' . $dropins[$plugin_file][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf(__('Requires <code>%s</code> in <code>wp-config.php</code>.'), "define('" . $dropins[$plugin_file][1] . "', true);") . '</p>'; } if ($plugin_data['Description']) { $description .= '<p>' . $plugin_data['Description'] . '</p>'; } } else { $is_active_for_network = is_plugin_active_for_network($plugin_file); if ($screen->is_network) { $is_active = $is_active_for_network; } else { $is_active = is_plugin_active($plugin_file); } if ($is_active_for_network && !is_super_admin() && !$screen->is_network) { return; } if ($screen->is_network) { if ($is_active_for_network) { if (current_user_can('manage_network_plugins')) { $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; } } else { if (current_user_can('manage_network_plugins')) { $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; } if (current_user_can('delete_plugins') && !is_plugin_active($plugin_file)) { $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; } } } else { if ($is_active) { $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; } else { $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; if (!is_multisite() && current_user_can('delete_plugins')) { $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; } } // end if $is_active } // end if $screen->is_network if ((!is_multisite() || $screen->is_network) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file)) { $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; } } // end if $context $prefix = $screen->is_network ? 'network_admin_' : ''; $actions = apply_filters($prefix . 'plugin_action_links', array_filter($actions), $plugin_file, $plugin_data, $context); $actions = apply_filters($prefix . "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context); $class = $is_active ? 'active' : 'inactive'; $checkbox_id = "checkbox_" . md5($plugin_data['Name']); $checkbox = in_array($status, array('mustuse', 'dropins')) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $plugin_data['Name'] . "</label>"; if ('dropins' != $context) { $description = '<p>' . ($plugin_data['Description'] ? $plugin_data['Description'] : ' ') . '</p>'; $plugin_name = $plugin_data['Name']; } $id = sanitize_title($plugin_name); echo "<tr id='{$id}' class='{$class}'>"; list($columns, $hidden) = $this->get_column_info(); foreach ($columns as $column_name => $column_display_name) { $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } switch ($column_name) { case 'cb': echo "<th scope='row' class='check-column'>{$checkbox}</th>"; break; case 'name': echo "<td class='plugin-title'{$style}><strong>{$plugin_name}</strong>"; echo $this->row_actions($actions, true); echo "</td>"; break; case 'description': echo "<td class='column-description desc'{$style}>\n\t\t\t\t\t\t<div class='plugin-description'>{$description}</div>\n\t\t\t\t\t\t<div class='{$class} second plugin-version-author-uri'>"; $plugin_meta = array(); if (!empty($plugin_data['Version'])) { $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']); } if (!empty($plugin_data['Author'])) { $author = $plugin_data['Author']; if (!empty($plugin_data['AuthorURI'])) { $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__('Visit author homepage') . '">' . $plugin_data['Author'] . '</a>'; } $plugin_meta[] = sprintf(__('By %s'), $author); } if (!empty($plugin_data['PluginURI'])) { $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__('Visit plugin site') . '">' . __('Visit plugin site') . '</a>'; } $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status); echo implode(' | ', $plugin_meta); echo "</div></td>"; break; default: echo "<td class='{$column_name} column-{$column_name}'{$style}>"; do_action('manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data); echo "</td>"; } } echo "</tr>"; do_action('after_plugin_row', $plugin_file, $plugin_data, $status); do_action("after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status); }
/** * Restore backed-up drop-ins. * * @since 4.2.0 * * @access private */ private function _restore_drop_ins() { $di_bu_dir = WP_CONTENT_DIR . '/drop-ins-backup'; foreach (_get_dropins() as $file_to_move => $v) { if (file_exists($di_bu_dir . '/' . $file_to_move)) { rename($di_bu_dir . '/' . $file_to_move, WP_CONTENT_DIR . '/' . $file_to_move); } } if (is_dir($di_bu_dir)) { rmdir($di_bu_dir); } }
/** * @ignore * * @param array $plugins * @param string $context */ function print_plugins_table($plugins, $context = '') { global $page; $checkbox = !in_array($context, array('mustuse', 'dropins')) ? '<input type="checkbox" />' : ''; ?> <table class="widefat" cellspacing="0" id="<?php echo $context; ?> -plugins-table"> <thead> <tr> <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?> </th> <th scope="col" class="manage-column"><?php _e('Plugin'); ?> </th> <th scope="col" class="manage-column"><?php _e('Description'); ?> </th> </tr> </thead> <tfoot> <tr> <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?> </th> <th scope="col" class="manage-column"><?php _e('Plugin'); ?> </th> <th scope="col" class="manage-column"><?php _e('Description'); ?> </th> </tr> </tfoot> <tbody class="plugins"> <?php if (empty($plugins)) { echo '<tr> <td colspan="3">' . __('No plugins to show') . '</td> </tr>'; } foreach ((array) $plugins as $plugin_file => $plugin_data) { // preorder $actions = array('network_deactivate' => '', 'deactivate' => '', 'network_only' => '', 'activate' => '', 'network_activate' => '', 'edit' => '', 'delete' => ''); if ('mustuse' == $context) { $is_active = true; } elseif ('dropins' == $context) { $dropins = _get_dropins(); $plugin_name = $plugin_file; if ($plugin_file != $plugin_data['Name']) { $plugin_name .= '<br/>' . $plugin_data['Name']; } if (true === $dropins[$plugin_file][1]) { // Doesn't require a constant $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } elseif (constant($dropins[$plugin_file][1])) { // Constant is true $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } else { $is_active = false; $description = '<p><strong>' . $dropins[$plugin_file][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf(__('Requires <code>%s</code> in <code>wp-config.php</code>.'), "define('" . $dropins[$plugin_file][1] . "', true);") . '</p>'; } if ($plugin_data['Description']) { $description .= '<p>' . $plugin_data['Description'] . '</p>'; } } else { $is_active_for_network = is_plugin_active_for_network($plugin_file); $is_active = $is_active_for_network || is_plugin_active($plugin_file); if ($is_active_for_network && !is_super_admin()) { continue; } if ($is_active) { if ($is_active_for_network) { if (is_super_admin()) { $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; } } else { $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; } } else { if (is_multisite() && is_network_only_plugin($plugin_file)) { $actions['network_only'] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>'; } else { $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; } if (is_multisite() && current_user_can('manage_network_plugins')) { $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; } if (current_user_can('delete_plugins')) { $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; } } // end if $is_active if (current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file)) { $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; } } // end if $context $actions = apply_filters('plugin_action_links', array_filter($actions), $plugin_file, $plugin_data, $context); $actions = apply_filters("plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context); $class = $is_active ? 'active' : 'inactive'; $checkbox = in_array($context, array('mustuse', 'dropins')) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />"; if ('dropins' != $context) { $description = '<p>' . $plugin_data['Description'] . '</p>'; $plugin_name = $plugin_data['Name']; } echo "\n\t<tr class='{$class}'>\n\t\t<th scope='row' class='check-column'>{$checkbox}</th>\n\t\t<td class='plugin-title'><strong>{$plugin_name}</strong></td>\n\t\t<td class='desc'>{$description}</td>\n\t</tr>\n\t<tr class='{$class} second'>\n\t\t<td></td>\n\t\t<td class='plugin-title'>"; echo '<div class="row-actions-visible">'; foreach ($actions as $action => $link) { $sep = end($actions) == $link ? '' : ' | '; echo "<span class='{$action}'>{$link}{$sep}</span>"; } echo "</div></td>\n\t\t<td class='desc'>"; $plugin_meta = array(); if (!empty($plugin_data['Version'])) { $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']); } if (!empty($plugin_data['Author'])) { $author = $plugin_data['Author']; if (!empty($plugin_data['AuthorURI'])) { $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __('Visit author homepage') . '">' . $plugin_data['Author'] . '</a>'; } $plugin_meta[] = sprintf(__('By %s'), $author); } if (!empty($plugin_data['PluginURI'])) { $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __('Visit plugin site') . '">' . __('Visit plugin site') . '</a>'; } $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $context); echo implode(' | ', $plugin_meta); echo "</td>\n\t</tr>\n"; do_action('after_plugin_row', $plugin_file, $plugin_data, $context); do_action("after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $context); } ?> </tbody> </table> <?php }
/** * @global string $status * @global int $page * @global string $s * @global array $totals * * @param array $item */ public function single_row($item) { global $status, $page, $s, $totals; list($plugin_file, $plugin_data) = $item; $context = $status; $screen = $this->screen; // Pre-order. $actions = array('deactivate' => '', 'activate' => '', 'details' => '', 'edit' => '', 'delete' => ''); // Do not restrict by default $restrict_network_active = false; $restrict_network_only = false; if ('mustuse' === $context) { $is_active = true; } elseif ('dropins' === $context) { $dropins = _get_dropins(); $plugin_name = $plugin_file; if ($plugin_file != $plugin_data['Name']) { $plugin_name .= '<br/>' . $plugin_data['Name']; } if (true === $dropins[$plugin_file][1]) { // Doesn't require a constant $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } elseif (defined($dropins[$plugin_file][1]) && constant($dropins[$plugin_file][1])) { // Constant is true $is_active = true; $description = '<p><strong>' . $dropins[$plugin_file][0] . '</strong></p>'; } else { $is_active = false; $description = '<p><strong>' . $dropins[$plugin_file][0] . ' <span class="error-message">' . __('Inactive:') . '</span></strong> ' . sprintf(__('Requires %1$s in %2$s file.'), "<code>define('" . $dropins[$plugin_file][1] . "', true);</code>", '<code>wp-config.php</code>') . '</p>'; } if ($plugin_data['Description']) { $description .= '<p>' . $plugin_data['Description'] . '</p>'; } } else { if ($screen->in_admin('network')) { $is_active = is_plugin_active_for_network($plugin_file); } else { $is_active = is_plugin_active($plugin_file); $restrict_network_active = is_multisite() && is_plugin_active_for_network($plugin_file); $restrict_network_only = is_multisite() && is_network_only_plugin($plugin_file) && !$is_active; } if ($screen->in_admin('network')) { if ($is_active) { if (current_user_can('manage_network_plugins')) { /* translators: %s: plugin name */ $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" aria-label="' . esc_attr(sprintf(__('Network deactivate %s'), $plugin_data['Name'])) . '">' . __('Network Deactivate') . '</a>'; } } else { if (current_user_can('manage_network_plugins')) { /* translators: %s: plugin name */ $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" class="edit" aria-label="' . esc_attr(sprintf(__('Network Activate %s'), $plugin_data['Name'])) . '">' . __('Network Activate') . '</a>'; } if (current_user_can('delete_plugins') && !is_plugin_active($plugin_file)) { /* translators: %s: plugin name */ $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" class="delete" aria-label="' . esc_attr(sprintf(__('Delete %s'), $plugin_data['Name'])) . '">' . __('Delete') . '</a>'; } } } else { if ($restrict_network_active) { $actions = array('network_active' => __('Network Active')); } elseif ($restrict_network_only) { $actions = array('network_only' => __('Network Only')); } elseif ($is_active) { /* translators: %s: plugin name */ $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" aria-label="' . esc_attr(sprintf(__('Deactivate %s'), $plugin_data['Name'])) . '">' . __('Deactivate') . '</a>'; } else { /* translators: %s: plugin name */ $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" class="edit" aria-label="' . esc_attr(sprintf(__('Activate %s'), $plugin_data['Name'])) . '">' . __('Activate') . '</a>'; if (!is_multisite() && current_user_can('delete_plugins')) { /* translators: %s: plugin name */ $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" class="delete" aria-label="' . esc_attr(sprintf(__('Delete %s'), $plugin_data['Name'])) . '">' . __('Delete') . '</a>'; } } // end if $is_active } // end if $screen->in_admin( 'network' ) if ((!is_multisite() || $screen->in_admin('network')) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file)) { /* translators: %s: plugin name */ $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" class="edit" aria-label="' . esc_attr(sprintf(__('Edit %s'), $plugin_data['Name'])) . '">' . __('Edit') . '</a>'; } } // end if $context $actions = array_filter($actions); if ($screen->in_admin('network')) { /** * Filter the action links displayed for each plugin in the Network Admin Plugins list table. * * The default action links for the Network plugins list table include * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'. * * @since 3.1.0 As `{$prefix}_plugin_action_links` * @since 4.4.0 * * @param array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters('network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context); /** * Filter the list of action links displayed for a specific plugin in the Network Admin Plugins list table. * * The dynamic portion of the hook name, $plugin_file, refers to the path * to the plugin file, relative to the plugins directory. * * @since 3.1.0 As `{$prefix}_plugin_action_links_{$plugin_file}` * @since 4.4.0 * * @param array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters("network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context); } else { /** * Filter the action links displayed for each plugin in the Plugins list table. * * The default action links for the site plugins list table include * 'Activate', 'Deactivate', and 'Edit', for a network site, and * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site. * * @since 2.5.0 As `{$prefix}_plugin_action_links` * @since 4.4.0 * * @param array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters('plugin_action_links', $actions, $plugin_file, $plugin_data, $context); /** * Filter the list of action links displayed for a specific plugin in the Plugins list table. * * The dynamic portion of the hook name, $plugin_file, refers to the path * to the plugin file, relative to the plugins directory. * * @since 2.7.0 As `{$prefix}_plugin_action_links_{$plugin_file}` * @since 4.4.0 * * @param array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters("plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context); } $class = $is_active ? 'active' : 'inactive'; $checkbox_id = "checkbox_" . md5($plugin_data['Name']); if ($restrict_network_active || $restrict_network_only || in_array($status, array('mustuse', 'dropins'))) { $checkbox = ''; } else { $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf(__('Select %s'), $plugin_data['Name']) . "</label>" . "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' id='" . $checkbox_id . "' />"; } if ('dropins' != $context) { $description = '<p>' . ($plugin_data['Description'] ? $plugin_data['Description'] : ' ') . '</p>'; $plugin_name = $plugin_data['Name']; } $id = sanitize_title($plugin_name); if (!empty($totals['upgrade']) && !empty($plugin_data['update'])) { $class .= ' update'; } $plugin_slug = isset($plugin_data['slug']) ? $plugin_data['slug'] : ''; printf("<tr id='%s' class='%s' data-slug='%s'>", $id, $class, $plugin_slug); list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); foreach ($columns as $column_name => $column_display_name) { $extra_classes = ''; if (in_array($column_name, $hidden)) { $extra_classes = ' hidden'; } switch ($column_name) { case 'cb': echo "<th scope='row' class='check-column'>{$checkbox}</th>"; break; case 'name': echo "<td class='plugin-title column-primary'><strong>{$plugin_name}</strong>"; echo $this->row_actions($actions, true); echo "</td>"; break; case 'description': $classes = 'column-description desc'; echo "<td class='{$classes}{$extra_classes}'>\n\t\t\t\t\t\t<div class='plugin-description'>{$description}</div>\n\t\t\t\t\t\t<div class='{$class} second plugin-version-author-uri'>"; $plugin_meta = array(); if (!empty($plugin_data['Version'])) { $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']); } if (!empty($plugin_data['Author'])) { $author = $plugin_data['Author']; if (!empty($plugin_data['AuthorURI'])) { $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; } $plugin_meta[] = sprintf(__('By %s'), $author); } // Details link using API info, if available if (!empty($plugin_data['PluginURI'])) { $plugin_meta[] = sprintf('<a href="%s">%s</a>', esc_url($plugin_data['PluginURI']), __('Visit plugin site')); } /** * Filter the array of row meta for each plugin in the Plugins list table. * * @since 2.8.0 * * @param array $plugin_meta An array of the plugin's metadata, * including the version, author, * author URI, and plugin URI. * @param string $plugin_file Path to the plugin file, relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $status Status of the plugin. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use', * 'Drop-ins', 'Search'. */ $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status); echo implode(' | ', $plugin_meta); echo "</div></td>"; break; default: $classes = "{$column_name} column-{$column_name}{$class}"; echo "<td class='{$classes}{$extra_classes}'>"; /** * Fires inside each custom column of the Plugins list table. * * @since 3.1.0 * * @param string $column_name Name of the column. * @param string $plugin_file Path to the plugin file. * @param array $plugin_data An array of plugin data. */ do_action('manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data); echo "</td>"; } } echo "</tr>"; /** * Fires after each row in the Plugins list table. * * @since 2.3.0 * * @param string $plugin_file Path to the plugin file, relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $status Status of the plugin. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use', * 'Drop-ins', 'Search'. */ do_action('after_plugin_row', $plugin_file, $plugin_data, $status); /** * Fires after each specific row in the Plugins list table. * * The dynamic portion of the hook name, `$plugin_file`, refers to the path * to the plugin file, relative to the plugins directory. * * @since 2.7.0 * * @param string $plugin_file Path to the plugin file, relative to the plugins directory. * @param array $plugin_data An array of plugin data. * @param string $status Status of the plugin. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use', * 'Drop-ins', 'Search'. */ do_action("after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status); }
public static function execute($params) { // Read blogs.json file $handle = fopen(ai1wm_blogs_path($params), 'r'); if ($handle === false) { throw new Ai1wm_Import_Exception('Unable to read blogs.json file'); } // Parse blogs.json file $blogs = fread($handle, filesize(ai1wm_blogs_path($params))); $blogs = json_decode($blogs); // Close handle fclose($handle); // Set content offset if (isset($params['content_offset'])) { $content_offset = (int) $params['content_offset']; } else { $content_offset = 0; } // Set archive offset if (isset($params['archive_offset'])) { $archive_offset = (int) $params['archive_offset']; } else { $archive_offset = 0; } // Get total files if (isset($params['total_files'])) { $total_files = (int) $params['total_files']; } else { $total_files = 1; } // Get total size if (isset($params['total_size'])) { $total_size = (int) $params['total_size']; } else { $total_size = 1; } // Get processed files if (isset($params['processed'])) { $processed = (int) $params['processed']; } else { $processed = 0; } // What percent of files have we processed? $progress = (int) ($processed / $total_size * 100); // Set progress if (empty($content_offset)) { Ai1wm_Status::info(sprintf(__('Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME), $total_files, $progress)); } // Start time $start = microtime(true); // Flag to hold if all files have been processed $completed = true; // Open the archive file for reading $archive = new Ai1wm_Extractor(ai1wm_archive_path($params)); // Set the file pointer to the one that we have saved $archive->set_file_pointer(null, $archive_offset); $old_paths = array(); $new_paths = array(); // Set extract paths foreach ($blogs as $blog) { if (defined('UPLOADBLOGSDIR')) { // Old sites dir style $old_paths[] = ai1wm_files_path($blog->Old->Id); $new_paths[] = ai1wm_files_path($blogs->New->Id); // New sites dir style $old_paths[] = ai1wm_sites_path($blog->Old->Id); $new_paths[] = ai1wm_files_path($blog->New->Id); } else { // Old sites dir style $old_paths[] = ai1wm_files_path($blog->Old->Id); $new_paths[] = ai1wm_sites_path($blog->New->Id); // New sites dir style $old_paths[] = ai1wm_sites_path($blog->Old->Id); $new_paths[] = ai1wm_sites_path($blog->New->Id); } } while ($archive->has_not_reached_eof()) { try { // Exclude WordPress files $exclude_files = array_keys(_get_dropins()); // Exclude plugin files $exclude_files = array_merge($exclude_files, array(AI1WM_PACKAGE_NAME, AI1WM_MULTISITE_NAME, AI1WM_DATABASE_NAME, AI1WM_MUPLUGINS_NAME)); // Extract a file from archive to WP_CONTENT_DIR if ($content_offset = $archive->extract_one_file_to(WP_CONTENT_DIR, $exclude_files, $old_paths, $new_paths, $content_offset, 10)) { // Set progress if ($processed += $content_offset) { $progress = (int) ($processed / $total_size * 100); } // Set progress Ai1wm_Status::info(sprintf(__('Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME), $total_files, $progress)); // Set content offset $params['content_offset'] = $content_offset; // Set archive offset $params['archive_offset'] = $archive_offset; // Set completed flag $params['completed'] = false; // Close the archive file $archive->close(); return $params; } // Set content offset $content_offset = 0; // Set archive offset $archive_offset = $archive->get_file_pointer(); } catch (Exception $e) { // Skip bad file permissions } // Increment processed files $processed += $archive->get_current_filesize(); // More than 10 seconds have passed, break and do another request if (microtime(true) - $start > 10) { $completed = false; break; } } // Set content offset $params['content_offset'] = $content_offset; // Set archive offset $params['archive_offset'] = $archive_offset; // Set processed files $params['processed'] = $processed; // Set completed flag $params['completed'] = $completed; // Close the archive file $archive->close(); return $params; }