WP to Twitter extension for qTranslateExtension de WP to Twitter para qTranslate

In the [intlink id="193" type="post"]previous post[/intlink] I commented the fact that WordPressready is using the qTranslate plugin to handle english and spanish languages. For the other hand the  WP to Twitter plugin sends messages in every post. Both plugins are very good indeed.

There is a small problem though. Wp to Twitter compose the message from the post title, which is ok except when the qTranslate plugin is installed. qTranslate uses a custom tag to separate languages inside the post title , for example:

This is an post title

WP to Twitter is doing the best it can to interpreting the title, supressing the customized tags to finally get:

This is an post titleEste es el título de una entrada

what is pretty ugly.

It could be nice if there is a simple way to solve it , don’t you think? Some kind of filter/action to handle this situation…

Ok, i’m still working on it. For the moment, I know where to put some filters, but remember this is a work in progress.

For the moment I did some code modification to WP to Twitter code so it will send a twitter message for every language set in the blog. This modification will work only when a post is created/updated (it won’t work when a page is created or when I post from xmlrpc). As I said, is a work in progress.

WP to Twitter hace lo mejor que puede para interpretar este título, eliminando los tags customizados, para obtener finalmente:

This is an post titleEste es el título de una entrada

lo cual deja bastante que desear.

Estaría mejor que WP to Twitter tuviera una manera sencilla de resolver esto verdad? Alguna posibilidad de filtro/action para manejar cierta customizacion…

Ok, todavía estoy trabajando en eso. Por lo pronto ya se donde poner algunos filtros, pero este es un trabajo en curso.

Mientras tanto realicé una modificación en el código del plugin WP to Twitter para que este envie un twitter por cada lenguaje que esté seteado en el blog. Esta modificación solamente afecta al plugin cuando se crea un post (si se crea una página o se trabaja por xmlrpc el es ignorado). Como les comento, es un trabajo en progreso.

Wp to Twitter: some details

This plugin solves every aspect of messaging to Twitter isolating every case: if you create a post, if you create a page, if you use xmlrpc, if you create a link, etc. etc.

jd_twit is a function to create a twit when a post is made. I modified the method to take in count the qTranslate format. So before the changes:

function jd_twit( $post_ID ) {
	$jd_tweet_this = get_post_meta( $post_ID, '_jd_tweet_this', TRUE);
	if ( $jd_tweet_this != "no" ) {
		$jd_post_info = jd_post_info( $post_ID );
	    $sentence = '';
		$customTweet = stripcslashes( trim( $_POST['_jd_twitter'] ) );
		if ( ( $jd_post_info['postStatus'] == 'publish' || $_POST['publish'] == 'Publish') && ($_POST['prev_status'] == 'draft' || $_POST['original_post_status'] == 'draft' || $_POST['prev_status'] == 'pending' || $_POST['original_post_status'] =='pending' || $_POST['original_post_status'] == 'auto-draft' ) ) {
		// publish new post
				if ( get_option( 'newpost-published-update' ) == '1' ) {
					$nptext = stripcslashes( get_option( 'newpost-published-text' ) );
					$newpost = true;
				}
		} else if ( (( $_POST['originalaction'] == "editpost" ) && ( ( $_POST['prev_status'] == 'publish' ) || ($_POST['original_post_status'] == 'publish') ) ) && $jd_post_info['postStatus'] == 'publish') {
				// if this is an old post and editing updates are enabled
				if ( get_option( 'oldpost-edited-update') == '1' ) {
				    $nptext = stripcslashes( get_option( 'oldpost-edited-text' ) );
					$oldpost = true;
				}
		}
		if ($newpost || $oldpost) {
			$sentence = ( $customTweet != "" ) ? $customTweet : $nptext;
			if ($jd_post_info['shortUrl'] != '') {
				$shrink = $jd_post_info['shortUrl'];
			} else {
				$shrink = jd_shorten_link( $jd_post_info['postLink'], $jd_post_info['postTitle'], $post_ID );
				store_url( $post_ID, $shrink );
			}
			$sentence = custom_shortcodes( $sentence, $post_ID );
			$sentence = jd_truncate_tweet( $sentence, $jd_post_info['postTitle'], $jd_post_info['blogTitle'], $jd_post_info['postExcerpt'], $shrink, $jd_post_info['category'], $jd_post_info['postDate'], $post_ID, $jd_post_info['authId'] );
		}

		if ( $sentence != '' ) {
			if ( get_option('limit_categories') == '0' || in_allowed_category( $jd_post_info['categoryIds'] ) ) {
				$sendToTwitter = ( get_option( 'x_jd_api_post_status' ) == '' )?jd_doTwitterAPIPost( $sentence ):jd_doUnknownAPIPost( $sentence, $jd_post_info['authId']  );
				if ( $sendToTwitter == false ) {
					update_post_meta( $post_ID,'_jd_wp_twitter',urldecode( $sentence ) );
					update_option( 'wp_twitter_failure','1' );
				}
			}
		}
	}
	return $post_ID;
}

and now:

function jd_twit( $post_ID ) {
	$jd_tweet_this = get_post_meta( $post_ID, '_jd_tweet_this', TRUE);
	if ( $jd_tweet_this != "no" ) {
		$jd_post_info = jd_post_info( $post_ID );
	    $sentence = '';
		$customTweet = stripcslashes( trim( $_POST['_jd_twitter'] ) );
		if ( ( $jd_post_info['postStatus'] == 'publish' || $_POST['publish'] == 'Publish') && ($_POST['prev_status'] == 'draft' || $_POST['original_post_status'] == 'draft' || $_POST['prev_status'] == 'pending' || $_POST['original_post_status'] =='pending' || $_POST['original_post_status'] == 'auto-draft' ) ) {
		// publish new post
				if ( get_option( 'newpost-published-update' ) == '1' ) {
					$nptext = stripcslashes( get_option( 'newpost-published-text' ) );
					$newpost = true;
				}
		} else if ( (( $_POST['originalaction'] == "editpost" ) && ( ( $_POST['prev_status'] == 'publish' ) || ($_POST['original_post_status'] == 'publish') ) ) && $jd_post_info['postStatus'] == 'publish') {
				// if this is an old post and editing updates are enabled
				if ( get_option( 'oldpost-edited-update') == '1' ) {
				    $nptext = stripcslashes( get_option( 'oldpost-edited-text' ) );
					$oldpost = true;
				}
		}
		if ($newpost || $oldpost) {
			$sentence = ( $customTweet != "" ) ? $customTweet : $nptext;
			if ($jd_post_info['shortUrl'] != '') {
				$shrink = $jd_post_info['shortUrl'];
			} else {
				$shrink = jd_shorten_link( $jd_post_info['postLink'], $jd_post_info['postTitle'], $post_ID );
				store_url( $post_ID, $shrink );
			}
			$sentence = custom_shortcodes( $sentence, $post_ID );
            $mybuffer= $sentence; //remember this data, we'll use it later					

            /* Begin Changes|Comienzo de Cambios**********************************/
            //pattern for qTranslate|Expresión regular para los patrones de qTranslate
            $regexp="/(.*)/U";
            //Return languages in the posttitle in array | Devolver todos los lenguajes en un array
            preg_match_all($regexp,$jd_post_info['postTitle'],$matches,PREG_PATTERN_ORDER);
            $counter=0;
            if (empty($matches[0])) //no matches maybe plugin deactivated| sin coincidencias tal vez plugin desactivado
            {
               //Proceed as usual | Proceder como es usual
                $sentence = jd_truncate_tweet( $sentence, $jd_post_info['postTitle'], $jd_post_info['blogTitle'], $jd_post_info['postExcerpt'], $shrink, $jd_post_info['category'], $jd_post_info['postDate'], $post_ID, $jd_post_info['authId'] );
        		if ( $sentence != '' ) {
        			if ( get_option('limit_categories') == '0' || in_allowed_category( $jd_post_info['categoryIds'] ) ) {
        				$sendToTwitter = ( get_option( 'x_jd_api_post_status' ) == '' )?jd_doTwitterAPIPost( $sentence ):jd_doUnknownAPIPost( $sentence, $jd_post_info['authId']  );
        				if ( $sendToTwitter == false ) {
        					update_post_meta( $post_ID,'_jd_wp_twitter',urldecode( $sentence ) );
        					update_option( 'wp_twitter_failure','1' );
        				}
        			}
        		}
            }
            else  //We have a match| Tenemos coincidencia
            {
                //Loop for all languages| Recorrer todos los lenguajes
                while ($counter

When i thought I was finishing, I realise that ‘something’ was prefiltering the custom qTranslate tags, deleting them.  So I didn’t finish yet… :(

After some revision, I found that jd_post_info function was doing the prefilter task. I had to deactivate this behavior and for the other to be sure that the text in every language was correctly processed (get rid of html tags). That is the mission of qTranslateStripTags.

Before:

function jd_post_info( $post_ID ) {
	$get_post_info = get_post( $post_ID );
	$values = array();
	// get post author
	$values['authId'] = $get_post_info->post_author;
		$postdate = $get_post_info->post_date;
		$dateformat = (get_option('jd_date_format')=='')?get_option('date_format'):get_option('jd_date_format');
		$thisdate = mysql2date( $dateformat,$postdate );
	$values['postDate'] = $thisdate;
	// get first category
		$category = null;
		$categories = get_the_category( $post_ID );
		if ( $categories > 0 ) {
			$category = $categories[0]->cat_name;
		}
		foreach ($categories AS $cat) {
			$category_ids[] = $cat->term_id;
		}
	$values['categoryIds'] = $category_ids;
	$values['category'] = $category;
		$excerpt_length = get_option( 'jd_post_excerpt' );
	$values['postExcerpt'] = ( trim( $get_post_info->post_excerpt ) == "" )?@mb_substr( strip_tags($get_post_info->post_content), 0, $excerpt_length ):@mb_substr( strip_tags($get_post_info->post_excerpt), 0, $excerpt_length );
	$thisposttitle =  stripcslashes( strip_tags( $get_post_info->post_title ) );
		if ($thisposttitle == "") {
			$thisposttitle =  stripcslashes( strip_tags( $_POST['title'] ) );
		}
	$values['postTitle'] = $thisposttitle;
	$values['postLink'] = external_or_permalink( $post_ID );
	$values['blogTitle'] = get_bloginfo( 'name' );
	$values['shortUrl'] = get_post_meta( $post_ID, '_wp_jd_clig', TRUE );
	$values['postStatus'] = $get_post_info->post_status;
	return $values;
}

After:

function jd_post_info( $post_ID ) {
	$get_post_info = get_post( $post_ID );
	$values = array();
	// get post author
	$values['authId'] = $get_post_info->post_author;
		$postdate = $get_post_info->post_date;
		$dateformat = (get_option('jd_date_format')=='')?get_option('date_format'):get_option('jd_date_format');
		$thisdate = mysql2date( $dateformat,$postdate );
	$values['postDate'] = $thisdate;
	// get first category
		$category = null;
		$categories = get_the_category( $post_ID );
		if ( $categories > 0 ) {
			$category = $categories[0]->cat_name;
		}
		foreach ($categories AS $cat) {
			$category_ids[] = $cat->term_id;
		}
	$values['categoryIds'] = $category_ids;
	$values['category'] = $category;
		$excerpt_length = get_option( 'jd_post_excerpt' );
	$values['postExcerpt'] = ( trim( $get_post_info->post_excerpt ) == "" )?@mb_substr( strip_tags($get_post_info->post_content), 0, $excerpt_length ):@mb_substr( strip_tags($get_post_info->post_excerpt), 0, $excerpt_length );
/*
	$thisposttitle =  stripcslashes( strip_tags( $get_post_info->post_title ) );
		if ($thisposttitle == "") {
			$thisposttitle =  stripcslashes( strip_tags( $_POST['title'] ) );
		}
*/
	$thisposttitle =  qTranslateStripTags( $get_post_info->post_title);
		if ($thisposttitle == "") {
			$thisposttitle =  qTranslateStripTags( $_POST['title'] ) ;
		}

	$values['postTitle'] = $thisposttitle;
	$values['postLink'] = external_or_permalink( $post_ID );
	$values['blogTitle'] = get_bloginfo( 'name' );
	$values['shortUrl'] = get_post_meta( $post_ID, '_wp_jd_clig', TRUE );
	$values['postStatus'] = $get_post_info->post_status;
	return $values;
}

function qTranslateStripTags($twit)
{
     $regexp='/()(.*)()/U';
    preg_match_all($regexp,$twit,$matches,PREG_PATTERN_ORDER);
    $counter=0;
    $result="";
    if (empty($matches[0]))
    {
       return $twit;
    }
    while ($counter

This last task was very boring, specially because I do little PHP programming.

If you have interest in the code you can download the wp-to-twitter.php(zip) with the changes. This file replace the original in the wp to twitter plugin. (2.2.3 version)

 

Wp to Twitter: algunos detalles

El plugin resuelve aspectos de  envio de Tweeter por separado y con rutinas por separado: si se crea una entrada, si se crea una página, si se usa xmlrpx, si se crea un link, si se crea un post con quickpress, etc. cada tarea un método por separado.

jd_twit es la función que crea un twit cuando se agrega una entrada. Modifiqué el método para tener en cuenta el formato del post creado por qTranslate:

Asi que antes:

function jd_twit( $post_ID ) {
	$jd_tweet_this = get_post_meta( $post_ID, '_jd_tweet_this', TRUE);
	if ( $jd_tweet_this != "no" ) {
		$jd_post_info = jd_post_info( $post_ID );
	    $sentence = '';
		$customTweet = stripcslashes( trim( $_POST['_jd_twitter'] ) );
		if ( ( $jd_post_info['postStatus'] == 'publish' || $_POST['publish'] == 'Publish') && ($_POST['prev_status'] == 'draft' || $_POST['original_post_status'] == 'draft' || $_POST['prev_status'] == 'pending' || $_POST['original_post_status'] =='pending' || $_POST['original_post_status'] == 'auto-draft' ) ) {
		// publish new post
				if ( get_option( 'newpost-published-update' ) == '1' ) {
					$nptext = stripcslashes( get_option( 'newpost-published-text' ) );
					$newpost = true;
				}
		} else if ( (( $_POST['originalaction'] == "editpost" ) && ( ( $_POST['prev_status'] == 'publish' ) || ($_POST['original_post_status'] == 'publish') ) ) && $jd_post_info['postStatus'] == 'publish') {
				// if this is an old post and editing updates are enabled
				if ( get_option( 'oldpost-edited-update') == '1' ) {
				    $nptext = stripcslashes( get_option( 'oldpost-edited-text' ) );
					$oldpost = true;
				}
		}
		if ($newpost || $oldpost) {
			$sentence = ( $customTweet != "" ) ? $customTweet : $nptext;
			if ($jd_post_info['shortUrl'] != '') {
				$shrink = $jd_post_info['shortUrl'];
			} else {
				$shrink = jd_shorten_link( $jd_post_info['postLink'], $jd_post_info['postTitle'], $post_ID );
				store_url( $post_ID, $shrink );
			}
			$sentence = custom_shortcodes( $sentence, $post_ID );
			$sentence = jd_truncate_tweet( $sentence, $jd_post_info['postTitle'], $jd_post_info['blogTitle'], $jd_post_info['postExcerpt'], $shrink, $jd_post_info['category'], $jd_post_info['postDate'], $post_ID, $jd_post_info['authId'] );
		}

		if ( $sentence != '' ) {
			if ( get_option('limit_categories') == '0' || in_allowed_category( $jd_post_info['categoryIds'] ) ) {
				$sendToTwitter = ( get_option( 'x_jd_api_post_status' ) == '' )?jd_doTwitterAPIPost( $sentence ):jd_doUnknownAPIPost( $sentence, $jd_post_info['authId']  );
				if ( $sendToTwitter == false ) {
					update_post_meta( $post_ID,'_jd_wp_twitter',urldecode( $sentence ) );
					update_option( 'wp_twitter_failure','1' );
				}
			}
		}
	}
	return $post_ID;
}

Y despues:

function jd_twit( $post_ID ) {
	$jd_tweet_this = get_post_meta( $post_ID, '_jd_tweet_this', TRUE);
	if ( $jd_tweet_this != "no" ) {
		$jd_post_info = jd_post_info( $post_ID );
	    $sentence = '';
		$customTweet = stripcslashes( trim( $_POST['_jd_twitter'] ) );
		if ( ( $jd_post_info['postStatus'] == 'publish' || $_POST['publish'] == 'Publish') && ($_POST['prev_status'] == 'draft' || $_POST['original_post_status'] == 'draft' || $_POST['prev_status'] == 'pending' || $_POST['original_post_status'] =='pending' || $_POST['original_post_status'] == 'auto-draft' ) ) {
		// publish new post
				if ( get_option( 'newpost-published-update' ) == '1' ) {
					$nptext = stripcslashes( get_option( 'newpost-published-text' ) );
					$newpost = true;
				}
		} else if ( (( $_POST['originalaction'] == "editpost" ) && ( ( $_POST['prev_status'] == 'publish' ) || ($_POST['original_post_status'] == 'publish') ) ) && $jd_post_info['postStatus'] == 'publish') {
				// if this is an old post and editing updates are enabled
				if ( get_option( 'oldpost-edited-update') == '1' ) {
				    $nptext = stripcslashes( get_option( 'oldpost-edited-text' ) );
					$oldpost = true;
				}
		}
		if ($newpost || $oldpost) {
			$sentence = ( $customTweet != "" ) ? $customTweet : $nptext;
			if ($jd_post_info['shortUrl'] != '') {
				$shrink = $jd_post_info['shortUrl'];
			} else {
				$shrink = jd_shorten_link( $jd_post_info['postLink'], $jd_post_info['postTitle'], $post_ID );
				store_url( $post_ID, $shrink );
			}
			$sentence = custom_shortcodes( $sentence, $post_ID );
            $mybuffer= $sentence; //remember this data, we'll use it later					

            /* Begin Changes|Comienzo de Cambios**********************************/
            //pattern for qTranslate|Expresión regular para los patrones de qTranslate
            $regexp="/(.*)/U";
            //Return languages in the posttitle in array | Devolver todos los lenguajes en un array
            preg_match_all($regexp,$jd_post_info['postTitle'],$matches,PREG_PATTERN_ORDER);
            $counter=0;
            if (empty($matches[0])) //no matches maybe plugin deactivated| sin coincidencias tal vez plugin desactivado
            {
               //Proceed as usual | Proceder como es usual
                $sentence = jd_truncate_tweet( $sentence, $jd_post_info['postTitle'], $jd_post_info['blogTitle'], $jd_post_info['postExcerpt'], $shrink, $jd_post_info['category'], $jd_post_info['postDate'], $post_ID, $jd_post_info['authId'] );
        		if ( $sentence != '' ) {
        			if ( get_option('limit_categories') == '0' || in_allowed_category( $jd_post_info['categoryIds'] ) ) {
        				$sendToTwitter = ( get_option( 'x_jd_api_post_status' ) == '' )?jd_doTwitterAPIPost( $sentence ):jd_doUnknownAPIPost( $sentence, $jd_post_info['authId']  );
        				if ( $sendToTwitter == false ) {
        					update_post_meta( $post_ID,'_jd_wp_twitter',urldecode( $sentence ) );
        					update_option( 'wp_twitter_failure','1' );
        				}
        			}
        		}
            }
            else  //We have a match| Tenemos coincidencia
            {
                //Loop for all languages| Recorrer todos los lenguajes
                while ($counter

Cuando ya consideraba el tema resuelto, me encuentro que alguna función hacía un prefiltrado de los tags y eliminaba los mismos. Asi que todavía me faltaba algo por hacer.

Luego de una revisión encontré que la función jd_post_info realizaba el prefiltrado. Lo que necesitaba era por un lado desactivar esta funcionalidad y por el otro asegurarme de que el texto en cada lenguaje tuviera un filtro que eliminara todos los tags html para evitar que estos se enviaran al Twitter:

Antes:

function jd_post_info( $post_ID ) {
	$get_post_info = get_post( $post_ID );
	$values = array();
	// get post author
	$values['authId'] = $get_post_info->post_author;
		$postdate = $get_post_info->post_date;
		$dateformat = (get_option('jd_date_format')=='')?get_option('date_format'):get_option('jd_date_format');
		$thisdate = mysql2date( $dateformat,$postdate );
	$values['postDate'] = $thisdate;
	// get first category
		$category = null;
		$categories = get_the_category( $post_ID );
		if ( $categories > 0 ) {
			$category = $categories[0]->cat_name;
		}
		foreach ($categories AS $cat) {
			$category_ids[] = $cat->term_id;
		}
	$values['categoryIds'] = $category_ids;
	$values['category'] = $category;
		$excerpt_length = get_option( 'jd_post_excerpt' );
	$values['postExcerpt'] = ( trim( $get_post_info->post_excerpt ) == "" )?@mb_substr( strip_tags($get_post_info->post_content), 0, $excerpt_length ):@mb_substr( strip_tags($get_post_info->post_excerpt), 0, $excerpt_length );
	$thisposttitle =  stripcslashes( strip_tags( $get_post_info->post_title ) );
		if ($thisposttitle == "") {
			$thisposttitle =  stripcslashes( strip_tags( $_POST['title'] ) );
		}
	$values['postTitle'] = $thisposttitle;
	$values['postLink'] = external_or_permalink( $post_ID );
	$values['blogTitle'] = get_bloginfo( 'name' );
	$values['shortUrl'] = get_post_meta( $post_ID, '_wp_jd_clig', TRUE );
	$values['postStatus'] = $get_post_info->post_status;
	return $values;
}

Despues:

function jd_post_info( $post_ID ) {
	$get_post_info = get_post( $post_ID );
	$values = array();
	// get post author
	$values['authId'] = $get_post_info->post_author;
		$postdate = $get_post_info->post_date;
		$dateformat = (get_option('jd_date_format')=='')?get_option('date_format'):get_option('jd_date_format');
		$thisdate = mysql2date( $dateformat,$postdate );
	$values['postDate'] = $thisdate;
	// get first category
		$category = null;
		$categories = get_the_category( $post_ID );
		if ( $categories > 0 ) {
			$category = $categories[0]->cat_name;
		}
		foreach ($categories AS $cat) {
			$category_ids[] = $cat->term_id;
		}
	$values['categoryIds'] = $category_ids;
	$values['category'] = $category;
		$excerpt_length = get_option( 'jd_post_excerpt' );
	$values['postExcerpt'] = ( trim( $get_post_info->post_excerpt ) == "" )?@mb_substr( strip_tags($get_post_info->post_content), 0, $excerpt_length ):@mb_substr( strip_tags($get_post_info->post_excerpt), 0, $excerpt_length );
/*
	$thisposttitle =  stripcslashes( strip_tags( $get_post_info->post_title ) );
		if ($thisposttitle == "") {
			$thisposttitle =  stripcslashes( strip_tags( $_POST['title'] ) );
		}
*/
	$thisposttitle =  qTranslateStripTags( $get_post_info->post_title);
		if ($thisposttitle == "") {
			$thisposttitle =  qTranslateStripTags( $_POST['title'] ) ;
		}

	$values['postTitle'] = $thisposttitle;
	$values['postLink'] = external_or_permalink( $post_ID );
	$values['blogTitle'] = get_bloginfo( 'name' );
	$values['shortUrl'] = get_post_meta( $post_ID, '_wp_jd_clig', TRUE );
	$values['postStatus'] = $get_post_info->post_status;
	return $values;
}

function qTranslateStripTags($twit)
{
     $regexp='/()(.*)()/U';
    preg_match_all($regexp,$twit,$matches,PREG_PATTERN_ORDER);
    $counter=0;
    $result="";
    if (empty($matches[0]))
    {
       return $twit;
    }
    while ($counter

Esto resultó bastante tedioso, especialmente porque programo PHP hace muy poco.

Quienes estén interesados en el código, pueden bajar el archivo wp-to-twitter.php(zip) donde hice los cambios. Este archivo reemplaza el original en el plugin wp to twitter (version 2.2.3)

Comments

  1. After reading your detailed and helpful post, I’ve tried to download the files and replace them at the hosting but when I did an error shows up:

    Warning: require_once(/hermes/bosoraweb181/b2067/ipw.conexioconsultingcom/public_html/wp-content/plugins/wp-to-twitter/functions.php) [function.require-once]: failed to open stream: No such file or directory in /hermes/bosoraweb181/b2067/ipw.conexioconsultingcom/public_html/wp-content/plugins/wp-to-twitter/wp-to-twitter.php on line 27

    Fatal error: require_once() [function.require]: Failed opening required ‘/hermes/bosoraweb181/b2067/ipw.conexioconsultingcom/public_html/wp-content/plugins/wp-to-twitter/functions.php’ (include_path=’.:/usr/local/lib/php-5.2.17/lib/php’) in /hermes/bosoraweb181/b2067/ipw.conexioconsultingcom/public_html/wp-content/plugins/wp-to-twitter/wp-to-twitter.php on line 27

    Could you please explain me what I did wrong?

  2. In fact, after checking out the “function jd_twit” is quite different:

    function jd_twit( $post_ID, $type=’instant’ ) {
    if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE || wp_is_post_revision($post_ID) ) { return $post_ID; }
    wpt_check_version();
    $jd_tweet_this = get_post_meta( $post_ID, ‘_jd_tweet_this’, true );
    $newpost = $oldpost = $is_inline_edit = false;
    $sentence = $template = ”;
    if ( get_option(‘wpt_inline_edits’) != 1 ) {
    if ( isset( $_POST['_inline_edit'] ) || isset( $_REQUEST['bulk_edit'] ) ) { return; }
    } else {
    if ( isset( $_POST['_inline_edit'] ) || isset( $_REQUEST['bulk_edit'] ) ) { $is_inline_edit = true; }
    }
    if ( get_option(‘jd_tweet_default’) == 0 ) {
    $test = ( $jd_tweet_this != ‘no’ ) ? true : false;
    } else {
    $test = ( $jd_tweet_this == ‘yes’ ) ? true : false;
    }
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “1: JD Tweet This Value: #$post_ID”,”Tweet this: $jd_tweet_this /”. get_option(‘jd_tweet_default’).” / $type”); // DEBUG
    }
    if ( $test ) { // test switch: depend on default settings.
    $post_info = jd_post_info( $post_ID );
    $media = wpt_post_with_media( $post_ID, $post_info );
    if ( function_exists( ‘wpt_pro_exists’ ) && wpt_pro_exists() == true ) {
    $auth = ( get_option( ‘wpt_cotweet_lock’ ) == ‘false’ || !get_option(‘wpt_cotweet_lock’) )?$post_info['authId']:get_option(‘wpt_cotweet_lock’);
    } else {
    $auth = $post_info['authId'];
    }
    /* debug data */
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “2: POST Debug Data #$post_ID”,”Post_Info: “.print_r($post_info,1).”\n\nPOST: “.print_r($_POST, 1). ” / $type” );
    }
    if ( function_exists( ‘wpt_pro_exists’ ) && wpt_pro_exists() == true && function_exists(‘wpt_filter_post_info’) ) {
    $filter = wpt_filter_post_info( $post_info );
    if ( $filter == true ) {
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “3a: Post filtered: #$post_ID”,print_r($post_info,1).” / $type”);
    }
    return false;
    }
    }
    /* Filter Tweet based on POST data — allows custom filtering of unknown plug-ins, etc. */
    $filter = apply_filters( ‘wpt_filter_post_data’, false, $_POST );
    if ( $filter ) {
    return false;
    }
    $post_type = $post_info['postType'];
    if ( $type == ‘future’ || get_post_meta( $post_ID, ‘wpt_publishing’ ) == ‘future’ ) {
    $new = 1; // if this is a future action, then it should be published regardless of relationship
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “4: Future post: #$post_ID”,print_r($post_info,1).” / $type”);
    }
    delete_post_meta( $post_ID, ‘wpt_publishing’ );
    } else {
    // if the post modified date and the post date are the same, this is new.
    // true if first date before or equal to last date
    $new = wpt_date_compare( $post_info['_postModified'], $post_info['_postDate'] );
    }
    // post is not previously published but has been backdated:
    // (post date is edited, but save option is ‘publish’)
    if ( $new == 0 && ( isset( $_POST['edit_date'] ) && $_POST['edit_date'] == 1 && !isset( $_POST['save'] ) ) ) { $new = 1; }
    // can’t catch posts that were set to a past date as a draft, then published.
    $post_type_settings = get_option(‘wpt_post_types’);
    $post_types = array_keys($post_type_settings);
    if ( in_array( $post_type, $post_types ) ) {
    // identify whether limited by category/taxonomy
    $continue = wpt_category_limit( $post_type, $post_info, $post_ID );
    if ( $continue == false ) { return; }
    // create Tweet and ID whether current action is edit or new
    $cT = get_post_meta( $post_ID, ‘_jd_twitter’, true );
    if ( isset( $_POST['_jd_twitter'] ) && $_POST['_jd_twitter'] != ” ) { $cT = $_POST['_jd_twitter']; }
    $customTweet = ( $cT != ” )?stripcslashes( trim( $cT ) ):”;
    // if ops is set and equals ‘publish’, this is being edited. Otherwise, it’s a new post.
    if ( $new == 0 || $is_inline_edit == true ) {
    // if this is an old post and editing updates are enabled
    if ( get_option( ‘jd_tweet_default_edit’ ) == 1 ) {
    $jd_tweet_this = apply_filters( ‘wpt_tweet_this_edit’, $jd_tweet_this, $_POST );
    if ( $jd_tweet_this != ‘yes’ ) { return; }
    }
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “4a: Edited post #$post_ID”,”Tweet this: “.print_r($post_info,1).” / $type”); // DEBUG
    }
    if ( $post_type_settings[$post_type]['post-edited-update'] == ‘1’ ) {
    $nptext = stripcslashes( $post_type_settings[$post_type]['post-edited-text'] );
    $oldpost = true;
    }
    } else {
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “4b: New Post #$post_ID”,”Tweet this: “.print_r($post_info,1).” / $type”); // DEBUG
    }
    if ( $post_type_settings[$post_type]['post-published-update'] == ‘1’ ) {
    $nptext = stripcslashes( $post_type_settings[$post_type]['post-published-text'] );
    $newpost = true;
    }
    }
    if ( $newpost || $oldpost ) {
    $template = ( $customTweet != “” ) ? $customTweet : $nptext;
    $sentence = jd_truncate_tweet( $template, $post_info, $post_ID );
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “5: Tweet Truncated #$post_ID”,”Truncated Tweet: $sentence / $template / $type”); // DEBUG
    }
    if ( function_exists(‘wpt_pro_exists’) && wpt_pro_exists() == true ) {
    $sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth );
    }
    }
    if ( $sentence != ” ) {
    // WPT PRO //
    if ( function_exists( ‘wpt_pro_exists’ ) && wpt_pro_exists() == true ) {
    $wpt_selected_users = $post_info['wpt_authorized_users'];
    /* set up basic author/main account values */
    $auth_verified = wtt_oauth_test( $auth,’verify’ );
    if ( empty( $wpt_selected_users ) && get_option( ‘jd_individual_twitter_users’ ) == 1 ) {
    $wpt_selected_users = ($auth_verified)? array( $auth ) : array( false );
    }
    if ( $post_info['wpt_cotweet'] == 1 || get_option( ‘jd_individual_twitter_users’ ) != 1 ) {
    $wpt_selected_users['main'] = false;
    }
    // filter selected users before using
    $wpt_selected_users = apply_filters( ‘wpt_filter_users’, $wpt_selected_users, $post_info );
    if ( $post_info['wpt_delay_tweet'] == 0 || $post_info['wpt_delay_tweet'] == ” || $post_info['wpt_no_delay'] == ‘on’ ) {
    foreach ( $wpt_selected_users as $acct ) {
    if ( wtt_oauth_test( $acct, ‘verify’ ) ) {
    $tweet = jd_doTwitterAPIPost( $sentence2, $acct, $post_ID, $media );
    }
    }
    } else {
    foreach ( $wpt_selected_users as $acct ) {
    if ( $auth != $acct ) {
    $offset = rand( 60,480 ); // offset by 1-8 minutes for additional users
    } else {
    $offset = 0;
    }
    if ( wtt_oauth_test( $acct,’verify’ ) ) {
    $time = apply_filters( ‘wpt_schedule_delay’,( (int) $post_info['wpt_delay_tweet'] )*60, $acct );
    $scheduled = wp_schedule_single_event( time()+$time+$offset, ‘wpt_schedule_tweet_action’, array( ‘id’=>$acct, ‘sentence’=>$sentence, ‘rt’=>0, ‘post_id’=>$post_ID ) );
    $tweet = true; // if scheduled, return true.
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    if ( $acct ) { $author_id = “#$acct”; } else { $author_id = ‘Main'; }
    wpt_mail( “7a: Tweet Scheduled for Auth ID $author_id #$post_ID”, print_r( array( ‘id’=>$acct, ‘sentence’=>$sentence, ‘rt’=>0, ‘post_id’=>$post_ID, ‘timestamp’=>time()+$time+$offset, ‘current_time’=>time(), ‘timezone’=>get_option(‘gmt_offset’), ‘scheduled’=>$scheduled, ‘timestamp_string’=>date( ‘Y-m-d H:i:s’,time()+$time+$offset ),’current_time_string’=>date( ‘Y-m-d H:i:s’,time() ), ),1 ) ); // DEBUG
    }
    }
    }
    }
    /* This cycle handles scheduling the automatic retweets */
    if ( $post_info['wpt_retweet_after'] != 0 && $post_info['wpt_no_repost'] != ‘on’ ) {
    $repeat = $post_info['wpt_retweet_repeat'];
    $first = true;
    foreach ( $wpt_selected_users as $acct ) {
    if ( wtt_oauth_test( $acct,’verify’ ) ) {
    for ( $i=1;$i$acct, ‘sentence’=>$retweet, ‘rt’=>$i, ‘post_id’=>$post_ID ) );
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    if ( $acct ) { $author_id = “#$acct”; } else { $author_id = ‘Main'; }
    wpt_mail( “7b: Retweet Scheduled for Auth ID $author_id #$post_ID”, print_r( array( ‘id’=>$acct, ‘sentence’=>$retweet, ‘rt’=>$i, ‘post_id’=>$post_ID, ‘timestamp’=>time()+$time+$offset+$delay, ‘current_time’=>time(), ‘timezone’=>get_option(‘gmt_offset’), ‘scheduled’=>$scheduled, ‘timestamp_string’=>date( ‘Y-m-d H:i:s’,time()+$time+$offset+$delay ),’current_time_string’=>date( ‘Y-m-d H:i:s’,time() ), ),1 ) ); // DEBUG
    }
    $tweet = true;
    if ( $i == 4 ) { break; }
    }
    }
    $first = false;
    }
    }
    } else {
    $tweet = jd_doTwitterAPIPost( $sentence, false, $post_ID, $media );
    }
    // END WPT PRO //
    }
    } else {
    if ( WPT_DEBUG && function_exists( ‘wpt_pro_exists’ ) ) {
    wpt_mail( “3c: Not a Tweeted post type #$post_ID”,”Post_Info: “.print_r($post_info,1). ” / $type” );
    }
    return $post_ID;
    }
    }
    return $post_ID;
    }

  3. Hi Estorde,
    this post is old and wp-to-twitter has changed a lot. It is probably this code no longer applies!

Speak Your Mind

*