/**
 * Update a plugin
 *
 * @access private
 * @param mixed $plugin
 * @return array
 */
function _wprp_upgrade_plugin($plugin)
{
    include_once ABSPATH . 'wp-admin/includes/admin.php';
    if (!_wprp_supports_plugin_upgrade()) {
        return array('status' => 'error', 'error' => 'WordPress version too old for plugin upgrades');
    }
    $skin = new WPRP_Plugin_Upgrader_Skin();
    $upgrader = new Plugin_Upgrader($skin);
    $is_active = is_plugin_active($plugin);
    // Do the upgrade
    ob_start();
    $result = $upgrader->upgrade($plugin);
    $data = ob_get_contents();
    ob_clean();
    if (!$result && !is_null($result) || $data) {
        return array('status' => 'error', 'error' => 'file_permissions_error');
    } elseif (is_wp_error($result)) {
        return array('status' => 'error', 'error' => $result->get_error_code());
    }
    if ($skin->error) {
        return array('status' => 'error', 'error' => $skin->error);
    }
    // If the plugin was activited, we have to re-activate it
    // @todo Shouldn't this use activate_plugin?
    if ($is_active) {
        $current = get_option('active_plugins', array());
        $current[] = plugin_basename(trim($plugin));
        sort($current);
        update_option('active_plugins', $current);
    }
    return array('status' => 'success');
}
示例#2
0
 // TODO Instead should just fire actions which we hook into.
 // TODO should namespace api methods?
 switch ($action) {
     // TODO should be dynamic
     case 'get_plugin_version':
         $actions[$action] = '1.1';
         break;
     case 'get_filesystem_method':
         $actions[$action] = get_filesystem_method();
         break;
     case 'get_wp_version':
         global $wp_version;
         $actions[$action] = (string) $wp_version;
         break;
     case 'get_plugins':
         $actions[$action] = _wprp_supports_plugin_upgrade() ? _wprp_get_plugins() : 'not-implemented';
         break;
     case 'upgrade_plugin':
         $actions[$action] = _wprp_upgrade_plugin((string) $_GET['plugin']);
         break;
     case 'get_themes':
         $actions[$action] = _wprp_supports_theme_upgrade() ? _wprp_get_themes() : 'not-implemented';
         break;
     case 'upgrade_theme':
         $actions[$action] = _wprp_upgrade_theme((string) $_GET['theme']);
         break;
     case 'do_backup':
     case 'delete_backup':
     case 'supports_backups':
     case 'get_backup':
         $actions[$action] = _wprp_backups_api_call($action);