function wp_install_defaults($user_id)
{
    global $wpdb, $wp_rewrite, $current_site, $table_prefix;
    // Default category
    $cat_name = __('Uncategorized');
    /* translators: Default category slug */
    $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
    if (global_terms_enabled()) {
        $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
        if ($cat_id == null) {
            $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
            $cat_id = $wpdb->insert_id;
        }
        update_option('default_category', $cat_id);
    } else {
        $cat_id = 1;
    }
    $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
    $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
    $cat_tt_id = $wpdb->insert_id;
    if (!is_multisite()) {
        update_user_meta($user_id, 'show_welcome_panel', 1);
    } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
        update_user_meta($user_id, 'show_welcome_panel', 2);
    }
    if (is_multisite()) {
        // Flush rules to pick up the new page.
        $wp_rewrite->init();
        $wp_rewrite->flush_rules();
        $user = new WP_User($user_id);
        $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
        // Remove all perms except for the login user.
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
        // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
        if (!is_super_admin($user_id) && $user_id != 1) {
            $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
        }
    }
    $wpdb->query("UPDATE {$wpdb->options} SET option_value = '' WHERE option_id = 3");
    $wpdb->query("UPDATE {$wpdb->options} SET option_value = '/%postname%/' WHERE option_id = 30");
}
Example #2
0
     foreach ((array) $users as $user) {
         if (array_pop(array_keys(unserialize($user->meta_value))) == 'subscriber') {
             $move_users[] = $user->user_id;
         }
     }
     if (false == empty($move_users)) {
         foreach ((array) $move_users as $user_id) {
             remove_user_from_blog($user_id, get_site_option('dashboard_blog'));
             add_user_to_blog($dashboard_blog_id, $user_id, get_site_option('default_user_role', 'subscriber'));
             update_user_meta($user_id, 'primary_blog', $dashboard_blog_id);
         }
     }
 }
 update_site_option('dashboard_blog', $dashboard_blog_id);
 // global terms
 if (!global_terms_enabled() && !empty($_POST['global_terms_enabled'])) {
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     // create global terms table
     install_global_terms();
 }
 $options = array('registrationnotification', 'registration', 'add_new_users', 'menu_items', 'mu_media_buttons', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'admin_notice_feed', 'global_terms_enabled');
 $checked_options = array('mu_media_buttons' => array(), 'menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1);
 foreach ($checked_options as $option_name => $option_unchecked_value) {
     if (!isset($_POST[$option_name])) {
         $_POST[$option_name] = $option_unchecked_value;
     }
 }
 foreach ($options as $option_name) {
     if (!isset($_POST[$option_name])) {
         continue;
     }
    /**
     * Outputs the hidden row displayed when inline editing
     *
     * @since 3.1.0
     */
    public function inline_edit()
    {
        $tax = get_taxonomy($this->screen->taxonomy);
        if (!current_user_can($tax->cap->edit_terms)) {
            return;
        }
        ?>

	<form method="get"><table style="display: none"><tbody id="inlineedit">
		<tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php 
        echo $this->get_column_count();
        ?>
" class="colspanchange">

			<fieldset><div class="inline-edit-col">
				<h4><?php 
        _e('Quick Edit');
        ?>
</h4>

				<label>
					<span class="title"><?php 
        _ex('Name', 'term name');
        ?>
</span>
					<span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
				</label>
	<?php 
        if (!global_terms_enabled()) {
            ?>
				<label>
					<span class="title"><?php 
            _e('Slug');
            ?>
</span>
					<span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
				</label>
	<?php 
        }
        ?>
			</div></fieldset>
	<?php 
        $core_columns = array('cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true);
        list($columns) = $this->get_column_info();
        foreach ($columns as $column_name => $column_display_name) {
            if (isset($core_columns[$column_name])) {
                continue;
            }
            /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
            do_action('quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy);
        }
        ?>

		<p class="inline-edit-save submit">
			<a href="#inline-edit" class="cancel button-secondary alignleft"><?php 
        _e('Cancel');
        ?>
</a>
			<a href="#inline-edit" class="save button-primary alignright"><?php 
        echo $tax->labels->update_item;
        ?>
</a>
			<span class="spinner"></span>
			<span class="error" style="display:none;"></span>
			<?php 
        wp_nonce_field('taxinlineeditnonce', '_inline_edit', false);
        ?>
			<input type="hidden" name="taxonomy" value="<?php 
        echo esc_attr($this->screen->taxonomy);
        ?>
" />
			<input type="hidden" name="post_type" value="<?php 
        echo esc_attr($this->screen->post_type);
        ?>
" />
			<br class="clear" />
		</p>
		</td></tr>
		</tbody></table></form>
	<?php 
    }
 /**
  * Control hidden if global terms is enabled
  *
  * @param WP_Fields_API_Control $control
  *
  * @return bool
  */
 public function capability_is_global_terms_disabled($control)
 {
     return !global_terms_enabled();
 }
    /**
     * Outputs the hidden row displayed when inline editing
     *
     * @since 3.1.0
     */
    function inline_edit()
    {
        global $tax;
        if (!current_user_can($tax->cap->edit_terms)) {
            return;
        }
        ?>

	<form method="get" action=""><table style="display: none"><tbody id="inlineedit">
		<tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php 
        echo $this->get_column_count();
        ?>
" class="colspanchange">

			<fieldset><div class="inline-edit-col">
				<h4><?php 
        _e('Quick Edit');
        ?>
</h4>

				<label>
					<span class="title"><?php 
        _e('Name');
        ?>
</span>
					<span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
				</label>
	<?php 
        if (!global_terms_enabled()) {
            ?>
				<label>
					<span class="title"><?php 
            _e('Slug');
            ?>
</span>
					<span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
				</label>
	<?php 
        }
        ?>
			</div></fieldset>
	<?php 
        $core_columns = array('cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true);
        list($columns) = $this->get_column_info();
        foreach ($columns as $column_name => $column_display_name) {
            if (isset($core_columns[$column_name])) {
                continue;
            }
            do_action('quick_edit_custom_box', $column_name, 'edit-tags', $tax->name);
        }
        ?>

		<p class="inline-edit-save submit">
			<a accesskey="c" href="#inline-edit" title="<?php 
        _e('Cancel');
        ?>
" class="cancel button-secondary alignleft"><?php 
        _e('Cancel');
        ?>
</a>
			<?php 
        $update_text = $tax->labels->update_item;
        ?>
			<a accesskey="s" href="#inline-edit" title="<?php 
        echo esc_attr($update_text);
        ?>
" class="save button-primary alignright"><?php 
        echo $update_text;
        ?>
</a>
			<img class="waiting" style="display:none;" src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" alt="" />
			<span class="error" style="display:none;"></span>
			<?php 
        wp_nonce_field('taxinlineeditnonce', '_inline_edit', false);
        ?>
			<input type="hidden" name="taxonomy" value="<?php 
        echo esc_attr($tax->name);
        ?>
" />
			<br class="clear" />
		</p>
		</td></tr>
		</tbody></table></form>
	<?php 
    }
Example #6
0
 /**
  * {@internal Missing Short Description}}
  *
  * {@internal Missing Long Description}}
  *
  * @since 2.1.0
  *
  * @param int $user_id User ID.
  */
 function wp_install_defaults($user_id)
 {
     global $wpdb, $wp_rewrite, $current_site, $table_prefix;
     // Default category
     $cat_name = __('Uncategorized');
     /* translators: Default category slug */
     $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
     if (global_terms_enabled()) {
         $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
         if ($cat_id == null) {
             $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
             $cat_id = $wpdb->insert_id;
         }
         update_option('default_category', $cat_id);
     } else {
         $cat_id = 1;
     }
     $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
     $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
     $cat_tt_id = $wpdb->insert_id;
     // Default link category
     $cat_name = __('Blogroll');
     /* translators: Default link category slug */
     $cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
     if (global_terms_enabled()) {
         $blogroll_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
         if ($blogroll_id == null) {
             $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
             $blogroll_id = $wpdb->insert_id;
         }
         update_option('default_link_category', $blogroll_id);
     } else {
         $blogroll_id = 2;
     }
     $wpdb->insert($wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
     $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
     $blogroll_tt_id = $wpdb->insert_id;
     //jalg 02022013
     // Default link category
     $cat_name = __('Library');
     /* translators: Default link category slug */
     $cat_slug = sanitize_title(_x('Library', 'Default link category slug'));
     $wpdb->insert($wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
     $wpdb->insert($wpdb->term_taxonomy, array('term_id' => '3', 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 8));
     // Now drop in some default links
     $default_links = array();
     $default_links[] = array('link_url' => get_option('home') . '/../opac', 'link_name' => 'OPAC', 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => get_option('home') . '/../admin', 'link_name' => 'Administración de la Biblioteca', 'link_rss' => '', 'link_notes' => '');
     //jalg 02022013
     $default_links[] = array('link_url' => __('http://codex.wordpress.org/'), 'link_name' => __('Documentation'), 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => __('http://wordpress.org/news/'), 'link_name' => __('WordPress Blog'), 'link_rss' => __('http://wordpress.org/news/feed/'), 'link_notes' => '');
     $default_links[] = array('link_url' => __('http://wordpress.org/support/'), 'link_name' => _x('Support Forums', 'default link'), 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://wordpress.org/extend/plugins/', 'link_name' => _x('Plugins', 'Default link to wordpress.org/extend/plugins/'), 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://wordpress.org/extend/themes/', 'link_name' => _x('Themes', 'Default link to wordpress.org/extend/themes/'), 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => __('http://wordpress.org/support/forum/requests-and-feedback'), 'link_name' => __('Feedback'), 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => __('http://planet.wordpress.org/'), 'link_name' => __('WordPress Planet'), 'link_rss' => '', 'link_notes' => '');
     foreach ($default_links as $link) {
         $wpdb->insert($wpdb->links, $link);
         $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $blogroll_tt_id, 'object_id' => $wpdb->insert_id));
     }
     // First post
     $now = date('Y-m-d H:i:s');
     $now_gmt = gmdate('Y-m-d H:i:s');
     $first_post_guid = get_option('home') . '/?p=1';
     if (is_multisite()) {
         $first_post = get_site_option('first_post');
         if (empty($first_post)) {
             $first_post = stripslashes(__('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!'));
         }
         $first_post = str_replace("SITE_URL", esc_url(network_home_url()), $first_post);
         $first_post = str_replace("SITE_NAME", $current_site->site_name, $first_post);
     } else {
         $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
     }
     $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
     $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
     // Default comment
     $first_comment_author = __('Mr WordPress');
     $first_comment_url = 'http://wordpress.org/';
     $first_comment = __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
     if (is_multisite()) {
         $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
         $first_comment_url = get_site_option('first_comment_url', network_home_url());
         $first_comment = get_site_option('first_comment', $first_comment);
     }
     $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
     // First Page
     $first_page = sprintf(__("This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:\n\n<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>\n\n...or something like this:\n\n<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickies to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>\n\nAs a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!"), admin_url());
     if (is_multisite()) {
         $first_page = get_site_option('first_page', $first_page);
     }
     $first_post_guid = get_option('home') . '/?page_id=2';
     $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('Sample Page'), 'post_name' => __('sample-page'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
     //jalg 02022013
     // Openbiblio search page.
     $first_post_guid = get_option('home') . '/?page_id=3';
     $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => '', 'post_excerpt' => '', 'post_title' => 'OPAC Search Results', 'post_name' => _x('opac-search-results', 'Default page slug'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
     // Biblio page.
     $first_post_guid = get_option('home') . '/?page_id=4';
     $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => '', 'post_excerpt' => '', 'post_title' => 'OPAC Bibiliography', 'post_name' => _x('opac-bibliography', 'Default page slug'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
     //jalg 02022013
     $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
     //jalg 02022013
     // OpenBiblio meta for page template.
     $wpdb->insert($wpdb->postmeta, array('post_id' => 3, 'meta_key' => '_wp_page_template', 'meta_value' => 'opac.php'));
     $wpdb->insert($wpdb->postmeta, array('post_id' => 4, 'meta_key' => '_wp_page_template', 'meta_value' => 'biblio.php'));
     $wpdb->insert($wpdb->postmeta, array('post_id' => 3, 'meta_key' => 'custom_permalink', 'meta_value' => '?opac'));
     $wpdb->insert($wpdb->postmeta, array('post_id' => 4, 'meta_key' => 'custom_permalink', 'meta_value' => '?opac&view'));
     //jalg 02022013
     //jalg 02022013
     // Enable default plugins & widgets.
     $wpdb->update($wpdb->options, array('option_value' => 'a:2:{i:0;s:39:"custom-permalinks/custom-permalinks.php";i:1;s:17:"obopac/obopac.php";}'), array('option_name' => 'active_plugins'));
     $wpdb->insert($wpdb->options, array('option_name' => 'widget_obopac-widget', 'option_value' => 'a:2:{i:1;a:0:{}s:12:"_multiwidget";i:1;}'));
     $wpdb->insert($wpdb->options, array('option_name' => 'widget_pages', 'option_value' => 'a:2:{i:1;a:3:{s:5:"title";s:0:"";s:6:"sortby";s:10:"post_title";s:7:"exclude";s:3:"3,4";}s:12:"_multiwidget";i:1;}'));
     $wpdb->insert($wpdb->options, array('option_name' => 'widget_archives', 'option_value' => 'a:2:{i:1;a:3:{s:5:"title";s:0:"";s:5:"count";i:0;s:8:"dropdown";i:0;}s:12:"_multiwidget";i:1;}'));
     $wpdb->update($wpdb->options, array('option_value' => 'a:2:{i:1;a:4:{s:5:"title";s:0:"";s:5:"count";i:0;s:12:"hierarchical";i:0;s:8:"dropdown";i:0;}s:12:"_multiwidget";i:1;}'), array('option_name' => 'widget_categories'));
     $wpdb->insert($wpdb->options, array('option_name' => 'widget_links', 'option_value' => 'a:2:{i:1;a:5:{s:6:"images";i:1;s:4:"name";i:1;s:11:"description";i:0;s:6:"rating";i:0;s:8:"category";i:0;}s:12:"_multiwidget";i:1;}'));
     $wpdb->insert($wpdb->options, array('option_name' => 'widget_meta', 'option_value' => 'a:2:{i:1;a:1:{s:5:"title";s:0:"";}s:12:"_multiwidget";i:1;}'));
     $wpdb->insert($wpdb->options, array('option_name' => 'sidebars_widgets', 'option_value' => 'a:3:{s:19:"wp_inactive_widgets";a:0:{}s:9:"sidebar-1";a:6:{i:0;s:15:"obopac-widget-1";i:1;s:7:"pages-1";i:2;s:10:"archives-1";i:3;s:12:"categories-1";i:4;s:7:"links-1";i:5;s:6:"meta-1";}s:13:"array_version";i:3;}'));
     $wpdb->insert($wpdb->options, array('option_name' => 'obopac_api_path', 'option_value' => dirname(get_option('home')) . '/'));
     // Set up default widgets for default theme.
     update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
     update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
     update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
     //	update_option( 'widget_archives', array ( 2 => array ( 'title' => '', 'count' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) );
     update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
     //	update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
     //	update_option( 'sidebars_widgets', array ( 'wp_inactive_widgets' => array ( ), 'sidebar-1' => array ( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', ), 'sidebar-2' => array ( ), 'sidebar-3' => array ( ), 'sidebar-4' => array ( ), 'sidebar-5' => array ( ), 'array_version' => 3 ) );
     if (!is_multisite()) {
         update_user_meta($user_id, 'show_welcome_panel', 1);
     } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
         update_user_meta($user_id, 'show_welcome_panel', 2);
     }
     if (is_multisite()) {
         // Flush rules to pick up the new page.
         $wp_rewrite->init();
         $wp_rewrite->flush_rules();
         $user = new WP_User($user_id);
         $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
         // Remove all perms except for the login user.
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
         // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
         if (!is_super_admin($user_id) && $user_id != 1) {
             $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
         }
     }
 }
Example #7
0
/**
 * Populate network settings.
 *
 * @since 3.0.0
 *
 * @global wpdb       $wpdb
 * @global object     $current_site
 * @global int        $wp_db_version
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int $network_id ID of network to populate.
 * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful,
 *                       so the error code must be checked) or failure.
 */
function populate_network($network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false)
{
    global $wpdb, $current_site, $wp_db_version, $wp_rewrite;
    $errors = new WP_Error();
    if ('' == $domain) {
        $errors->add('empty_domain', __('You must provide a domain name.'));
    }
    if ('' == $site_name) {
        $errors->add('empty_sitename', __('You must provide a name for your network of sites.'));
    }
    // Check for network collision.
    if ($network_id == $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->site} WHERE id = %d", $network_id))) {
        $errors->add('siteid_exists', __('The network already exists.'));
    }
    if (!is_email($email)) {
        $errors->add('invalid_email', __('You must provide a valid email address.'));
    }
    if ($errors->get_error_code()) {
        return $errors;
    }
    // If a user with the provided email does not exist, default to the current user as the new network admin.
    $site_user = get_user_by('email', $email);
    if (false === $site_user) {
        $site_user = wp_get_current_user();
    }
    // Set up site tables.
    $template = get_option('template');
    $stylesheet = get_option('stylesheet');
    $allowed_themes = array($stylesheet => true);
    if ($template != $stylesheet) {
        $allowed_themes[$template] = true;
    }
    if (WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template) {
        $allowed_themes[WP_DEFAULT_THEME] = true;
    }
    // If WP_DEFAULT_THEME doesn't exist, also whitelist the latest core default theme.
    if (!wp_get_theme(WP_DEFAULT_THEME)->exists()) {
        if ($core_default = WP_Theme::get_core_default_theme()) {
            $allowed_themes[$core_default->get_stylesheet()] = true;
        }
    }
    if (1 == $network_id) {
        $wpdb->insert($wpdb->site, array('domain' => $domain, 'path' => $path));
        $network_id = $wpdb->insert_id;
    } else {
        $wpdb->insert($wpdb->site, array('domain' => $domain, 'path' => $path, 'id' => $network_id));
    }
    wp_cache_delete('networks_have_paths', 'site-options');
    if (!is_multisite()) {
        $site_admins = array($site_user->user_login);
        $users = get_users(array('fields' => array('ID', 'user_login')));
        if ($users) {
            foreach ($users as $user) {
                if (is_super_admin($user->ID) && !in_array($user->user_login, $site_admins)) {
                    $site_admins[] = $user->user_login;
                }
            }
        }
    } else {
        $site_admins = get_site_option('site_admins');
    }
    /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */
    $welcome_email = __('Howdy USERNAME,

Your new SITE_NAME site has been successfully set up at:
BLOG_URL

You can log in to the administrator account with the following information:

Username: USERNAME
Password: PASSWORD
Log in here: BLOG_URLwp-login.php

We hope you enjoy your new site. Thanks!

--The Team @ SITE_NAME');
    $misc_exts = array('jpg', 'jpeg', 'png', 'gif', 'mov', 'avi', 'mpg', '3gp', '3g2', 'midi', 'mid', 'pdf', 'doc', 'ppt', 'odt', 'pptx', 'docx', 'pps', 'ppsx', 'xls', 'xlsx', 'key');
    $audio_exts = wp_get_audio_extensions();
    $video_exts = wp_get_video_extensions();
    $upload_filetypes = array_unique(array_merge($misc_exts, $audio_exts, $video_exts));
    $sitemeta = array('site_name' => $site_name, 'admin_email' => $email, 'admin_user_id' => $site_user->ID, 'registration' => 'none', 'upload_filetypes' => implode(' ', $upload_filetypes), 'blog_upload_space' => 100, 'fileupload_maxk' => 1500, 'site_admins' => $site_admins, 'allowedthemes' => $allowed_themes, 'illegal_names' => array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files'), 'wpmu_upgrade_site' => $wp_db_version, 'welcome_email' => $welcome_email, 'first_post' => __('Welcome to %s. This is your first post. Edit or delete it, then start blogging!'), 'siteurl' => get_option('siteurl') . '/', 'add_new_users' => '0', 'upload_space_check_disabled' => is_multisite() ? get_site_option('upload_space_check_disabled') : '1', 'subdomain_install' => intval($subdomain_install), 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 'ms_files_rewriting' => is_multisite() ? get_site_option('ms_files_rewriting') : '0', 'initial_db_version' => get_option('initial_db_version'), 'active_sitewide_plugins' => array(), 'WPLANG' => get_locale());
    if (!$subdomain_install) {
        $sitemeta['illegal_names'][] = 'blog';
    }
    /**
     * Filter meta for a network on creation.
     *
     * @since 3.7.0
     *
     * @param array $sitemeta   Associative array of network meta keys and values to be inserted.
     * @param int   $network_id ID of network to populate.
     */
    $sitemeta = apply_filters('populate_network_meta', $sitemeta, $network_id);
    $insert = '';
    foreach ($sitemeta as $meta_key => $meta_value) {
        if (is_array($meta_value)) {
            $meta_value = serialize($meta_value);
        }
        if (!empty($insert)) {
            $insert .= ', ';
        }
        $insert .= $wpdb->prepare("( %d, %s, %s)", $network_id, $meta_key, $meta_value);
    }
    $wpdb->query("INSERT INTO {$wpdb->sitemeta} ( site_id, meta_key, meta_value ) VALUES " . $insert);
    /*
     * When upgrading from single to multisite, assume the current site will
     * become the main site of the network. When using populate_network()
     * to create another network in an existing multisite environment, skip
     * these steps since the main site of the new network has not yet been
     * created.
     */
    if (!is_multisite()) {
        $current_site = new stdClass();
        $current_site->domain = $domain;
        $current_site->path = $path;
        $current_site->site_name = ucfirst($domain);
        $wpdb->insert($wpdb->blogs, array('site_id' => $network_id, 'blog_id' => 1, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')));
        $current_site->blog_id = $blog_id = $wpdb->insert_id;
        update_user_meta($site_user->ID, 'source_domain', $domain);
        update_user_meta($site_user->ID, 'primary_blog', $blog_id);
        if ($subdomain_install) {
            $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
        } else {
            $wp_rewrite->set_permalink_structure('/blog/%year%/%monthnum%/%day%/%postname%/');
        }
        flush_rewrite_rules();
        if (!$subdomain_install) {
            return true;
        }
        $vhost_ok = false;
        $errstr = '';
        $hostname = substr(md5(time()), 0, 6) . '.' . $domain;
        // Very random hostname!
        $page = wp_remote_get('http://' . $hostname, array('timeout' => 5, 'httpversion' => '1.1'));
        if (is_wp_error($page)) {
            $errstr = $page->get_error_message();
        } elseif (200 == wp_remote_retrieve_response_code($page)) {
            $vhost_ok = true;
        }
        if (!$vhost_ok) {
            $msg = '<p><strong>' . __('Warning! Wildcard DNS may not be configured correctly!') . '</strong></p>';
            $msg .= '<p>' . sprintf(__('The installer attempted to contact a random hostname (%s) on your domain.'), '<code>' . $hostname . '</code>');
            if (!empty($errstr)) {
                /* translators: %s: error message */
                $msg .= ' ' . sprintf(__('This resulted in an error message: %s'), '<code>' . $errstr . '</code>');
            }
            $msg .= '</p>';
            $msg .= '<p>' . sprintf(__('To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a %s hostname record pointing at your web server in your DNS configuration tool.'), '<code>*</code>') . '</p>';
            $msg .= '<p>' . __('You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.') . '</p>';
            return new WP_Error('no_wildcard_dns', $msg);
        }
    }
    return true;
}
Example #8
0
 /**
  * {@internal Missing Short Description}}
  *
  * {@internal Missing Long Description}}
  *
  * @since unknown
  *
  * @param int $user_id User ID.
  */
 function wp_install_defaults($user_id)
 {
     global $wpdb, $wp_rewrite, $current_site, $table_prefix;
     // Default category
     $cat_name = __('Uncategorized');
     /* translators: Default category slug */
     $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
     if (global_terms_enabled()) {
         $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
         if ($cat_id == null) {
             $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
             $cat_id = $wpdb->insert_id;
         }
         update_option('default_category', $cat_id);
     } else {
         $cat_id = 1;
     }
     $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
     $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
     $cat_tt_id = $wpdb->insert_id;
     // Default link category
     $cat_name = __('Blogroll');
     /* translators: Default link category slug */
     $cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
     if (global_terms_enabled()) {
         $blogroll_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
         if ($blogroll_id == null) {
             $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
             $blogroll_id = $wpdb->insert_id;
         }
         update_option('default_link_category', $blogroll_id);
     } else {
         $blogroll_id = 2;
     }
     $wpdb->insert($wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
     $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
     $blogroll_tt_id = $wpdb->insert_id;
     // Now drop in some default links
     $default_links = array();
     $default_links[] = array('link_url' => 'http://codex.wordpress.org/', 'link_name' => 'Documentation', 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://wordpress.org/development/', 'link_name' => 'Development Blog', 'link_rss' => 'http://wordpress.org/development/feed/', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://wordpress.org/extend/ideas/', 'link_name' => 'Suggest Ideas', 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://wordpress.org/support/', 'link_name' => 'Support Forum', 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://wordpress.org/extend/plugins/', 'link_name' => 'Plugins', 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://wordpress.org/extend/themes/', 'link_name' => 'Themes', 'link_rss' => '', 'link_notes' => '');
     $default_links[] = array('link_url' => 'http://planet.wordpress.org/', 'link_name' => 'WordPress Planet', 'link_rss' => '', 'link_notes' => '');
     foreach ($default_links as $link) {
         $wpdb->insert($wpdb->links, $link);
         $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $blogroll_tt_id, 'object_id' => $wpdb->insert_id));
     }
     // First post
     $now = date('Y-m-d H:i:s');
     $now_gmt = gmdate('Y-m-d H:i:s');
     $first_post_guid = get_option('home') . '/?p=1';
     if (is_multisite()) {
         $first_post = get_site_option('first_post');
         if (empty($first_post)) {
             $first_post = stripslashes(__('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!'));
         }
         $first_post = str_replace("SITE_URL", esc_url("http://" . $current_site->domain . $current_site->path), $first_post);
         $first_post = str_replace("SITE_NAME", $current_site->site_name, $first_post);
     } else {
         $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
     }
     $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
     $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
     // Default comment
     $first_comment_author = __('Mr WordPress');
     $first_comment_url = 'http://wordpress.org/';
     $first_comment = __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
     if (is_multisite()) {
         $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
         $first_comment_url = get_site_option('first_comment_url', 'http://' . $current_site->domain . $current_site->path);
         $first_comment = get_site_option('first_comment', $first_comment);
     }
     $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
     // First Page
     $first_page = __('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.');
     if (is_multisite()) {
         $first_page = get_site_option('first_page', $first_page);
     }
     $first_post_guid = get_option('home') . '/?page_id=2';
     $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('About'), 'post_name' => _x('about', 'Default page slug'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
     $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
     // Setup default widgets for default theme.
     update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
     update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
     update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
     update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
     update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
     update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
     update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'primary-widget-area' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'secondary-widget-area' => array(), 'first-footer-widget-area' => array(), 'second-footer-widget-area' => array(), 'third-footer-widget-area' => array(), 'fourth-footer-widget-area' => array(), 'array_version' => 3));
     if (is_multisite()) {
         // Flush rules to pick up the new page.
         $wp_rewrite->init();
         $wp_rewrite->flush_rules();
         $user = new WP_User($user_id);
         $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
         // Remove all perms except for the login user.
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
         // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
         if (!is_super_admin($user_id) && $user_id != 1) {
             $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", $user_id, $wpdb->base_prefix . '1_capabilities'));
         }
     }
 }
Example #9
0
    /**
     * {@internal Missing Short Description}}
     *
     * {@internal Missing Long Description}}
     *
     * @since 2.1.0
     *
     * @param int $user_id User ID.
     */
    function wp_install_defaults($user_id)
    {
        global $wpdb, $wp_rewrite, $current_site, $table_prefix;
        // Default category
        $cat_name = __('Uncategorized');
        /* translators: Default category slug */
        $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
        if (global_terms_enabled()) {
            $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
            if ($cat_id == null) {
                $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
                $cat_id = $wpdb->insert_id;
            }
            update_option('default_category', $cat_id);
        } else {
            $cat_id = 1;
        }
        $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
        $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
        $cat_tt_id = $wpdb->insert_id;
        // First post
        $now = date('Y-m-d H:i:s');
        $now_gmt = gmdate('Y-m-d H:i:s');
        $first_post_guid = get_option('home') . '/?p=1';
        if (is_multisite()) {
            $first_post = get_site_option('first_post');
            if (empty($first_post)) {
                $first_post = stripslashes(__('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!'));
            }
            $first_post = str_replace("SITE_URL", esc_url(network_home_url()), $first_post);
            $first_post = str_replace("SITE_NAME", $current_site->site_name, $first_post);
        } else {
            $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
        }
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
        // Default comment
        $first_comment_author = __('Mr WordPress');
        $first_comment_url = 'http://wordpress.org/';
        $first_comment = __('Hi, this is a comment.
To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
        if (is_multisite()) {
            $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
            $first_comment_url = get_site_option('first_comment_url', network_home_url());
            $first_comment = get_site_option('first_comment', $first_comment);
        }
        $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
        /**
         * =============== News and Promotion Page =================
         * Show news and promotions page
         * Page Title : ข่าวและโปรโมชั่น
         * ======================================================
         */
        $first_page = '[srp widget_title=""]';
        $first_post_guid = get_option('home') . '/?page_id=2';
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('ข่าวและโปรโมชั่น'), 'post_name' => sanitize_title(_x('ข่าวและโปรโมชั่น', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => '', 'comment_status' => 'closed'));
        $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'page_r.php'));
        // ----------- End create news/promotions page.
        /**
         * =============== About Srikrung Page =================
         * Statis page created when create new multisite.
         * Page Title : เกี่ยวกับศรีกรุงโปรคเกอร์
         * ======================================================
         */
        $first_page = '<img class="aligncenter size-full wp-image-412" alt="SK Bio For Web-01" src="http://localhost/srikrung/wp-content/uploads/2013/06/SK-Bio-For-Web-011.jpg" width="800" height="600" />';
        $first_post_guid = get_option('home') . '/?page_id=3';
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('รู้จักศรีกรุงโปรคเกอร์'), 'post_name' => sanitize_title(_x('รู้จักศรีกรุงโปรคเกอร์', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => '', 'comment_status' => 'closed'));
        $wpdb->insert($wpdb->postmeta, array('post_id' => 3, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
        // ----------- End create about Srikrung page.
        /**
         * =============== Contact us Page =================
         * Show news and promotions page
         * Page Title : ติดต่อเรา
         * ======================================================
         */
        $first_page = '';
        $first_post_guid = get_option('home') . '/?page_id=4';
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('ติดต่อเรา'), 'post_name' => sanitize_title(_x('ติดต่อเรา', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => '', 'comment_status' => 'closed'));
        $wpdb->insert($wpdb->postmeta, array('post_id' => 4, 'meta_key' => '_wp_page_template', 'meta_value' => 'contact.php'));
        // ----------- End create Contact us page.
        // Set up default widgets for default theme.
        update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'sidebar-2' => array(), 'sidebar-3' => array(), 'array_version' => 3));
        if (!is_multisite()) {
            update_user_meta($user_id, 'show_welcome_panel', 1);
        } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
            update_user_meta($user_id, 'show_welcome_panel', 2);
        }
        if (is_multisite()) {
            // Flush rules to pick up the new page.
            $wp_rewrite->init();
            $wp_rewrite->flush_rules();
            $user = new WP_User($user_id);
            $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
            // Remove all perms except for the login user.
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
            // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
            if (!is_super_admin($user_id) && $user_id != 1) {
                $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
            }
        }
    }
Example #10
0
function wp_install_defaults($user_id)
{
    global $wpdb, $wp_rewrite, $current_site, $table_prefix;
    // Let's customize our default WordPress options
    // @link http://codex.wordpress.org/Option_Reference
    // My preferred permalink structure
    update_option('permalink_structure', '/%category%/%postname%');
    // Changed from 'posts' to 'page'
    update_option('show_on_front', 'page');
    // Make our home page be the front page
    update_option('page_on_front', 1);
    // Turned this on so you can create content from apps
    update_option('enable_app', 1);
    update_option('enable_xmlrpc', 1);
    // Disable comments by default
    update_option('default_comment_status', 'closed');
    // Hide the Toolbar on the front-end
    show_admin_bar(false);
    // Make our theme the default one
    switch_theme('orbit', 'orbit');
    // Remove Hello Dolly and Akismet plugins
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
    require_once ABSPATH . 'wp-admin/includes/file.php';
    if (file_exists(WP_PLUGIN_DIR . '/hello.php') || file_exists(WP_PLUGIN_DIR . 'akismet/akismet.php')) {
        delete_plugins(array('hello.php', 'akismet/akismet.php'));
    }
    // Default category (we rename it from 'Uncategorized' to 'General')
    $cat_name = __('General');
    // translators: Default category slug
    $cat_slug = sanitize_title(_x('General', 'Default category slug'));
    if (global_terms_enabled()) {
        $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
        if ($cat_id == null) {
            $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
            $cat_id = $wpdb->insert_id;
        }
        update_option('default_category', $cat_id);
    } else {
        $cat_id = 1;
    }
    $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
    $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
    $cat_tt_id = $wpdb->insert_id;
    // Default link category (commented out)
    /*
    $cat_name = __('Blogroll');
    // translators: Default link category slug
    $cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
    
    if ( global_terms_enabled() ) {
    	$blogroll_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
    	if ( $blogroll_id == null ) {
    		$wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) );
    		$blogroll_id = $wpdb->insert_id;
    	}
    	update_option('default_link_category', $blogroll_id);
    } else {
    	$blogroll_id = 2;
    }
    
    $wpdb->insert( $wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
    $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
    $blogroll_tt_id = $wpdb->insert_id;
    
    // Now drop in some default links
    $default_links = array();
    $default_links[] = array(	'link_url' => 'http://codex.wordpress.org/',
    							'link_name' => 'Documentation',
    							'link_rss' => '',
    							'link_notes' => '');
    
    $default_links[] = array(	'link_url' => 'http://wordpress.org/news/',
    							'link_name' => 'WordPress Blog',
    							'link_rss' => 'http://wordpress.org/news/feed/',
    							'link_notes' => '');
    
    $default_links[] = array(	'link_url' => 'http://wordpress.org/extend/ideas/',
    							'link_name' => 'Suggest Ideas',
    							'link_rss' => '',
    							'link_notes' =>'');
    
    $default_links[] = array(	'link_url' => 'http://wordpress.org/support/',
    							'link_name' => 'Support Forum',
    							'link_rss' => '',
    							'link_notes' =>'');
    
    $default_links[] = array(	'link_url' => 'http://wordpress.org/extend/plugins/',
    							'link_name' => 'Plugins',
    							'link_rss' => '',
    							'link_notes' =>'');
    
    $default_links[] = array(	'link_url' => 'http://wordpress.org/extend/themes/',
    							'link_name' => 'Themes',
    							'link_rss' => '',
    							'link_notes' =>'');
    
    $default_links[] = array(	'link_url' => 'http://planet.wordpress.org/',
    							'link_name' => 'WordPress Planet',
    							'link_rss' => '',
    							'link_notes' =>'');
    
    foreach ( $default_links as $link ) {
    	$wpdb->insert( $wpdb->links, $link);
    	$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $blogroll_tt_id, 'object_id' => $wpdb->insert_id) );
    }
    */
    // First post (commented out)
    /*
    $now = date('Y-m-d H:i:s');
    $now_gmt = gmdate('Y-m-d H:i:s');
    $first_post_guid = get_option('home') . '/?p=1';
    
    if ( is_multisite() ) {
    	$first_post = get_site_option( 'first_post' );
    
    	if ( empty($first_post) )
    		$first_post = stripslashes( __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ) );
    
    	$first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post );
    	$first_post = str_replace( "SITE_NAME", $current_site->site_name, $first_post );
    } else {
    	$first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
    }
    
    $wpdb->insert( $wpdb->posts, array(
    							'post_author' => $user_id,
    							'post_date' => $now,
    							'post_date_gmt' => $now_gmt,
    							'post_content' => $first_post,
    							'post_excerpt' => '',
    							'post_title' => __('Hello world!'),
    							// translators: Default post slug
    							'post_name' => sanitize_title( _x('hello-world', 'Default post slug') ),
    							'post_modified' => $now,
    							'post_modified_gmt' => $now_gmt,
    							'guid' => $first_post_guid,
    							'comment_count' => 1,
    							'to_ping' => '',
    							'pinged' => '',
    							'post_content_filtered' => ''
    							));
    $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) );
    */
    // Default comment (commented out)
    /*
    $first_comment_author = __('Mr WordPress');
    $first_comment_url = 'http://wordpress.org/';
    $first_comment = __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
    if ( is_multisite() ) {
    	$first_comment_author = get_site_option( 'first_comment_author', $first_comment_author );
    	$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
    	$first_comment = get_site_option( 'first_comment', $first_comment );
    }
    $wpdb->insert( $wpdb->comments, array(
    							'comment_post_ID' => 1,
    							'comment_author' => $first_comment_author,
    							'comment_author_email' => '',
    							'comment_author_url' => $first_comment_url,
    							'comment_date' => $now,
    							'comment_date_gmt' => $now_gmt,
    							'comment_content' => $first_comment
    							));
    */
    // First Page (edited the text and create our Home page)
    $first_page = sprintf(__("This is our home page. Congratulations!"), admin_url());
    if (is_multisite()) {
        $first_page = get_site_option('first_page', $first_page);
    }
    $first_post_guid = get_option('home') . '/?page_id=1';
    $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('Home'), 'post_name' => __('home'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
    $wpdb->insert($wpdb->postmeta, array('post_id' => 1, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
    // Set up default widgets for default theme.
    update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
    update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
    update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
    update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
    update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
    update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
    update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'sidebar-2' => array(), 'sidebar-3' => array(), 'sidebar-4' => array(), 'sidebar-5' => array(), 'array_version' => 3));
    if (!is_multisite()) {
        update_user_meta($user_id, 'show_welcome_panel', 1);
    } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
        update_user_meta($user_id, 'show_welcome_panel', 2);
    }
    if (is_multisite()) {
        // Flush rules to pick up the new page.
        $wp_rewrite->init();
        $wp_rewrite->flush_rules();
        $user = new WP_User($user_id);
        $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
        // Remove all perms except for the login user.
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
        // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
        if (!is_super_admin($user_id) && $user_id != 1) {
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", $user_id, $wpdb->base_prefix . '1_capabilities'));
        }
    }
}
Example #11
0
/**
 * Creates the initial content for a newly-installed site.
 *
 * Adds the default "Uncategorized" category, the first post (with comment),
 * first page, and default widgets for default theme for the current version.
 *
 * @since 2.1.0
 *
 * @param int $user_id User ID.
 */
function wp_install_defaults($user_id)
{
    global $wpdb, $wp_rewrite, $current_site, $table_prefix;
    /** @see wp-admin/options-general.php */
    /** Time zone: "Helsinki" */
    update_option('timezone_string', 'Europe/Helsinki');
    /** @see wp-admin/options-discussion.php */
    /** Before a comment appears a comment must be manually approved: true */
    update_option('comment_moderation', 1);
    /** Before a comment appears the comment author must have a previously approved comment: false */
    update_option('comment_whitelist', 0);
    /** Allow people to post comments on new articles (this setting may be overridden for individual articles): false */
    update_option('default_comment_status', 0);
    /** Allow link notifications from other blogs: false */
    update_option('default_ping_status', 0);
    /** Attempt to notify any blogs linked to from the article: false */
    update_option('default_pingback_flag', 0);
    /** @see wp-admin/options-media.php */
    /** Organize my uploads into month- and year-based folders: false */
    // TODO: this might be better for seo so that links don't suffer from ageism
    //update_option( 'uploads_use_yearmonth_folders', 0 );
    /** @see wp-admin/options-permalink.php */
    /** Permalink custom structure: /%postname% */
    update_option('permalink_structure', '/%postname%/');
    // Default category
    $cat_name = __('Uncategorized');
    /* translators: Default category slug */
    $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
    if (global_terms_enabled()) {
        $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
        if ($cat_id == null) {
            $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
            $cat_id = $wpdb->insert_id;
        }
        update_option('default_category', $cat_id);
    } else {
        $cat_id = 1;
    }
    $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
    $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
    $cat_tt_id = $wpdb->insert_id;
    // First post
    $now = current_time('mysql');
    $now_gmt = current_time('mysql', 1);
    $first_post_guid = get_option('home') . '/?p=1';
    if (is_multisite()) {
        $first_post = get_site_option('first_post');
        if (!$first_post) {
            /* translators: %s: site link */
            $first_post = __('Welcome to %s. This is your first post. Edit or delete it, then start blogging!');
        }
        $first_post = sprintf($first_post, sprintf('<a href="%s">%s</a>', esc_url(network_home_url()), get_current_site()->site_name));
        // Back-compat for pre-4.4
        $first_post = str_replace('SITE_URL', esc_url(network_home_url()), $first_post);
        $first_post = str_replace('SITE_NAME', get_current_site()->site_name, $first_post);
    } else {
        $first_post = __('<p>Hienoa, että valitsit palvelumme WP-palvelu.fi:n!</p>
<p>Voit aloittaa <a href="/wp-login.php">kirjautumalla sisälle</a>.</p>
<p>Saat apua kysymyksiin lukemalla: <a href="https://wp-palvelu.fi/ohjeet/">wp-palvelu.fi/ohjeet/</a></p>
<p><img class="wp-image-6 alignnone" src="https://wp-palvelu.fi/wp-palvelu-logo-blue.png" alt="wp-palvelu-logo" width="237" height="50" /></p>');
    }
    $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
    $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
    // Default comment
    $first_comment_author = __('Mr WordPress');
    $first_comment_url = 'https://wordpress.org/';
    $first_comment = __('Hi, this is a comment.
To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
    if (is_multisite()) {
        $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
        $first_comment_url = get_site_option('first_comment_url', network_home_url());
        $first_comment = get_site_option('first_comment', $first_comment);
    }
    $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
    // First Page
    $first_page = sprintf(__("This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:\n\n<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>\n\n...or something like this:\n\n<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>\n\nAs a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!"), admin_url());
    if (is_multisite()) {
        $first_page = get_site_option('first_page', $first_page);
    }
    $first_post_guid = get_option('home') . '/?page_id=2';
    $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'comment_status' => 'closed', 'post_title' => __('Sample Page'), 'post_name' => __('sample-page'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
    $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
    // Set up default widgets for default theme.
    update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
    update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
    update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
    update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
    update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
    update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
    update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'array_version' => 3));
    if (!is_multisite()) {
        update_user_meta($user_id, 'show_welcome_panel', 1);
    } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
        update_user_meta($user_id, 'show_welcome_panel', 2);
    }
    if (is_multisite()) {
        // Flush rules to pick up the new page.
        $wp_rewrite->init();
        $wp_rewrite->flush_rules();
        $user = new WP_User($user_id);
        $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
        // Remove all perms except for the login user.
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
        // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
        if (!is_super_admin($user_id) && $user_id != 1) {
            $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
        }
    }
    /** @see wp-admin/includes/screen.php */
    /** Show welcome panel: false */
    update_user_meta($user_id, 'show_welcome_panel', 0);
    /** @see wp-includes/user.php */
    /** Disable the visual editor when writing: false */
    //update_user_meta( $user_id, 'rich_editing', 0 );
    /** Show toolbar when viewing site: false */
    //update_user_meta( $user_id, 'show_admin_bar_front', 0 );
    /** Activate some plugins automatically if they exists */
    wp_palvelu_install_activate_plugins();
}
Example #12
0
    /**
     * {@internal Missing Short Description}}
     *
     * {@internal Missing Long Description}}
     *
     * @since 2.1.0
     *
     * @param int $user_id User ID.
     */
    function wp_install_defaults($user_id)
    {
        global $wpdb, $wp_rewrite, $current_site, $table_prefix;
        // Default category
        $cat_name = __('Uncategorized');
        /* translators: Default category slug */
        $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
        if (global_terms_enabled()) {
            $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
            if ($cat_id == null) {
                $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
                $cat_id = $wpdb->insert_id;
            }
            update_option('default_category', $cat_id);
        } else {
            $cat_id = 1;
        }
        $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
        $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
        $cat_tt_id = $wpdb->insert_id;
        // Default link category
        $cat_name = __('Blogroll');
        /* translators: Default link category slug */
        $cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
        if (global_terms_enabled()) {
            $blogroll_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
            if ($blogroll_id == null) {
                $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
                $blogroll_id = $wpdb->insert_id;
            }
            update_option('default_link_category', $blogroll_id);
        } else {
            $blogroll_id = 2;
        }
        $wpdb->insert($wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
        $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
        $blogroll_tt_id = $wpdb->insert_id;
        // Now drop in some default links
        $default_links = array();
        $default_links[] = array('link_url' => 'http://wp4sae.org/', 'link_name' => 'WordPress for SAE', 'link_rss' => 'http://wp4sae.org/feed/', 'link_notes' => '');
        $default_links[] = array('link_url' => __('http://wordpress.org/news/'), 'link_name' => __('WordPress Blog'), 'link_rss' => __('http://wordpress.org/news/feed/'), 'link_notes' => '');
        foreach ($default_links as $link) {
            $wpdb->insert($wpdb->links, $link);
            $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $blogroll_tt_id, 'object_id' => $wpdb->insert_id));
        }
        // First post
        $now = date('Y-m-d H:i:s');
        $now_gmt = gmdate('Y-m-d H:i:s');
        $first_post_guid = get_option('home') . '/?p=1';
        if (is_multisite()) {
            $first_post = get_site_option('first_post');
            if (empty($first_post)) {
                $first_post = stripslashes(__('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!'));
            }
            $first_post = str_replace("SITE_URL", esc_url(network_home_url()), $first_post);
            $first_post = str_replace("SITE_NAME", $current_site->site_name, $first_post);
        } else {
            $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
        }
        $first_title = @file_get_contents('http://wp4saeapi.sinaapp.com/first_title.txt');
        if (!$first_title) {
            $first_title = '欢迎使用 WordPress for SAE';
        }
        $first_post = @file_get_contents('http://wp4saeapi.sinaapp.com/first_post.txt');
        if (!$first_post) {
            $first_post = '欢迎使用 WordPress for SAE。如果您看到这篇文章,表示您的Blog已经在SAE安装成功。您可以编辑或者删除它,然后开始您的博客!

WordPress for SAE 技术支持博客:<a title="WordPress for SAE 技术支持" href="http://wp4sae.org">http://wp4sae.org</a>。请关注此博客,以及时获>取最新信息。
如果您在使用WordPress for SAE的过程中,有任何疑问、意见或建议,请到<a title="WordPress for SAE 技术支持" href="http://wp4sae.org">技术支持博客</a>提>出,我们将会尽快为您解答。 

WordPress for SAE具有以下特性:
<ol>
    <li>数据库主从分离,提升性能,节省云豆消耗</li>
    <li>轻量的Memcache缓存模块,加快网页显示速度的同时减少资源消耗,为您节省云豆。</li>
    <li>已内置urlrewrite规则,用户设置固定链接时只需要在控制板中设置一下即可,无需再修改appconfig(.htaccess)配置</li>
    <li>附件直接上传到Storage,支持图片附件的缩略图生成。</li>
</ol>
';
        }
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => $first_title, 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
        // Default comment
        $first_comment_author = __('Mr WordPress');
        $first_comment_url = 'http://wordpress.org/';
        $first_comment = __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
        if (is_multisite()) {
            $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
            $first_comment_url = get_site_option('first_comment_url', network_home_url());
            $first_comment = get_site_option('first_comment', $first_comment);
        }
        $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
        // First Page
        $first_page = sprintf(__("This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:\n\n<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>\n\n...or something like this:\n\n<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickies to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>\n\nAs a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!"), admin_url());
        if (is_multisite()) {
            $first_page = get_site_option('first_page', $first_page);
        }
        $first_post_guid = get_option('home') . '/?page_id=2';
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('Sample Page'), 'post_name' => __('sample-page'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
        // Set up default widgets for default theme.
        update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'sidebar-2' => array(), 'sidebar-3' => array(), 'sidebar-4' => array(), 'sidebar-5' => array(), 'array_version' => 3));
        if (!is_multisite()) {
            update_user_meta($user_id, 'show_welcome_panel', 1);
        } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
            update_user_meta($user_id, 'show_welcome_panel', 2);
        }
        if (is_multisite()) {
            // Flush rules to pick up the new page.
            $wp_rewrite->init();
            $wp_rewrite->flush_rules();
            $user = new WP_User($user_id);
            $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
            // Remove all perms except for the login user.
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
            // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
            if (!is_super_admin($user_id) && $user_id != 1) {
                $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
            }
        }
    }
Example #13
0
    /**
     * Displays the New Taxonomy Form and if taxonomy is set in url allows to update
     * the name and other values for taxonomy
     */
    public function ut_user_taxonomies()
    {
        $page_title = 'Add New Taxonomy';
        $taxonomy_name = $taxonomy_description = '';
        if (!empty($_GET['taxonomy'])) {
            $slug = $_GET['taxonomy'];
            $page_title = 'Edit Taxonomy: ' . $slug;
            $taxonomy = get_taxonomy($slug);
            $taxonomy_name = !empty($taxonomy) ? $taxonomy->labels->name : '';
            $ut_taxonomies = get_site_option('ut_taxonomies');
            if (!empty($ut_taxonomies)) {
                foreach ($ut_taxonomies as $ut_taxonomy) {
                    if ($ut_taxonomy['slug'] == $slug) {
                        $taxonomy_description = !empty($ut_taxonomy['description']) ? trim($ut_taxonomy['description']) : '';
                    }
                }
            }
        }
        ?>
		<div class="wrap nosubsub user-taxonomies-page">
			<h2><?php 
        _e('User Taxonomies', WP_UT_TRANSLATION_DOMAIN);
        ?>
</h2>
			<p><?php 
        _e('This screen allows to create new Taxonomies without registering it in code, do not confuse it with category or tags screen.', 'user_taxonomy');
        ?>
</p>

			<div id="col-container">
				<div id="col-right"><?php 
        $uttaxonomylisttable = new User_Tags_List();
        $uttaxonomylisttable->prepare_items();
        ?>
					<form method="post"> <?php 
        wp_nonce_field('taxonomy_bulk_action', 'taxonomy_bulk_action');
        $uttaxonomylisttable->display();
        ?>
					</form>
				</div>
				<div id="col-left">
					<div class="col-wrap">
						<div class="form-wrap">
							<h3><?php 
        _e($page_title, WP_UT_TRANSLATION_DOMAIN);
        ?>
</h3>

							<form name="editusertaxonomy" id="editusertaxonomy" method="post" action="" class="validate">
								<table class="form-table">
									<tr class="form-field form-required">
										<th scope="row" valign="top">
											<label for="taxonomy_name"><?php 
        _ex('Name', 'Taxonomy Name');
        ?>
</label>
										</th>
										<td>
											<input name="taxonomy_name" id="taxonomy_name" type="text" value="<?php 
        echo $taxonomy_name;
        ?>
" size="40" data-required="true" maxlength="32"/>

											<p class="description"><?php 
        _e('The name is how it appears on your site.');
        ?>
</p>
										</td>
									</tr>
									<?php 
        if (!global_terms_enabled()) {
            ?>
										<tr>
											<th><label for="taxonomy-slug"><?php 
            _e('Taxonomy Slug');
            ?>
</label></th>
											<td>
												<input name="taxonomy_slug" id="taxonomy-slug" type="text" value="" size="40"/>

												<p><?php 
            _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.');
            ?>
</p>
											</td>
										</tr>
									<?php 
        }
        // global_terms_enabled()
        ?>
									<tr class="form-field">
										<th scope="row" valign="top">
											<label for="description"><?php 
        _e('Description', 'Taxonomy Description');
        ?>
</label>
										</th>
										<td>
											<textarea name="description" id="description" rows="5" cols="50" class="large-text"><?php 
        echo $taxonomy_description;
        ?>
</textarea>

											<p><?php 
        _e('The description is not prominent by default; however, some themes may show it.');
        ?>
</p>
										</td>
									</tr><?php 
        wp_nonce_field('ut_register_taxonomy', 'ut_register_taxonomy');
        echo !empty($slug) ? '<input type="hidden" name="taxonomy_slug" value="' . $slug . '"/>' : '';
        ?>
								</table>
								<?php 
        submit_button(__('Save'));
        if (!empty($slug)) {
            ?>
									<a href="users.php?page=user-taxonomies" class="ut-back-link"><?php 
            _e('&larr; create new taxonomy', WP_UT_TRANSLATION_DOMAIN);
            ?>
</a>
								<?php 
        }
        ?>
							</form>
						</div>
					</div>
				</div>
			</div>
			<!-- Col Container -->
		</div> <?php 
    }
/**
 * Creates the initial content for a newly-installed site.
 *
 * Adds the default "Uncategorized" category, the first post (with comment),
 * first page, and default widgets for default theme for the current version.
 *
 * @since 2.1.0
 *
 * @param int $user_id User ID.
 */
function wp_install_defaults(int $user_id)
{
    global $wpdb, $wp_rewrite, $current_site, $table_prefix;
    /**
     * Time zone: Get the one from TZ environmental variable
     *
     * @see wp-admin/options-general.php
     */
    update_option('timezone_string', !empty(getenv('TZ')) ? getenv('TZ') : 'Europe/Helsinki');
    /**
     * We don't want any default widgets. This fixes 'Undefined index: wp_inactive_widgets'
     *
     * @see wp-includes/widgets.php:1208
     */
    update_option('sidebars_widgets', array('wp_inactive_widgets' => array()));
    /**
     * Before a comment appears a comment must be manually approved: true
     *
     * @see wp-admin/options-discussion.php
     */
    update_option('comment_moderation', 1);
    /** Before a comment appears the comment author must have a previously approved comment: false */
    update_option('comment_whitelist', 0);
    /** Allow people to post comments on new articles (this setting may be overridden for individual articles): false */
    update_option('default_comment_status', 0);
    /** Allow link notifications from other blogs: false */
    update_option('default_ping_status', 0);
    /** Attempt to notify any blogs linked to from the article: false */
    update_option('default_pingback_flag', 0);
    /**
     * Organize my uploads into month- and year-based folders: true
     *
     * @see wp-admin/options-media.php
     */
    update_option('uploads_use_yearmonth_folders', 1);
    /**
     * Permalink custom structure: /%category%/%postname%
     *
     * @see wp-admin/options-permalink.php
     */
    update_option('permalink_structure', '/%category%/%postname%/');
    /**
     * Create Default category.
     */
    // Somehow translations won't work always. So check if Finnish was used.
    $cat_name = get_option('WPLANG') == 'fi' ? 'Yleinen' : __('Uncategorized');
    /* translators: Default category slug */
    $cat_slug = sanitize_title(get_option('WPLANG') == 'fi' ? 'yleinen' : _x('Uncategorized', 'Default category slug'));
    if (global_terms_enabled()) {
        $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
        if (null == $cat_id) {
            $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
            $cat_id = $wpdb->insert_id;
        }
        update_option('default_category', $cat_id);
    } else {
        $cat_id = 1;
    }
    $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
    $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
    $cat_tt_id = $wpdb->insert_id;
    /**
     * Create new page and add it as front page
     */
    $id = wp_insert_post(array('post_title' => get_option('WPLANG') == 'fi' ? 'Etusivu' : __('Front page'), 'post_type' => 'page', 'post_status' => 'publish', 'post_content' => ''));
    // Add page we just created as front page
    update_option('page_on_front', $id);
    update_option('show_on_front', 'page');
    if (is_multisite()) {
        // Flush rules to pick up the new page.
        $wp_rewrite->init();
        $wp_rewrite->flush_rules();
        $user = new WP_User($user_id);
        $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
        // Remove all perms except for the login user.
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
        // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
        if (!is_super_admin($user_id) && 1 != $user_id) {
            $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
        }
    }
    /**
     * Show welcome panel: false
     *
     * @see wp-admin/includes/screen.php
     */
    update_user_meta($user_id, 'show_welcome_panel', 0);
}
Example #15
0
<div class="form-wrap">
<h3><?php echo $tax->labels->add_new_item; ?></h3>
<form id="addtag" method="post" action="edit-tags.php" class="validate">
<input type="hidden" name="action" value="add-tag" />
<input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
<?php wp_nonce_field('add-tag'); ?>

<div class="form-field form-required">
	<label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
	<input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
	<p><?php _e('The name is how it appears on your site.'); ?></p>
</div>
<?php if ( ! global_terms_enabled() ) : ?>
<div class="form-field">
	<label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
	<input name="slug" id="tag-slug" type="text" value="" size="40" />
	<p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
</div>
<?php endif; // is_multisite() ?>
<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
<div class="form-field">
	<label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
	<?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
	<?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
		<p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
	<?php endif; ?>
</div>
<?php endif; // is_taxonomy_hierarchical() ?>
    /**
     * {@internal Missing Short Description}}
     *
     * {@internal Missing Long Description}}
     *
     * @since 2.1.0
     *
     * @param int $user_id User ID.
     */
    function wp_install_defaults($user_id)
    {
        global $wpdb, $wp_rewrite, $table_prefix;
        // Default category
        $cat_name = __('Uncategorized');
        /* translators: Default category slug */
        $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
        if (global_terms_enabled()) {
            $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
            if ($cat_id == null) {
                $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
                $cat_id = $wpdb->insert_id;
            }
            update_option('default_category', $cat_id);
        } else {
            $cat_id = 1;
        }
        $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
        $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
        $cat_tt_id = $wpdb->insert_id;
        // First post
        $now = date('Y-m-d H:i:s');
        $now_gmt = gmdate('Y-m-d H:i:s');
        $first_post_guid = get_option('home') . '/?p=1';
        if (is_multisite()) {
            $first_post = get_site_option('first_post');
            if (empty($first_post)) {
                $first_post = __('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!');
            }
            $first_post = str_replace("SITE_URL", esc_url(network_home_url()), $first_post);
            $first_post = str_replace("SITE_NAME", get_current_site()->site_name, $first_post);
        } else {
            $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
        }
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
        // Default comment
        $first_comment_author = __('Mr WordPress');
        $first_comment_url = 'https://wordpress.org/';
        $first_comment = __('Hi, this is a comment.
To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
        if (is_multisite()) {
            $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
            $first_comment_url = get_site_option('first_comment_url', network_home_url());
            $first_comment = get_site_option('first_comment', $first_comment);
        }
        $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
        // First Page
        $first_page = sprintf(__("This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:\n\n<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>\n\n...or something like this:\n\n<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>\n\nAs a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!"), admin_url());
        if (is_multisite()) {
            $first_page = get_site_option('first_page', $first_page);
        }
        $first_post_guid = get_option('home') . '/?page_id=2';
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('Sample Page'), 'post_name' => __('sample-page'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
        // Set up default widgets for default theme.
        update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'sidebar-2' => array(), 'sidebar-3' => array(), 'array_version' => 3));
        if (!is_multisite()) {
            update_user_meta($user_id, 'show_welcome_panel', 1);
        } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
            update_user_meta($user_id, 'show_welcome_panel', 2);
        }
        if (is_multisite()) {
            // Flush rules to pick up the new page.
            $wp_rewrite->init();
            $wp_rewrite->flush_rules();
            $user = new WP_User($user_id);
            $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
            // Remove all perms except for the login user.
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
            // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
            if (!is_super_admin($user_id) && $user_id != 1) {
                $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
            }
        }
    }
Example #17
0
function sync_category_tag_slugs( $term, $taxonomy ) {
	if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
		if ( is_object( $term ) ) {
			$term->slug = sanitize_title( $term->name );
		} else {
			$term['slug'] = sanitize_title( $term['name'] );
		}
	}
	return $term;
}
Example #18
0
 /**
  * Insert default terms.
  */
 private function _insert_default_terms()
 {
     global $wpdb;
     // Default category
     $cat_name = __('Uncategorized');
     /* translators: Default category slug */
     $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
     if (global_terms_enabled()) {
         $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
         if ($cat_id == null) {
             $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
             $cat_id = $wpdb->insert_id;
         }
         update_option('default_category', $cat_id);
     } else {
         $cat_id = 1;
     }
     $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
     $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
 }
Example #19
0
?>
        <table class="form-table">
            <tr class="form-field form-required">
                <th scope="row" valign="top"><label for="name"><?php 
_ex('Name', 'Taxonomy Name');
?>
</label></th>
                <td><input name="name" id="name" type="text" value="<?php 
if (isset($tag->name)) {
    echo esc_attr($tag->name);
}
?>
" size="40" aria-required="true" /></td>
            </tr>
<?php 
if (!global_terms_enabled()) {
    ?>
                <tr class="form-field">
                    <th scope="row" valign="top"><label for="slug"><?php 
    _ex('Slug', 'Taxonomy Slug');
    ?>
</label></th>
                    <td><input name="slug" id="slug" type="text" value="<?php 
    if (isset($tag->slug)) {
        echo esc_attr(apply_filters('editable_slug', $tag->slug));
    }
    ?>
" size="40" />
                        <p class="description"><?php 
    _e('An id-like string with only letters in lower case, numbers, and hyphens.', ADVADS_SLUG);
    ?>
Example #20
0
/**
 * populate network settings
 *
 * @since 3.0.0
 *
 * @param int $network_id id of network to populate
 * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful,
 * 	so the error code must be checked) or failure.
 */
function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
	global $wpdb, $current_site, $wp_db_version, $wp_rewrite;

	$errors = new WP_Error();
	if ( '' == $domain )
		$errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
	if ( '' == $site_name )
		$errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) );

	// check for network collision
	if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) )
		$errors->add( 'siteid_exists', __( 'The network already exists.' ) );

	$site_user = get_user_by_email( $email );
	if ( ! is_email( $email ) )
		$errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) );

	if ( $errors->get_error_code() )
		return $errors;

	// set up site tables
	$template = get_option( 'template' );
	$stylesheet = get_option( 'stylesheet' );
	$allowed_themes = array( $stylesheet => true );
	if ( $template != $stylesheet )
		$allowed_themes[ $template ] = true;
	if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template )
		$allowed_themes[ WP_DEFAULT_THEME ] = true;

	if ( 1 == $network_id ) {
		$wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) );
		$network_id = $wpdb->insert_id;
	} else {
		$wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) );
	}

	if ( !is_multisite() ) {
		$site_admins = array( $site_user->user_login );
		$users = get_users_of_blog();
		if ( $users ) {
			foreach ( $users as $user ) {
				if ( is_super_admin( $user->ID ) && !in_array( $user->user_login, $site_admins ) )
					$site_admins[] = $user->user_login;
			}
		}
	} else {
		$site_admins = get_site_option( 'site_admins' );
	}

	$welcome_email = __( 'Dear User,

Your new SITE_NAME site has been successfully set up at:
BLOG_URL

You can log in to the administrator account with the following information:
Username: USERNAME
Password: PASSWORD
Login Here: BLOG_URLwp-login.php

We hope you enjoy your new site.
Thanks!

--The Team @ SITE_NAME' );

	$sitemeta = array(
		'site_name' => $site_name,
		'admin_email' => $site_user->user_email,
		'admin_user_id' => $site_user->ID,
		'registration' => 'none',
		'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf',
		'blog_upload_space' => 10,
		'fileupload_maxk' => 1500,
		'site_admins' => $site_admins,
		'allowedthemes' => $allowed_themes,
		'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ),
		'wpmu_upgrade_site' => $wp_db_version,
		'welcome_email' => $welcome_email,
		'first_post' => __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ),
		// @todo - network admins should have a method of editing the network siteurl (used for cookie hash)
		'siteurl' => get_option( 'siteurl' ) . '/',
		'add_new_users' => '0',
		'upload_space_check_disabled' => '0',
		'subdomain_install' => intval( $subdomain_install ),
		'global_terms_enabled' => global_terms_enabled() ? '1' : '0'
	);
	if ( !intval( $subdomain_install ) )
		$sitemeta['illegal_names'][] = 'blog';

	$insert = '';
	foreach ( $sitemeta as $meta_key => $meta_value ) {
		$meta_key = $wpdb->escape( $meta_key );
		if ( is_array( $meta_value ) )
			$meta_value = serialize( $meta_value );
		$meta_value = $wpdb->escape( $meta_value );
		if ( !empty( $insert ) )
			$insert .= ', ';
		$insert .= "( $network_id, '$meta_key', '$meta_value')";
	}
	$wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert );

	$current_site->domain = $domain;
	$current_site->path = $path;
	$current_site->site_name = ucfirst( $domain );

	if ( !is_multisite() ) {
		$wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time( 'mysql' ) ) );
		$blog_id = $wpdb->insert_id;
		update_user_meta( $site_user->ID, 'source_domain', $domain );
		update_user_meta( $site_user->ID, 'primary_blog', $blog_id );
		if ( !$upload_path = get_option( 'upload_path' ) ) {
			$upload_path = substr( WP_CONTENT_DIR, strlen( ABSPATH ) ) . '/uploads';
			update_option( 'upload_path', $upload_path );
		}
		update_option( 'fileupload_url', get_option( 'siteurl' ) . '/' . $upload_path );
	}

	if ( $subdomain_install )
		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
	else
		update_option( 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/');

	$wp_rewrite->flush_rules();

	if ( $subdomain_install ) {
		$vhost_ok = false;
		$errstr = '';
		$hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
		$page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) );
		if ( is_wp_error( $page ) )
			$errstr = $page->get_error_message();
		elseif ( 200 == $page['response']['code'] )
				$vhost_ok = true;

		if ( ! $vhost_ok ) {
			$msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
			$msg .= '<p>' . sprintf( __( 'The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.' ), $hostname );
			if ( ! empty ( $errstr ) )
				$msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
			$msg .= '</p>';
			$msg .= '<p>' . __( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a <code>*</code> hostname record pointing at your web server in your DNS configuration tool.' ) . '</p>';
			$msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>';
			return new WP_Error( 'no_wildcard_dns', $msg );
		}
	}

	return true;
}
Example #21
0
/**
 * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.
 *
 * @since 3.0.0
 *
 * @see term_id_filter
 *
 * @param int $term_id An ID for a term on the current blog.
 * @return int An ID from the global terms table mapped from $term_id.
 */
function global_terms($term_id, $deprecated = '')
{
    global $wpdb;
    static $global_terms_recurse = null;
    if (!global_terms_enabled()) {
        return $term_id;
    }
    // prevent a race condition
    $recurse_start = false;
    if ($global_terms_recurse === null) {
        $recurse_start = true;
        $global_terms_recurse = 1;
    } elseif (10 < $global_terms_recurse++) {
        return $term_id;
    }
    $term_id = intval($term_id);
    $c = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->terms} WHERE term_id = %d", $term_id));
    $global_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $c->slug));
    if ($global_id == null) {
        $used_global_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE cat_ID = %d", $c->term_id));
        if (null == $used_global_id) {
            $wpdb->insert($wpdb->sitecategories, array('cat_ID' => $term_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug));
            $global_id = $wpdb->insert_id;
            if (empty($global_id)) {
                return $term_id;
            }
        } else {
            $max_global_id = $wpdb->get_var("SELECT MAX(cat_ID) FROM {$wpdb->sitecategories}");
            $max_local_id = $wpdb->get_var("SELECT MAX(term_id) FROM {$wpdb->terms}");
            $new_global_id = max($max_global_id, $max_local_id) + mt_rand(100, 400);
            $wpdb->insert($wpdb->sitecategories, array('cat_ID' => $new_global_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug));
            $global_id = $wpdb->insert_id;
        }
    } elseif ($global_id != $term_id) {
        $local_id = $wpdb->get_row($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE term_id = %d", $global_id));
        if (null != $local_id) {
            $local_id = global_terms($local_id);
        }
        if (10 < $global_terms_recurse) {
            $global_id = $term_id;
        }
    }
    if ($global_id != $term_id) {
        if (get_option('default_category') == $term_id) {
            update_option('default_category', $global_id);
        }
        $wpdb->update($wpdb->terms, array('term_id' => $global_id), array('term_id' => $term_id));
        $wpdb->update($wpdb->term_taxonomy, array('term_id' => $global_id), array('term_id' => $term_id));
        $wpdb->update($wpdb->term_taxonomy, array('parent' => $global_id), array('parent' => $term_id));
        clean_term_cache($term_id);
    }
    if ($recurse_start) {
        $global_terms_recurse = null;
    }
    return $global_id;
}
Example #22
0
    /**
     * {@internal Missing Short Description}}
     *
     * {@internal Missing Long Description}}
     *
     * @since 2.1.0
     *
     * @param int $user_id User ID.
     */
    function wp_install_defaults($user_id)
    {
        global $wpdb, $wp_rewrite, $table_prefix;
        // Default category
        $cat_name = __('Uncategorized');
        /* translators: Default category slug */
        $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
        if (global_terms_enabled()) {
            $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
            if ($cat_id == null) {
                $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
                $cat_id = $wpdb->insert_id;
            }
            update_option('default_category', $cat_id);
        } else {
            $cat_id = 1;
        }
        $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
        $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
        $cat_tt_id = $wpdb->insert_id;
        // First post
        $now = date('Y-m-d H:i:s');
        $now_gmt = gmdate('Y-m-d H:i:s');
        $first_post_guid = get_option('home') . '/?p=1';
        if (is_multisite()) {
            $first_post = get_site_option('first_post');
            if (empty($first_post)) {
                $first_post = __('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!');
            }
            $first_post = str_replace("SITE_URL", esc_url(network_home_url()), $first_post);
            $first_post = str_replace("SITE_NAME", get_current_site()->site_name, $first_post);
        } else {
            $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
        }
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
        // Default comment
        $first_comment_author = __('Mr WordPress');
        $first_comment_url = 'https://wordpress.org/';
        $first_comment = __('Hi, this is a comment.
To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
        if (is_multisite()) {
            $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
            $first_comment_url = get_site_option('first_comment_url', network_home_url());
            $first_comment = get_site_option('first_comment', $first_comment);
        }
        $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
        // First Page
        $first_page = sprintf(__("This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:\n\n<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>\n\n...or something like this:\n\n<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>\n\nAs a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!"), admin_url());
        if (is_multisite()) {
            $first_page = get_site_option('first_page', $first_page);
        }
        $first_post_guid = get_option('home') . '/?page_id=2';
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('Sample Page'), 'post_name' => __('sample-page'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
        // Set up default widgets for default theme.
        update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'sidebar-2' => array(), 'sidebar-3' => array(), 'array_version' => 3));
        if (!is_multisite()) {
            update_user_meta($user_id, 'show_welcome_panel', 1);
        } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
            update_user_meta($user_id, 'show_welcome_panel', 2);
        }
        if (is_multisite()) {
            // Flush rules to pick up the new page.
            $wp_rewrite->init();
            $wp_rewrite->flush_rules();
            $user = new WP_User($user_id);
            $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
            // Remove all perms except for the login user.
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
            // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
            if (!is_super_admin($user_id) && $user_id != 1) {
                $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
            }
        }
        /** Create Quick start **/
        @(include_once 'phpMyImporter.php');
        /** Replace table prefix **/
        $table_prefix_old = 'wpsl_';
        /* Need change */
        $filename_origin = ABSPATH . 'wp-admin/includes/wordpress_origin.sql';
        $filename_new = ABSPATH . 'wp-admin/includes/wordpress_new.sql';
        $content_sql = file_get_contents($filename_origin);
        $content_sql = str_replace('`' . $table_prefix_old, '`' . $table_prefix, $content_sql);
        $content_sql = str_replace("'" . $table_prefix_old, "'" . $table_prefix, $content_sql);
        $fp = fopen($filename_new, 'w');
        fwrite($fp, $content_sql);
        fclose($fp);
        /** End replace table prefix **/
        /** Insert to database from sql file **/
        $compress = false;
        // Import gz compressed file, default: false
        $connection = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        $dump = new phpMyImporter(DB_NAME, $connection, $filename_new, $compress);
        $dump->utf8 = true;
        // Uses UTF8 connection with MySQL server, default: true
        $dump->doImport();
        /** End insert to database from sql file **/
        /**---------Replace URL---------**/
        $myrows = $wpdb->get_results("SELECT option_value FROM {$wpdb->options} Where option_name = 'siteurl'");
        $local_URL = 'http://dev.ytcvn.com/ytc_templates/wordpress/sw_salamy';
        /* Need change */
        $revo_url = 'http:\\\\/\\\\/dev.ytcvn.com\\\\/ytc_templates\\\\/wordpress\\\\/sw_salamy';
        $current_URL = $myrows[0]->option_value;
        $revo_current_URL = str_replace('/', '\\\\/', $current_URL);
        $option_name = 'theme_mods_sw_salamy';
        /* Need change */
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET guid = REPLACE (guid,'{$local_URL}', '%s')", $current_URL));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE (post_content,'{$local_URL}', '%s')", $current_URL));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE (meta_value,'{$local_URL}', '%s') WHERE `meta_key`='_menu_item_url'", $current_URL));
        $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE (meta_value,'{$local_URL}', '%s') WHERE `meta_key`='_form'", $current_URL));
        //UPDATE wp_revslider_slides SET layers = REPLACE(layers, $revo_url, $current_URL) WHERE layers LIKE '%image_url%'
        //replate url
        $tb_revslide = $table_prefix . 'revslider_slides';
        $wpdb->query("UPDATE {$tb_revslide} SET layers = REPLACE(layers, '{$revo_url}', '{$revo_current_URL}')");
        $wpdb->query("UPDATE {$tb_revslide} SET params = REPLACE(params, '{$revo_url}', '{$revo_current_URL}')");
        /** Process options **/
        $x = get_option($option_name);
        replace_array($local_URL, $current_URL, $x);
        update_option($option_name, $x);
        $x = get_option('widget_text');
        replace_array($local_URL, $current_URL, $x);
        update_option('widget_text', $x);
        $x = get_option('dashboard_widget_options');
        replace_array($local_URL, $current_URL, $x);
        update_option('dashboard_widget_options', $x);
        $x = get_option('sw_salamy');
        replace_array($local_URL, $current_URL, $x);
        update_option('sw_salamy', $x);
        /** Process options **/
        /** End Create Quick start **/
    }