Use two queries to populate all options during install/upgrade instead of 2 times the number of options.

git-svn-id: http://svn.automattic.com/wordpress/trunk@10766 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-03-10 22:41:33 +00:00
parent df58ca2a41
commit 2f4b8b8566
1 changed files with 128 additions and 104 deletions

View File

@ -182,126 +182,150 @@ function populate_options() {
do_action('populate_options'); do_action('populate_options');
add_option('siteurl', $guessurl);
add_option('blogname', __('My Blog'));
add_option('blogdescription', __('Just another WordPress weblog'));
add_option('users_can_register', 0);
add_option('admin_email', 'you@example.com');
add_option('start_of_week', 1);
add_option('use_balanceTags', 0);
add_option('use_smilies', 1);
add_option('require_name_email', 1);
add_option('comments_notify', 1);
add_option('posts_per_rss', 10);
add_option('rss_excerpt_length', 50);
add_option('rss_use_excerpt', 0);
add_option('mailserver_url', 'mail.example.com');
add_option('mailserver_login', 'login@example.com');
add_option('mailserver_pass', 'password');
add_option('mailserver_port', 110);
add_option('default_category', 1);
add_option('default_comment_status', 'open');
add_option('default_ping_status', 'open');
add_option('default_pingback_flag', 1);
add_option('default_post_edit_rows', 10);
add_option('posts_per_page', 10);
add_option('what_to_show', 'posts');
add_option('date_format', __('F j, Y'));
add_option('time_format', __('g:i a'));
add_option('links_updated_date_format', __('F j, Y g:i a'));
add_option('links_recently_updated_prepend', '<em>');
add_option('links_recently_updated_append', '</em>');
add_option('links_recently_updated_time', 120);
add_option('comment_moderation', 0);
add_option('moderation_notify', 1);
add_option('permalink_structure');
add_option('gzipcompression', 0);
add_option('hack_file', 0);
add_option('blog_charset', 'UTF-8');
add_option('moderation_keys');
add_option('active_plugins');
add_option('home', $guessurl);
// in case it is set, but blank, update "home"
if ( !__get_option('home') ) update_option('home', $guessurl);
add_option('category_base');
add_option('ping_sites', 'http://rpc.pingomatic.com/');
add_option('advanced_edit', 0);
add_option('comment_max_links', 2);
add_option('gmt_offset', date('Z') / 3600);
// 1.5
add_option('default_email_category', 1);
add_option('recently_edited');
add_option('use_linksupdate', 0);
add_option('template', 'default');
add_option('stylesheet', 'default');
add_option('comment_whitelist', 1);
add_option('page_uris');
add_option('blacklist_keys');
add_option('comment_registration', 0);
add_option('rss_language', 'en');
add_option('html_type', 'text/html');
// 1.5.1
add_option('use_trackback', 0);
// 2.0
add_option('default_role', 'subscriber');
add_option('db_version', $wp_db_version);
// 2.0.1
if ( ini_get('safe_mode') ) { if ( ini_get('safe_mode') ) {
// Safe mode screws up mkdir(), so we must use a flat structure. // Safe mode screws up mkdir(), so we must use a flat structure.
add_option('uploads_use_yearmonth_folders', 0); $uploads_use_yearmonth_folders = 0;
add_option('upload_path', WP_CONTENT_DIR); $upload_path = WP_CONTENT_DIR;
} else { } else {
add_option('uploads_use_yearmonth_folders', 1); $uploads_use_yearmonth_folders = 1;
add_option('upload_path', WP_CONTENT_DIR . '/uploads'); $upload_path = WP_CONTENT_DIR . '/uploads';
} }
$options = array(
'siteurl' => $guessurl,
'blogname' => __('My Blog'),
'blogdescription' => __('Just another WordPress weblog'),
'users_can_register' => 0,
'admin_email' => 'you@example.com',
'start_of_week' => 1,
'use_balanceTags' => 0,
'use_smilies' => 1,
'require_name_email' => 1,
'comments_notify' => 1,
'posts_per_rss' => 10,
'rss_excerpt_length' => 50,
'rss_use_excerpt' => 0,
'mailserver_url' => 'mail.example.com',
'mailserver_login' => 'login@example.com',
'mailserver_pass' => 'password',
'mailserver_port' => 110,
'default_category' => 1,
'default_comment_status' => 'open',
'default_ping_status' => 'open',
'default_pingback_flag' => 1,
'default_post_edit_rows' => 10,
'posts_per_page' => 10,
'what_to_show' => 'posts',
'date_format' => __('F j, Y'),
'time_format' => __('g:i a'),
'links_updated_date_format' => __('F j, Y g:i a'),
'links_recently_updated_prepend' => '<em>',
'links_recently_updated_append' => '</em>',
'links_recently_updated_time' => 120,
'comment_moderation' => 0,
'moderation_notify' => 1,
'permalink_structure' => '',
'gzipcompression' => 0,
'hack_file' => 0,
'blog_charset' => 'UTF-8',
'moderation_keys' => '',
'active_plugins' => array(),
'home' => $guessurl,
'category_base' => '',
'ping_sites' => 'http://rpc.pingomatic.com/',
'advanced_edit' => 0,
'comment_max_links' => 2,
'gmt_offset' => date('Z') / 3600,
// 1.5
'default_email_category' => 1,
'recently_edited' => '',
'use_linksupdate' => 0,
'template' => 'default',
'stylesheet' => 'default',
'comment_whitelist' => 1,
'page_uris' => '',
'blacklist_keys' => '',
'comment_registration' => 0,
'rss_language' => 'en',
'html_type' => 'text/html',
// 1.5.1
'use_trackback' => 0,
// 2.0
'default_role' => 'subscriber',
'db_version' => $wp_db_version,
// 2.0.1
'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders,
'upload_path' => $upload_path,
// 2.0.3 // 2.0.3
add_option('secret', wp_generate_password(64)); 'secret' => wp_generate_password(64),
// 2.1 // 2.1
add_option('blog_public', '1'); 'blog_public' => '1',
add_option('default_link_category', 2); 'default_link_category' => 2,
add_option('show_on_front', 'posts'); 'show_on_front' => 'posts',
// 2.2 // 2.2
add_option('tag_base'); 'tag_base' => '',
// 2.5 // 2.5
add_option('show_avatars', '1'); 'show_avatars' => '1',
add_option('avatar_rating', 'G'); 'avatar_rating' => 'G',
add_option('upload_url_path', ''); 'upload_url_path' => '',
add_option('thumbnail_size_w', 150); 'thumbnail_size_w' => 150,
add_option('thumbnail_size_h', 150); 'thumbnail_size_h' => 150,
add_option('thumbnail_crop', 1); 'thumbnail_crop' => 1,
add_option('medium_size_w', 300); 'medium_size_w' => 300,
add_option('medium_size_h', 300); 'medium_size_h' => 300,
// 2.6 // 2.6
add_option('avatar_default', 'mystery'); 'avatar_default' => 'mystery',
add_option('enable_app', 0); 'enable_app' => 0,
add_option('enable_xmlrpc', 0); 'enable_xmlrpc' => 0,
// 2.7 // 2.7
add_option('large_size_w', 1024); 'large_size_w' => 1024,
add_option('large_size_h', 1024); 'large_size_h' => 1024,
add_option('image_default_link_type', 'file'); 'image_default_link_type' => 'file',
add_option('image_default_size', ''); 'image_default_size' => '',
add_option('image_default_align', ''); 'image_default_align' => '',
add_option('close_comments_for_old_posts', 0); 'close_comments_for_old_posts' => 0,
add_option('close_comments_days_old', 14); 'close_comments_days_old' => 14,
add_option('thread_comments', 0); 'thread_comments' => 0,
add_option('thread_comments_depth', 5); 'thread_comments_depth' => 5,
add_option('page_comments', 1); 'page_comments' => 1,
add_option('comments_per_page', 50); 'comments_per_page' => 50,
add_option('default_comments_page', 'newest'); 'default_comments_page' => 'newest',
add_option('comment_order', 'asc'); 'comment_order' => 'asc',
add_option('use_ssl', 0); 'use_ssl' => 0,
add_option('sticky_posts', array()); 'sticky_posts' => array(),
add_option('widget_categories', array()); 'widget_categories' => array(),
add_option('widget_text', array()); 'widget_text' => array(),
add_option('widget_rss', array()); 'widget_rss' => array()
add_option('update_core', array()); );
add_option('dismissed_update_core', array());
$existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options");
$insert = '';
foreach ( $options as $option => $value ) {
if ( in_array($option, $existing_options) )
continue;
$option = $wpdb->escape($option);
$value = $wpdb->escape($value);
if ( !empty($insert) )
$insert .= ', ';
$insert .= "('$option', '$value')";
}
if ( !empty($insert) )
$wpdb->query("INSERT INTO $wpdb->options (option_name, option_value) VALUES " . $insert);
// in case it is set, but blank, update "home"
if ( !__get_option('home') ) update_option('home', $guessurl);
// Delete unused options // Delete unused options
$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'); $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');