示例#1
0
/**
 * Delete a theme.
 *
 * @param mixed $theme
 * @return array
 */
function _wprp_delete_theme($theme)
{
    global $wp_filesystem;
    if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
        return new WP_Error('disallow-file-mods', __("File modification is disabled with the DISALLOW_FILE_MODS constant.", 'wpremote'));
    }
    if (!wp_get_theme($theme)->exists()) {
        return new WP_Error('theme-missing', __('Theme is not installed.', 'wpremote'));
    }
    include_once ABSPATH . 'wp-admin/includes/admin.php';
    include_once ABSPATH . 'wp-admin/includes/upgrade.php';
    include_once ABSPATH . 'wp-includes/update.php';
    if (!_wpr_check_filesystem_access() || !WP_Filesystem()) {
        return new WP_Error('filesystem-not-writable', __('The filesystem is not writable with the supplied credentials', 'wpremote'));
    }
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('theme-dir-missing', __('Unable to locate WordPress theme directory', 'wpremote'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $theme);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('theme-delete', sprintf(__('Could not fully delete the theme: %s.', 'wpremote'), $theme));
    }
    // Force refresh of theme update information
    delete_site_transient('update_themes');
    return array('status' => 'success');
}
示例#2
0
/**
 * Uninstall a plugin on this site.
 */
function _wprp_uninstall_plugin($plugin)
{
    global $wp_filesystem;
    if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
        return new WP_Error('disallow-file-mods', __("File modification is disabled with the DISALLOW_FILE_MODS constant.", 'wpremote'));
    }
    include_once ABSPATH . 'wp-admin/includes/admin.php';
    include_once ABSPATH . 'wp-admin/includes/upgrade.php';
    include_once ABSPATH . 'wp-includes/update.php';
    if (!_wpr_check_filesystem_access() || !WP_Filesystem()) {
        return new WP_Error('filesystem-not-writable', __('The filesystem is not writable with the supplied credentials', 'wpremote'));
    }
    $plugins_dir = $wp_filesystem->wp_plugins_dir();
    if (empty($plugins_dir)) {
        return new WP_Error('missing-plugin-dir', __('Unable to locate WordPress Plugin directory.', 'wpremote'));
    }
    $plugins_dir = trailingslashit($plugins_dir);
    if (is_uninstallable_plugin($plugin)) {
        uninstall_plugin($plugin);
    }
    $this_plugin_dir = trailingslashit(dirname($plugins_dir . $plugin));
    // If plugin is in its own directory, recursively delete the directory.
    if (strpos($plugin, '/') && $this_plugin_dir != $plugins_dir) {
        //base check on if plugin includes directory separator AND that it's not the root plugin folder
        $deleted = $wp_filesystem->delete($this_plugin_dir, true);
    } else {
        $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
    }
    if ($deleted) {
        if ($current = get_site_transient('update_plugins')) {
            unset($current->response[$plugin]);
            set_site_transient('update_plugins', $current);
        }
        return array('status' => 'success');
    } else {
        return new WP_Error('plugin-uninstall', __('Plugin uninstalled, but not deleted.', 'wpremote'));
    }
}
示例#3
0
function _wprp_upgrade_core()
{
    if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
        return new WP_Error('disallow-file-mods', __("File modification is disabled with the DISALLOW_FILE_MODS constant.", 'wpremote'));
    }
    include_once ABSPATH . 'wp-admin/includes/admin.php';
    include_once ABSPATH . 'wp-admin/includes/upgrade.php';
    include_once ABSPATH . 'wp-includes/update.php';
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    require_once WPRP_PLUGIN_PATH . 'inc/class-wprp-core-upgrader-skin.php';
    // check for filesystem access
    if (!_wpr_check_filesystem_access()) {
        return new WP_Error('filesystem-not-writable', __('The filesystem is not writable with the supplied credentials', 'wpremote'));
    }
    // force refresh
    wp_version_check();
    $updates = get_core_updates();
    if (is_wp_error($updates) || !$updates) {
        return new WP_Error('no-update-available');
    }
    $update = reset($updates);
    if (!$update) {
        return new WP_Error('no-update-available');
    }
    $skin = new WPRP_Core_Upgrader_Skin();
    $upgrader = new Core_Upgrader($skin);
    $result = $upgrader->upgrade($update);
    if (is_wp_error($result)) {
        return $result;
    }
    global $wp_current_db_version, $wp_db_version;
    // we have to include version.php so $wp_db_version
    // will take the version of the updated version of wordpress
    require ABSPATH . WPINC . '/version.php';
    wp_upgrade();
    return true;
}