Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Last active November 18, 2017 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bappi-d-great/f4d6e4de373b010ce294 to your computer and use it in GitHub Desktop.
Save bappi-d-great/f4d6e4de373b010ce294 to your computer and use it in GitHub Desktop.
Change post author to subsite admin if the author is super admin
<?php
add_action( 'admin_init', 'change_author_cb' );
function change_author_cb() {
//$sites = wp_get_sites();
// Set super admin ID here
$super_admin_id = 1;
//foreach( $sites as $site ){
for( $i = 2; $i <= 10; $i++ ) {
//if( $site['blog_id'] == 1 ) continue;
switch_to_blog( $site['blog_id'] );
$args = array(
'posts_per_page' => -1,
'post_status' => 'publish',
'post_author' => $super_admin_id,
);
$posts = get_posts( $args );
$admin = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
foreach( $posts as $post ){
$my_post = array(
'ID' => $post->ID,
'post_author' => $admin->ID
);
wp_update_post( $my_post );
}
restore_current_blog();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment