[wp-trac] [WordPress Trac] #48878: 5.1 wp_insert_site bug

WordPress Trac noreply at wordpress.org
Wed Dec 4 16:33:46 UTC 2019


#48878: 5.1 wp_insert_site bug
--------------------------+-----------------------------
 Reporter:  bikecrazyy    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The action hook `wp_insert_site` will not allow wp_insert_post() to be
 ran.
 wp_insert_site() will return '''Could not insert post into the database:
 Table "wordpress.wp_9_posts" doesn't exist'''

 The old action 'wpmu_new_blog' works with wp_insert_post() in it.

 Working with old action hook `wpmu_new_blog`
 {{{#!php
 <?php
 add_action(
         'wpmu_new_blog',
         function ( $blog_id ) {

                 switch_to_blog( $blog_id );

                 $home_page_id = wp_insert_post(
                         array(
                                 'post_title'    => 'Home',
                                 'post_name'     => 'home',
                                 'post_content'  => '',
                                 'post_status'   => 'publish',
                                 'post_author'   => 1,
                                 'post_type'     => 'page',
                                 'page_template' => 'page-
 templates/location_home.php',
                         )
                         , true);
                 echo 'dump:';
                 var_dump($home_page_id);

                 restore_current_blog();
     }
 );
 }}}

 This fails, using new action hook 'wp_insert_site'.

 {{{#!php
 <?php
 add_action(
         'wp_insert_site',
         function ( $wp_site ) {

                 switch_to_blog( $wp_site->blog_id );

                 $home_page_id = wp_insert_post(
                         array(
                                 'post_title'    => 'Home',
                                 'post_name'     => 'home',
                                 'post_content'  => '',
                                 'post_status'   => 'publish',
                                 'post_author'   => 1,
                                 'post_type'     => 'post'
                         )
                         , true);
                 echo 'dump:';
                 var_dump($home_page_id);

                 restore_current_blog();
         }
 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48878>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list