Last active
November 18, 2017 23:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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