| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
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 // Declare these as global in case schema.php is included from a function. 12 global $wpdb, $wp_queries, $charset_collate; 13 14 /** 15 * The database character collate. 16 * @var string 17 * @global string 18 * @name $charset_collate 19 */ 20 $charset_collate = ''; 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 /** 28 * Retrieve the SQL for creating database tables. 29 * 30 * @since 3.3.0 31 * 32 * @param string $scope Optional. The tables for which to retrieve SQL. Can be all, global, ms_global, or blog tables. Defaults to all. 33 * @param int $blog_id Optional. The blog ID for which to retrieve SQL. Default is the current blog ID. 34 * @return string The SQL needed to create the requested tables. 35 */ 36 function wp_get_db_schema( $scope = 'all', $blog_id = null ) { 37 global $wpdb; 38 39 $charset_collate = ''; 40 41 if ( ! empty($wpdb->charset) ) 42 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 43 if ( ! empty($wpdb->collate) ) 44 $charset_collate .= " COLLATE $wpdb->collate"; 45 46 if ( $blog_id && $blog_id != $wpdb->blogid ) 47 $old_blog_id = $wpdb->set_blog_id( $blog_id ); 48 49 // Engage multisite if in the middle of turning it on from network.php. 50 $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ); 51 52 // Blog specific tables. 53 $blog_tables = "CREATE TABLE $wpdb->terms ( 54 term_id bigint(20) unsigned NOT NULL auto_increment, 55 name varchar(200) NOT NULL default '', 56 slug varchar(200) NOT NULL default '', 57 term_group bigint(10) NOT NULL default 0, 58 PRIMARY KEY (term_id), 59 UNIQUE KEY slug (slug), 60 KEY name (name) 61 ) $charset_collate; 62 CREATE TABLE $wpdb->term_taxonomy ( 63 term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, 64 term_id bigint(20) unsigned NOT NULL default 0, 65 taxonomy varchar(32) NOT NULL default '', 66 description longtext NOT NULL, 67 parent bigint(20) unsigned NOT NULL default 0, 68 count bigint(20) NOT NULL default 0, 69 PRIMARY KEY (term_taxonomy_id), 70 UNIQUE KEY term_id_taxonomy (term_id,taxonomy), 71 KEY taxonomy (taxonomy) 72 ) $charset_collate; 73 CREATE TABLE $wpdb->term_relationships ( 74 object_id bigint(20) unsigned NOT NULL default 0, 75 term_taxonomy_id bigint(20) unsigned NOT NULL default 0, 76 term_order int(11) NOT NULL default 0, 77 PRIMARY KEY (object_id,term_taxonomy_id), 78 KEY term_taxonomy_id (term_taxonomy_id) 79 ) $charset_collate; 80 CREATE TABLE $wpdb->commentmeta ( 81 meta_id bigint(20) unsigned NOT NULL auto_increment, 82 comment_id bigint(20) unsigned NOT NULL default '0', 83 meta_key varchar(255) default NULL, 84 meta_value longtext, 85 PRIMARY KEY (meta_id), 86 KEY comment_id (comment_id), 87 KEY meta_key (meta_key) 88 ) $charset_collate; 89 CREATE TABLE $wpdb->comments ( 90 comment_ID bigint(20) unsigned NOT NULL auto_increment, 91 comment_post_ID bigint(20) unsigned NOT NULL default '0', 92 comment_author tinytext NOT NULL, 93 comment_author_email varchar(100) NOT NULL default '', 94 comment_author_url varchar(200) NOT NULL default '', 95 comment_author_IP varchar(100) NOT NULL default '', 96 comment_date datetime NOT NULL default '0000-00-00 00:00:00', 97 comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', 98 comment_content text NOT NULL, 99 comment_karma int(11) NOT NULL default '0', 100 comment_approved varchar(20) NOT NULL default '1', 101 comment_agent varchar(255) NOT NULL default '', 102 comment_type varchar(20) NOT NULL default '', 103 comment_parent bigint(20) unsigned NOT NULL default '0', 104 user_id bigint(20) unsigned NOT NULL default '0', 105 PRIMARY KEY (comment_ID), 106 KEY comment_post_ID (comment_post_ID), 107 KEY comment_approved_date_gmt (comment_approved,comment_date_gmt), 108 KEY comment_date_gmt (comment_date_gmt), 109 KEY comment_parent (comment_parent) 110 ) $charset_collate; 111 CREATE TABLE $wpdb->links ( 112 link_id bigint(20) unsigned NOT NULL auto_increment, 113 link_url varchar(255) NOT NULL default '', 114 link_name varchar(255) NOT NULL default '', 115 link_image varchar(255) NOT NULL default '', 116 link_target varchar(25) NOT NULL default '', 117 link_description varchar(255) NOT NULL default '', 118 link_visible varchar(20) NOT NULL default 'Y', 119 link_owner bigint(20) unsigned NOT NULL default '1', 120 link_rating int(11) NOT NULL default '0', 121 link_updated datetime NOT NULL default '0000-00-00 00:00:00', 122 link_rel varchar(255) NOT NULL default '', 123 link_notes mediumtext NOT NULL, 124 link_rss varchar(255) NOT NULL default '', 125 PRIMARY KEY (link_id), 126 KEY link_visible (link_visible) 127 ) $charset_collate; 128 CREATE TABLE $wpdb->options ( 129 option_id bigint(20) unsigned NOT NULL auto_increment, 130 option_name varchar(64) NOT NULL default '', 131 option_value longtext NOT NULL, 132 autoload varchar(20) NOT NULL default 'yes', 133 PRIMARY KEY (option_id), 134 UNIQUE KEY option_name (option_name) 135 ) $charset_collate; 136 CREATE TABLE $wpdb->postmeta ( 137 meta_id bigint(20) unsigned NOT NULL auto_increment, 138 post_id bigint(20) unsigned NOT NULL default '0', 139 meta_key varchar(255) default NULL, 140 meta_value longtext, 141 PRIMARY KEY (meta_id), 142 KEY post_id (post_id), 143 KEY meta_key (meta_key) 144 ) $charset_collate; 145 CREATE TABLE $wpdb->posts ( 146 ID bigint(20) unsigned NOT NULL auto_increment, 147 post_author bigint(20) unsigned NOT NULL default '0', 148 post_date datetime NOT NULL default '0000-00-00 00:00:00', 149 post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', 150 post_content longtext NOT NULL, 151 post_title text NOT NULL, 152 post_excerpt text NOT NULL, 153 post_status varchar(20) NOT NULL default 'publish', 154 comment_status varchar(20) NOT NULL default 'open', 155 ping_status varchar(20) NOT NULL default 'open', 156 post_password varchar(20) NOT NULL default '', 157 post_name varchar(200) NOT NULL default '', 158 to_ping text NOT NULL, 159 pinged text NOT NULL, 160 post_modified datetime NOT NULL default '0000-00-00 00:00:00', 161 post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00', 162 post_content_filtered longtext NOT NULL, 163 post_parent bigint(20) unsigned NOT NULL default '0', 164 guid varchar(255) NOT NULL default '', 165 menu_order int(11) NOT NULL default '0', 166 post_type varchar(20) NOT NULL default 'post', 167 post_mime_type varchar(100) NOT NULL default '', 168 comment_count bigint(20) NOT NULL default '0', 169 PRIMARY KEY (ID), 170 KEY post_name (post_name), 171 KEY type_status_date (post_type,post_status,post_date,ID), 172 KEY post_parent (post_parent), 173 KEY post_author (post_author) 174 ) $charset_collate;\n"; 175 176 // Single site users table. The multisite flavor of the users table is handled below. 177 $users_single_table = "CREATE TABLE $wpdb->users ( 178 ID bigint(20) unsigned NOT NULL auto_increment, 179 user_login varchar(60) NOT NULL default '', 180 user_pass varchar(64) NOT NULL default '', 181 user_nicename varchar(50) NOT NULL default '', 182 user_email varchar(100) NOT NULL default '', 183 user_url varchar(100) NOT NULL default '', 184 user_registered datetime NOT NULL default '0000-00-00 00:00:00', 185 user_activation_key varchar(60) NOT NULL default '', 186 user_status int(11) NOT NULL default '0', 187 display_name varchar(250) NOT NULL default '', 188 PRIMARY KEY (ID), 189 KEY user_login_key (user_login), 190 KEY user_nicename (user_nicename) 191 ) $charset_collate;\n"; 192 193 // Multisite users table 194 $users_multi_table = "CREATE TABLE $wpdb->users ( 195 ID bigint(20) unsigned NOT NULL auto_increment, 196 user_login varchar(60) NOT NULL default '', 197 user_pass varchar(64) NOT NULL default '', 198 user_nicename varchar(50) NOT NULL default '', 199 user_email varchar(100) NOT NULL default '', 200 user_url varchar(100) NOT NULL default '', 201 user_registered datetime NOT NULL default '0000-00-00 00:00:00', 202 user_activation_key varchar(60) NOT NULL default '', 203 user_status int(11) NOT NULL default '0', 204 display_name varchar(250) NOT NULL default '', 205 spam tinyint(2) NOT NULL default '0', 206 deleted tinyint(2) NOT NULL default '0', 207 PRIMARY KEY (ID), 208 KEY user_login_key (user_login), 209 KEY user_nicename (user_nicename) 210 ) $charset_collate;\n"; 211 212 // usermeta 213 $usermeta_table = "CREATE TABLE $wpdb->usermeta ( 214 umeta_id bigint(20) unsigned NOT NULL auto_increment, 215 user_id bigint(20) unsigned NOT NULL default '0', 216 meta_key varchar(255) default NULL, 217 meta_value longtext, 218 PRIMARY KEY (umeta_id), 219 KEY user_id (user_id), 220 KEY meta_key (meta_key) 221 ) $charset_collate;\n"; 222 223 // Global tables 224 if ( $is_multisite ) 225 $global_tables = $users_multi_table . $usermeta_table; 226 else 227 $global_tables = $users_single_table . $usermeta_table; 228 229 // Multisite global tables. 230 $ms_global_tables = "CREATE TABLE $wpdb->blogs ( 231 blog_id bigint(20) NOT NULL auto_increment, 232 site_id bigint(20) NOT NULL default '0', 233 domain varchar(200) NOT NULL default '', 234 path varchar(100) NOT NULL default '', 235 registered datetime NOT NULL default '0000-00-00 00:00:00', 236 last_updated datetime NOT NULL default '0000-00-00 00:00:00', 237 public tinyint(2) NOT NULL default '1', 238 archived enum('0','1') NOT NULL default '0', 239 mature tinyint(2) NOT NULL default '0', 240 spam tinyint(2) NOT NULL default '0', 241 deleted tinyint(2) NOT NULL default '0', 242 lang_id int(11) NOT NULL default '0', 243 PRIMARY KEY (blog_id), 244 KEY domain (domain(50),path(5)), 245 KEY lang_id (lang_id) 246 ) $charset_collate; 247 CREATE TABLE $wpdb->blog_versions ( 248 blog_id bigint(20) NOT NULL default '0', 249 db_version varchar(20) NOT NULL default '', 250 last_updated datetime NOT NULL default '0000-00-00 00:00:00', 251 PRIMARY KEY (blog_id), 252 KEY db_version (db_version) 253 ) $charset_collate; 254 CREATE TABLE $wpdb->registration_log ( 255 ID bigint(20) NOT NULL auto_increment, 256 email varchar(255) NOT NULL default '', 257 IP varchar(30) NOT NULL default '', 258 blog_id bigint(20) NOT NULL default '0', 259 date_registered datetime NOT NULL default '0000-00-00 00:00:00', 260 PRIMARY KEY (ID), 261 KEY IP (IP) 262 ) $charset_collate; 263 CREATE TABLE $wpdb->site ( 264 id bigint(20) NOT NULL auto_increment, 265 domain varchar(200) NOT NULL default '', 266 path varchar(100) NOT NULL default '', 267 PRIMARY KEY (id), 268 KEY domain (domain,path) 269 ) $charset_collate; 270 CREATE TABLE $wpdb->sitemeta ( 271 meta_id bigint(20) NOT NULL auto_increment, 272 site_id bigint(20) NOT NULL default '0', 273 meta_key varchar(255) default NULL, 274 meta_value longtext, 275 PRIMARY KEY (meta_id), 276 KEY meta_key (meta_key), 277 KEY site_id (site_id) 278 ) $charset_collate; 279 CREATE TABLE $wpdb->signups ( 280 domain varchar(200) NOT NULL default '', 281 path varchar(100) NOT NULL default '', 282 title longtext NOT NULL, 283 user_login varchar(60) NOT NULL default '', 284 user_email varchar(100) NOT NULL default '', 285 registered datetime NOT NULL default '0000-00-00 00:00:00', 286 activated datetime NOT NULL default '0000-00-00 00:00:00', 287 active tinyint(1) NOT NULL default '0', 288 activation_key varchar(50) NOT NULL default '', 289 meta longtext, 290 KEY activation_key (activation_key), 291 KEY domain (domain) 292 ) $charset_collate;"; 293 294 switch ( $scope ) { 295 case 'blog' : 296 $queries = $blog_tables; 297 break; 298 case 'global' : 299 $queries = $global_tables; 300 if ( $is_multisite ) 301 $queries .= $ms_global_tables; 302 break; 303 case 'ms_global' : 304 $queries = $ms_global_tables; 305 break; 306 default: 307 case 'all' : 308 $queries = $global_tables . $blog_tables; 309 if ( $is_multisite ) 310 $queries .= $ms_global_tables; 311 break; 312 } 313 314 if ( isset( $old_blog_id ) ) 315 $wpdb->set_blog_id( $old_blog_id ); 316 317 return $queries; 318 } 319 320 // Populate for back compat. 321 $wp_queries = wp_get_db_schema( 'all' ); 322 323 /** 324 * Create WordPress options and set the default values. 325 * 326 * @since 1.5.0 327 * @uses $wpdb 328 * @uses $wp_db_version 329 */ 330 function populate_options() { 331 global $wpdb, $wp_db_version, $current_site, $wp_current_db_version; 332 333 $guessurl = wp_guess_url(); 334 335 do_action('populate_options'); 336 337 if ( ini_get('safe_mode') ) { 338 // Safe mode can break mkdir() so use a flat structure by default. 339 $uploads_use_yearmonth_folders = 0; 340 } else { 341 $uploads_use_yearmonth_folders = 1; 342 } 343 344 $template = WP_DEFAULT_THEME; 345 // If default theme is a child theme, we need to get its template 346 $theme = wp_get_theme( $template ); 347 if ( ! $theme->errors() ) 348 $template = $theme->get_template(); 349 350 $timezone_string = ''; 351 $gmt_offset = 0; 352 /* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14) 353 or a valid timezone string (America/New_York). See http://us3.php.net/manual/en/timezones.php 354 for all timezone strings supported by PHP. 355 */ 356 $offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); 357 if ( is_numeric( $offset_or_tz ) ) 358 $gmt_offset = $offset_or_tz; 359 elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) 360 $timezone_string = $offset_or_tz; 361 362 $options = array( 363 'siteurl' => $guessurl, 364 'blogname' => __('My Site'), 365 /* translators: blog tagline */ 366 'blogdescription' => __('Just another WordPress site'), 367 'users_can_register' => 0, 368 'admin_email' => 'you@example.com', 369 /* translators: default start of the week. 0 = Sunday, 1 = Monday */ 370 'start_of_week' => _x( '1', 'start of week' ), 371 'use_balanceTags' => 0, 372 'use_smilies' => 1, 373 'require_name_email' => 1, 374 'comments_notify' => 1, 375 'posts_per_rss' => 10, 376 'rss_use_excerpt' => 0, 377 'mailserver_url' => 'mail.example.com', 378 'mailserver_login' => 'login@example.com', 379 'mailserver_pass' => 'password', 380 'mailserver_port' => 110, 381 'default_category' => 1, 382 'default_comment_status' => 'open', 383 'default_ping_status' => 'open', 384 'default_pingback_flag' => 1, 385 'default_post_edit_rows' => 20, 386 'posts_per_page' => 10, 387 /* translators: default date format, see http://php.net/date */ 388 'date_format' => __('F j, Y'), 389 /* translators: default time format, see http://php.net/date */ 390 'time_format' => __('g:i a'), 391 /* translators: links last updated date format, see http://php.net/date */ 392 'links_updated_date_format' => __('F j, Y g:i a'), 393 'links_recently_updated_prepend' => '<em>', 394 'links_recently_updated_append' => '</em>', 395 'links_recently_updated_time' => 120, 396 'comment_moderation' => 0, 397 'moderation_notify' => 1, 398 'permalink_structure' => '', 399 'gzipcompression' => 0, 400 'hack_file' => 0, 401 'blog_charset' => 'UTF-8', 402 'moderation_keys' => '', 403 'active_plugins' => array(), 404 'home' => $guessurl, 405 'category_base' => '', 406 'ping_sites' => 'http://rpc.pingomatic.com/', 407 'advanced_edit' => 0, 408 'comment_max_links' => 2, 409 'gmt_offset' => $gmt_offset, 410 411 // 1.5 412 'default_email_category' => 1, 413 'recently_edited' => '', 414 'template' => $template, 415 'stylesheet' => WP_DEFAULT_THEME, 416 'comment_whitelist' => 1, 417 'blacklist_keys' => '', 418 'comment_registration' => 0, 419 'html_type' => 'text/html', 420 421 // 1.5.1 422 'use_trackback' => 0, 423 424 // 2.0 425 'default_role' => 'subscriber', 426 'db_version' => $wp_db_version, 427 428 // 2.0.1 429 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders, 430 'upload_path' => '', 431 432 // 2.1 433 'blog_public' => '1', 434 'default_link_category' => 2, 435 'show_on_front' => 'posts', 436 437 // 2.2 438 'tag_base' => '', 439 440 // 2.5 441 'show_avatars' => '1', 442 'avatar_rating' => 'G', 443 'upload_url_path' => '', 444 'thumbnail_size_w' => 150, 445 'thumbnail_size_h' => 150, 446 'thumbnail_crop' => 1, 447 'medium_size_w' => 300, 448 'medium_size_h' => 300, 449 450 // 2.6 451 'avatar_default' => 'mystery', 452 'enable_app' => 0, 453 'enable_xmlrpc' => 0, 454 455 // 2.7 456 'large_size_w' => 1024, 457 'large_size_h' => 1024, 458 'image_default_link_type' => 'file', 459 'image_default_size' => '', 460 'image_default_align' => '', 461 'close_comments_for_old_posts' => 0, 462 'close_comments_days_old' => 14, 463 'thread_comments' => 1, 464 'thread_comments_depth' => 5, 465 'page_comments' => 0, 466 'comments_per_page' => 50, 467 'default_comments_page' => 'newest', 468 'comment_order' => 'asc', 469 'sticky_posts' => array(), 470 'widget_categories' => array(), 471 'widget_text' => array(), 472 'widget_rss' => array(), 473 'uninstall_plugins' => array(), 474 475 // 2.8 476 'timezone_string' => $timezone_string, 477 478 // 2.9 479 'embed_autourls' => 1, 480 'embed_size_w' => '', 481 'embed_size_h' => 600, 482 483 // 3.0 484 'page_for_posts' => 0, 485 'page_on_front' => 0, 486 487 // 3.1 488 'default_post_format' => 0, 489 ); 490 491 // 3.3 492 if ( ! is_multisite() ) { 493 $options['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version 494 ? $wp_current_db_version : $wp_db_version; 495 } 496 497 // 3.0 multisite 498 if ( is_multisite() ) { 499 /* translators: blog tagline */ 500 $options[ 'blogdescription' ] = sprintf(__('Just another %s site'), $current_site->site_name ); 501 $options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/'; 502 } 503 504 // Set autoload to no for these options 505 $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' ); 506 507 $existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options"); 508 509 $insert = ''; 510 foreach ( $options as $option => $value ) { 511 if ( in_array($option, $existing_options) ) 512 continue; 513 if ( in_array($option, $fat_options) ) 514 $autoload = 'no'; 515 else 516 $autoload = 'yes'; 517 518 $option = $wpdb->escape($option); 519 if ( is_array($value) ) 520 $value = serialize($value); 521 $value = $wpdb->escape($value); 522 if ( !empty($insert) ) 523 $insert .= ', '; 524 $insert .= "('$option', '$value', '$autoload')"; 525 } 526 527 if ( !empty($insert) ) 528 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert); 529 530 // in case it is set, but blank, update "home" 531 if ( !__get_option('home') ) update_option('home', $guessurl); 532 533 // Delete unused options 534 $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', 'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron', 'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page', 'wporg_popular_tags', 'what_to_show', 'rss_language'); 535 foreach ( $unusedoptions as $option ) 536 delete_option($option); 537 538 // delete obsolete magpie stuff 539 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'"); 540 } 541 542 /** 543 * Execute WordPress role creation for the various WordPress versions. 544 * 545 * @since 2.0.0 546 */ 547 function populate_roles() { 548 populate_roles_160(); 549 populate_roles_210(); 550 populate_roles_230(); 551 populate_roles_250(); 552 populate_roles_260(); 553 populate_roles_270(); 554 populate_roles_280(); 555 populate_roles_300(); 556 } 557 558 /** 559 * Create the roles for WordPress 2.0 560 * 561 * @since 2.0.0 562 */ 563 function populate_roles_160() { 564 // Add roles 565 566 // Dummy gettext calls to get strings in the catalog. 567 /* translators: user role */ 568 _x('Administrator', 'User role'); 569 /* translators: user role */ 570 _x('Editor', 'User role'); 571 /* translators: user role */ 572 _x('Author', 'User role'); 573 /* translators: user role */ 574 _x('Contributor', 'User role'); 575 /* translators: user role */ 576 _x('Subscriber', 'User role'); 577 578 add_role('administrator', 'Administrator'); 579 add_role('editor', 'Editor'); 580 add_role('author', 'Author'); 581 add_role('contributor', 'Contributor'); 582 add_role('subscriber', 'Subscriber'); 583 584 // Add caps for Administrator role 585 $role =& get_role('administrator'); 586 $role->add_cap('switch_themes'); 587 $role->add_cap('edit_themes'); 588 $role->add_cap('activate_plugins'); 589 $role->add_cap('edit_plugins'); 590 $role->add_cap('edit_users'); 591 $role->add_cap('edit_files'); 592 $role->add_cap('manage_options'); 593 $role->add_cap('moderate_comments'); 594 $role->add_cap('manage_categories'); 595 $role->add_cap('manage_links'); 596 $role->add_cap('upload_files'); 597 $role->add_cap('import'); 598 $role->add_cap('unfiltered_html'); 599 $role->add_cap('edit_posts'); 600 $role->add_cap('edit_others_posts'); 601 $role->add_cap('edit_published_posts'); 602 $role->add_cap('publish_posts'); 603 $role->add_cap('edit_pages'); 604 $role->add_cap('read'); 605 $role->add_cap('level_10'); 606 $role->add_cap('level_9'); 607 $role->add_cap('level_8'); 608 $role->add_cap('level_7'); 609 $role->add_cap('level_6'); 610 $role->add_cap('level_5'); 611 $role->add_cap('level_4'); 612 $role->add_cap('level_3'); 613 $role->add_cap('level_2'); 614 $role->add_cap('level_1'); 615 $role->add_cap('level_0'); 616 617 // Add caps for Editor role 618 $role =& get_role('editor'); 619 $role->add_cap('moderate_comments'); 620 $role->add_cap('manage_categories'); 621 $role->add_cap('manage_links'); 622 $role->add_cap('upload_files'); 623 $role->add_cap('unfiltered_html'); 624 $role->add_cap('edit_posts'); 625 $role->add_cap('edit_others_posts'); 626 $role->add_cap('edit_published_posts'); 627 $role->add_cap('publish_posts'); 628 $role->add_cap('edit_pages'); 629 $role->add_cap('read'); 630 $role->add_cap('level_7'); 631 $role->add_cap('level_6'); 632 $role->add_cap('level_5'); 633 $role->add_cap('level_4'); 634 $role->add_cap('level_3'); 635 $role->add_cap('level_2'); 636 $role->add_cap('level_1'); 637 $role->add_cap('level_0'); 638 639 // Add caps for Author role 640 $role =& get_role('author'); 641 $role->add_cap('upload_files'); 642 $role->add_cap('edit_posts'); 643 $role->add_cap('edit_published_posts'); 644 $role->add_cap('publish_posts'); 645 $role->add_cap('read'); 646 $role->add_cap('level_2'); 647 $role->add_cap('level_1'); 648 $role->add_cap('level_0'); 649 650 // Add caps for Contributor role 651 $role =& get_role('contributor'); 652 $role->add_cap('edit_posts'); 653 $role->add_cap('read'); 654 $role->add_cap('level_1'); 655 $role->add_cap('level_0'); 656 657 // Add caps for Subscriber role 658 $role =& get_role('subscriber'); 659 $role->add_cap('read'); 660 $role->add_cap('level_0'); 661 } 662 663 /** 664 * Create and modify WordPress roles for WordPress 2.1. 665 * 666 * @since 2.1.0 667 */ 668 function populate_roles_210() { 669 $roles = array('administrator', 'editor'); 670 foreach ($roles as $role) { 671 $role =& get_role($role); 672 if ( empty($role) ) 673 continue; 674 675 $role->add_cap('edit_others_pages'); 676 $role->add_cap('edit_published_pages'); 677 $role->add_cap('publish_pages'); 678 $role->add_cap('delete_pages'); 679 $role->add_cap('delete_others_pages'); 680 $role->add_cap('delete_published_pages'); 681 $role->add_cap('delete_posts'); 682 $role->add_cap('delete_others_posts'); 683 $role->add_cap('delete_published_posts'); 684 $role->add_cap('delete_private_posts'); 685 $role->add_cap('edit_private_posts'); 686 $role->add_cap('read_private_posts'); 687 $role->add_cap('delete_private_pages'); 688 $role->add_cap('edit_private_pages'); 689 $role->add_cap('read_private_pages'); 690 } 691 692 $role =& get_role('administrator'); 693 if ( ! empty($role) ) { 694 $role->add_cap('delete_users'); 695 $role->add_cap('create_users'); 696 } 697 698 $role =& get_role('author'); 699 if ( ! empty($role) ) { 700 $role->add_cap('delete_posts'); 701 $role->add_cap('delete_published_posts'); 702 } 703 704 $role =& get_role('contributor'); 705 if ( ! empty($role) ) { 706 $role->add_cap('delete_posts'); 707 } 708 } 709 710 /** 711 * Create and modify WordPress roles for WordPress 2.3. 712 * 713 * @since 2.3.0 714 */ 715 function populate_roles_230() { 716 $role =& get_role( 'administrator' ); 717 718 if ( !empty( $role ) ) { 719 $role->add_cap( 'unfiltered_upload' ); 720 } 721 } 722 723 /** 724 * Create and modify WordPress roles for WordPress 2.5. 725 * 726 * @since 2.5.0 727 */ 728 function populate_roles_250() { 729 $role =& get_role( 'administrator' ); 730 731 if ( !empty( $role ) ) { 732 $role->add_cap( 'edit_dashboard' ); 733 } 734 } 735 736 /** 737 * Create and modify WordPress roles for WordPress 2.6. 738 * 739 * @since 2.6.0 740 */ 741 function populate_roles_260() { 742 $role =& get_role( 'administrator' ); 743 744 if ( !empty( $role ) ) { 745 $role->add_cap( 'update_plugins' ); 746 $role->add_cap( 'delete_plugins' ); 747 } 748 } 749 750 /** 751 * Create and modify WordPress roles for WordPress 2.7. 752 * 753 * @since 2.7.0 754 */ 755 function populate_roles_270() { 756 $role =& get_role( 'administrator' ); 757 758 if ( !empty( $role ) ) { 759 $role->add_cap( 'install_plugins' ); 760 $role->add_cap( 'update_themes' ); 761 } 762 } 763 764 /** 765 * Create and modify WordPress roles for WordPress 2.8. 766 * 767 * @since 2.8.0 768 */ 769 function populate_roles_280() { 770 $role =& get_role( 'administrator' ); 771 772 if ( !empty( $role ) ) { 773 $role->add_cap( 'install_themes' ); 774 } 775 } 776 777 /** 778 * Create and modify WordPress roles for WordPress 3.0. 779 * 780 * @since 3.0.0 781 */ 782 function populate_roles_300() { 783 $role =& get_role( 'administrator' ); 784 785 if ( !empty( $role ) ) { 786 $role->add_cap( 'update_core' ); 787 $role->add_cap( 'list_users' ); 788 $role->add_cap( 'remove_users' ); 789 $role->add_cap( 'add_users' ); 790 $role->add_cap( 'promote_users' ); 791 $role->add_cap( 'edit_theme_options' ); 792 $role->add_cap( 'delete_themes' ); 793 $role->add_cap( 'export' ); 794 } 795 } 796 797 /** 798 * Install Network. 799 * 800 * @since 3.0.0 801 * 802 */ 803 if ( !function_exists( 'install_network' ) ) : 804 function install_network() { 805 if ( ! defined( 'WP_INSTALLING_NETWORK' ) ) 806 define( 'WP_INSTALLING_NETWORK', true ); 807 808 dbDelta( wp_get_db_schema( 'global' ) ); 809 } 810 endif; 811 812 /** 813 * populate network settings 814 * 815 * @since 3.0.0 816 * 817 * @param int $network_id id of network to populate 818 * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful, 819 * so the error code must be checked) or failure. 820 */ 821 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) { 822 global $wpdb, $current_site, $wp_db_version, $wp_rewrite; 823 824 $errors = new WP_Error(); 825 if ( '' == $domain ) 826 $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) ); 827 if ( '' == $site_name ) 828 $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) ); 829 830 // check for network collision 831 if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) 832 $errors->add( 'siteid_exists', __( 'The network already exists.' ) ); 833 834 $site_user = get_user_by( 'email', $email ); 835 if ( ! is_email( $email ) ) 836 $errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) ); 837 838 if ( $errors->get_error_code() ) 839 return $errors; 840 841 // set up site tables 842 $template = get_option( 'template' ); 843 $stylesheet = get_option( 'stylesheet' ); 844 $allowed_themes = array( $stylesheet => true ); 845 if ( $template != $stylesheet ) 846 $allowed_themes[ $template ] = true; 847 if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) 848 $allowed_themes[ WP_DEFAULT_THEME ] = true; 849 850 if ( 1 == $network_id ) { 851 $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) ); 852 $network_id = $wpdb->insert_id; 853 } else { 854 $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) ); 855 } 856 857 if ( !is_multisite() ) { 858 $site_admins = array( $site_user->user_login ); 859 $users = get_users( array( 'fields' => array( 'ID', 'user_login' ) ) ); 860 if ( $users ) { 861 foreach ( $users as $user ) { 862 if ( is_super_admin( $user->ID ) && !in_array( $user->user_login, $site_admins ) ) 863 $site_admins[] = $user->user_login; 864 } 865 } 866 } else { 867 $site_admins = get_site_option( 'site_admins' ); 868 } 869 870 $welcome_email = __( 'Dear User, 871 872 Your new SITE_NAME site has been successfully set up at: 873 BLOG_URL 874 875 You can log in to the administrator account with the following information: 876 Username: USERNAME 877 Password: PASSWORD 878 Log in here: BLOG_URLwp-login.php 879 880 We hope you enjoy your new site. Thanks! 881 882 --The Team @ SITE_NAME' ); 883 884 $sitemeta = array( 885 'site_name' => $site_name, 886 'admin_email' => $site_user->user_email, 887 'admin_user_id' => $site_user->ID, 888 'registration' => 'none', 889 'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf', 890 'blog_upload_space' => 100, 891 'fileupload_maxk' => 1500, 892 'site_admins' => $site_admins, 893 'allowedthemes' => $allowed_themes, 894 'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ), 895 'wpmu_upgrade_site' => $wp_db_version, 896 'welcome_email' => $welcome_email, 897 'first_post' => __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ), 898 // @todo - network admins should have a method of editing the network siteurl (used for cookie hash) 899 'siteurl' => get_option( 'siteurl' ) . '/', 900 'add_new_users' => '0', 901 'upload_space_check_disabled' => '0', 902 'subdomain_install' => intval( $subdomain_install ), 903 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 904 'initial_db_version' => get_option( 'initial_db_version' ), 905 'active_sitewide_plugins' => array(), 906 ); 907 if ( ! $subdomain_install ) 908 $sitemeta['illegal_names'][] = 'blog'; 909 910 $insert = ''; 911 foreach ( $sitemeta as $meta_key => $meta_value ) { 912 $meta_key = $wpdb->escape( $meta_key ); 913 if ( is_array( $meta_value ) ) 914 $meta_value = serialize( $meta_value ); 915 $meta_value = $wpdb->escape( $meta_value ); 916 if ( !empty( $insert ) ) 917 $insert .= ', '; 918 $insert .= "( $network_id, '$meta_key', '$meta_value')"; 919 } 920 $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); 921 922 $current_site->domain = $domain; 923 $current_site->path = $path; 924 $current_site->site_name = ucfirst( $domain ); 925 926 if ( !is_multisite() ) { 927 $wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time( 'mysql' ) ) ); 928 $blog_id = $wpdb->insert_id; 929 update_user_meta( $site_user->ID, 'source_domain', $domain ); 930 update_user_meta( $site_user->ID, 'primary_blog', $blog_id ); 931 if ( !$upload_path = get_option( 'upload_path' ) ) { 932 $upload_path = substr( WP_CONTENT_DIR, strlen( ABSPATH ) ) . '/uploads'; 933 update_option( 'upload_path', $upload_path ); 934 } 935 update_option( 'fileupload_url', get_option( 'siteurl' ) . '/' . $upload_path ); 936 } 937 938 if ( $subdomain_install ) 939 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 940 else 941 $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' ); 942 943 flush_rewrite_rules(); 944 945 if ( $subdomain_install ) { 946 $vhost_ok = false; 947 $errstr = ''; 948 $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname! 949 $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) ); 950 if ( is_wp_error( $page ) ) 951 $errstr = $page->get_error_message(); 952 elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) 953 $vhost_ok = true; 954 955 if ( ! $vhost_ok ) { 956 $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>'; 957 $msg .= '<p>' . sprintf( __( 'The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.' ), $hostname ); 958 if ( ! empty ( $errstr ) ) 959 $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' ); 960 $msg .= '</p>'; 961 $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>'; 962 $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>'; 963 return new WP_Error( 'no_wildcard_dns', $msg ); 964 } 965 } 966 967 return true; 968 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri May 25 03:56:23 2012 | Hosted by follow the white rabbit. |