• Resolved shaalan

    (@shaalan)


    Greetings. Working swimmingly and want to move our publication to this new workflow, but…

    When we move posts through Gdocs to WordPress, an author is assigned, and it seems the assignment is random. Today using my Google Drive, I created a document and moved it through and Docs to WP did it’s thing just fine. But when logging into WP, I saw the author of the post was one of our other team members who had not participated in the process at all.

    How does WP determine the author of a post submitted through GDrive? How can I make it, either accurately reflect the owner of the document, or default to a particular author for all docs?

    Thanks,

    N*

    http://wordpress.org/extend/plugins/docs-to-wordpress/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter shaalan

    (@shaalan)

    Is no one else having this issue? It’s really odd. I have created 4 or 5 new documents and each one moved to wordpress with a different post author. Baffling.

    Plugin Author William P. Davis

    (@wpdavis)

    Hi Nadine!

    The plugin should look for a username in WordPress that matches the username in docs. This works best with Google Apps. So if your email address is me@myapps.domain, you’d want your WordPress username to be me. In my case, my email address is wdavis@bangordailynews.com, so my WordPress username is wdavis.

    You can modify the default behavior in a few ways, though.

    I should warn you these code snippets are untested, but they should get you pointed in the right direction.

    You can set a default author for each post like so:

    add_filter( 'pre_docs_to_wp_insert', 'dtwp_fix_author' );
    function dtwp_fix_author( $post_array = array() ) {
    
    	//Where post_author equals the ID of the default author
    	$post_array[ 'post_author' ] = 1;
    
    	return $post_array;
    
    }

    At the BDN, we use a comment to override the default author. We simply leave a comment like this:

    byline:username

    You can do that if you’re using the clean extender like so:

    add_filter( 'pre_docs_to_wp_insert', 'dtwp_byline_from_comments', 25, 1 );
    function dtwp_byline_from_comments( $post_array ) {	
    
    	$comments = explode( "</span>", $post_array[ 'custom_fields' ][ '_gdocs_comments' ] );
    	foreach( $comments as $line ) {
    		if( substr( trim( strip_tags( strtolower( $line ) ) ), 0, 7 ) == "byline:" )
    			$post_array[ 'custom_fields' ][ 'byline' ] = trim( str_ireplace( 'byline:', '', strip_tags( $line ) ) );
    	}
    
    	if( !empty( $post_array[ 'custom_fields' ][ 'byline' ] ) && false != ( $user = get_user_by( 'login', $post_array[ 'custom_fields' ][ 'byline' ] ) && is_object( $user ) ) ) {
    		$post_array[ 'post_author' ] = $user->ID;
    		unset( $post_array[ 'custom_fields' ][ 'byline' ] );
    	}
    
    	return $post_array;
    
    }

    Let me know if you have any questions.

    Thread Starter shaalan

    (@shaalan)

    Well an email address is difficult to change and the WP user name is impossible to change. Given that I’m new to coding, I’m not confident about where to put the above snippet or what to do with it. (I don’t use the clean extender.)

    In the meantime, we are manually changing the author of each post. (Not very efficient.)

    If you, or someone, can give me the step-by-step, I’d be grateful. If not, I understand.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Random Author Assigned’ is closed to new replies.