[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress 3.0.1

Provided by Yoast

title

Body

[close]

/wp-admin/includes/ -> schema.php (source)

   1  <?php
   2  /**
   3   * WordPress Administration Scheme API
   4   *
   5   * Here we keep the DB structure and option values.
   6   *
   7   * @package WordPress
   8   * @subpackage Administration
   9   */
  10  
  11  /**
  12   * The database character collate.
  13   * @var string
  14   * @global string
  15   * @name $charset_collate
  16   */
  17  $charset_collate = '';
  18  
  19  // Declare these as global in case schema.php is included from a function.
  20  global $wpdb, $wp_queries;
  21  
  22  if ( ! empty($wpdb->charset) )
  23      $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  24  if ( ! empty($wpdb->collate) )
  25      $charset_collate .= " COLLATE $wpdb->collate";
  26  
  27  /** Create WordPress database tables SQL */
  28  $wp_queries = "CREATE TABLE $wpdb->terms (
  29   term_id bigint(20) unsigned NOT NULL auto_increment,
  30   name varchar(200) NOT NULL default '',
  31   slug varchar(200) NOT NULL default '',
  32   term_group bigint(10) NOT NULL default 0,
  33   PRIMARY KEY  (term_id),
  34   UNIQUE KEY slug (slug),
  35   KEY name (name)
  36  ) $charset_collate;
  37  CREATE TABLE $wpdb->term_taxonomy (
  38   term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment,
  39   term_id bigint(20) unsigned NOT NULL default 0,
  40   taxonomy varchar(32) NOT NULL default '',
  41   description longtext NOT NULL,
  42   parent bigint(20) unsigned NOT NULL default 0,
  43   count bigint(20) NOT NULL default 0,
  44   PRIMARY KEY  (term_taxonomy_id),
  45   UNIQUE KEY term_id_taxonomy (term_id,taxonomy),
  46   KEY taxonomy (taxonomy)
  47  ) $charset_collate;
  48  CREATE TABLE $wpdb->term_relationships (
  49   object_id bigint(20) unsigned NOT NULL default 0,
  50   term_taxonomy_id bigint(20) unsigned NOT NULL default 0,
  51   term_order int(11) NOT NULL default 0,
  52   PRIMARY KEY  (object_id,term_taxonomy_id),
  53   KEY term_taxonomy_id (term_taxonomy_id)
  54  ) $charset_collate;
  55  CREATE TABLE $wpdb->commentmeta (
  56    meta_id bigint(20) unsigned NOT NULL auto_increment,
  57    comment_id bigint(20) unsigned NOT NULL default '0',
  58    meta_key varchar(255) default NULL,
  59    meta_value longtext,
  60    PRIMARY KEY  (meta_id),
  61    KEY comment_id (comment_id),
  62    KEY meta_key (meta_key)
  63  ) $charset_collate;
  64  CREATE TABLE $wpdb->comments (
  65    comment_ID bigint(20) unsigned NOT NULL auto_increment,
  66    comment_post_ID bigint(20) unsigned NOT NULL default '0',
  67    comment_author tinytext NOT NULL,
  68    comment_author_email varchar(100) NOT NULL default '',
  69    comment_author_url varchar(200) NOT NULL default '',
  70    comment_author_IP varchar(100) NOT NULL default '',
  71    comment_date datetime NOT NULL default '0000-00-00 00:00:00',
  72    comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
  73    comment_content text NOT NULL,
  74    comment_karma int(11) NOT NULL default '0',
  75    comment_approved varchar(20) NOT NULL default '1',
  76    comment_agent varchar(255) NOT NULL default '',
  77    comment_type varchar(20) NOT NULL default '',
  78    comment_parent bigint(20) unsigned NOT NULL default '0',
  79    user_id bigint(20) unsigned NOT NULL default '0',
  80    PRIMARY KEY  (comment_ID),
  81    KEY comment_approved (comment_approved),
  82    KEY comment_post_ID (comment_post_ID),
  83    KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
  84    KEY comment_date_gmt (comment_date_gmt),
  85    KEY comment_parent (comment_parent)
  86  ) $charset_collate;
  87  CREATE TABLE $wpdb->links (
  88    link_id bigint(20) unsigned NOT NULL auto_increment,
  89    link_url varchar(255) NOT NULL default '',
  90    link_name varchar(255) NOT NULL default '',
  91    link_image varchar(255) NOT NULL default '',
  92    link_target varchar(25) NOT NULL default '',
  93    link_description varchar(255) NOT NULL default '',
  94    link_visible varchar(20) NOT NULL default 'Y',
  95    link_owner bigint(20) unsigned NOT NULL default '1',
  96    link_rating int(11) NOT NULL default '0',
  97    link_updated datetime NOT NULL default '0000-00-00 00:00:00',
  98    link_rel varchar(255) NOT NULL default '',
  99    link_notes mediumtext NOT NULL,
 100    link_rss varchar(255) NOT NULL default '',
 101    PRIMARY KEY  (link_id),
 102    KEY link_visible (link_visible)
 103  ) $charset_collate;
 104  CREATE TABLE $wpdb->options (
 105    option_id bigint(20) unsigned NOT NULL auto_increment,
 106    blog_id int(11) NOT NULL default '0',
 107    option_name varchar(64) NOT NULL default '',
 108    option_value longtext NOT NULL,
 109    autoload varchar(20) NOT NULL default 'yes',
 110    PRIMARY KEY  (option_id),
 111    UNIQUE KEY option_name (option_name)
 112  ) $charset_collate;
 113  CREATE TABLE $wpdb->postmeta (
 114    meta_id bigint(20) unsigned NOT NULL auto_increment,
 115    post_id bigint(20) unsigned NOT NULL default '0',
 116    meta_key varchar(255) default NULL,
 117    meta_value longtext,
 118    PRIMARY KEY  (meta_id),
 119    KEY post_id (post_id),
 120    KEY meta_key (meta_key)
 121  ) $charset_collate;
 122  CREATE TABLE $wpdb->posts (
 123    ID bigint(20) unsigned NOT NULL auto_increment,
 124    post_author bigint(20) unsigned NOT NULL default '0',
 125    post_date datetime NOT NULL default '0000-00-00 00:00:00',
 126    post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
 127    post_content longtext NOT NULL,
 128    post_title text NOT NULL,
 129    post_excerpt text NOT NULL,
 130    post_status varchar(20) NOT NULL default 'publish',
 131    comment_status varchar(20) NOT NULL default 'open',
 132    ping_status varchar(20) NOT NULL default 'open',
 133    post_password varchar(20) NOT NULL default '',
 134    post_name varchar(200) NOT NULL default '',
 135    to_ping text NOT NULL,
 136    pinged text NOT NULL,
 137    post_modified datetime NOT NULL default '0000-00-00 00:00:00',
 138    post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
 139    post_content_filtered text NOT NULL,
 140    post_parent bigint(20) unsigned NOT NULL default '0',
 141    guid varchar(255) NOT NULL default '',
 142    menu_order int(11) NOT NULL default '0',
 143    post_type varchar(20) NOT NULL default 'post',
 144    post_mime_type varchar(100) NOT NULL default '',
 145    comment_count bigint(20) NOT NULL default '0',
 146    PRIMARY KEY  (ID),
 147    KEY post_name (post_name),
 148    KEY type_status_date (post_type,post_status,post_date,ID),
 149    KEY post_parent (post_parent),
 150    KEY post_author (post_author)
 151  ) $charset_collate;
 152  CREATE TABLE $wpdb->users (
 153    ID bigint(20) unsigned NOT NULL auto_increment,
 154    user_login varchar(60) NOT NULL default '',
 155    user_pass varchar(64) NOT NULL default '',
 156    user_nicename varchar(50) NOT NULL default '',
 157    user_email varchar(100) NOT NULL default '',
 158    user_url varchar(100) NOT NULL default '',
 159    user_registered datetime NOT NULL default '0000-00-00 00:00:00',
 160    user_activation_key varchar(60) NOT NULL default '',
 161    user_status int(11) NOT NULL default '0',
 162    display_name varchar(250) NOT NULL default '',
 163    PRIMARY KEY  (ID),
 164    KEY user_login_key (user_login),
 165    KEY user_nicename (user_nicename)
 166  ) $charset_collate;
 167  CREATE TABLE $wpdb->usermeta (
 168    umeta_id bigint(20) unsigned NOT NULL auto_increment,
 169    user_id bigint(20) unsigned NOT NULL default '0',
 170    meta_key varchar(255) default NULL,
 171    meta_value longtext,
 172    PRIMARY KEY  (umeta_id),
 173    KEY user_id (user_id),
 174    KEY meta_key (meta_key)
 175  ) $charset_collate;";
 176  
 177  /**
 178   * Create WordPress options and set the default values.
 179   *
 180   * @since 1.5.0
 181   * @uses $wpdb
 182   * @uses $wp_db_version
 183   */
 184  function populate_options() {
 185      global $wpdb, $wp_db_version, $current_site;
 186  
 187      $guessurl = wp_guess_url();
 188  
 189      do_action('populate_options');
 190  
 191      if ( ini_get('safe_mode') ) {
 192          // Safe mode can break mkdir() so use a flat structure by default.
 193          $uploads_use_yearmonth_folders = 0;
 194      } else {
 195          $uploads_use_yearmonth_folders = 1;
 196      }
 197  
 198      $options = array(
 199      'siteurl' => $guessurl,
 200      'blogname' => __('My Site'),
 201      /* translators: blog tagline */
 202      'blogdescription' => __('Just another WordPress site'),
 203      'users_can_register' => 0,
 204      'admin_email' => 'you@example.com',
 205      'start_of_week' => 1,
 206      'use_balanceTags' => 0,
 207      'use_smilies' => 1,
 208      'require_name_email' => 1,
 209      'comments_notify' => 1,
 210      'posts_per_rss' => 10,
 211      'rss_use_excerpt' => 0,
 212      'mailserver_url' => 'mail.example.com',
 213      'mailserver_login' => 'login@example.com',
 214      'mailserver_pass' => 'password',
 215      'mailserver_port' => 110,
 216      'default_category' => 1,
 217      'default_comment_status' => 'open',
 218      'default_ping_status' => 'open',
 219      'default_pingback_flag' => 1,
 220      'default_post_edit_rows' => 10,
 221      'posts_per_page' => 10,
 222      /* translators: default date format, see http://php.net/date */
 223      'date_format' => __('F j, Y'),
 224      /* translators: default time format, see http://php.net/date */
 225      'time_format' => __('g:i a'),
 226      /* translators: links last updated date format, see http://php.net/date */
 227      'links_updated_date_format' => __('F j, Y g:i a'),
 228      'links_recently_updated_prepend' => '<em>',
 229      'links_recently_updated_append' => '</em>',
 230      'links_recently_updated_time' => 120,
 231      'comment_moderation' => 0,
 232      'moderation_notify' => 1,
 233      'permalink_structure' => '',
 234      'gzipcompression' => 0,
 235      'hack_file' => 0,
 236      'blog_charset' => 'UTF-8',
 237      'moderation_keys' => '',
 238      'active_plugins' => array(),
 239      'home' => $guessurl,
 240      'category_base' => '',
 241      'ping_sites' => 'http://rpc.pingomatic.com/',
 242      'advanced_edit' => 0,
 243      'comment_max_links' => 2,
 244      'gmt_offset' => date('Z') / 3600,
 245  
 246      // 1.5
 247      'default_email_category' => 1,
 248      'recently_edited' => '',
 249      'template' => WP_DEFAULT_THEME,
 250      'stylesheet' => WP_DEFAULT_THEME,
 251      'comment_whitelist' => 1,
 252      'blacklist_keys' => '',
 253      'comment_registration' => 0,
 254      'rss_language' => 'en',
 255      'html_type' => 'text/html',
 256  
 257      // 1.5.1
 258      'use_trackback' => 0,
 259  
 260      // 2.0
 261      'default_role' => 'subscriber',
 262      'db_version' => $wp_db_version,
 263  
 264      // 2.0.1
 265      'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders,
 266      'upload_path' => '',
 267  
 268      // 2.1
 269      'blog_public' => '1',
 270      'default_link_category' => 2,
 271      'show_on_front' => 'posts',
 272  
 273      // 2.2
 274      'tag_base' => '',
 275  
 276      // 2.5
 277      'show_avatars' => '1',
 278      'avatar_rating' => 'G',
 279      'upload_url_path' => '',
 280      'thumbnail_size_w' => 150,
 281      'thumbnail_size_h' => 150,
 282      'thumbnail_crop' => 1,
 283      'medium_size_w' => 300,
 284      'medium_size_h' => 300,
 285  
 286      // 2.6
 287      'avatar_default' => 'mystery',
 288      'enable_app' => 0,
 289      'enable_xmlrpc' => 0,
 290  
 291      // 2.7
 292      'large_size_w' => 1024,
 293      'large_size_h' => 1024,
 294      'image_default_link_type' => 'file',
 295      'image_default_size' => '',
 296      'image_default_align' => '',
 297      'close_comments_for_old_posts' => 0,
 298      'close_comments_days_old' => 14,
 299      'thread_comments' => 1,
 300      'thread_comments_depth' => 5,
 301      'page_comments' => 0,
 302      'comments_per_page' => 50,
 303      'default_comments_page' => 'newest',
 304      'comment_order' => 'asc',
 305      'sticky_posts' => array(),
 306      'widget_categories' => array(),
 307      'widget_text' => array(),
 308      'widget_rss' => array(),
 309  
 310      // 2.8
 311      'timezone_string' => '',
 312  
 313      // 2.9
 314      'embed_autourls' => 1,
 315      'embed_size_w' => '',
 316      'embed_size_h' => 600,
 317  
 318      // 3.0
 319      'page_for_posts' => 0,
 320      'page_on_front' => 0,
 321      );
 322  
 323      // 3.0 multisite
 324      if ( is_multisite() ) {
 325          /* translators: blog tagline */
 326          $options[ 'blogdescription' ] = sprintf(__('Just another %s site'), $current_site->site_name );
 327          $options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/';
 328      }
 329  
 330      // Set autoload to no for these options
 331      $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
 332  
 333      $existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options");
 334  
 335      $insert = '';
 336      foreach ( $options as $option => $value ) {
 337          if ( in_array($option, $existing_options) )
 338              continue;
 339          if ( in_array($option, $fat_options) )
 340              $autoload = 'no';
 341          else
 342              $autoload = 'yes';
 343  
 344          $option = $wpdb->escape($option);
 345          if ( is_array($value) )
 346              $value = serialize($value);
 347          $value = $wpdb->escape($value);
 348          if ( !empty($insert) )
 349              $insert .= ', ';
 350          $insert .= "('$option', '$value', '$autoload')";
 351      }
 352  
 353      if ( !empty($insert) )
 354          $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert);
 355  
 356      // in case it is set, but blank, update "home"
 357      if ( !__get_option('home') ) update_option('home', $guessurl);
 358  
 359      // Delete unused options
 360      $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins', 'can_compress_scripts',
 361          'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron', 'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page' );
 362      foreach ($unusedoptions as $option)
 363          delete_option($option);
 364  
 365      // delete obsolete magpie stuff
 366      $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'");
 367  }
 368  
 369  /**
 370   * Execute WordPress role creation for the various WordPress versions.
 371   *
 372   * @since 2.0.0
 373   */
 374  function populate_roles() {
 375      populate_roles_160();
 376      populate_roles_210();
 377      populate_roles_230();
 378      populate_roles_250();
 379      populate_roles_260();
 380      populate_roles_270();
 381      populate_roles_280();
 382      populate_roles_300();
 383  }
 384  
 385  /**
 386   * Create the roles for WordPress 2.0
 387   *
 388   * @since 2.0.0
 389   */
 390  function populate_roles_160() {
 391      // Add roles
 392  
 393      // Dummy gettext calls to get strings in the catalog.
 394      /* translators: user role */
 395      _x('Administrator', 'User role');
 396      /* translators: user role */
 397      _x('Editor', 'User role');
 398      /* translators: user role */
 399      _x('Author', 'User role');
 400      /* translators: user role */
 401      _x('Contributor', 'User role');
 402      /* translators: user role */
 403      _x('Subscriber', 'User role');
 404  
 405      add_role('administrator', 'Administrator');
 406      add_role('editor', 'Editor');
 407      add_role('author', 'Author');
 408      add_role('contributor', 'Contributor');
 409      add_role('subscriber', 'Subscriber');
 410  
 411      // Add caps for Administrator role
 412      $role =& get_role('administrator');
 413      $role->add_cap('switch_themes');
 414      $role->add_cap('edit_themes');
 415      $role->add_cap('activate_plugins');
 416      $role->add_cap('edit_plugins');
 417      $role->add_cap('edit_users');
 418      $role->add_cap('edit_files');
 419      $role->add_cap('manage_options');
 420      $role->add_cap('moderate_comments');
 421      $role->add_cap('manage_categories');
 422      $role->add_cap('manage_links');
 423      $role->add_cap('upload_files');
 424      $role->add_cap('import');
 425      $role->add_cap('unfiltered_html');
 426      $role->add_cap('edit_posts');
 427      $role->add_cap('edit_others_posts');
 428      $role->add_cap('edit_published_posts');
 429      $role->add_cap('publish_posts');
 430      $role->add_cap('edit_pages');
 431      $role->add_cap('read');
 432      $role->add_cap('level_10');
 433      $role->add_cap('level_9');
 434      $role->add_cap('level_8');
 435      $role->add_cap('level_7');
 436      $role->add_cap('level_6');
 437      $role->add_cap('level_5');
 438      $role->add_cap('level_4');
 439      $role->add_cap('level_3');
 440      $role->add_cap('level_2');
 441      $role->add_cap('level_1');
 442      $role->add_cap('level_0');
 443  
 444      // Add caps for Editor role
 445      $role =& get_role('editor');
 446      $role->add_cap('moderate_comments');
 447      $role->add_cap('manage_categories');
 448      $role->add_cap('manage_links');
 449      $role->add_cap('upload_files');
 450      $role->add_cap('unfiltered_html');
 451      $role->add_cap('edit_posts');
 452      $role->add_cap('edit_others_posts');
 453      $role->add_cap('edit_published_posts');
 454      $role->add_cap('publish_posts');
 455      $role->add_cap('edit_pages');
 456      $role->add_cap('read');
 457      $role->add_cap('level_7');
 458      $role->add_cap('level_6');
 459      $role->add_cap('level_5');
 460      $role->add_cap('level_4');
 461      $role->add_cap('level_3');
 462      $role->add_cap('level_2');
 463      $role->add_cap('level_1');
 464      $role->add_cap('level_0');
 465  
 466      // Add caps for Author role
 467      $role =& get_role('author');
 468      $role->add_cap('upload_files');
 469      $role->add_cap('edit_posts');
 470      $role->add_cap('edit_published_posts');
 471      $role->add_cap('publish_posts');
 472      $role->add_cap('read');
 473      $role->add_cap('level_2');
 474      $role->add_cap('level_1');
 475      $role->add_cap('level_0');
 476  
 477      // Add caps for Contributor role
 478      $role =& get_role('contributor');
 479      $role->add_cap('edit_posts');
 480      $role->add_cap('read');
 481      $role->add_cap('level_1');
 482      $role->add_cap('level_0');
 483  
 484      // Add caps for Subscriber role
 485      $role =& get_role('subscriber');
 486      $role->add_cap('read');
 487      $role->add_cap('level_0');
 488  }
 489  
 490  /**
 491   * Create and modify WordPress roles for WordPress 2.1.
 492   *
 493   * @since 2.1.0
 494   */
 495  function populate_roles_210() {
 496      $roles = array('administrator', 'editor');
 497      foreach ($roles as $role) {
 498          $role =& get_role($role);
 499          if ( empty($role) )
 500              continue;
 501  
 502          $role->add_cap('edit_others_pages');
 503          $role->add_cap('edit_published_pages');
 504          $role->add_cap('publish_pages');
 505          $role->add_cap('delete_pages');
 506          $role->add_cap('delete_others_pages');
 507          $role->add_cap('delete_published_pages');
 508          $role->add_cap('delete_posts');
 509          $role->add_cap('delete_others_posts');
 510          $role->add_cap('delete_published_posts');
 511          $role->add_cap('delete_private_posts');
 512          $role->add_cap('edit_private_posts');
 513          $role->add_cap('read_private_posts');
 514          $role->add_cap('delete_private_pages');
 515          $role->add_cap('edit_private_pages');
 516          $role->add_cap('read_private_pages');
 517      }
 518  
 519      $role =& get_role('administrator');
 520      if ( ! empty($role) ) {
 521          $role->add_cap('delete_users');
 522          $role->add_cap('create_users');
 523      }
 524  
 525      $role =& get_role('author');
 526      if ( ! empty($role) ) {
 527          $role->add_cap('delete_posts');
 528          $role->add_cap('delete_published_posts');
 529      }
 530  
 531      $role =& get_role('contributor');
 532      if ( ! empty($role) ) {
 533          $role->add_cap('delete_posts');
 534      }
 535  }
 536  
 537  /**
 538   * Create and modify WordPress roles for WordPress 2.3.
 539   *
 540   * @since 2.3.0
 541   */
 542  function populate_roles_230() {
 543      $role =& get_role( 'administrator' );
 544  
 545      if ( !empty( $role ) ) {
 546          $role->add_cap( 'unfiltered_upload' );
 547      }
 548  }
 549  
 550  /**
 551   * Create and modify WordPress roles for WordPress 2.5.
 552   *
 553   * @since 2.5.0
 554   */
 555  function populate_roles_250() {
 556      $role =& get_role( 'administrator' );
 557  
 558      if ( !empty( $role ) ) {
 559          $role->add_cap( 'edit_dashboard' );
 560      }
 561  }
 562  
 563  /**
 564   * Create and modify WordPress roles for WordPress 2.6.
 565   *
 566   * @since 2.6.0
 567   */
 568  function populate_roles_260() {
 569      $role =& get_role( 'administrator' );
 570  
 571      if ( !empty( $role ) ) {
 572          $role->add_cap( 'update_plugins' );
 573          $role->add_cap( 'delete_plugins' );
 574      }
 575  }
 576  
 577  /**
 578   * Create and modify WordPress roles for WordPress 2.7.
 579   *
 580   * @since 2.7.0
 581   */
 582  function populate_roles_270() {
 583      $role =& get_role( 'administrator' );
 584  
 585      if ( !empty( $role ) ) {
 586          $role->add_cap( 'install_plugins' );
 587          $role->add_cap( 'update_themes' );
 588      }
 589  }
 590  
 591  /**
 592   * Create and modify WordPress roles for WordPress 2.8.
 593   *
 594   * @since 2.8.0
 595   */
 596  function populate_roles_280() {
 597      $role =& get_role( 'administrator' );
 598  
 599      if ( !empty( $role ) ) {
 600          $role->add_cap( 'install_themes' );
 601      }
 602  }
 603  
 604  /**
 605   * Create and modify WordPress roles for WordPress 3.0.
 606   *
 607   * @since 3.0.0
 608   */
 609  function populate_roles_300() {
 610      $role =& get_role( 'administrator' );
 611  
 612      if ( !empty( $role ) ) {
 613          $role->add_cap( 'update_core' );
 614          $role->add_cap( 'list_users' );
 615          $role->add_cap( 'remove_users' );
 616          $role->add_cap( 'add_users' );
 617          $role->add_cap( 'promote_users' );
 618          $role->add_cap( 'edit_theme_options' );
 619          $role->add_cap( 'delete_themes' );
 620          $role->add_cap( 'export' );
 621      }
 622  }
 623  
 624  /**
 625   * populate network settings
 626   *
 627   * @since 3.0.0
 628   *
 629   * @param int $network_id id of network to populate
 630   * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful,
 631   *     so the error code must be checked) or failure.
 632   */
 633  function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
 634      global $wpdb, $current_site, $wp_db_version, $wp_rewrite;
 635  
 636      $errors = new WP_Error();
 637      if ( '' == $domain )
 638          $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
 639      if ( '' == $site_name )
 640          $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) );
 641  
 642      // check for network collision
 643      if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) )
 644          $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
 645  
 646      $site_user = get_user_by_email( $email );
 647      if ( ! is_email( $email ) )
 648          $errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) );
 649  
 650      if ( $errors->get_error_code() )
 651          return $errors;
 652  
 653      // set up site tables
 654      $template = get_option( 'template' );
 655      $stylesheet = get_option( 'stylesheet' );
 656      $allowed_themes = array( $stylesheet => true );
 657      if ( $template != $stylesheet )
 658          $allowed_themes[ $template ] = true;
 659      if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template )
 660          $allowed_themes[ WP_DEFAULT_THEME ] = true;
 661  
 662      if ( 1 == $network_id ) {
 663          $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) );
 664          $network_id = $wpdb->insert_id;
 665      } else {
 666          $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) );
 667      }
 668  
 669      if ( !is_multisite() ) {
 670          $site_admins = array( $site_user->user_login );
 671          $users = get_users_of_blog();
 672          if ( $users ) {
 673              foreach ( $users as $user ) {
 674                  if ( is_super_admin( $user->ID ) && !in_array( $user->user_login, $site_admins ) )
 675                      $site_admins[] = $user->user_login;
 676              }
 677          }
 678      } else {
 679          $site_admins = get_site_option( 'site_admins' );
 680      }
 681  
 682      $welcome_email = __( 'Dear User,
 683  
 684  Your new SITE_NAME site has been successfully set up at:
 685  BLOG_URL
 686  
 687  You can log in to the administrator account with the following information:
 688  Username: USERNAME
 689  Password: PASSWORD
 690  Login Here: BLOG_URLwp-login.php
 691  
 692  We hope you enjoy your new site.
 693  Thanks!
 694  
 695  --The Team @ SITE_NAME' );
 696  
 697      $sitemeta = array(
 698          'site_name' => $site_name,
 699          'admin_email' => $site_user->user_email,
 700          'admin_user_id' => $site_user->ID,
 701          'registration' => 'none',
 702          'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf',
 703          'blog_upload_space' => 10,
 704          'fileupload_maxk' => 1500,
 705          'site_admins' => $site_admins,
 706          'allowedthemes' => $allowed_themes,
 707          'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ),
 708          'wpmu_upgrade_site' => $wp_db_version,
 709          'welcome_email' => $welcome_email,
 710          'first_post' => __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ),
 711          // @todo - network admins should have a method of editing the network siteurl (used for cookie hash)
 712          'siteurl' => get_option( 'siteurl' ) . '/',
 713          'add_new_users' => '0',
 714          'upload_space_check_disabled' => '0',
 715          'subdomain_install' => intval( $subdomain_install ),
 716          'global_terms_enabled' => global_terms_enabled() ? '1' : '0'
 717      );
 718      if ( !intval( $subdomain_install ) )
 719          $sitemeta['illegal_names'][] = 'blog';
 720  
 721      $insert = '';
 722      foreach ( $sitemeta as $meta_key => $meta_value ) {
 723          $meta_key = $wpdb->escape( $meta_key );
 724          if ( is_array( $meta_value ) )
 725              $meta_value = serialize( $meta_value );
 726          $meta_value = $wpdb->escape( $meta_value );
 727          if ( !empty( $insert ) )
 728              $insert .= ', ';
 729          $insert .= "( $network_id, '$meta_key', '$meta_value')";
 730      }
 731      $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert );
 732  
 733      $current_site->domain = $domain;
 734      $current_site->path = $path;
 735      $current_site->site_name = ucfirst( $domain );
 736  
 737      if ( !is_multisite() ) {
 738          $wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time( 'mysql' ) ) );
 739          $blog_id = $wpdb->insert_id;
 740          update_user_meta( $site_user->ID, 'source_domain', $domain );
 741          update_user_meta( $site_user->ID, 'primary_blog', $blog_id );
 742          if ( !$upload_path = get_option( 'upload_path' ) ) {
 743              $upload_path = substr( WP_CONTENT_DIR, strlen( ABSPATH ) ) . '/uploads';
 744              update_option( 'upload_path', $upload_path );
 745          }
 746          update_option( 'fileupload_url', get_option( 'siteurl' ) . '/' . $upload_path );
 747      }
 748  
 749      if ( $subdomain_install )
 750          update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
 751      else
 752          update_option( 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/');
 753  
 754      $wp_rewrite->flush_rules();
 755  
 756      if ( $subdomain_install ) {
 757          $vhost_ok = false;
 758          $errstr = '';
 759          $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
 760          $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) );
 761          if ( is_wp_error( $page ) )
 762              $errstr = $page->get_error_message();
 763          elseif ( 200 == $page['response']['code'] )
 764                  $vhost_ok = true;
 765  
 766          if ( ! $vhost_ok ) {
 767              $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
 768              $msg .= '<p>' . sprintf( __( 'The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.' ), $hostname );
 769              if ( ! empty ( $errstr ) )
 770                  $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
 771              $msg .= '</p>';
 772              $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>';
 773              $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>';
 774              return new WP_Error( 'no_wildcard_dns', $msg );
 775          }
 776      }
 777  
 778      return true;
 779  }
 780  
 781  ?>


Generated: Thu Oct 14 05:12:05 2010 Cross-referenced by PHPXref 0.7