WordPress.org

Ready to get started?Download WordPress

Forums

WP to Twitter
Using WP to Twitter with Auto YouTube Video Posts plugin - hack to fix issue (1 post)

  1. wspencer
    Member
    Posted 2 years ago #

    I currently use this plugin to auto post all of one of my sites new posts to Twitter. However, I also use another plugin called Automatic YouTube Video Posts plugin. The AYTVP plugin automatically creates a new post on the site whenever one of several YouTube accounts uploads a new video.

    http://wordpress.org/extend/plugins/automatic-youtube-video-posts/

    The issue I had was the AYTVP plugin only allows you to use one default author for the newly created posts. So even though I had several people creating videos, when posted to Twitter it always appeared as if the same author was creating each video. Trying to make sure I gave credit where it was due, I edited the WP to Twitter plugin to alter the #account# short code if the new post was in a certain category...in this case, "videos".

    So since I got the plugins working nicely together, I thought I'd share the code for others to use as well. Please let me know if you have any questions.

    The file I altered was wp-to-twitter.php

    Around line 322, you should see something that says

    if ( get_option( 'jd_individual_twitter_users' ) == 1 ) {
    if ( get_user_meta( $auth, 'wtt_twitter_username', true ) == '' ) {
    					if ( get_user_meta( $auth, 'wp-to-twitter-enable-user',true ) == 'mainAtTwitter' ) {
    						$thisaccount = "@" . stripcslashes(get_user_meta( $auth, 'wp-to-twitter-user-username',true ));
    					}
    					else if ( get_user_meta( $auth, 'wp-to-twitter-enable-user',true ) == 'mainAtTwitterPlus' ) {
    						$thisaccount = "@" . stripcslashes(get_user_meta( $auth, 'wp-to-twitter-user-username',true ) . ' @' . get_option( 'wtt_twitter_username' ));
    					} }

    This statement checks to see if the options the user has selected allows the posting of individual author's Twitter accounts. I replaced the above code block with the following....

    if ( get_option( 'jd_individual_twitter_users' ) == 1 ) {
    
    		/* Start custom editing for use with Auto YouTube Post plugin here
    		** Hack checks post category and if it is a "video" it will grab the post meta that holds the YouTube account name
    		** Then that YouTube account name is matched with the Twittter account of the video creator
    		** Twitter account of video creator is then going to be used for the #account# short tag  */
    
    		$vid_category = get_the_category( $post_ID );
    		$video_author = get_post_meta ( $post_ID, '_tern_wp_youtube_author', true );
    
    		if ( $vid_category[0]->slug == 'videos' ) {
    
    			switch ( $video_author ) {
    
    			case 'YTAccount1':
    
    				$thisaccount = "@" . stripcslashes(get_user_meta( 31, 'wp-to-twitter-user-username',true ));
    
    				break;
    
    			case 'YTAccount2':
    
    				$thisaccount = "@" . stripcslashes(get_user_meta( 31, 'wp-to-twitter-user-username',true ));
    
    				break;
    
    			case 'YTAccount3':
    
    				$thisaccount = "@" . stripcslashes(get_user_meta( 25, 'wp-to-twitter-user-username',true ));
    
    				break;
    			}
    		}
    
    		/* End of custom hack
    		** To restore, eliminate the else brackets below */
    
    		else {
    				if ( get_user_meta( $auth, 'wtt_twitter_username', true ) == '' ) {
    					if ( get_user_meta( $auth, 'wp-to-twitter-enable-user',true ) == 'mainAtTwitter' ) {
    						$thisaccount = "@" . stripcslashes(get_user_meta( $auth, 'wp-to-twitter-user-username',true ));
    					}
    					else if ( get_user_meta( $auth, 'wp-to-twitter-enable-user',true ) == 'mainAtTwitterPlus' ) {
    						$thisaccount = "@" . stripcslashes(get_user_meta( $auth, 'wp-to-twitter-user-username',true ) . ' @' . get_option( 'wtt_twitter_username' ));
    					}
    				}
    		}
    	}

    Here's a basic breakdown of what the code does.....

    First it checks to see if the post is in the Video category

    If it is, it grabs the post meta in the _tern_wp_youtube_author meta field. This is the field that the AYTVP plugin stores the YouTube Account name for the video that is being uploaded/pulled into the WordPress site. The info from that field is then saved in a variable.

    A switch statement checks to see if that variable is equal to different account names. The code above uses generic account names like "YTAccount1". You can obviously replace that with your own account names if you plan on using this.

    If there's a match in the switch statement, it sets the $thisaccount variable to equal the Twitter account name of the author that is the owner of the YouTube account that created the video. As you can see above, one author has multiple YouTube accounts that are uploading videos. You'll have to change the first parameter of the get_user_meta function to the author ID that corresponds to the author you're trying to match the YouTube account up with.

    The end result changes the #account# short code that you use in the WP to Twitter settings page to use the Twitter account of the person that created and uploaded the video to YouTube, rather than the Twitter account of the author of the post the AYTVP plugin creates.

    Since the AYTVP plugin uses a pretty good amount of Javascript, I decided that it was much easier to edit the WP to Twitter code to meet my needs.

    So yeah....just thought I'd share. If you have any questions for me, please let me know and I'd be happy to help.

    http://wordpress.org/extend/plugins/wp-to-twitter/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.