Skip to content

Instantly share code, notes, and snippets.

@afuggetta
Created June 10, 2015 16:45
Show Gist options
  • Save afuggetta/75f1dde5e26af0277272 to your computer and use it in GitHub Desktop.
Save afuggetta/75f1dde5e26af0277272 to your computer and use it in GitHub Desktop.
/**
* THOSE FUNCTIONS ARE TEMPORARY @todo: TO REMOVE
*/
/*
* Creating Guest authors from users
*/
$users = get_users();
$created = 0;
$skipped = 0;
foreach( $users as $user ) {
$result = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $user->ID );
if ( is_wp_error( $result ) ) {
$skipped++;
} else {
$created++;
}
}
global $wpdb;
$defaults = array(
'user_login' => '',
'coauthor' => '',
);
$assoc_args['user_login'] = 'mesoto';
$assoc_args['coauthor'] = 'mesoto';
$user = get_user_by( 'login', $assoc_args['user_login'] );
$coauthor = $coauthors_plus->get_coauthor_by( 'login', $assoc_args['coauthor'] );
if ( ! $user )
wp_die( __( 'Please specify a valid user_login', 'co-authors-plus' ) );
if ( ! $coauthor )
wp_die( __( 'Please specify a valid co-author login', 'co-authors-plus' ) );
$post_types = implode( "','", $coauthors_plus->supported_post_types );
$posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author=%d AND post_type IN ('$post_types')", $user->ID ) );
$affected = 0;
foreach( $posts as $post_id ) {
if ( $coauthors = wp_get_post_terms( $post_id, $coauthors_plus->coauthor_taxonomy ) ) {
continue;
}
$coauthors_plus->add_coauthors( $post_id, array( $coauthor->user_login ) );
$affected++;
if ( $affected && $affected % 20 == 0 )
sleep( 5 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment