protected function delete()
 {
     foreach ($this->themes as $theme) {
         // Don't delete an active child theme
         if (is_child_theme() && $theme == get_stylesheet()) {
             $error = $this->log[$theme]['error'] = 'You cannot delete a theme while it is active on the main site.';
             continue;
         }
         if ($theme == get_template()) {
             $error = $this->log[$theme]['error'] = 'You cannot delete a theme while it is active on the main site.';
             continue;
         }
         /**
          * Filters whether to use an alternative process for deleting a WordPress.com theme.
          * The alternative process can be executed during the filter.
          *
          * The filter can also return an instance of WP_Error; in which case the endpoint response will
          * contain this error.
          *
          * @module json-api
          *
          * @since 4.4.2
          *
          * @param bool   $use_alternative_delete_method Whether to use the alternative method of deleting
          *                                              a WPCom theme.
          * @param string $theme_slug                    Theme name (slug). If it is a WPCom theme,
          *                                              it should be suffixed with `-wpcom`.
          */
         $result = apply_filters('jetpack_wpcom_theme_delete', false, $theme);
         if (!$result) {
             $result = delete_theme($theme);
         }
         if (is_wp_error($result)) {
             $error = $this->log[$theme]['error'] = $result->get_error_messages;
         } else {
             $this->log[$theme][] = 'Theme deleted';
         }
     }
     if (!$this->bulk && isset($error)) {
         return new WP_Error('delete_theme_error', $error, 400);
     }
     return true;
 }
 protected function delete()
 {
     foreach ($this->themes as $theme) {
         // Don't delete an active child theme
         if (is_child_theme() && $theme == get_stylesheet()) {
             $error = $this->log[$theme]['error'] = 'You cannot delete a theme while it is active on the main site.';
             continue;
         }
         if ($theme == get_template()) {
             $error = $this->log[$theme]['error'] = 'You cannot delete a theme while it is active on the main site.';
             continue;
         }
         $result = delete_theme($theme);
         if (is_wp_error($result)) {
             $error = $this->log[$theme]['error'] = $result->get_error_messages;
         } else {
             $this->log[$theme][] = 'Theme deleted';
         }
     }
     if (!$this->bulk && isset($error)) {
         return new WP_Error('delete_theme_error', $error, 400);
     }
     return true;
 }
Example #3
0
 public function edit_themes($args)
 {
     extract($args);
     $return = array();
     foreach ($items as $item) {
         switch ($items_edit_action) {
             case 'activate':
                 switch_theme($item['path'], $item['stylesheet']);
                 break;
             case 'delete':
                 $result = delete_theme($item['path']);
                 break;
             default:
                 break;
         }
         if (is_wp_error($result)) {
             $result = array('error' => $result->get_error_message());
         } elseif ($result === false) {
             $result = array('error' => "Failed to perform action.");
         } else {
             $result = "OK";
         }
         $return[$item['name']] = $result;
     }
     return $return;
 }
/**
 * Ajax handler for deleting a theme.
 *
 * @since 4.6.0
 *
 * @see delete_theme()
 */
function wp_ajax_delete_theme()
{
    check_ajax_referer('updates');
    if (empty($_POST['slug'])) {
        wp_send_json_error(array('slug' => '', 'errorCode' => 'no_theme_specified', 'errorMessage' => __('No theme specified.')));
    }
    $stylesheet = sanitize_key(wp_unslash($_POST['slug']));
    $status = array('delete' => 'theme', 'slug' => $stylesheet);
    if (!current_user_can('delete_themes')) {
        $status['errorMessage'] = __('Sorry, you are not allowed to delete themes on this site.');
        wp_send_json_error($status);
    }
    if (!wp_get_theme($stylesheet)->exists()) {
        $status['errorMessage'] = __('The requested theme does not exist.');
        wp_send_json_error($status);
    }
    // Check filesystem credentials. `delete_theme()` will bail otherwise.
    $url = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    ob_start();
    $credentials = request_filesystem_credentials($url);
    ob_end_clean();
    if (false === $credentials || !WP_Filesystem($credentials)) {
        global $wp_filesystem;
        $status['errorCode'] = 'unable_to_connect_to_filesystem';
        $status['errorMessage'] = __('Unable to connect to the filesystem. Please confirm your credentials.');
        // Pass through the error from WP_Filesystem if one was raised.
        if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
            $status['errorMessage'] = esc_html($wp_filesystem->errors->get_error_message());
        }
        wp_send_json_error($status);
    }
    include_once ABSPATH . 'wp-admin/includes/theme.php';
    $result = delete_theme($stylesheet);
    if (is_wp_error($result)) {
        $status['errorMessage'] = $result->get_error_message();
        wp_send_json_error($status);
    } elseif (false === $result) {
        $status['errorMessage'] = __('Theme could not be deleted.');
        wp_send_json_error($status);
    }
    wp_send_json_success($status);
}
 function delete_default_content()
 {
     delete_theme('twentysixteen');
     delete_theme('twentyfifteen');
     delete_theme('twentyfourteen');
     delete_theme('twentythirteen');
     delete_theme('twentytwelve');
     delete_theme('twentyeleven');
     delete_theme('twentyten');
     delete_plugins(array('hello.php', 'akismet/akismet.php'));
 }
Example #6
0
 /**
  * Delete a theme.
  *
  * Removes the theme from the filesystem.
  *
  * ## OPTIONS
  *
  * <theme>...
  * : One or more themes to delete.
  *
  * ## EXAMPLES
  *
  *     $ wp theme delete twentytwelve
  *     Deleted 'twentytwelve' theme.
  *     Success: Deleted 1 of 1 themes.
  *
  * @alias uninstall
  */
 public function delete($args)
 {
     $successes = $errors = 0;
     foreach ($this->fetcher->get_many($args) as $theme) {
         $theme_slug = $theme->get_stylesheet();
         if ($this->is_active_theme($theme)) {
             WP_CLI::warning("Can't delete the currently active theme: {$theme_slug}");
             $errors++;
             continue;
         }
         $r = delete_theme($theme_slug);
         if (is_wp_error($r)) {
             WP_CLI::warning($r);
             $errors++;
         } else {
             WP_CLI::log("Deleted '{$theme_slug}' theme.");
             $successes++;
         }
     }
     if (!$this->chained_command) {
         Utils\report_batch_operation_results('theme', 'delete', count($args), $successes, $errors);
     }
 }
Example #7
0
            wp_die(__('Cheatin&#8217; uh?'), 403);
        }
        switch_theme($theme->get_stylesheet());
        wp_redirect(admin_url('themes.php?activated=true'));
        exit;
    } elseif ('delete' == $_GET['action']) {
        check_admin_referer('delete-theme_' . $_GET['stylesheet']);
        $theme = wp_get_theme($_GET['stylesheet']);
        if (!current_user_can('delete_themes') || !$theme->exists()) {
            wp_die(__('Cheatin&#8217; uh?'), 403);
        }
        $active = wp_get_theme();
        if ($active->get('Template') == $_GET['stylesheet']) {
            wp_redirect(admin_url('themes.php?delete-active-child=true'));
        } else {
            delete_theme($_GET['stylesheet']);
            wp_redirect(admin_url('themes.php?deleted=true'));
        }
        exit;
    }
}
$title = __('Manage Themes');
$parent_file = 'themes.php';
// Help tab: Overview
if (current_user_can('switch_themes')) {
    $help_overview = '<p>' . __('This screen is used for managing your installed themes. Aside from the default theme(s) included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' . '<p>' . __('From this screen you can:') . '</p>' . '<ul><li>' . __('Hover or tap to see Activate and Live Preview buttons') . '</li>' . '<li>' . __('Click on the theme to see the theme name, version, author, description, tags, and the Delete link') . '</li>' . '<li>' . __('Click Customize for the current theme or Live Preview for any other theme to see a live preview') . '</li></ul>' . '<p>' . __('The current theme is displayed highlighted as the first theme.') . '</p>' . '<p>' . __('The search for installed themes will search for terms in their name, description, author, or tag.') . ' <span id="live-search-desc">' . __('The search results will be updated as you type.') . '</span></p>';
    get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => $help_overview));
}
// switch_themes
// Help tab: Adding Themes
if (current_user_can('install_themes')) {
Example #8
0
 /**
  * Delete a theme.
  *
  * ## OPTIONS
  *
  * <theme>...
  * : One or more themes to delete.
  *
  * ## EXAMPLES
  *
  *     wp theme delete twentyeleven
  */
 function delete($args)
 {
     foreach ($this->fetcher->get_many($args) as $theme) {
         $theme_slug = $theme->get_stylesheet();
         if ($this->is_active_theme($theme)) {
             WP_CLI::warning("Can't delete the currently active theme: {$theme_slug}");
             continue;
         }
         $r = delete_theme($theme_slug);
         if (is_wp_error($r)) {
             WP_CLI::warning($r);
         } else {
             WP_CLI::success("Deleted '{$theme_slug}' theme.");
         }
     }
 }
Example #9
0
 function delete($args)
 {
     $this->_escape($args);
     $username = $args[0];
     $password = $args[1];
     $template = $args[2];
     if ($password != get_option('wpr_cron')) {
         if (!($user = $this->login($username, $password))) {
             return $this->error;
         }
         if (!current_user_can('update_themes')) {
             return new IXR_Error(401, 'Sorry, you are not allowed to delete themes from the remote blog.');
         }
     }
     ob_start();
     $result = delete_theme($template);
     ob_end_clean();
     if (is_wp_error($result)) {
         return new IXR_Error(401, 'Theme could not be deleted. ' . $result->get_error_message());
     }
     return TRUE;
 }
Example #10
0
 /**
  * Delete a theme.
  *
  * @synopsis <theme>
  */
 function delete($args)
 {
     list($file, $name) = $this->parse_name($args);
     $r = delete_theme($name);
     if (is_wp_error($r)) {
         WP_CLI::error($r);
     }
 }
Example #11
0
  switch ($data['action']) {
    case 'getAllThemesList':
      get_all_themes_list();
      break;
    case 'getAllThemes':
      get_all_themes();
      break;
    case 'getThemeInfo':
      get_theme_info();
      break;
    case 'saveThemeInfo':
      save_theme_info();
      break;
    case 'deleteTheme':
      delete_theme();
      break;
    case 'getAllCategoriesList':
      get_all_categories_list();
      break;
    case 'getCategoryInfo':
      get_category_info();
      break;
    case 'saveCategoryInfo':
      save_category_info();
      break;
    case 'deleteCategory':
      delete_category();
      break;
    case 'getAllLayersList':
      get_all_layers_list();
Example #12
0
 /**
  * Supprime les themes default de Wordpress
  *
  */
 public function wp_delete_theme()
 {
     require_once 'wp-load.php';
     require_once 'wp-admin/includes/upgrade.php';
     delete_theme('twentyfourteen');
     delete_theme('twentythirteen');
     delete_theme('twentytwelve');
     delete_theme('twentyeleven');
     delete_theme('twentyten');
     // We delete the _MACOSX folder (bug with a Mac)
     delete_theme('__MACOSX');
 }
 public function handleInstall($postInfo)
 {
     $this->_construct();
     // We add  ../ to directory
     $directory = !empty($postInfo['directory']) ? $postInfo['directory'] . '/' : '';
     // Every directory should be an extension of a user's
     // public_html directory
     $directory = Setting::where('name', 'DEFAULT_HOME_DIRECTORY')->first()->setting . Auth::user()->uid . "/public_html/" . $directory;
     // try {
     //    $db = new \PDO('mysql:host=127.0.0.1;dbname=tester_db_3496', 'tester_wp_3496', '9NQJ66gGN3XVDLm');
     // }
     // catch (Exception $e) {
     // 	$this->data['db'] = "error etablishing connection";
     // }
     // dd();
     switch ($postInfo['action']) {
         case "check_before_upload":
             $this->data = array();
             /*--------------------------*/
             /*	We verify if we can connect to DB or WP is not installed yet
             			/*--------------------------*/
             // WordPress test
             if (file_exists($directory . 'wp-config.php')) {
                 $this->data['wp'] = "error directory";
             }
             if (substr(sprintf('%o', fileperms($directory)), -4) != '0775') {
                 $this->data['wp'] = "error directory-permissions";
             }
             try {
                 MySQLDatabase::where('db_name', $postInfo['dbname'])->firstOrfail();
             } catch (ModelNotFoundException $e) {
                 // Create a database and a user
                 MySQLController::createDatabase($postInfo['dbname']);
                 MySQLController::createSoleUser($postInfo['uname'], $postInfo['pwd'], $postInfo['dbname']);
             }
             // We send the response
             echo json_encode($this->data);
             break;
         case "download_wp":
             // Get WordPress language
             $language = substr($postInfo['language'], 0, 6);
             // Get WordPress data
             $wp = json_decode(file_get_contents($this->WP_API_CORE . $language))->offers[0];
             /*--------------------------*/
             /*	We download the latest version of WordPress
             			/*--------------------------*/
             if (!file_exists($this->WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip')) {
                 file_put_contents($this->WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip', file_get_contents($wp->download));
             }
             break;
         case "unzip_wp":
             // Get WordPress language
             $language = substr($postInfo['language'], 0, 6);
             // Get WordPress data
             $wp = json_decode(file_get_contents($this->WP_API_CORE . $language))->offers[0];
             /*--------------------------*/
             /*	We create the website folder with the files and the WordPress folder
             			/*--------------------------*/
             $zip = new \ZipArchive();
             // We verify if we can use the archive
             if ($zip->open($this->WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip') === true) {
                 // Let's unzip
                 $zip->extractTo('.');
                 $zip->close();
                 // We scan the folder
                 $files = scandir('wordpress');
                 // We remove the "." and ".." from the current folder and its parent
                 $files = array_diff($files, array('.', '..'));
                 $this->recursive_copy('wordpress', $directory);
                 $this->rrmdir('wordpress');
                 // We remove WordPress folder
                 unlink($directory . '/license.txt');
                 // We remove licence.txt
                 unlink($directory . '/readme.html');
                 // We remove readme.html
                 unlink($directory . '/wp-content/plugins/hello.php');
                 // We remove Hello Dolly plugin
             }
             break;
         case "wp_config":
             /*--------------------------*/
             /*	Let's create the wp-config file
             			/*--------------------------*/
             // We retrieve each line as an array
             $config_file = file($directory . 'wp-config-sample.php');
             // Managing the security keys
             $secret_keys = explode("\n", file_get_contents('https://api.wordpress.org/secret-key/1.1/salt/'));
             foreach ($secret_keys as $k => $v) {
                 $secret_keys[$k] = substr($v, 28, 64);
             }
             // We change the data
             $key = 0;
             foreach ($config_file as &$line) {
                 if ('$table_prefix  =' == substr($line, 0, 16)) {
                     $line = '$table_prefix  = \'' . $this->sanit($postInfo['prefix']) . "';\r\n";
                     continue;
                 }
                 if (!preg_match('/^define\\(\'([A-Z_]+)\',([ ]+)/', $line, $match)) {
                     continue;
                 }
                 $constant = $match[1];
                 switch ($constant) {
                     case 'WP_DEBUG':
                         // Debug mod
                         if (isset($postInfo['debug']) && (int) $postInfo['debug'] == 1) {
                             $line = "define('WP_DEBUG', 'true');\r\n";
                             // Display error
                             if (isset($postInfo['debug_display']) && (int) $postInfo['debug_display'] == 1) {
                                 $line .= "\r\n\n " . "/** Affichage des erreurs à l'écran */" . "\r\n";
                                 $line .= "define('WP_DEBUG_DISPLAY', 'true');\r\n";
                             }
                             // To write error in a log files
                             if (isset($postInfo['debug_log']) && (int) $postInfo['debug_log'] == 1) {
                                 $line .= "\r\n\n " . "/** Ecriture des erreurs dans un fichier log */" . "\r\n";
                                 $line .= "define('WP_DEBUG_LOG', 'true');\r\n";
                             }
                         }
                         // We add the extras constant
                         if (isset($postInfo['uploads']) && !empty($postInfo['uploads'])) {
                             $line .= "\r\n\n " . "/** Dossier de destination des fichiers uploadés */" . "\r\n";
                             $line .= "define('UPLOADS', '" . $this->sanit($postInfo['uploads']) . "');";
                         }
                         if (isset($postInfo['post_revisions']) && (int) $postInfo['post_revisions'] >= 0) {
                             $line .= "\r\n\n " . "/** Désactivation des révisions d'articles */" . "\r\n";
                             $line .= "define('WP_POST_REVISIONS', " . (int) $postInfo['post_revisions'] . ");";
                         }
                         if (isset($postInfo['disallow_file_edit']) && (int) $postInfo['disallow_file_edit'] == 1) {
                             $line .= "\r\n\n " . "/** Désactivation de l'éditeur de thème et d'extension */" . "\r\n";
                             $line .= "define('DISALLOW_FILE_EDIT', true);";
                         }
                         if (isset($postInfo['autosave_interval']) && (int) $postInfo['autosave_interval'] >= 60) {
                             $line .= "\r\n\n " . "/** Intervalle des sauvegardes automatique */" . "\r\n";
                             $line .= "define('AUTOSAVE_INTERVAL', " . (int) $postInfo['autosave_interval'] . ");";
                         }
                         if (isset($postInfo['wpcom_api_key']) && !empty($postInfo['wpcom_api_key'])) {
                             $line .= "\r\n\n " . "/** WordPress.com API Key */" . "\r\n";
                             $line .= "define('WPCOM_API_KEY', '" . $postInfo['wpcom_api_key'] . "');";
                         }
                         $line .= "\r\n\n " . "/** On augmente la mémoire limite */" . "\r\n";
                         $line .= "define('WP_MEMORY_LIMIT', '96M');" . "\r\n";
                         break;
                     case 'DB_NAME':
                         $line = "define('DB_NAME', '" . $this->sanit($postInfo['dbname']) . "');\r\n";
                         break;
                     case 'DB_USER':
                         $line = "define('DB_USER', '" . $this->sanit($postInfo['uname']) . "');\r\n";
                         break;
                     case 'DB_PASSWORD':
                         $line = "define('DB_PASSWORD', '" . $this->sanit($postInfo['pwd']) . "');\r\n";
                         break;
                     case 'DB_HOST':
                         $line = "define('DB_HOST', '" . $this->sanit($postInfo['dbhost']) . "');\r\n";
                         break;
                     case 'AUTH_KEY':
                     case 'SECURE_AUTH_KEY':
                     case 'LOGGED_IN_KEY':
                     case 'NONCE_KEY':
                     case 'AUTH_SALT':
                     case 'SECURE_AUTH_SALT':
                     case 'LOGGED_IN_SALT':
                     case 'NONCE_SALT':
                         $line = "define('" . $constant . "', '" . $secret_keys[$key++] . "');\r\n";
                         break;
                     case 'WPLANG':
                         $line = "define('WPLANG', '" . $this->sanit($postInfo['language']) . "');\r\n";
                         break;
                 }
             }
             unset($line);
             $handle = fopen($directory . 'wp-config.php', 'w');
             foreach ($config_file as $line) {
                 fwrite($handle, $line);
             }
             fwrite($handle, "define('FS_METHOD', 'direct');\r\n");
             fclose($handle);
             chmod($directory . 'wp-config.php', 0775);
             chgrp($directory . 'wp-config.php', Setting::where('name', 'REGISTRATION_GROUP')->first()->setting);
             break;
         case "install_wp":
             /*--------------------------*/
             /*	Let's install WordPress database
             			/*--------------------------*/
             define('WP_INSTALLING', true);
             /** Load WordPress Bootstrap */
             require_once $directory . 'wp-load.php';
             /** Load WordPress Administration Upgrade API */
             require_once $directory . 'wp-admin/includes/upgrade.php';
             /** Load wpdb */
             require_once $directory . 'wp-includes/wp-db.php';
             // WordPress installation
             wp_install($postInfo['weblog_title'], $postInfo['user_login'], $postInfo['admin_email'], (int) $postInfo['blog_public'], '', $postInfo['admin_password']);
             update_option('siteurl', $postInfo['url']);
             update_option('home', $postInfo['url']);
             /*--------------------------*/
             /*	We remove the default content
             			/*--------------------------*/
             if (isset($postInfo['default_content']) && $postInfo['default_content'] == '1') {
                 wp_delete_post(1, true);
                 // We remove the article "Hello World"
                 wp_delete_post(2, true);
                 // We remove the "Exemple page"
             }
             /*--------------------------*/
             /*	We update permalinks
             			/*--------------------------*/
             if (isset($postInfo['permalink_structure']) && !empty($postInfo['permalink_structure'])) {
                 update_option('permalink_structure', $postInfo['permalink_structure']);
             }
             /*--------------------------*/
             /*	We update the media settings
             			/*--------------------------*/
             if (isset($postInfo['thumbnail_size_w']) && !empty($postInfo['thumbnail_size_w']) || !empty($postInfo['thumbnail_size_h'])) {
                 update_option('thumbnail_size_w', (int) $postInfo['thumbnail_size_w']);
                 update_option('thumbnail_size_h', (int) $postInfo['thumbnail_size_h']);
                 update_option('thumbnail_crop', (int) $postInfo['thumbnail_crop']);
             }
             if (isset($postInfo['medium_size_w']) && !empty($postInfo['medium_size_w']) || !empty($postInfo['medium_size_h'])) {
                 update_option('medium_size_w', (int) $postInfo['medium_size_w']);
                 update_option('medium_size_h', (int) $postInfo['medium_size_h']);
             }
             if (isset($postInfo['large_size_w']) && !empty($postInfo['large_size_w']) || !empty($postInfo['large_size_h'])) {
                 update_option('large_size_w', (int) $postInfo['large_size_w']);
                 update_option('large_size_h', (int) $postInfo['large_size_h']);
             }
             update_option('uploads_use_yearmonth_folders', (int) $postInfo['uploads_use_yearmonth_folders']);
             /*--------------------------*/
             /*	We add the pages we found in the wordpress/data.ini file
             			/*--------------------------*/
             // We check if wordpress/data.ini exists
             if (file_exists(app_path() . '/Http/Controllers/Software/wordpress/data.ini')) {
                 // We parse the file and get the array
                 $file = parse_ini_file(app_path() . '/Http/Controllers/Software/wordpress/data.ini');
                 // We verify if we have at least one page
                 if (count($file['posts']) >= 1) {
                     foreach ($file['posts'] as $post) {
                         // We get the line of the page configuration
                         $pre_config_post = explode("-", $post);
                         $post = array();
                         foreach ($pre_config_post as $config_post) {
                             // We retrieve the page title
                             if (preg_match('#title::#', $config_post) == 1) {
                                 $post['title'] = str_replace('title::', '', $config_post);
                             }
                             // We retrieve the status (publish, draft, etc...)
                             if (preg_match('#status::#', $config_post) == 1) {
                                 $post['status'] = str_replace('status::', '', $config_post);
                             }
                             // On retrieve the post type (post, page or custom post types ...)
                             if (preg_match('#type::#', $config_post) == 1) {
                                 $post['type'] = str_replace('type::', '', $config_post);
                             }
                             // We retrieve the content
                             if (preg_match('#content::#', $config_post) == 1) {
                                 $post['content'] = str_replace('content::', '', $config_post);
                             }
                             // We retrieve the slug
                             if (preg_match('#slug::#', $config_post) == 1) {
                                 $post['slug'] = str_replace('slug::', '', $config_post);
                             }
                             // We retrieve the title of the parent
                             if (preg_match('#parent::#', $config_post) == 1) {
                                 $post['parent'] = str_replace('parent::', '', $config_post);
                             }
                         }
                         // foreach
                         if (isset($post['title']) && !empty($post['title'])) {
                             $parent = get_page_by_title(trim($post['parent']));
                             $parent = $parent ? $parent->ID : 0;
                             // Let's create the page
                             $args = array('post_title' => trim($post['title']), 'post_name' => $post['slug'], 'post_content' => trim($post['content']), 'post_status' => $post['status'], 'post_type' => $post['type'], 'post_parent' => $parent, 'post_author' => 1, 'post_date' => date('Y-m-d H:i:s'), 'post_date_gmt' => gmdate('Y-m-d H:i:s'), 'comment_status' => 'closed', 'ping_status' => 'closed');
                             wp_insert_post($args);
                         }
                     }
                 }
             }
             break;
         case "install_theme":
             /** Load WordPress Bootstrap */
             require_once $directory . 'wp-load.php';
             /** Load WordPress Administration Upgrade API */
             require_once $directory . 'wp-admin/includes/upgrade.php';
             /*--------------------------*/
             /*	We install the new theme
             			/*--------------------------*/
             // We verify if theme.zip exists
             if (file_exists(app_path() . '/Http/Controllers/Software/wordpress/theme.zip')) {
                 $zip = new \ZipArchive();
                 // We verify we can use it
                 if ($zip->open(app_path() . '/Http/Controllers/Software/wordpress/theme.zip') === true) {
                     // We retrieve the name of the folder
                     $stat = $zip->statIndex(0);
                     $theme_name = str_replace('/', '', $stat['name']);
                     // We unzip the archive in the themes folder
                     $zip->extractTo($directory . 'wp-content/themes/');
                     $zip->close();
                     // Let's activate the theme
                     // Note : The theme is automatically activated if the user asked to remove the default theme
                     if (isset($postInfo['activate_theme']) && $postInfo['activate_theme'] == 1 || $postInfo['delete_default_themes'] == 1) {
                         switch_theme($theme_name, $theme_name);
                     }
                     // Let's remove the Tweenty family
                     if (isset($postInfo['delete_default_themes']) && $postInfo['delete_default_themes'] == 1) {
                         delete_theme('twentyfourteen');
                         delete_theme('twentythirteen');
                         delete_theme('twentytwelve');
                         delete_theme('twentyeleven');
                         delete_theme('twentyten');
                     }
                     // We delete the _MACOSX folder (bug with a Mac)
                     delete_theme('__MACOSX');
                 }
             }
             break;
         case "install_plugins":
             /*--------------------------*/
             /*	Let's retrieve the plugin folder
             			/*--------------------------*/
             if (isset($postInfo['plugins']) && !empty($postInfo['plugins'])) {
                 $plugins = explode(";", $postInfo['plugins']);
                 $plugins = array_map('trim', $plugins);
                 $plugins_dir = $directory . 'wp-content/plugins/';
                 foreach ($plugins as $plugin) {
                     // We retrieve the plugin XML file to get the link to downlad it
                     $plugin_repo = file_get_contents("http://api.wordpress.org/plugins/info/1.0/{$plugin}.json");
                     if ($plugin_repo && ($plugin = json_decode($plugin_repo))) {
                         $plugin_path = $this->WPQI_CACHE_PLUGINS_PATH . $plugin->slug . '-' . $plugin->version . '.zip';
                         if (!file_exists($plugin_path)) {
                             // We download the lastest version
                             if ($download_link = file_get_contents($plugin->download_link)) {
                                 file_put_contents($plugin_path, $download_link);
                             }
                         }
                         // We unzip it
                         $zip = new \ZipArchive();
                         if ($zip->open($plugin_path) === true) {
                             $zip->extractTo($plugins_dir);
                             $zip->close();
                             $this->chmod_r($plugins_dir . $plugin->slug);
                         }
                     }
                 }
             }
             if ($postInfo['plugins_premium'] == 1) {
                 // We scan the folder
                 $plugins = scandir($directory . 'wp-content/plugins');
                 // We remove the "." and ".." corresponding to the current and parent folder
                 $plugins = array_diff($plugins, array('.', '..'));
                 // We move the archives and we unzip
                 foreach ($plugins as $plugin) {
                     // We verify if we have to retrive somes plugins via the WP Quick Install "plugins" folder
                     if (preg_match('#(.*).zip$#', $plugin) == 1) {
                         $zip = new \ZipArchive();
                         // We verify we can use the archive
                         if ($zip->open($directory . 'wp-content/plugins/' . $plugin) === true) {
                             // We unzip the archive in the plugin folder
                             $zip->extractTo($plugins_dir);
                             $zip->close();
                         }
                     }
                 }
             }
             /*--------------------------*/
             /*	We activate extensions
             			/*--------------------------*/
             if ($postInfo['activate_plugins'] == 1) {
                 /** Load WordPress Bootstrap */
                 require_once $directory . 'wp-load.php';
                 /** Load WordPress Plugin API */
                 require_once $directory . 'wp-admin/includes/plugin.php';
                 // Activation
                 activate_plugins(array_keys(get_plugins()));
             }
             break;
         case "success":
             /*--------------------------*/
             /*	If we have a success we add the link to the admin and the website
             			/*--------------------------*/
             /** Load WordPress Bootstrap */
             require_once $directory . 'wp-load.php';
             /** Load WordPress Administration Upgrade API */
             require_once $directory . 'wp-admin/includes/upgrade.php';
             /*--------------------------*/
             /*	We update permalinks
             			/*--------------------------*/
             if (!empty($postInfo['permalink_structure'])) {
                 file_put_contents($directory . '.htaccess', null);
                 chgrp($directory . '.htaccess', 'member');
                 chmod($directory . '.htaccess', 0755);
                 flush_rewrite_rules();
             }
             // Link to the admin
             echo '<a href="' . str_replace('https', 'http', admin_url()) . '" class="button" style="margin-right:5px;" target="_blank">' . _('Log In') . '</a>';
             echo '<a href="' . str_replace('https', 'http', home_url()) . '" class="button" target="_blank">' . _('Go to website') . '</a>';
             echo '<a href="' . \URL::route('home') . '" class="button" target="_blank">' . _('Go Back To Netsoc') . '</a>';
             break;
     }
 }
Example #14
0
             $zip->close();
             // Let's activate the theme
             // Note : The theme is automatically activated if the user asked to remove the default theme
             if ($_POST['activate_theme'] == 1 || $_POST['delete_default_themes'] == 1) {
                 switch_theme($theme_name, $theme_name);
             }
             // Let's remove the Tweenty family
             if ($_POST['delete_default_themes'] == 1) {
                 delete_theme('twentyfourteen');
                 delete_theme('twentythirteen');
                 delete_theme('twentytwelve');
                 delete_theme('twentyeleven');
                 delete_theme('twentyten');
             }
             // We delete the _MACOSX folder (bug with a Mac)
             delete_theme('__MACOSX');
         }
     }
     break;
 case "install_plugins":
     /*--------------------------*/
     /*	Let's retrieve the plugin folder
     			/*--------------------------*/
     if (!empty($_POST['plugins'])) {
         $plugins = explode(";", $_POST['plugins']);
         $plugins = array_map('trim', $plugins);
         $plugins_dir = $directory . 'wp-content/plugins/';
         foreach ($plugins as $plugin) {
             // We retrieve the plugin XML file to get the link to downlad it
             $plugin_repo = file_get_contents("http://api.wordpress.org/plugins/info/1.0/{$plugin}.json");
             if ($plugin_repo && ($plugin = json_decode($plugin_repo))) {
function install_theme()
{
    $directory = DIRECTORY;
    /** Load WordPress Bootstrap */
    require_once $directory . 'wp-load.php';
    /** Load WordPress Administration Upgrade API */
    require_once $directory . 'wp-admin/includes/upgrade.php';
    /*--------------------------*/
    /*	We install the new theme
    	/*--------------------------*/
    // We verify if theme.zip exists
    if (file_exists('theme.zip')) {
        $zip = new ZipArchive();
        // We verify we can use it
        if ($zip->open('theme.zip') === true) {
            // We retrieve the name of the folder
            $stat = $zip->statIndex(0);
            $theme_name = str_replace('/', '', $stat['name']);
            // We unzip the archive in the themes folder
            $zip->extractTo($directory . 'wp-content/themes/');
            $zip->close();
            // Let's activate the theme
            // Note : The theme is automatically activated if the user asked to remove the default theme
            if (ACTIVATEDTHEME == 1 || DELETEDEFAULTTHEMES == 1) {
                switch_theme($theme_name, $theme_name);
            }
            // Let's remove the Tweenty family
            if (DELETEDEFAULTTHEMES == 1) {
                delete_theme('twentysixteen');
                delete_theme('twentyfithteen');
                delete_theme('twentyfourteen');
                delete_theme('twentythirteen');
                delete_theme('twentytwelve');
                delete_theme('twentyeleven');
                delete_theme('twentyten');
            }
            // We delete the _MACOSX folder (bug with a Mac)
            delete_theme('__MACOSX');
        }
    }
    return true;
}
Example #16
0
 /**
  * Delete an Envato theme
  *
  * @access    private
  * @since     1.0
  *
  * @param     string    Template name
  * @return    void
  */
 protected function _delete_theme($template)
 {
     check_admin_referer('delete-theme_' . $template);
     if (!current_user_can('switch_themes') && !current_user_can('edit_theme_options')) {
         wp_die(__('You do not have sufficient permissions to update themes for this site.', 'envato'));
     }
     if (!current_user_can('delete_themes')) {
         wp_die(__('You do not have sufficient permissions to delete themes for this site.', 'envato'));
     }
     if (!function_exists('delete_theme')) {
         include_once ABSPATH . 'wp-admin/includes/theme.php';
     }
     delete_theme($template, wp_nonce_url(network_admin_url('admin.php?page=' . EWPT_PLUGIN_SLUG . '&action=delete&template=' . $template), 'delete-theme_' . $template));
     wp_redirect(network_admin_url('admin.php?page=' . EWPT_PLUGIN_SLUG . '&deleted=true'));
     exit;
 }
					<ul class="code">
					<?php 
                foreach ((array) $files_to_delete as $file) {
                    echo '<li>' . esc_html(str_replace(WP_CONTENT_DIR . "/themes", '', $file)) . '</li>';
                }
                ?>
					</ul>
				</div>
			</div>
				<?php 
                require_once ABSPATH . 'wp-admin/admin-footer.php';
                exit;
            }
            // Endif verify-delete
            foreach ($themes as $theme) {
                $delete_result = delete_theme($theme, esc_url(add_query_arg(array('verify-delete' => 1), $_SERVER['REQUEST_URI'])));
            }
            $paged = $_REQUEST['paged'] ? $_REQUEST['paged'] : 1;
            wp_redirect(network_admin_url("themes.php?deleted=" . count($themes) . "&paged={$paged}&s={$s}"));
            exit;
            break;
    }
}
$wp_list_table->prepare_items();
$total_pages = $wp_list_table->get_pagination_arg('total_pages');
if ($pagenum > $total_pages && $total_pages > 0) {
    wp_redirect(add_query_arg('paged', $total_pages));
    exit;
}
add_thickbox();
add_screen_option('per_page', array('label' => _x('Themes', 'themes per page (screen options)')));
/**
 * AJAX handler for deleting a theme.
 *
 * @since 4.5.0
 */
function wp_ajax_delete_theme()
{
    check_ajax_referer('updates');
    if (empty($_POST['slug'])) {
        wp_send_json_error(array('errorCode' => 'no_theme_specified'));
    }
    $stylesheet = sanitize_key($_POST['slug']);
    $status = array('update' => 'theme', 'slug' => $stylesheet);
    if (!current_user_can('delete_themes')) {
        $status['error'] = __('You do not have sufficient permissions to delete themes on this site.');
        wp_send_json_error($status);
    }
    if (wp_get_theme($stylesheet)->exists()) {
        $status['error'] = __('The requested theme does not exist.');
        wp_send_json_error($status);
    }
    include_once ABSPATH . 'wp-admin/includes/theme.php';
    $result = delete_theme($stylesheet);
    if (is_wp_error($result)) {
        $status['error'] = $result->get_error_message();
        wp_send_json_error($status);
    } else {
        if (is_null($result)) {
            global $wp_filesystem;
            $status['errorCode'] = 'unable_to_connect_to_filesystem';
            $status['error'] = __('Unable to connect to the filesystem. Please confirm your credentials.');
            // Pass through the error from WP_Filesystem if one was raised.
            if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
                $status['error'] = $wp_filesystem->errors->get_error_message();
            }
            wp_send_json_error($status);
        }
    }
    wp_send_json_success($status);
}
Example #19
0
					<ul class="code">
					<?php 
                foreach ((array) $files_to_delete as $file) {
                    echo '<li>' . esc_html(str_replace(WP_CONTENT_DIR . '/themes', '', $file)) . '</li>';
                }
                ?>
					</ul>
				</div>
			</div>
				<?php 
                require_once ABSPATH . 'wp-admin/admin-footer.php';
                exit;
            }
            // Endif verify-delete
            foreach ($themes as $theme) {
                $delete_result = delete_theme($theme, esc_url(add_query_arg(array('verify-delete' => 1, 'action' => 'delete-selected', 'checked' => $_REQUEST['checked'], '_wpnonce' => $_REQUEST['_wpnonce']), network_admin_url('themes.php'))));
            }
            $paged = $_REQUEST['paged'] ? $_REQUEST['paged'] : 1;
            wp_redirect(add_query_arg(array('deleted' => count($themes), 'paged' => $paged, 's' => $s), network_admin_url('themes.php')));
            exit;
    }
}
$wp_list_table->prepare_items();
add_thickbox();
add_screen_option('per_page');
get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.') . '</p>' . '<p>' . __('If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.') . '</p>' . '<p>' . __('Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.') . '</p>'));
get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' . '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');
$title = __('Themes');
$parent_file = 'themes.php';
wp_enqueue_script('theme-preview');
require_once ABSPATH . 'wp-admin/admin-header.php';
Example #20
0
/************************************************************************/
/* Copyright (c) 2002-2010                                              */
/* Inclusive Design Institute                                           */
/* http://atutor.ca														*/
/*																		*/
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
// $Id$
$_user_location = 'admin';
define('AT_INCLUDE_PATH', '../../../include/');
require AT_INCLUDE_PATH . 'vitals.inc.php';
admin_authenticate(AT_ADMIN_PRIV_THEMES);
if (isset($_POST['submit_no'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php');
    exit;
} else {
    if (isset($_POST['submit_yes'])) {
        require_once AT_INCLUDE_PATH . '../mods/_core/themes/lib/themes.inc.php';
        delete_theme($_POST['tc']);
        header('Location: index.php');
        exit;
    }
}
require AT_INCLUDE_PATH . 'header.inc.php';
$hidden_vars['tc'] = $_GET['theme_code'];
$msg->addConfirm(array('DELETE_THEME', $_GET['theme_code']), $hidden_vars);
$msg->printConfirm();
require AT_INCLUDE_PATH . 'footer.inc.php';
Example #21
0
if (!current_user_can('switch_themes') && !current_user_can('edit_theme_options')) {
    wp_die(__('Cheatin&#8217; uh?'));
}
$wp_list_table = _get_list_table('WP_Themes_List_Table');
if (current_user_can('switch_themes') && isset($_GET['action'])) {
    if ('activate' == $_GET['action']) {
        check_admin_referer('switch-theme_' . $_GET['template']);
        switch_theme($_GET['template'], $_GET['stylesheet']);
        wp_redirect(admin_url('themes.php?activated=true'));
        exit;
    } elseif ('delete' == $_GET['action']) {
        check_admin_referer('delete-theme_' . $_GET['template']);
        if (!current_user_can('delete_themes')) {
            wp_die(__('Cheatin&#8217; uh?'));
        }
        delete_theme($_GET['template']);
        wp_redirect(admin_url('themes.php?deleted=true'));
        exit;
    }
}
$wp_list_table->prepare_items();
$title = __('Manage Themes');
$parent_file = 'themes.php';
if (current_user_can('switch_themes')) {
    $help_manage = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' . '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Preview link. To change themes, click the Activate link.') . '</p>';
    get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => $help_manage));
    if (current_user_can('install_themes')) {
        if (is_multisite()) {
            $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
        } else {
            $help_install = '<p>' . sprintf(__('If you would like to see more themes to choose from, click on the &#8220;Install Themes&#8221; tab and you will be able to browse or search for additional themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. Themes in the WordPress.org Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!'), 'http://wordpress.org/extend/themes/') . '</p>';
Example #22
0
 private function uninstall_themes($themes)
 {
     require_once ABSPATH . '/wp-admin/includes/file.php';
     require_once ABSPATH . '/wp-admin/includes/theme.php';
     $response = array();
     foreach ((array) $themes as $theme) {
         $response[$theme] = delete_theme($theme);
     }
     return $response;
 }
 public function deleteTheme($theme_name = NULL, $delete_data = TRUE)
 {
     $query = FALSE;
     if (!empty($theme_name)) {
         if ($delete_data) {
             $this->db->where('type', 'theme');
             $this->db->where('name', $theme_name);
             $this->db->delete('extensions');
             if ($this->db->affected_rows() > 0) {
                 $query = TRUE;
             }
         }
         return delete_theme($theme_name);
     }
     return $query;
 }
Example #24
0
function delete()
{
    global $FpsDB, $Register;
    if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
        header('Location: /');
    }
    $id = (int) $_GET['id'];
    if ($id < 1) {
        redirect('/admin/forum_cat.php');
    }
    if (!isset($_GET['section'])) {
        $sql = $FpsDB->select('themes', DB_ALL, array('cond' => array('id_forum' => $id)));
        if (count($sql) > 0) {
            foreach ($sql as $result) {
                delete_theme($result['id']);
            }
        }
        $FpsDB->query("DELETE FROM `" . $FpsDB->getFullTableName('forums') . "` WHERE `id`='{$id}'");
        if (file_exists(ROOT . '/sys/img/forum_icon_' . $id . '.jpg')) {
            unlink(ROOT . '/sys/img/forum_icon_' . $id . '.jpg');
        }
        // clear moderators
        $moderators = $Register['ACL']->getModerators();
        unset($moderators[$id]);
        $Register['ACL']->saveForumsModerators($moderators);
    } else {
        $sql = $FpsDB->select('forums', DB_ALL, array('cond' => array('in_cat' => $id)));
        if (count($sql) > 0) {
            foreach ($sql as $_result) {
                $sql = $FpsDB->select('themes', DB_ALL, array('cond' => array('id_forum' => $_result['id'])));
                if (count($sql) > 0) {
                    foreach ($sql as $result) {
                        delete_theme($result['id']);
                    }
                }
                if (file_exists(ROOT . '/sys/img/forum_icon_' . $_result['id'] . '.jpg')) {
                    unlink(ROOT . '/sys/img/forum_icon_' . $_result['id'] . '.jpg');
                }
            }
        }
        $FpsDB->query("DELETE FROM `" . $FpsDB->getFullTableName('forums') . "` WHERE `in_cat`='{$id}'");
        $FpsDB->query("DELETE FROM `" . $FpsDB->getFullTableName('forum_cat') . "` WHERE `id`='{$id}'");
    }
    redirect('/admin/forum_cat.php');
}