0

How do I prevent the creation of these when creating a new Multisite?

Everytime I create a new multisite this gets created:

  • Hello World
  • Sample Page
  • A sample Comment

I tried adding this to the functions.php

add_action( 'wpmu_new_blog', 'delete_wordpress_defaults', 100, 1 );

function delete_wordpress_defaults(){

// 'Hello World!' post
wp_delete_post( 1, true );

// 'Sample page' page
wp_delete_post( 2, true );
}

It still created Hello world and Sample page. And I don't know how to disable the sample comment.

2 Answers 2

1

When you create a new site with multisite WP does not automatically change the context. So your action is added to the current site, not the new site. You have to switch first. Like this:

add_action ('wpmu_new_blog', 'wpse296303_delete_wordpress_defaults', 100, 1);

function wpse296303_delete_wordpress_defaults ($blog_id, $user_id, $domain, $path, $site_id, $meta) {
  // Switch to the newly created blog
  switch_to_blog ($blog_id);
  // Delete 'Hello World!' post
  wp_delete_post (1, true);
  // Delete 'Sample page' page
  wp_delete_post (2, true);
  // Delete 'Sample comment' page
  wp_delete_comment (1, true)
  }

I'm not sure if the ID of the default comment is 1, so you'd have to check that.

2
  • I'm not completely sure I understand. Do I have to do something else than adding this to my functions.php file? And creating a new site will not create this? What do you mean with "You have to switch first"? I tried adding this code (checked that comment id 1 is correct) and added the ending ";" after comment line. It did not work, I got a white screen when creating a new site. The site was created, but the sample post/pages/comments where there!
    – jockebq
    Commented Mar 9, 2018 at 11:59
  • Code is always executed in the context of the current site. So if you put the snippet in the functions.php of site A, which is active when you create site B, it will be executed on site A and delete the posts on site A. So you have to switch to site B first then and the delete the posts. If you put the snippet in the functions.php of site B it will only be executed after the theme was activated. That might be after the posts have been created. You can use switch_theme after switchting the blog to activate the functions file.
    – cjbj
    Commented Mar 11, 2018 at 12:08
0

best luck i got:

/public_html/wp-includes/widgets/class-wp-widget-meta.php \public_html\wp-admin\includes\schema.php /public_html\wp-admin\includes\upgrade.php

deleteing code of post comment page url etc. 5.1.11

yes after update they might be restored but you will know where to fix up again.

5
  • Modifying core code is a bad idea. As you've pointed out, your changes will be undone when WordPress is updated.
    – Pat J
    Commented Jan 4, 2022 at 14:09
  • as i noticed those files unchanged 3-4 years Commented Jan 5, 2022 at 19:10
  • That may be true, but every WordPress update will reset them anyway.
    – Rup
    Commented Jan 6, 2022 at 10:32
  • as there are no info how this is best what i found over weeks of reserch Commented Jan 7, 2022 at 12:26
  • you can always make backup of both. edited and original file. and if will change you will see where what to edit. Commented Jan 7, 2022 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.