最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Prevent Multisite from creating sample page, sample post and sample comments

programmeradmin3浏览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.

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.

Share Improve this question edited Mar 9, 2018 at 10:50 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Mar 9, 2018 at 10:21 jockebqjockebq 4631 gold badge6 silver badges18 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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.

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.

发布评论

评论列表(0)

  1. 暂无评论