wp_install_defaults() – Creates the initial content for a newly-installed site.

You appear to be a bot. Output may be restricted

Description

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.

Usage

wp_install_defaults( $user_id );

Parameters

$user_id
( int ) required – User ID.

Returns

void

Source

File name: wordpress/wp-admin/includes/upgrade.php
Lines:

1 to 100 of 302
  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' ) );

    $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 ) {
        $first_post = "<!-- wp:paragraph -->\n<p>" .
        /* translators: First post content. %s: Site link. */
        __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) .
        "</p>\n<!-- /wp:paragraph -->";
      }

      $first_post = sprintf(
        $first_post,
        sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->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_network()->site_name, $first_post );
    } else {
      $first_post = "<!-- wp:paragraph -->\n<p>" .
      /* translators: First post content. %s: Site link. */
      __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) .
      "</p>\n<!-- /wp:paragraph -->";
    }

    $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' => '',
      )
    );

    if ( is_multisite() ) {
      update_posts_count();
    }

    $wpdb->insert(
      $wpdb->term_relationships,
      array(
        'term_taxonomy_id' => $cat_tt_id,
        'object_id'        => 1,
      )
    );

    // Default comment.
    if ( is_multisite() ) {
      $first_comment_author = get_site_option( 'first_comment_author' );
      $first_comment_email  = get_site_option( 'first_comment_email' );
      $first_comment_url    = get_site_option( 'first_comment_url', network_home_url() );
      $first_comment        = get_site_option( 'first_comment' );
 

 View on GitHub View on Trac