populate_options

Create WordPress options and set the default values.

Description

populate_options(); 

Usage

  1. if ( !function_exists( 'populate_options' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/schema.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = populate_options(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/schema.php  
  1. function populate_options() { 
  2. global $wpdb, $wp_db_version, $wp_current_db_version; 
  3.  
  4. $guessurl = wp_guess_url(); 
  5. /** 
  6. * Fires before creating WordPress options and populating their default values. 
  7. * @since 2.6.0 
  8. */ 
  9.  
  10. if ( ini_get('safe_mode') ) { 
  11. // Safe mode can break mkdir() so use a flat structure by default. 
  12. $uploads_use_yearmonth_folders = 0; 
  13. } else { 
  14. $uploads_use_yearmonth_folders = 1; 
  15.  
  16. // If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme. 
  17. $stylesheet = $template = WP_DEFAULT_THEME
  18. if ( ! $theme->exists() ) { 
  19. $theme = WP_Theme::get_core_default_theme(); 
  20.  
  21. // If we can't find a core default theme, WP_DEFAULT_THEME is the best we can do. 
  22. if ( $theme ) { 
  23. $stylesheet = $theme->get_stylesheet(); 
  24. $template = $theme->get_template(); 
  25.  
  26. $timezone_string = ''; 
  27. $gmt_offset = 0; 
  28. /** translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14) 
  29. or a valid timezone string (America/New_York). See https://secure.php.net/manual/en/timezones.php 
  30. for all timezone strings supported by PHP. 
  31. */ 
  32. $offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); 
  33. if ( is_numeric( $offset_or_tz ) ) 
  34. $gmt_offset = $offset_or_tz; 
  35. elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) 
  36. $timezone_string = $offset_or_tz; 
  37.  
  38. $options = array( 
  39. 'siteurl' => $guessurl,  
  40. 'home' => $guessurl,  
  41. 'blogname' => __('My Site'),  
  42. /** translators: site tagline */ 
  43. 'blogdescription' => __('Just another WordPress site'),  
  44. 'users_can_register' => 0,  
  45. 'admin_email' => 'you@example.com',  
  46. /** translators: default start of the week. 0 = Sunday, 1 = Monday */ 
  47. 'start_of_week' => _x( '1', 'start of week' ),  
  48. 'use_balanceTags' => 0,  
  49. 'use_smilies' => 1,  
  50. 'require_name_email' => 1,  
  51. 'comments_notify' => 1,  
  52. 'posts_per_rss' => 10,  
  53. 'rss_use_excerpt' => 0,  
  54. 'mailserver_url' => 'mail.example.com',  
  55. 'mailserver_login' => 'login@example.com',  
  56. 'mailserver_pass' => 'password',  
  57. 'mailserver_port' => 110,  
  58. 'default_category' => 1,  
  59. 'default_comment_status' => 'open',  
  60. 'default_ping_status' => 'open',  
  61. 'default_pingback_flag' => 1,  
  62. 'posts_per_page' => 10,  
  63. /** translators: default date format, see https://secure.php.net/date */ 
  64. 'date_format' => __('F j, Y'),  
  65. /** translators: default time format, see https://secure.php.net/date */ 
  66. 'time_format' => __('g:i a'),  
  67. /** translators: links last updated date format, see https://secure.php.net/date */ 
  68. 'links_updated_date_format' => __('F j, Y g:i a'),  
  69. 'comment_moderation' => 0,  
  70. 'moderation_notify' => 1,  
  71. 'permalink_structure' => '',  
  72. 'rewrite_rules' => '',  
  73. 'hack_file' => 0,  
  74. 'blog_charset' => 'UTF-8',  
  75. 'moderation_keys' => '',  
  76. 'active_plugins' => array(),  
  77. 'category_base' => '',  
  78. 'ping_sites' => 'http://rpc.pingomatic.com/',  
  79. 'comment_max_links' => 2,  
  80. 'gmt_offset' => $gmt_offset,  
  81.  
  82. // 1.5 
  83. 'default_email_category' => 1,  
  84. 'recently_edited' => '',  
  85. 'template' => $template,  
  86. 'stylesheet' => $stylesheet,  
  87. 'comment_whitelist' => 1,  
  88. 'blacklist_keys' => '',  
  89. 'comment_registration' => 0,  
  90. 'html_type' => 'text/html',  
  91.  
  92. // 1.5.1 
  93. 'use_trackback' => 0,  
  94.  
  95. // 2.0 
  96. 'default_role' => 'subscriber',  
  97. 'db_version' => $wp_db_version,  
  98.  
  99. // 2.0.1 
  100. 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders,  
  101. 'upload_path' => '',  
  102.  
  103. // 2.1 
  104. 'blog_public' => '1',  
  105. 'default_link_category' => 2,  
  106. 'show_on_front' => 'posts',  
  107.  
  108. // 2.2 
  109. 'tag_base' => '',  
  110.  
  111. // 2.5 
  112. 'show_avatars' => '1',  
  113. 'avatar_rating' => 'G',  
  114. 'upload_url_path' => '',  
  115. 'thumbnail_size_w' => 150,  
  116. 'thumbnail_size_h' => 150,  
  117. 'thumbnail_crop' => 1,  
  118. 'medium_size_w' => 300,  
  119. 'medium_size_h' => 300,  
  120.  
  121. // 2.6 
  122. 'avatar_default' => 'mystery',  
  123.  
  124. // 2.7 
  125. 'large_size_w' => 1024,  
  126. 'large_size_h' => 1024,  
  127. 'image_default_link_type' => 'none',  
  128. 'image_default_size' => '',  
  129. 'image_default_align' => '',  
  130. 'close_comments_for_old_posts' => 0,  
  131. 'close_comments_days_old' => 14,  
  132. 'thread_comments' => 1,  
  133. 'thread_comments_depth' => 5,  
  134. 'page_comments' => 0,  
  135. 'comments_per_page' => 50,  
  136. 'default_comments_page' => 'newest',  
  137. 'comment_order' => 'asc',  
  138. 'sticky_posts' => array(),  
  139. 'widget_categories' => array(),  
  140. 'widget_text' => array(),  
  141. 'widget_rss' => array(),  
  142. 'uninstall_plugins' => array(),  
  143.  
  144. // 2.8 
  145. 'timezone_string' => $timezone_string,  
  146.  
  147. // 3.0 
  148. 'page_for_posts' => 0,  
  149. 'page_on_front' => 0,  
  150.  
  151. // 3.1 
  152. 'default_post_format' => 0,  
  153.  
  154. // 3.5 
  155. 'link_manager_enabled' => 0,  
  156.  
  157. // 4.3.0 
  158. 'finished_splitting_shared_terms' => 1,  
  159. 'site_icon' => 0,  
  160.  
  161. // 4.4.0 
  162. 'medium_large_size_w' => 768,  
  163. 'medium_large_size_h' => 0,  
  164. ); 
  165.  
  166. // 3.3 
  167. if ( ! is_multisite() ) { 
  168. $options['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version 
  169. ? $wp_current_db_version : $wp_db_version; 
  170.  
  171. // 3.0 multisite 
  172. if ( is_multisite() ) { 
  173. /** translators: site tagline */ 
  174. $options[ 'blogdescription' ] = sprintf(__('Just another %s site'), get_network()->site_name ); 
  175. $options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/'; 
  176.  
  177. // Set autoload to no for these options 
  178. $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' ); 
  179.  
  180. $keys = "'" . implode( "', '", array_keys( $options ) ) . "'"; 
  181. $existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); 
  182.  
  183. $insert = ''; 
  184. foreach ( $options as $option => $value ) { 
  185. if ( in_array($option, $existing_options) ) 
  186. continue; 
  187. if ( in_array($option, $fat_options) ) 
  188. $autoload = 'no'; 
  189. else 
  190. $autoload = 'yes'; 
  191.  
  192. if ( is_array($value) ) 
  193. $value = serialize($value); 
  194. if ( !empty($insert) ) 
  195. $insert .= ', '; 
  196. $insert .= $wpdb->prepare( "(%s, %s, %s)", $option, $value, $autoload ); 
  197.  
  198. if ( !empty($insert) ) 
  199. $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert); 
  200.  
  201. // In case it is set, but blank, update "home". 
  202. if ( !__get_option('home') ) update_option('home', $guessurl); 
  203.  
  204. // Delete unused options. 
  205. $unusedoptions = array( 
  206. 'blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory',  
  207. 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping',  
  208. 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers',  
  209. 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference',  
  210. 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char',  
  211. 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1',  
  212. 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5',  
  213. 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9',  
  214. 'links_recently_updated_time', 'links_recently_updated_prepend', 'links_recently_updated_append',  
  215. 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat',  
  216. 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce',  
  217. '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins',  
  218. 'can_compress_scripts', 'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron',  
  219. 'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page',  
  220. 'wporg_popular_tags', 'what_to_show', 'rss_language', 'language', 'enable_xmlrpc', 'enable_app',  
  221. 'embed_autourls', 'default_post_edit_rows', 'gzipcompression', 'advanced_edit' 
  222. ); 
  223. foreach ( $unusedoptions as $option ) 
  224. delete_option($option); 
  225.  
  226. // Delete obsolete magpie stuff. 
  227. $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'"); 
  228.  
  229. /** 
  230. * Deletes all expired transients. The multi-table delete syntax is used 
  231. * to delete the transient record from table a, and the corresponding 
  232. * transient_timeout record from table b. 
  233. */ 
  234. $time = time(); 
  235. $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b 
  236. WHERE a.option_name LIKE %s 
  237. AND a.option_name NOT LIKE %s 
  238. AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) 
  239. AND b.option_value < %d"; 
  240. $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_transient_' ) . '%', $wpdb->esc_like( '_transient_timeout_' ) . '%', $time ) ); 
  241.  
  242. if ( is_main_site() && is_main_network() ) { 
  243. $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b 
  244. WHERE a.option_name LIKE %s 
  245. AND a.option_name NOT LIKE %s 
  246. AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) 
  247. AND b.option_value < %d"; 
  248. $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like( '_site_transient_timeout_' ) . '%', $time ) );