该代码在本地多站点测试中进行了测试。看起来还可以,但发现了一个小问题:
-运行后,所有草稿/挂起的帖子都会从列表页中消失,但刷新后会再次出现,不知道为什么。。。
虽然我相信这是无害的,但请在运行此之前备份您的数据库
/*
* Turn off trackback/pingbacks and comments on all existing multisite sites
*
* Important: Run Only Once, visit any admin page and delete/disable the hook
*
*/
add_action(\'admin_init\',\'wpse_55209_run_only_once\');
function wpse_55209_run_only_once()
{
global $wpdb;
$blogs = $wpdb->get_results("
SELECT blog_id
FROM {$wpdb->blogs}
WHERE site_id = \'{$wpdb->siteid}\'
AND spam = \'0\'
AND deleted = \'0\'
AND archived = \'0\'
AND mature = \'0\'
AND public = \'1\'
");
foreach ($blogs as $blog)
{
update_blog_option($blog->blog_id, \'default_ping_status\', \'closed\');
update_blog_option($blog->blog_id, \'default_pingback_flag\', \'closed\');
update_blog_option($blog->blog_id, \'default_comment_status\', \'closed\');
switch_to_blog( $blog->blog_id );
$wpdb->set_blog_id($blog->blog_id);
$allposts = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status != \'inherit\'" );
foreach( $allposts as $pt )
{
$my_post = array();
$my_post[\'ID\'] = $pt->ID;
$my_post[\'comment_status\'] = \'closed\';
$my_post[\'ping_status\'] = \'closed\';
wp_update_post( $my_post );
}
}
}