33 * @param string $user_email User's email. |
33 * @param string $user_email User's email. |
34 * @param bool $public Whether site is public. |
34 * @param bool $public Whether site is public. |
35 * @param string $deprecated Optional. Not used. |
35 * @param string $deprecated Optional. Not used. |
36 * @param string $user_password Optional. User's chosen password. Default empty (random password). |
36 * @param string $user_password Optional. User's chosen password. Default empty (random password). |
37 * @param string $language Optional. Language chosen. Default empty. |
37 * @param string $language Optional. Language chosen. Default empty. |
38 * @return array Array keys 'url', 'user_id', 'password', and 'password_message'. |
38 * @return array { |
|
39 * Data for the newly installed site. |
|
40 * |
|
41 * @type string $url The URL of the site. |
|
42 * @type int $user_id The ID of the site owner. |
|
43 * @type string $password The password of the site owner, if their user account didn't already exist. |
|
44 * @type string $password_message The explanatory message regarding the password. |
|
45 * } |
39 */ |
46 */ |
40 function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) { |
47 function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) { |
41 if ( ! empty( $deprecated ) ) { |
48 if ( ! empty( $deprecated ) ) { |
42 _deprecated_argument( __FUNCTION__, '2.6.0' ); |
49 _deprecated_argument( __FUNCTION__, '2.6.0' ); |
43 } |
50 } |
73 * being shared among sites. Just set the role in that case. |
80 * being shared among sites. Just set the role in that case. |
74 */ |
81 */ |
75 $user_id = username_exists( $user_name ); |
82 $user_id = username_exists( $user_name ); |
76 $user_password = trim( $user_password ); |
83 $user_password = trim( $user_password ); |
77 $email_password = false; |
84 $email_password = false; |
|
85 $user_created = false; |
|
86 |
78 if ( ! $user_id && empty( $user_password ) ) { |
87 if ( ! $user_id && empty( $user_password ) ) { |
79 $user_password = wp_generate_password( 12, false ); |
88 $user_password = wp_generate_password( 12, false ); |
80 $message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' ); |
89 $message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' ); |
81 $user_id = wp_create_user( $user_name, $user_password, $user_email ); |
90 $user_id = wp_create_user( $user_name, $user_password, $user_email ); |
82 update_user_option( $user_id, 'default_password_nag', true, true ); |
91 update_user_option( $user_id, 'default_password_nag', true, true ); |
83 $email_password = true; |
92 $email_password = true; |
|
93 $user_created = true; |
84 } elseif ( ! $user_id ) { |
94 } elseif ( ! $user_id ) { |
85 // Password has been provided |
95 // Password has been provided. |
86 $message = '<em>' . __( 'Your chosen password.' ) . '</em>'; |
96 $message = '<em>' . __( 'Your chosen password.' ) . '</em>'; |
87 $user_id = wp_create_user( $user_name, $user_password, $user_email ); |
97 $user_id = wp_create_user( $user_name, $user_password, $user_email ); |
|
98 $user_created = true; |
88 } else { |
99 } else { |
89 $message = __( 'User already exists. Password inherited.' ); |
100 $message = __( 'User already exists. Password inherited.' ); |
90 } |
101 } |
91 |
102 |
92 $user = new WP_User( $user_id ); |
103 $user = new WP_User( $user_id ); |
93 $user->set_role( 'administrator' ); |
104 $user->set_role( 'administrator' ); |
|
105 |
|
106 if ( $user_created ) { |
|
107 $user->user_url = $guessurl; |
|
108 wp_update_user( $user ); |
|
109 } |
94 |
110 |
95 wp_install_defaults( $user_id ); |
111 wp_install_defaults( $user_id ); |
96 |
112 |
97 wp_install_maybe_enable_pretty_permalinks(); |
113 wp_install_maybe_enable_pretty_permalinks(); |
98 |
114 |
127 * Adds the default "Uncategorized" category, the first post (with comment), |
143 * Adds the default "Uncategorized" category, the first post (with comment), |
128 * first page, and default widgets for default theme for the current version. |
144 * first page, and default widgets for default theme for the current version. |
129 * |
145 * |
130 * @since 2.1.0 |
146 * @since 2.1.0 |
131 * |
147 * |
132 * @global wpdb $wpdb |
148 * @global wpdb $wpdb WordPress database abstraction object. |
133 * @global WP_Rewrite $wp_rewrite |
149 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
134 * @global string $table_prefix |
150 * @global string $table_prefix |
135 * |
151 * |
136 * @param int $user_id User ID. |
152 * @param int $user_id User ID. |
137 */ |
153 */ |
138 function wp_install_defaults( $user_id ) { |
154 function wp_install_defaults( $user_id ) { |
139 global $wpdb, $wp_rewrite, $table_prefix; |
155 global $wpdb, $wp_rewrite, $table_prefix; |
140 |
156 |
141 // Default category |
157 // Default category. |
142 $cat_name = __( 'Uncategorized' ); |
158 $cat_name = __( 'Uncategorized' ); |
143 /* translators: Default category slug */ |
159 /* translators: Default category slug. */ |
144 $cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) ); |
160 $cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) ); |
145 |
161 |
146 if ( global_terms_enabled() ) { |
162 if ( global_terms_enabled() ) { |
147 $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); |
163 $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); |
148 if ( $cat_id == null ) { |
164 if ( null == $cat_id ) { |
149 $wpdb->insert( |
165 $wpdb->insert( |
150 $wpdb->sitecategories, |
166 $wpdb->sitecategories, |
151 array( |
167 array( |
152 'cat_ID' => 0, |
168 'cat_ID' => 0, |
153 'cat_name' => $cat_name, |
169 'cat_name' => $cat_name, |
181 'count' => 1, |
197 'count' => 1, |
182 ) |
198 ) |
183 ); |
199 ); |
184 $cat_tt_id = $wpdb->insert_id; |
200 $cat_tt_id = $wpdb->insert_id; |
185 |
201 |
186 // First post |
202 // First post. |
187 $now = current_time( 'mysql' ); |
203 $now = current_time( 'mysql' ); |
188 $now_gmt = current_time( 'mysql', 1 ); |
204 $now_gmt = current_time( 'mysql', 1 ); |
189 $first_post_guid = get_option( 'home' ) . '/?p=1'; |
205 $first_post_guid = get_option( 'home' ) . '/?p=1'; |
190 |
206 |
191 if ( is_multisite() ) { |
207 if ( is_multisite() ) { |
192 $first_post = get_site_option( 'first_post' ); |
208 $first_post = get_site_option( 'first_post' ); |
193 |
209 |
194 if ( ! $first_post ) { |
210 if ( ! $first_post ) { |
195 $first_post = "<!-- wp:paragraph -->\n<p>" . |
211 $first_post = "<!-- wp:paragraph -->\n<p>" . |
196 /* translators: first post content, %s: site link */ |
212 /* translators: First post content. %s: Site link. */ |
197 __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) . |
213 __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) . |
198 "</p>\n<!-- /wp:paragraph -->"; |
214 "</p>\n<!-- /wp:paragraph -->"; |
199 } |
215 } |
200 |
216 |
201 $first_post = sprintf( |
217 $first_post = sprintf( |
202 $first_post, |
218 $first_post, |
203 sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name ) |
219 sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name ) |
204 ); |
220 ); |
205 |
221 |
206 // Back-compat for pre-4.4 |
222 // Back-compat for pre-4.4. |
207 $first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post ); |
223 $first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post ); |
208 $first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post ); |
224 $first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post ); |
209 } else { |
225 } else { |
210 $first_post = "<!-- wp:paragraph -->\n<p>" . |
226 $first_post = "<!-- wp:paragraph -->\n<p>" . |
211 /* translators: first post content, %s: site link */ |
227 /* translators: First post content. %s: Site link. */ |
212 __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) . |
228 __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) . |
213 "</p>\n<!-- /wp:paragraph -->"; |
229 "</p>\n<!-- /wp:paragraph -->"; |
214 } |
230 } |
215 |
231 |
216 $wpdb->insert( |
232 $wpdb->insert( |
220 'post_date' => $now, |
236 'post_date' => $now, |
221 'post_date_gmt' => $now_gmt, |
237 'post_date_gmt' => $now_gmt, |
222 'post_content' => $first_post, |
238 'post_content' => $first_post, |
223 'post_excerpt' => '', |
239 'post_excerpt' => '', |
224 'post_title' => __( 'Hello world!' ), |
240 'post_title' => __( 'Hello world!' ), |
225 /* translators: Default post slug */ |
241 /* translators: Default post slug. */ |
226 'post_name' => sanitize_title( _x( 'hello-world', 'Default post slug' ) ), |
242 'post_name' => sanitize_title( _x( 'hello-world', 'Default post slug' ) ), |
227 'post_modified' => $now, |
243 'post_modified' => $now, |
228 'post_modified_gmt' => $now_gmt, |
244 'post_modified_gmt' => $now_gmt, |
229 'guid' => $first_post_guid, |
245 'guid' => $first_post_guid, |
230 'comment_count' => 1, |
246 'comment_count' => 1, |
265 'comment_author_email' => $first_comment_email, |
281 'comment_author_email' => $first_comment_email, |
266 'comment_author_url' => $first_comment_url, |
282 'comment_author_url' => $first_comment_url, |
267 'comment_date' => $now, |
283 'comment_date' => $now, |
268 'comment_date_gmt' => $now_gmt, |
284 'comment_date_gmt' => $now_gmt, |
269 'comment_content' => $first_comment, |
285 'comment_content' => $first_comment, |
|
286 'comment_type' => 'comment', |
270 ) |
287 ) |
271 ); |
288 ); |
272 |
289 |
273 // First Page |
290 // First page. |
274 if ( is_multisite() ) { |
291 if ( is_multisite() ) { |
275 $first_page = get_site_option( 'first_page' ); |
292 $first_page = get_site_option( 'first_page' ); |
276 } |
293 } |
277 |
294 |
278 if ( empty( $first_page ) ) { |
295 if ( empty( $first_page ) ) { |
279 $first_page = "<!-- wp:paragraph -->\n<p>"; |
296 $first_page = "<!-- wp:paragraph -->\n<p>"; |
280 /* translators: first page content */ |
297 /* translators: First page content. */ |
281 $first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" ); |
298 $first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" ); |
282 $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n"; |
299 $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n"; |
283 |
300 |
284 $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>"; |
301 $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>"; |
285 /* translators: first page content */ |
302 /* translators: First page content. */ |
286 $first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)" ); |
303 $first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)" ); |
287 $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n"; |
304 $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n"; |
288 |
305 |
289 $first_page .= "<!-- wp:paragraph -->\n<p>"; |
306 $first_page .= "<!-- wp:paragraph -->\n<p>"; |
290 /* translators: first page content */ |
307 /* translators: First page content. */ |
291 $first_page .= __( '...or something like this:' ); |
308 $first_page .= __( '...or something like this:' ); |
292 $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n"; |
309 $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n"; |
293 |
310 |
294 $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>"; |
311 $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>"; |
295 /* translators: first page content */ |
312 /* translators: First page content. */ |
296 $first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' ); |
313 $first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' ); |
297 $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n"; |
314 $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n"; |
298 |
315 |
299 $first_page .= "<!-- wp:paragraph -->\n<p>"; |
316 $first_page .= "<!-- wp:paragraph -->\n<p>"; |
300 $first_page .= sprintf( |
317 $first_page .= sprintf( |
301 /* translators: first page content, %s: site admin URL */ |
318 /* translators: First page content. %s: Site admin URL. */ |
302 __( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ), |
319 __( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ), |
303 admin_url() |
320 admin_url() |
304 ); |
321 ); |
305 $first_page .= "</p>\n<!-- /wp:paragraph -->"; |
322 $first_page .= "</p>\n<!-- /wp:paragraph -->"; |
306 } |
323 } |
314 'post_date_gmt' => $now_gmt, |
331 'post_date_gmt' => $now_gmt, |
315 'post_content' => $first_page, |
332 'post_content' => $first_page, |
316 'post_excerpt' => '', |
333 'post_excerpt' => '', |
317 'comment_status' => 'closed', |
334 'comment_status' => 'closed', |
318 'post_title' => __( 'Sample Page' ), |
335 'post_title' => __( 'Sample Page' ), |
319 /* translators: Default page slug */ |
336 /* translators: Default page slug. */ |
320 'post_name' => __( 'sample-page' ), |
337 'post_name' => __( 'sample-page' ), |
321 'post_modified' => $now, |
338 'post_modified' => $now, |
322 'post_modified_gmt' => $now_gmt, |
339 'post_modified_gmt' => $now_gmt, |
323 'guid' => $first_post_guid, |
340 'guid' => $first_post_guid, |
324 'post_type' => 'page', |
341 'post_type' => 'page', |
359 'post_date_gmt' => $now_gmt, |
376 'post_date_gmt' => $now_gmt, |
360 'post_content' => $privacy_policy_content, |
377 'post_content' => $privacy_policy_content, |
361 'post_excerpt' => '', |
378 'post_excerpt' => '', |
362 'comment_status' => 'closed', |
379 'comment_status' => 'closed', |
363 'post_title' => __( 'Privacy Policy' ), |
380 'post_title' => __( 'Privacy Policy' ), |
364 /* translators: Privacy Policy page slug */ |
381 /* translators: Privacy Policy page slug. */ |
365 'post_name' => __( 'privacy-policy' ), |
382 'post_name' => __( 'privacy-policy' ), |
366 'post_modified' => $now, |
383 'post_modified' => $now, |
367 'post_modified_gmt' => $now_gmt, |
384 'post_modified_gmt' => $now_gmt, |
368 'guid' => $privacy_policy_guid, |
385 'guid' => $privacy_policy_guid, |
369 'post_type' => 'page', |
386 'post_type' => 'page', |
523 |
543 |
524 foreach ( (array) $permalink_structures as $permalink_structure ) { |
544 foreach ( (array) $permalink_structures as $permalink_structure ) { |
525 $wp_rewrite->set_permalink_structure( $permalink_structure ); |
545 $wp_rewrite->set_permalink_structure( $permalink_structure ); |
526 |
546 |
527 /* |
547 /* |
528 * Flush rules with the hard option to force refresh of the web-server's |
548 * Flush rules with the hard option to force refresh of the web-server's |
529 * rewrite config file (e.g. .htaccess or web.config). |
549 * rewrite config file (e.g. .htaccess or web.config). |
530 */ |
550 */ |
531 $wp_rewrite->flush_rules( true ); |
551 $wp_rewrite->flush_rules( true ); |
532 |
552 |
533 $test_url = ''; |
553 $test_url = ''; |
534 |
554 |
535 // Test against a real WordPress Post |
555 // Test against a real WordPress post. |
536 $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' ); |
556 $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' ); |
537 if ( $first_post ) { |
557 if ( $first_post ) { |
538 $test_url = get_permalink( $first_post->ID ); |
558 $test_url = get_permalink( $first_post->ID ); |
539 } |
559 } |
540 |
560 |
541 /* |
561 /* |
542 * Send a request to the site, and check whether |
562 * Send a request to the site, and check whether |
543 * the 'x-pingback' header is returned as expected. |
563 * the 'x-pingback' header is returned as expected. |
544 * |
564 * |
545 * Uses wp_remote_get() instead of wp_remote_head() because web servers |
565 * Uses wp_remote_get() instead of wp_remote_head() because web servers |
546 * can block head requests. |
566 * can block head requests. |
547 */ |
567 */ |
548 $response = wp_remote_get( $test_url, array( 'timeout' => 5 ) ); |
568 $response = wp_remote_get( $test_url, array( 'timeout' => 5 ) ); |
549 $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' ); |
569 $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' ); |
550 $pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo( 'pingback_url' ); |
570 $pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header; |
551 |
571 |
552 if ( $pretty_permalinks ) { |
572 if ( $pretty_permalinks ) { |
553 return true; |
573 return true; |
554 } |
574 } |
555 } |
575 } |
832 * @global wpdb $wpdb WordPress database abstraction object. |
857 * @global wpdb $wpdb WordPress database abstraction object. |
833 */ |
858 */ |
834 function upgrade_100() { |
859 function upgrade_100() { |
835 global $wpdb; |
860 global $wpdb; |
836 |
861 |
837 // Get the title and ID of every post, post_name to check if it already has a value |
862 // Get the title and ID of every post, post_name to check if it already has a value. |
838 $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" ); |
863 $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" ); |
839 if ( $posts ) { |
864 if ( $posts ) { |
840 foreach ( $posts as $post ) { |
865 foreach ( $posts as $post ) { |
841 if ( '' == $post->post_name ) { |
866 if ( '' === $post->post_name ) { |
842 $newtitle = sanitize_title( $post->post_title ); |
867 $newtitle = sanitize_title( $post->post_title ); |
843 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) ); |
868 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) ); |
844 } |
869 } |
845 } |
870 } |
846 } |
871 } |
847 |
872 |
848 $categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" ); |
873 $categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" ); |
849 foreach ( $categories as $category ) { |
874 foreach ( $categories as $category ) { |
850 if ( '' == $category->category_nicename ) { |
875 if ( '' === $category->category_nicename ) { |
851 $newtitle = sanitize_title( $category->cat_name ); |
876 $newtitle = sanitize_title( $category->cat_name ); |
852 $wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) ); |
877 $wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) ); |
853 } |
878 } |
854 } |
879 } |
855 |
880 |
934 if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) { |
959 if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) { |
935 $wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) ); |
960 $wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) ); |
936 } |
961 } |
937 } |
962 } |
938 |
963 |
939 // Get the GMT offset, we'll use that later on |
964 // Get the GMT offset, we'll use that later on. |
940 $all_options = get_alloptions_110(); |
965 $all_options = get_alloptions_110(); |
941 |
966 |
942 $time_difference = $all_options->time_difference; |
967 $time_difference = $all_options->time_difference; |
943 |
968 |
944 $server_time = time() + date( 'Z' ); |
969 $server_time = time() + gmdate( 'Z' ); |
945 $weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS; |
970 $weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS; |
946 $gmt_time = time(); |
971 $gmt_time = time(); |
947 |
972 |
948 $diff_gmt_server = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS; |
973 $diff_gmt_server = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS; |
949 $diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS; |
974 $diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS; |
950 $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server; |
975 $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server; |
951 $gmt_offset = -$diff_gmt_weblogger; |
976 $gmt_offset = -$diff_gmt_weblogger; |
952 |
977 |
953 // Add a gmt_offset option, with value $gmt_offset |
978 // Add a gmt_offset option, with value $gmt_offset. |
954 add_option( 'gmt_offset', $gmt_offset ); |
979 add_option( 'gmt_offset', $gmt_offset ); |
955 |
980 |
956 // Check if we already set the GMT fields (if we did, then |
981 /* |
957 // MAX(post_date_gmt) can't be '0000-00-00 00:00:00' |
982 * Check if we already set the GMT fields. If we did, then |
958 // <michel_v> I just slapped myself silly for not thinking about it earlier |
983 * MAX(post_date_gmt) can't be '0000-00-00 00:00:00'. |
959 $got_gmt_fields = ! ( $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) == '0000-00-00 00:00:00' ); |
984 * <michel_v> I just slapped myself silly for not thinking about it earlier. |
|
985 */ |
|
986 $got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) ); |
960 |
987 |
961 if ( ! $got_gmt_fields ) { |
988 if ( ! $got_gmt_fields ) { |
962 |
989 |
963 // Add or subtract time to all dates, to get GMT dates |
990 // Add or subtract time to all dates, to get GMT dates. |
964 $add_hours = intval( $diff_gmt_weblogger ); |
991 $add_hours = intval( $diff_gmt_weblogger ); |
965 $add_minutes = intval( 60 * ( $diff_gmt_weblogger - $add_hours ) ); |
992 $add_minutes = intval( 60 * ( $diff_gmt_weblogger - $add_hours ) ); |
966 $wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" ); |
993 $wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" ); |
967 $wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" ); |
994 $wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" ); |
968 $wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" ); |
995 $wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" ); |
1032 if ( ! is_array( $active_plugins ) ) { |
1059 if ( ! is_array( $active_plugins ) ) { |
1033 $active_plugins = explode( "\n", trim( $active_plugins ) ); |
1060 $active_plugins = explode( "\n", trim( $active_plugins ) ); |
1034 update_option( 'active_plugins', $active_plugins ); |
1061 update_option( 'active_plugins', $active_plugins ); |
1035 } |
1062 } |
1036 |
1063 |
1037 // Obsolete tables |
1064 // Obsolete tables. |
1038 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' ); |
1065 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' ); |
1039 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' ); |
1066 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' ); |
1040 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' ); |
1067 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' ); |
1041 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' ); |
1068 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' ); |
1042 |
1069 |
1043 // Update comments table to use comment_type |
1070 // Update comments table to use comment_type. |
1044 $wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" ); |
1071 $wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" ); |
1045 $wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" ); |
1072 $wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" ); |
1046 |
1073 |
1047 // Some versions have multiple duplicate option_name rows with the same values |
1074 // Some versions have multiple duplicate option_name rows with the same values. |
1048 $options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" ); |
1075 $options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" ); |
1049 foreach ( $options as $option ) { |
1076 foreach ( $options as $option ) { |
1050 if ( 1 != $option->dupes ) { // Could this be done in the query? |
1077 if ( 1 != $option->dupes ) { // Could this be done in the query? |
1051 $limit = $option->dupes - 1; |
1078 $limit = $option->dupes - 1; |
1052 $dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) ); |
1079 $dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) ); |
1053 if ( $dupe_ids ) { |
1080 if ( $dupe_ids ) { |
1054 $dupe_ids = join( $dupe_ids, ',' ); |
1081 $dupe_ids = join( ',', $dupe_ids ); |
1055 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" ); |
1082 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" ); |
1056 } |
1083 } |
1057 } |
1084 } |
1058 } |
1085 } |
1059 |
1086 |
1104 update_user_meta( $user->ID, 'description', wp_slash( $user->user_description ) ); |
1131 update_user_meta( $user->ID, 'description', wp_slash( $user->user_description ) ); |
1105 } |
1132 } |
1106 |
1133 |
1107 if ( isset( $user->user_idmode ) ) : |
1134 if ( isset( $user->user_idmode ) ) : |
1108 $idmode = $user->user_idmode; |
1135 $idmode = $user->user_idmode; |
1109 if ( $idmode == 'nickname' ) { |
1136 if ( 'nickname' === $idmode ) { |
1110 $id = $user->user_nickname; |
1137 $id = $user->user_nickname; |
1111 } |
1138 } |
1112 if ( $idmode == 'login' ) { |
1139 if ( 'login' === $idmode ) { |
1113 $id = $user->user_login; |
1140 $id = $user->user_login; |
1114 } |
1141 } |
1115 if ( $idmode == 'firstname' ) { |
1142 if ( 'firstname' === $idmode ) { |
1116 $id = $user->user_firstname; |
1143 $id = $user->user_firstname; |
1117 } |
1144 } |
1118 if ( $idmode == 'lastname' ) { |
1145 if ( 'lastname' === $idmode ) { |
1119 $id = $user->user_lastname; |
1146 $id = $user->user_lastname; |
1120 } |
1147 } |
1121 if ( $idmode == 'namefl' ) { |
1148 if ( 'namefl' === $idmode ) { |
1122 $id = $user->user_firstname . ' ' . $user->user_lastname; |
1149 $id = $user->user_firstname . ' ' . $user->user_lastname; |
1123 } |
1150 } |
1124 if ( $idmode == 'namelf' ) { |
1151 if ( 'namelf' === $idmode ) { |
1125 $id = $user->user_lastname . ' ' . $user->user_firstname; |
1152 $id = $user->user_lastname . ' ' . $user->user_firstname; |
1126 } |
1153 } |
1127 if ( ! $idmode ) { |
1154 if ( ! $idmode ) { |
1128 $id = $user->user_nickname; |
1155 $id = $user->user_nickname; |
1129 } |
1156 } |
1183 * Execute changes made in WordPress 2.1. |
1210 * Execute changes made in WordPress 2.1. |
1184 * |
1211 * |
1185 * @ignore |
1212 * @ignore |
1186 * @since 2.1.0 |
1213 * @since 2.1.0 |
1187 * |
1214 * |
1188 * @global wpdb $wpdb WordPress database abstraction object. |
1215 * @global int $wp_current_db_version The old (current) database version. |
1189 * @global int $wp_current_db_version |
1216 * @global wpdb $wpdb WordPress database abstraction object. |
1190 */ |
1217 */ |
1191 function upgrade_210() { |
1218 function upgrade_210() { |
1192 global $wpdb, $wp_current_db_version; |
1219 global $wp_current_db_version, $wpdb; |
1193 |
1220 |
1194 if ( $wp_current_db_version < 3506 ) { |
1221 if ( $wp_current_db_version < 3506 ) { |
1195 // Update status and type. |
1222 // Update status and type. |
1196 $posts = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" ); |
1223 $posts = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" ); |
1197 |
1224 |
1198 if ( ! empty( $posts ) ) { |
1225 if ( ! empty( $posts ) ) { |
1199 foreach ( $posts as $post ) { |
1226 foreach ( $posts as $post ) { |
1200 $status = $post->post_status; |
1227 $status = $post->post_status; |
1201 $type = 'post'; |
1228 $type = 'post'; |
1202 |
1229 |
1203 if ( 'static' == $status ) { |
1230 if ( 'static' === $status ) { |
1204 $status = 'publish'; |
1231 $status = 'publish'; |
1205 $type = 'page'; |
1232 $type = 'page'; |
1206 } elseif ( 'attachment' == $status ) { |
1233 } elseif ( 'attachment' === $status ) { |
1207 $status = 'inherit'; |
1234 $status = 'inherit'; |
1208 $type = 'attachment'; |
1235 $type = 'attachment'; |
1209 } |
1236 } |
1210 |
1237 |
1211 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID ) ); |
1238 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID ) ); |
1438 ); |
1467 ); |
1439 } |
1468 } |
1440 } |
1469 } |
1441 |
1470 |
1442 if ( $wp_current_db_version < 4772 ) { |
1471 if ( $wp_current_db_version < 4772 ) { |
1443 // Obsolete linkcategories table |
1472 // Obsolete linkcategories table. |
1444 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' ); |
1473 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' ); |
1445 } |
1474 } |
1446 |
1475 |
1447 // Recalculate all counts |
1476 // Recalculate all counts. |
1448 $terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" ); |
1477 $terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" ); |
1449 foreach ( (array) $terms as $term ) { |
1478 foreach ( (array) $terms as $term ) { |
1450 if ( ( 'post_tag' == $term->taxonomy ) || ( 'category' == $term->taxonomy ) ) { |
1479 if ( 'post_tag' === $term->taxonomy || 'category' === $term->taxonomy ) { |
1451 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) ); |
1480 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) ); |
1452 } else { |
1481 } else { |
1453 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) ); |
1482 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) ); |
1454 } |
1483 } |
1455 $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_taxonomy_id' => $term->term_taxonomy_id ) ); |
1484 $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_taxonomy_id' => $term->term_taxonomy_id ) ); |
2111 function upgrade_510() { |
2144 function upgrade_510() { |
2112 delete_site_option( 'upgrade_500_was_gutenberg_active' ); |
2145 delete_site_option( 'upgrade_500_was_gutenberg_active' ); |
2113 } |
2146 } |
2114 |
2147 |
2115 /** |
2148 /** |
|
2149 * Executes changes made in WordPress 5.3.0. |
|
2150 * |
|
2151 * @ignore |
|
2152 * @since 5.3.0 |
|
2153 */ |
|
2154 function upgrade_530() { |
|
2155 /* |
|
2156 * The `admin_email_lifespan` option may have been set by an admin that just logged in, |
|
2157 * saw the verification screen, clicked on a button there, and is now upgrading the db, |
|
2158 * or by populate_options() that is called earlier in upgrade_all(). |
|
2159 * In the second case `admin_email_lifespan` should be reset so the verification screen |
|
2160 * is shown next time an admin logs in. |
|
2161 */ |
|
2162 if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) { |
|
2163 update_option( 'admin_email_lifespan', 0 ); |
|
2164 } |
|
2165 } |
|
2166 |
|
2167 /** |
|
2168 * Executes changes made in WordPress 5.5.0. |
|
2169 * |
|
2170 * @ignore |
|
2171 * @since 5.5.0 |
|
2172 */ |
|
2173 function upgrade_550() { |
|
2174 global $wp_current_db_version; |
|
2175 |
|
2176 if ( $wp_current_db_version < 48121 ) { |
|
2177 $comment_previously_approved = get_option( 'comment_whitelist', '' ); |
|
2178 update_option( 'comment_previously_approved', $comment_previously_approved ); |
|
2179 delete_option( 'comment_whitelist' ); |
|
2180 } |
|
2181 |
|
2182 if ( $wp_current_db_version < 48575 ) { |
|
2183 // Use more clear and inclusive language. |
|
2184 $disallowed_list = get_option( 'blacklist_keys' ); |
|
2185 |
|
2186 /* |
|
2187 * This option key was briefly renamed `blocklist_keys`. |
|
2188 * Account for sites that have this key present when the original key does not exist. |
|
2189 */ |
|
2190 if ( false === $disallowed_list ) { |
|
2191 $disallowed_list = get_option( 'blocklist_keys' ); |
|
2192 } |
|
2193 |
|
2194 update_option( 'disallowed_keys', $disallowed_list ); |
|
2195 delete_option( 'blacklist_keys' ); |
|
2196 delete_option( 'blocklist_keys' ); |
|
2197 } |
|
2198 |
|
2199 if ( $wp_current_db_version < 48748 ) { |
|
2200 update_option( 'finished_updating_comment_type', 0 ); |
|
2201 wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' ); |
|
2202 } |
|
2203 } |
|
2204 |
|
2205 /** |
2116 * Executes network-level upgrade routines. |
2206 * Executes network-level upgrade routines. |
2117 * |
2207 * |
2118 * @since 3.0.0 |
2208 * @since 3.0.0 |
2119 * |
2209 * |
2120 * @global int $wp_current_db_version |
2210 * @global int $wp_current_db_version The old (current) database version. |
2121 * @global wpdb $wpdb |
2211 * @global wpdb $wpdb WordPress database abstraction object. |
2122 */ |
2212 */ |
2123 function upgrade_network() { |
2213 function upgrade_network() { |
2124 global $wp_current_db_version, $wpdb; |
2214 global $wp_current_db_version, $wpdb; |
2125 |
2215 |
2126 // Always clear expired transients |
2216 // Always clear expired transients. |
2127 delete_expired_transients( true ); |
2217 delete_expired_transients( true ); |
2128 |
2218 |
2129 // 2.8. |
2219 // 2.8.0 |
2130 if ( $wp_current_db_version < 11549 ) { |
2220 if ( $wp_current_db_version < 11549 ) { |
2131 $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); |
2221 $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); |
2132 $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); |
2222 $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); |
2133 if ( $wpmu_sitewide_plugins ) { |
2223 if ( $wpmu_sitewide_plugins ) { |
2134 if ( ! $active_sitewide_plugins ) { |
2224 if ( ! $active_sitewide_plugins ) { |
2155 } |
2245 } |
2156 $start += 20; |
2246 $start += 20; |
2157 } |
2247 } |
2158 } |
2248 } |
2159 |
2249 |
2160 // 3.0 |
2250 // 3.0.0 |
2161 if ( $wp_current_db_version < 13576 ) { |
2251 if ( $wp_current_db_version < 13576 ) { |
2162 update_site_option( 'global_terms_enabled', '1' ); |
2252 update_site_option( 'global_terms_enabled', '1' ); |
2163 } |
2253 } |
2164 |
2254 |
2165 // 3.3 |
2255 // 3.3.0 |
2166 if ( $wp_current_db_version < 19390 ) { |
2256 if ( $wp_current_db_version < 19390 ) { |
2167 update_site_option( 'initial_db_version', $wp_current_db_version ); |
2257 update_site_option( 'initial_db_version', $wp_current_db_version ); |
2168 } |
2258 } |
2169 |
2259 |
2170 if ( $wp_current_db_version < 19470 ) { |
2260 if ( $wp_current_db_version < 19470 ) { |
2171 if ( false === get_site_option( 'active_sitewide_plugins' ) ) { |
2261 if ( false === get_site_option( 'active_sitewide_plugins' ) ) { |
2172 update_site_option( 'active_sitewide_plugins', array() ); |
2262 update_site_option( 'active_sitewide_plugins', array() ); |
2173 } |
2263 } |
2174 } |
2264 } |
2175 |
2265 |
2176 // 3.4 |
2266 // 3.4.0 |
2177 if ( $wp_current_db_version < 20148 ) { |
2267 if ( $wp_current_db_version < 20148 ) { |
2178 // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. |
2268 // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. |
2179 $allowedthemes = get_site_option( 'allowedthemes' ); |
2269 $allowedthemes = get_site_option( 'allowedthemes' ); |
2180 $allowed_themes = get_site_option( 'allowed_themes' ); |
2270 $allowed_themes = get_site_option( 'allowed_themes' ); |
2181 if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) { |
2271 if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) { |
2254 maybe_convert_table_to_utf8mb4( $table ); |
2344 maybe_convert_table_to_utf8mb4( $table ); |
2255 } |
2345 } |
2256 } |
2346 } |
2257 } |
2347 } |
2258 |
2348 |
2259 // 5.1 |
2349 // 5.1.0 |
2260 if ( $wp_current_db_version < 44467 ) { |
2350 if ( $wp_current_db_version < 44467 ) { |
2261 $network_id = get_main_network_id(); |
2351 $network_id = get_main_network_id(); |
2262 delete_network_option( $network_id, 'site_meta_supported' ); |
2352 delete_network_option( $network_id, 'site_meta_supported' ); |
2263 is_site_meta_supported(); |
2353 is_site_meta_supported(); |
2264 } |
2354 } |
2265 } |
2355 } |
2266 |
2356 |
2267 // |
2357 // |
2268 // General functions we use to actually do stuff |
2358 // General functions we use to actually do stuff. |
2269 // |
2359 // |
2270 |
2360 |
2271 /** |
2361 /** |
2272 * Creates a table in the database if it doesn't already exist. |
2362 * Creates a table in the database, if it doesn't already exist. |
2273 * |
2363 * |
2274 * This method checks for an existing database and creates a new one if it's not |
2364 * This method checks for an existing database and creates a new one if it's not |
2275 * already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses |
2365 * already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses |
2276 * to query all tables first and then run the SQL statement creating the table. |
2366 * to query all tables first and then run the SQL statement creating the table. |
2277 * |
2367 * |
2278 * @since 1.0.0 |
2368 * @since 1.0.0 |
2279 * |
2369 * |
2280 * @global wpdb $wpdb |
2370 * @global wpdb $wpdb WordPress database abstraction object. |
2281 * |
2371 * |
2282 * @param string $table_name Database table name to create. |
2372 * @param string $table_name Database table name. |
2283 * @param string $create_ddl SQL statement to create table. |
2373 * @param string $create_ddl SQL statement to create table. |
2284 * @return bool If table already exists or was created by function. |
2374 * @return bool True on success or if the table already exists. False on failure. |
2285 */ |
2375 */ |
2286 function maybe_create_table( $table_name, $create_ddl ) { |
2376 function maybe_create_table( $table_name, $create_ddl ) { |
2287 global $wpdb; |
2377 global $wpdb; |
2288 |
2378 |
2289 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ); |
2379 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ); |
2290 |
2380 |
2291 if ( $wpdb->get_var( $query ) == $table_name ) { |
2381 if ( $wpdb->get_var( $query ) === $table_name ) { |
2292 return true; |
2382 return true; |
2293 } |
2383 } |
2294 |
2384 |
2295 // Didn't find it try to create it.. |
2385 // Didn't find it, so try to create it. |
2296 $wpdb->query( $create_ddl ); |
2386 $wpdb->query( $create_ddl ); |
2297 |
2387 |
2298 // We cannot directly tell that whether this succeeded! |
2388 // We cannot directly tell that whether this succeeded! |
2299 if ( $wpdb->get_var( $query ) == $table_name ) { |
2389 if ( $wpdb->get_var( $query ) === $table_name ) { |
2300 return true; |
2390 return true; |
2301 } |
2391 } |
|
2392 |
2302 return false; |
2393 return false; |
2303 } |
2394 } |
2304 |
2395 |
2305 /** |
2396 /** |
2306 * Drops a specified index from a table. |
2397 * Drops a specified index from a table. |
2307 * |
2398 * |
2308 * @since 1.0.1 |
2399 * @since 1.0.1 |
2309 * |
2400 * |
2310 * @global wpdb $wpdb |
2401 * @global wpdb $wpdb WordPress database abstraction object. |
2311 * |
2402 * |
2312 * @param string $table Database table name. |
2403 * @param string $table Database table name. |
2313 * @param string $index Index name to drop. |
2404 * @param string $index Index name to drop. |
2314 * @return true True, when finished. |
2405 * @return true True, when finished. |
2315 */ |
2406 */ |
2316 function drop_index( $table, $index ) { |
2407 function drop_index( $table, $index ) { |
2317 global $wpdb; |
2408 global $wpdb; |
|
2409 |
2318 $wpdb->hide_errors(); |
2410 $wpdb->hide_errors(); |
|
2411 |
2319 $wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" ); |
2412 $wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" ); |
2320 // Now we need to take out all the extra ones we may have created |
2413 |
|
2414 // Now we need to take out all the extra ones we may have created. |
2321 for ( $i = 0; $i < 25; $i++ ) { |
2415 for ( $i = 0; $i < 25; $i++ ) { |
2322 $wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" ); |
2416 $wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" ); |
2323 } |
2417 } |
|
2418 |
2324 $wpdb->show_errors(); |
2419 $wpdb->show_errors(); |
|
2420 |
2325 return true; |
2421 return true; |
2326 } |
2422 } |
2327 |
2423 |
2328 /** |
2424 /** |
2329 * Adds an index to a specified table. |
2425 * Adds an index to a specified table. |
2330 * |
2426 * |
2331 * @since 1.0.1 |
2427 * @since 1.0.1 |
2332 * |
2428 * |
2333 * @global wpdb $wpdb |
2429 * @global wpdb $wpdb WordPress database abstraction object. |
2334 * |
2430 * |
2335 * @param string $table Database table name. |
2431 * @param string $table Database table name. |
2336 * @param string $index Database table index column. |
2432 * @param string $index Database table index column. |
2337 * @return true True, when done with execution. |
2433 * @return true True, when done with execution. |
2338 */ |
2434 */ |
2339 function add_clean_index( $table, $index ) { |
2435 function add_clean_index( $table, $index ) { |
2340 global $wpdb; |
2436 global $wpdb; |
|
2437 |
2341 drop_index( $table, $index ); |
2438 drop_index( $table, $index ); |
2342 $wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" ); |
2439 $wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" ); |
|
2440 |
2343 return true; |
2441 return true; |
2344 } |
2442 } |
2345 |
2443 |
2346 /** |
2444 /** |
2347 * Adds column to a database table if it doesn't already exist. |
2445 * Adds column to a database table, if it doesn't already exist. |
2348 * |
2446 * |
2349 * @since 1.3.0 |
2447 * @since 1.3.0 |
2350 * |
2448 * |
2351 * @global wpdb $wpdb |
2449 * @global wpdb $wpdb WordPress database abstraction object. |
2352 * |
2450 * |
2353 * @param string $table_name The table name to modify. |
2451 * @param string $table_name Database table name. |
2354 * @param string $column_name The column name to add to the table. |
2452 * @param string $column_name Table column name. |
2355 * @param string $create_ddl The SQL statement used to add the column. |
2453 * @param string $create_ddl SQL statement to add column. |
2356 * @return bool True if already exists or on successful completion, false on error. |
2454 * @return bool True on success or if the column already exists. False on failure. |
2357 */ |
2455 */ |
2358 function maybe_add_column( $table_name, $column_name, $create_ddl ) { |
2456 function maybe_add_column( $table_name, $column_name, $create_ddl ) { |
2359 global $wpdb; |
2457 global $wpdb; |
|
2458 |
2360 foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { |
2459 foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { |
2361 if ( $column == $column_name ) { |
2460 if ( $column === $column_name ) { |
2362 return true; |
2461 return true; |
2363 } |
2462 } |
2364 } |
2463 } |
2365 |
2464 |
2366 // Didn't find it try to create it. |
2465 // Didn't find it, so try to create it. |
2367 $wpdb->query( $create_ddl ); |
2466 $wpdb->query( $create_ddl ); |
2368 |
2467 |
2369 // We cannot directly tell that whether this succeeded! |
2468 // We cannot directly tell that whether this succeeded! |
2370 foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { |
2469 foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { |
2371 if ( $column == $column_name ) { |
2470 if ( $column === $column_name ) { |
2372 return true; |
2471 return true; |
2373 } |
2472 } |
2374 } |
2473 } |
|
2474 |
2375 return false; |
2475 return false; |
2376 } |
2476 } |
2377 |
2477 |
2378 /** |
2478 /** |
2379 * If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4. |
2479 * If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4. |
2380 * |
2480 * |
2381 * @since 4.2.0 |
2481 * @since 4.2.0 |
2382 * |
2482 * |
2383 * @global wpdb $wpdb |
2483 * @global wpdb $wpdb WordPress database abstraction object. |
2384 * |
2484 * |
2385 * @param string $table The table to convert. |
2485 * @param string $table The table to convert. |
2386 * @return bool true if the table was converted, false if it wasn't. |
2486 * @return bool True if the table was converted, false if it wasn't. |
2387 */ |
2487 */ |
2388 function maybe_convert_table_to_utf8mb4( $table ) { |
2488 function maybe_convert_table_to_utf8mb4( $table ) { |
2389 global $wpdb; |
2489 global $wpdb; |
2390 |
2490 |
2391 $results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" ); |
2491 $results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" ); |
2446 * |
2547 * |
2447 * @ignore |
2548 * @ignore |
2448 * @since 1.5.1 |
2549 * @since 1.5.1 |
2449 * @access private |
2550 * @access private |
2450 * |
2551 * |
2451 * @global wpdb $wpdb |
2552 * @global wpdb $wpdb WordPress database abstraction object. |
2452 * |
2553 * |
2453 * @param string $setting Option name. |
2554 * @param string $setting Option name. |
2454 * @return mixed |
2555 * @return mixed |
2455 */ |
2556 */ |
2456 function __get_option( $setting ) { |
2557 function __get_option( $setting ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore |
2457 global $wpdb; |
2558 global $wpdb; |
2458 |
2559 |
2459 if ( $setting == 'home' && defined( 'WP_HOME' ) ) { |
2560 if ( 'home' === $setting && defined( 'WP_HOME' ) ) { |
2460 return untrailingslashit( WP_HOME ); |
2561 return untrailingslashit( WP_HOME ); |
2461 } |
2562 } |
2462 |
2563 |
2463 if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) { |
2564 if ( 'siteurl' === $setting && defined( 'WP_SITEURL' ) ) { |
2464 return untrailingslashit( WP_SITEURL ); |
2565 return untrailingslashit( WP_SITEURL ); |
2465 } |
2566 } |
2466 |
2567 |
2467 $option = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) ); |
2568 $option = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) ); |
2468 |
2569 |
2469 if ( 'home' == $setting && '' == $option ) { |
2570 if ( 'home' === $setting && ! $option ) { |
2470 return __get_option( 'siteurl' ); |
2571 return __get_option( 'siteurl' ); |
2471 } |
2572 } |
2472 |
2573 |
2473 if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting ) { |
2574 if ( in_array( $setting, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { |
2474 $option = untrailingslashit( $option ); |
2575 $option = untrailingslashit( $option ); |
2475 } |
2576 } |
2476 |
2577 |
2477 return maybe_unserialize( $option ); |
2578 return maybe_unserialize( $option ); |
2478 } |
2579 } |
2511 * |
2612 * |
2512 * Useful for creating new tables and updating existing tables to a new structure. |
2613 * Useful for creating new tables and updating existing tables to a new structure. |
2513 * |
2614 * |
2514 * @since 1.5.0 |
2615 * @since 1.5.0 |
2515 * |
2616 * |
2516 * @global wpdb $wpdb |
2617 * @global wpdb $wpdb WordPress database abstraction object. |
2517 * |
2618 * |
2518 * @param string[]|string $queries Optional. The query to run. Can be multiple queries |
2619 * @param string[]|string $queries Optional. The query to run. Can be multiple queries |
2519 * in an array, or a string of queries separated by |
2620 * in an array, or a string of queries separated by |
2520 * semicolons. Default empty string. |
2621 * semicolons. Default empty string. |
2521 * @param bool $execute Optional. Whether or not to execute the query right away. |
2622 * @param bool $execute Optional. Whether or not to execute the query right away. |
2522 * Default true. |
2623 * Default true. |
2523 * @return array Strings containing the results of the various update queries. |
2624 * @return array Strings containing the results of the various update queries. |
2524 */ |
2625 */ |
2525 function dbDelta( $queries = '', $execute = true ) { |
2626 function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
2526 global $wpdb; |
2627 global $wpdb; |
2527 |
2628 |
2528 if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) { |
2629 if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) { |
2529 $queries = wp_get_db_schema( $queries ); |
2630 $queries = wp_get_db_schema( $queries ); |
2530 } |
2631 } |
2531 |
2632 |
2532 // Separate individual queries into an array |
2633 // Separate individual queries into an array. |
2533 if ( ! is_array( $queries ) ) { |
2634 if ( ! is_array( $queries ) ) { |
2534 $queries = explode( ';', $queries ); |
2635 $queries = explode( ';', $queries ); |
2535 $queries = array_filter( $queries ); |
2636 $queries = array_filter( $queries ); |
2536 } |
2637 } |
2537 |
2638 |
2542 * |
2643 * |
2543 * @param string[] $queries An array of dbDelta SQL queries. |
2644 * @param string[] $queries An array of dbDelta SQL queries. |
2544 */ |
2645 */ |
2545 $queries = apply_filters( 'dbdelta_queries', $queries ); |
2646 $queries = apply_filters( 'dbdelta_queries', $queries ); |
2546 |
2647 |
2547 $cqueries = array(); // Creation Queries |
2648 $cqueries = array(); // Creation queries. |
2548 $iqueries = array(); // Insertion Queries |
2649 $iqueries = array(); // Insertion queries. |
2549 $for_update = array(); |
2650 $for_update = array(); |
2550 |
2651 |
2551 // Create a tablename index for an array ($cqueries) of queries |
2652 // Create a tablename index for an array ($cqueries) of queries. |
2552 foreach ( $queries as $qry ) { |
2653 foreach ( $queries as $qry ) { |
2553 if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) { |
2654 if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) { |
2554 $cqueries[ trim( $matches[1], '`' ) ] = $qry; |
2655 $cqueries[ trim( $matches[1], '`' ) ] = $qry; |
2555 $for_update[ $matches[1] ] = 'Created table ' . $matches[1]; |
2656 $for_update[ $matches[1] ] = 'Created table ' . $matches[1]; |
2556 } elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) { |
2657 } elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) { |
2590 $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); |
2691 $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); |
2591 |
2692 |
2592 $global_tables = $wpdb->tables( 'global' ); |
2693 $global_tables = $wpdb->tables( 'global' ); |
2593 foreach ( $cqueries as $table => $qry ) { |
2694 foreach ( $cqueries as $table => $qry ) { |
2594 // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal. |
2695 // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal. |
2595 if ( in_array( $table, $global_tables ) && ! wp_should_upgrade_global_tables() ) { |
2696 if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) { |
2596 unset( $cqueries[ $table ], $for_update[ $table ] ); |
2697 unset( $cqueries[ $table ], $for_update[ $table ] ); |
2597 continue; |
2698 continue; |
2598 } |
2699 } |
2599 |
2700 |
2600 // Fetch the table column structure from the database |
2701 // Fetch the table column structure from the database. |
2601 $suppress = $wpdb->suppress_errors(); |
2702 $suppress = $wpdb->suppress_errors(); |
2602 $tablefields = $wpdb->get_results( "DESCRIBE {$table};" ); |
2703 $tablefields = $wpdb->get_results( "DESCRIBE {$table};" ); |
2603 $wpdb->suppress_errors( $suppress ); |
2704 $wpdb->suppress_errors( $suppress ); |
2604 |
2705 |
2605 if ( ! $tablefields ) { |
2706 if ( ! $tablefields ) { |
2606 continue; |
2707 continue; |
2607 } |
2708 } |
2608 |
2709 |
2609 // Clear the field and index arrays. |
2710 // Clear the field and index arrays. |
2610 $cfields = $indices = $indices_without_subparts = array(); |
2711 $cfields = array(); |
|
2712 $indices = array(); |
|
2713 $indices_without_subparts = array(); |
2611 |
2714 |
2612 // Get all of the field names in the query from between the parentheses. |
2715 // Get all of the field names in the query from between the parentheses. |
2613 preg_match( '|\((.*)\)|ms', $qry, $match2 ); |
2716 preg_match( '|\((.*)\)|ms', $qry, $match2 ); |
2614 $qryline = trim( $match2[1] ); |
2717 $qryline = trim( $match2[1] ); |
2615 |
2718 |
2740 // For every field in the table. |
2844 // For every field in the table. |
2741 foreach ( $tablefields as $tablefield ) { |
2845 foreach ( $tablefields as $tablefield ) { |
2742 $tablefield_field_lowercased = strtolower( $tablefield->Field ); |
2846 $tablefield_field_lowercased = strtolower( $tablefield->Field ); |
2743 $tablefield_type_lowercased = strtolower( $tablefield->Type ); |
2847 $tablefield_type_lowercased = strtolower( $tablefield->Type ); |
2744 |
2848 |
2745 // If the table field exists in the field array ... |
2849 // If the table field exists in the field array... |
2746 if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) { |
2850 if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) { |
2747 |
2851 |
2748 // Get the field type from the query. |
2852 // Get the field type from the query. |
2749 preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches ); |
2853 preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches ); |
2750 $fieldtype = $matches[1]; |
2854 $fieldtype = $matches[1]; |
2751 $fieldtype_lowercased = strtolower( $fieldtype ); |
2855 $fieldtype_lowercased = strtolower( $fieldtype ); |
2752 |
2856 |
2753 // Is actual field type different from the field type in query? |
2857 // Is actual field type different from the field type in query? |
2754 if ( $tablefield->Type != $fieldtype ) { |
2858 if ( $tablefield->Type != $fieldtype ) { |
2755 $do_change = true; |
2859 $do_change = true; |
2756 if ( in_array( $fieldtype_lowercased, $text_fields ) && in_array( $tablefield_type_lowercased, $text_fields ) ) { |
2860 if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) { |
2757 if ( array_search( $fieldtype_lowercased, $text_fields ) < array_search( $tablefield_type_lowercased, $text_fields ) ) { |
2861 if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) { |
2758 $do_change = false; |
2862 $do_change = false; |
2759 } |
2863 } |
2760 } |
2864 } |
2761 |
2865 |
2762 if ( in_array( $fieldtype_lowercased, $blob_fields ) && in_array( $tablefield_type_lowercased, $blob_fields ) ) { |
2866 if ( in_array( $fieldtype_lowercased, $blob_fields, true ) && in_array( $tablefield_type_lowercased, $blob_fields, true ) ) { |
2763 if ( array_search( $fieldtype_lowercased, $blob_fields ) < array_search( $tablefield_type_lowercased, $blob_fields ) ) { |
2867 if ( array_search( $fieldtype_lowercased, $blob_fields, true ) < array_search( $tablefield_type_lowercased, $blob_fields, true ) ) { |
2764 $do_change = false; |
2868 $do_change = false; |
2765 } |
2869 } |
2766 } |
2870 } |
2767 |
2871 |
2768 if ( $do_change ) { |
2872 if ( $do_change ) { |
2769 // Add a query to change the column type. |
2873 // Add a query to change the column type. |
2770 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ]; |
2874 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ]; |
|
2875 |
2771 $for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; |
2876 $for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; |
2772 } |
2877 } |
2773 } |
2878 } |
2774 |
2879 |
2775 // Get the default value from the array. |
2880 // Get the default value from the array. |
2776 if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) { |
2881 if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) { |
2777 $default_value = $matches[1]; |
2882 $default_value = $matches[1]; |
2778 if ( $tablefield->Default != $default_value ) { |
2883 if ( $tablefield->Default != $default_value ) { |
2779 // Add a query to change the column's default value |
2884 // Add a query to change the column's default value |
2780 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'"; |
2885 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'"; |
|
2886 |
2781 $for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}"; |
2887 $for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}"; |
2782 } |
2888 } |
2783 } |
2889 } |
2784 |
2890 |
2785 // Remove the field from the array (so it's not added). |
2891 // Remove the field from the array (so it's not added). |
2803 // Clear the index array. |
2910 // Clear the index array. |
2804 $index_ary = array(); |
2911 $index_ary = array(); |
2805 |
2912 |
2806 // For every index in the table. |
2913 // For every index in the table. |
2807 foreach ( $tableindices as $tableindex ) { |
2914 foreach ( $tableindices as $tableindex ) { |
|
2915 $keyname = strtolower( $tableindex->Key_name ); |
2808 |
2916 |
2809 // Add the index to the index data array. |
2917 // Add the index to the index data array. |
2810 $keyname = strtolower( $tableindex->Key_name ); |
|
2811 $index_ary[ $keyname ]['columns'][] = array( |
2918 $index_ary[ $keyname ]['columns'][] = array( |
2812 'fieldname' => $tableindex->Column_name, |
2919 'fieldname' => $tableindex->Column_name, |
2813 'subpart' => $tableindex->Sub_part, |
2920 'subpart' => $tableindex->Sub_part, |
2814 ); |
2921 ); |
2815 $index_ary[ $keyname ]['unique'] = ( $tableindex->Non_unique == 0 ) ? true : false; |
2922 $index_ary[ $keyname ]['unique'] = ( 0 == $tableindex->Non_unique ) ? true : false; |
2816 $index_ary[ $keyname ]['index_type'] = $tableindex->Index_type; |
2923 $index_ary[ $keyname ]['index_type'] = $tableindex->Index_type; |
2817 } |
2924 } |
2818 |
2925 |
2819 // For each actual index in the index array. |
2926 // For each actual index in the index array. |
2820 foreach ( $index_ary as $index_name => $index_data ) { |
2927 foreach ( $index_ary as $index_name => $index_data ) { |
2821 |
2928 |
2822 // Build a create string to compare to the query. |
2929 // Build a create string to compare to the query. |
2823 $index_string = ''; |
2930 $index_string = ''; |
2824 if ( $index_name == 'primary' ) { |
2931 if ( 'primary' === $index_name ) { |
2825 $index_string .= 'PRIMARY '; |
2932 $index_string .= 'PRIMARY '; |
2826 } elseif ( $index_data['unique'] ) { |
2933 } elseif ( $index_data['unique'] ) { |
2827 $index_string .= 'UNIQUE '; |
2934 $index_string .= 'UNIQUE '; |
2828 } |
2935 } |
2829 if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) { |
2936 if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) { |
2850 |
2957 |
2851 // Add the column list to the index create string. |
2958 // Add the column list to the index create string. |
2852 $index_string .= " ($index_columns)"; |
2959 $index_string .= " ($index_columns)"; |
2853 |
2960 |
2854 // Check if the index definition exists, ignoring subparts. |
2961 // Check if the index definition exists, ignoring subparts. |
2855 if ( ! ( ( $aindex = array_search( $index_string, $indices_without_subparts ) ) === false ) ) { |
2962 $aindex = array_search( $index_string, $indices_without_subparts, true ); |
|
2963 if ( false !== $aindex ) { |
2856 // If the index already exists (even with different subparts), we don't need to create it. |
2964 // If the index already exists (even with different subparts), we don't need to create it. |
2857 unset( $indices_without_subparts[ $aindex ] ); |
2965 unset( $indices_without_subparts[ $aindex ] ); |
2858 unset( $indices[ $aindex ] ); |
2966 unset( $indices[ $aindex ] ); |
2859 } |
2967 } |
2860 } |
2968 } |
2861 } |
2969 } |
2862 |
2970 |
2863 // For every remaining index specified for the table. |
2971 // For every remaining index specified for the table. |
2864 foreach ( (array) $indices as $index ) { |
2972 foreach ( (array) $indices as $index ) { |
2865 // Push a query line into $cqueries that adds the index to that table. |
2973 // Push a query line into $cqueries that adds the index to that table. |
2866 $cqueries[] = "ALTER TABLE {$table} ADD $index"; |
2974 $cqueries[] = "ALTER TABLE {$table} ADD $index"; |
|
2975 |
2867 $for_update[] = 'Added index ' . $table . ' ' . $index; |
2976 $for_update[] = 'Added index ' . $table . ' ' . $index; |
2868 } |
2977 } |
2869 |
2978 |
2870 // Remove the original table creation query from processing. |
2979 // Remove the original table creation query from processing. |
2871 unset( $cqueries[ $table ], $for_update[ $table ] ); |
2980 unset( $cqueries[ $table ], $for_update[ $table ] ); |
2947 'wp-comments.php' => 'comments.php', |
3056 'wp-comments.php' => 'comments.php', |
2948 'wp-comments-popup.php' => 'comments-popup.php', |
3057 'wp-comments-popup.php' => 'comments-popup.php', |
2949 ); |
3058 ); |
2950 |
3059 |
2951 foreach ( $files as $oldfile => $newfile ) { |
3060 foreach ( $files as $oldfile => $newfile ) { |
2952 if ( $oldfile == 'index.php' ) { |
3061 if ( 'index.php' === $oldfile ) { |
2953 $oldpath = $home_path; |
3062 $oldpath = $home_path; |
2954 } else { |
3063 } else { |
2955 $oldpath = ABSPATH; |
3064 $oldpath = ABSPATH; |
2956 } |
3065 } |
2957 |
3066 |
2958 // Check to make sure it's not a new index. |
3067 // Check to make sure it's not a new index. |
2959 if ( $oldfile == 'index.php' ) { |
3068 if ( 'index.php' === $oldfile ) { |
2960 $index = implode( '', file( "$oldpath/$oldfile" ) ); |
3069 $index = implode( '', file( "$oldpath/$oldfile" ) ); |
2961 if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) { |
3070 if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) { |
2962 if ( ! @copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) { |
3071 if ( ! copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) { |
2963 return false; |
3072 return false; |
2964 } |
3073 } |
2965 |
3074 |
2966 // Don't copy anything. |
3075 // Don't copy anything. |
2967 continue; |
3076 continue; |
2968 } |
3077 } |
2969 } |
3078 } |
2970 |
3079 |
2971 if ( ! @copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) { |
3080 if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) { |
2972 return false; |
3081 return false; |
2973 } |
3082 } |
2974 |
3083 |
2975 chmod( "$site_dir/$newfile", 0777 ); |
3084 chmod( "$site_dir/$newfile", 0777 ); |
2976 |
3085 |
3018 * |
3127 * |
3019 * @since 1.5.0 |
3128 * @since 1.5.0 |
3020 * |
3129 * |
3021 * @param string $theme_name The name of the theme. |
3130 * @param string $theme_name The name of the theme. |
3022 * @param string $template The directory name of the theme. |
3131 * @param string $template The directory name of the theme. |
3023 * @return false|void |
3132 * @return void|false |
3024 */ |
3133 */ |
3025 function make_site_theme_from_default( $theme_name, $template ) { |
3134 function make_site_theme_from_default( $theme_name, $template ) { |
3026 $site_dir = WP_CONTENT_DIR . "/themes/$template"; |
3135 $site_dir = WP_CONTENT_DIR . "/themes/$template"; |
3027 $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME; |
3136 $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME; |
3028 |
3137 |
3029 // Copy files from the default theme to the site theme. |
3138 // Copy files from the default theme to the site theme. |
3030 //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css'); |
3139 // $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' ); |
3031 |
3140 |
3032 $theme_dir = @ opendir( $default_dir ); |
3141 $theme_dir = @opendir( $default_dir ); |
3033 if ( $theme_dir ) { |
3142 if ( $theme_dir ) { |
3034 while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) { |
3143 while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) { |
3035 if ( is_dir( "$default_dir/$theme_file" ) ) { |
3144 if ( is_dir( "$default_dir/$theme_file" ) ) { |
3036 continue; |
3145 continue; |
3037 } |
3146 } |
3038 if ( ! @copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) { |
3147 if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) { |
3039 return; |
3148 return; |
3040 } |
3149 } |
3041 chmod( "$site_dir/$theme_file", 0777 ); |
3150 chmod( "$site_dir/$theme_file", 0777 ); |
3042 } |
3151 } |
3043 } |
3152 |
3044 @closedir( $theme_dir ); |
3153 closedir( $theme_dir ); |
|
3154 } |
3045 |
3155 |
3046 // Rewrite the theme header. |
3156 // Rewrite the theme header. |
3047 $stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) ); |
3157 $stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) ); |
3048 if ( $stylelines ) { |
3158 if ( $stylelines ) { |
3049 $f = fopen( "$site_dir/style.css", 'w' ); |
3159 $f = fopen( "$site_dir/style.css", 'w' ); |
3069 umask( 0 ); |
3179 umask( 0 ); |
3070 if ( ! mkdir( "$site_dir/images", 0777 ) ) { |
3180 if ( ! mkdir( "$site_dir/images", 0777 ) ) { |
3071 return false; |
3181 return false; |
3072 } |
3182 } |
3073 |
3183 |
3074 $images_dir = @ opendir( "$default_dir/images" ); |
3184 $images_dir = @opendir( "$default_dir/images" ); |
3075 if ( $images_dir ) { |
3185 if ( $images_dir ) { |
3076 while ( ( $image = readdir( $images_dir ) ) !== false ) { |
3186 while ( ( $image = readdir( $images_dir ) ) !== false ) { |
3077 if ( is_dir( "$default_dir/images/$image" ) ) { |
3187 if ( is_dir( "$default_dir/images/$image" ) ) { |
3078 continue; |
3188 continue; |
3079 } |
3189 } |
3080 if ( ! @copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) { |
3190 if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) { |
3081 return; |
3191 return; |
3082 } |
3192 } |
3083 chmod( "$site_dir/images/$image", 0777 ); |
3193 chmod( "$site_dir/images/$image", 0777 ); |
3084 } |
3194 } |
3085 } |
3195 |
3086 @closedir( $images_dir ); |
3196 closedir( $images_dir ); |
|
3197 } |
3087 } |
3198 } |
3088 |
3199 |
3089 /** |
3200 /** |
3090 * Creates a site theme. |
3201 * Creates a site theme. |
3091 * |
3202 * |
3092 * {@internal Missing Long Description}} |
3203 * {@internal Missing Long Description}} |
3093 * |
3204 * |
3094 * @since 1.5.0 |
3205 * @since 1.5.0 |
3095 * |
3206 * |
3096 * @return false|string |
3207 * @return string|false |
3097 */ |
3208 */ |
3098 function make_site_theme() { |
3209 function make_site_theme() { |
3099 // Name the theme after the blog. |
3210 // Name the theme after the blog. |
3100 $theme_name = __get_option( 'blogname' ); |
3211 $theme_name = __get_option( 'blogname' ); |
3101 $template = sanitize_title( $theme_name ); |
3212 $template = sanitize_title( $theme_name ); |