WP to Twitter - Version 3.3.8

Version Description

  • Change function name for checking edit vs. new for clarity.
  • Update debugging function to pass post ID of current Tweet.
  • Bug fix: PHP Notice in settings.
  • Bug fix: If rate limiting cron not set, automatically recreate.
Download this release

Release Info

Developer joedolson
Plugin Icon 128x128 WP to Twitter
Version 3.3.8
Comparing to
See all releases

Code changes from version 3.3.7 to 3.3.8

classes/class-tmhoauth.php CHANGED
@@ -433,9 +433,7 @@ class TmhOAuth {
433
 
434
  $this->auth_params['oauth_signature'] = $this->safe_encode(
435
  base64_encode(
436
- hash_hmac(
437
- 'sha1', $this->base_string, $this->signing_key, true
438
- )
439
  )
440
  );
441
 
@@ -550,11 +548,14 @@ class TmhOAuth {
550
  $request = substr_replace( $request, '', $pos );
551
  }
552
 
553
- return implode( '/', array(
554
- $proto,
555
- $this->config['host'],
556
- $request . $format,
557
- ) );
 
 
 
558
  }
559
 
560
  /**
@@ -679,22 +680,25 @@ class TmhOAuth {
679
 
680
  // configure curl.
681
  $c = curl_init();
682
- curl_setopt_array( $c, array(
683
- CURLOPT_USERAGENT => $this->config['user_agent'],
684
- CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
685
- CURLOPT_TIMEOUT => $this->config['curl_timeout'],
686
- CURLOPT_RETURNTRANSFER => true,
687
- CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
688
- CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'],
689
- CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
690
- CURLOPT_PROXY => $this->config['curl_proxy'],
691
- CURLOPT_ENCODING => $this->config['curl_encoding'],
692
- CURLOPT_URL => $this->url,
693
- // process the headers.
694
- CURLOPT_HEADERFUNCTION => array( $this, 'curl_header' ),
695
- CURLOPT_HEADER => false,
696
- CURLINFO_HEADER_OUT => true,
697
- ) );
 
 
 
698
 
699
  if ( false !== $this->config['curl_cainfo'] ) {
700
  curl_setopt( $c, CURLOPT_CAINFO, $this->config['curl_cainfo'] );
433
 
434
  $this->auth_params['oauth_signature'] = $this->safe_encode(
435
  base64_encode(
436
+ hash_hmac( 'sha1', $this->base_string, $this->signing_key, true )
 
 
437
  )
438
  );
439
 
548
  $request = substr_replace( $request, '', $pos );
549
  }
550
 
551
+ return implode(
552
+ '/',
553
+ array(
554
+ $proto,
555
+ $this->config['host'],
556
+ $request . $format,
557
+ )
558
+ );
559
  }
560
 
561
  /**
680
 
681
  // configure curl.
682
  $c = curl_init();
683
+ curl_setopt_array(
684
+ $c,
685
+ array(
686
+ CURLOPT_USERAGENT => $this->config['user_agent'],
687
+ CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
688
+ CURLOPT_TIMEOUT => $this->config['curl_timeout'],
689
+ CURLOPT_RETURNTRANSFER => true,
690
+ CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
691
+ CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'],
692
+ CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
693
+ CURLOPT_PROXY => $this->config['curl_proxy'],
694
+ CURLOPT_ENCODING => $this->config['curl_encoding'],
695
+ CURLOPT_URL => $this->url,
696
+ // process the headers.
697
+ CURLOPT_HEADERFUNCTION => array( $this, 'curl_header' ),
698
+ CURLOPT_HEADER => false,
699
+ CURLINFO_HEADER_OUT => true,
700
+ )
701
+ );
702
 
703
  if ( false !== $this->config['curl_cainfo'] ) {
704
  curl_setopt( $c, CURLOPT_CAINFO, $this->config['curl_cainfo'] );
classes/class-wpt-twitterfeed.php CHANGED
@@ -254,11 +254,14 @@ class WPT_TwitterFeed {
254
  $token = $this->defaults['token'];
255
  $token_secret = $this->defaults['token_secret'];
256
  $cachename = $screenname . '-' . $this->get_options_hash( $options );
257
- $options = array_merge( $options, array(
258
- 'screen_name' => $screenname,
259
- 'count' => 20,
260
- 'include_ext_alt_text' => 'true',
261
- ) );
 
 
 
262
 
263
  if ( empty( $key ) ) {
264
  return array( 'error' => __( 'Missing Consumer Key - Check settings', 'wp-to-twitter' ) );
254
  $token = $this->defaults['token'];
255
  $token_secret = $this->defaults['token_secret'];
256
  $cachename = $screenname . '-' . $this->get_options_hash( $options );
257
+ $options = array_merge(
258
+ $options,
259
+ array(
260
+ 'screen_name' => $screenname,
261
+ 'count' => 20,
262
+ 'include_ext_alt_text' => 'true',
263
+ )
264
+ );
265
 
266
  if ( empty( $key ) ) {
267
  return array( 'error' => __( 'Missing Consumer Key - Check settings', 'wp-to-twitter' ) );
classes/class-wpt-twitteroauth.php CHANGED
@@ -321,6 +321,8 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
321
  $size = array_pop( $image_sizes );
322
  }
323
  $upload = wp_get_attachment_image_src( $attachment, apply_filters( 'wpt_upload_image_size', $size ) );
 
 
324
  $image_url = $upload[0];
325
  $remote = wp_remote_get( $image_url );
326
  if ( is_wp_error( $remote ) ) {
@@ -330,7 +332,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
330
  $transport = 'wp_http';
331
  $binary = wp_remote_retrieve_body( $remote );
332
  }
333
- wpt_mail( 'Media fetched binary', print_r( $remote, 1 ) . "\n\n" . print_r( $binary, 1 ) );
334
  if ( ! $binary ) {
335
  return;
336
  }
@@ -343,11 +345,10 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
343
  $code = $tmh_oauth->request( 'POST', $url, array( 'media' => "$binary" ), true, true );
344
  $response = $tmh_oauth->response['response'];
345
  $full = $tmh_oauth->response;
346
- wpt_mail( 'Media Posted', "
347
- Media ID #$args[media] ($transport)" . "\n\n" .
348
- 'Twitter Response' . "\n" . print_r( $full, 1 ) . "\n\n" .
349
- 'Attachment Details' . "\n" . print_r( $upload, 1 ) . "\n\n" .
350
- 'Img Request Response' . "\n" . print_r( $remote, 1 )
351
  );
352
 
353
  if ( is_wp_error( $response ) ) {
@@ -398,10 +399,13 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
398
  // TODO: add content-type when JSON.
399
  $url = $req->get_normalized_http_url();
400
  $args = wp_parse_args( $req->to_postdata() );
401
- $response = wp_remote_post( $url, array(
402
- 'body' => $args,
403
- 'timeout' => 30,
404
- ) );
 
 
 
405
  break;
406
  }
407
 
321
  $size = array_pop( $image_sizes );
322
  }
323
  $upload = wp_get_attachment_image_src( $attachment, apply_filters( 'wpt_upload_image_size', $size ) );
324
+ $parent = get_post_ancestors( $attachment );
325
+ $parent = ( is_array( $parent ) ) ? $parent[0] : false;
326
  $image_url = $upload[0];
327
  $remote = wp_remote_get( $image_url );
328
  if ( is_wp_error( $remote ) ) {
332
  $transport = 'wp_http';
333
  $binary = wp_remote_retrieve_body( $remote );
334
  }
335
+ wpt_mail( 'Media fetched binary', print_r( $remote, 1 ) . "\n\n" . print_r( $binary, 1 ), $parent );
336
  if ( ! $binary ) {
337
  return;
338
  }
345
  $code = $tmh_oauth->request( 'POST', $url, array( 'media' => "$binary" ), true, true );
346
  $response = $tmh_oauth->response['response'];
347
  $full = $tmh_oauth->response;
348
+ wpt_mail(
349
+ 'Media Posted',
350
+ "Media ID #$args[media] ($transport)" . "\n\n" . 'Twitter Response' . "\n" . print_r( $full, 1 ) . "\n\n" . 'Attachment Details' . "\n" . print_r( $upload, 1 ) . "\n\n" . 'Img Request Response' . "\n" . print_r( $remote, 1 ),
351
+ $parent
 
352
  );
353
 
354
  if ( is_wp_error( $response ) ) {
399
  // TODO: add content-type when JSON.
400
  $url = $req->get_normalized_http_url();
401
  $args = wp_parse_args( $req->to_postdata() );
402
+ $response = wp_remote_post(
403
+ $url,
404
+ array(
405
+ 'body' => $args,
406
+ 'timeout' => 30,
407
+ )
408
+ );
409
  break;
410
  }
411
 
readme.txt CHANGED
@@ -7,7 +7,7 @@ Tested up to: 4.9
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
- Stable tag: 3.3.7
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
@@ -65,6 +65,13 @@ Check out my <a href="https://github.com/joedolson/plugin-extensions/tree/master
65
 
66
  == Changelog ==
67
 
 
 
 
 
 
 
 
68
  = 3.3.7 =
69
 
70
  * Change: Remove replacement character setting unless in use for non-space character
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
+ Stable tag: 3.3.8
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
65
 
66
  == Changelog ==
67
 
68
+ = 3.3.8 =
69
+
70
+ * Change function name for checking edit vs. new for clarity.
71
+ * Update debugging function to pass post ID of current Tweet.
72
+ * Bug fix: PHP Notice in settings.
73
+ * Bug fix: If rate limiting cron not set, automatically recreate.
74
+
75
  = 3.3.7 =
76
 
77
  * Change: Remove replacement character setting unless in use for non-space character
wp-to-twitter-manager.php CHANGED
@@ -99,7 +99,7 @@ function wpt_updated_settings() {
99
  update_option( 'wpt_use_cats', $use_cats );
100
  update_option( 'wpt_tag_source', ( ( isset( $_POST['wpt_tag_source'] ) && 'slug' == $_POST['wpt_tag_source'] ) ? 'slug' : '' ) );
101
  update_option( 'jd_max_characters', $_POST['jd_max_characters'] );
102
- update_option( 'jd_replace_character', $_POST['jd_replace_character'] );
103
  update_option( 'jd_date_format', $_POST['jd_date_format'] );
104
  update_option( 'jd_dynamic_analytics', $_POST['jd-dynamic-analytics'] );
105
 
@@ -906,10 +906,13 @@ function wpt_do_server_check( $test = false ) {
906
  $wpt_server_string = get_option( 'wpt_server_string' );
907
  if ( ! $wpt_server_string || isset( $_GET['refresh_wpt_server_string'] ) || true == $test ) {
908
  $server_time = date( DATE_COOKIE );
909
- $response = wp_remote_get( 'https://twitter.com/', array(
910
- 'timeout' => 30,
911
- 'redirection' => 1,
912
- ) );
 
 
 
913
 
914
  if ( is_wp_error( $response ) ) {
915
  $warning = '';
99
  update_option( 'wpt_use_cats', $use_cats );
100
  update_option( 'wpt_tag_source', ( ( isset( $_POST['wpt_tag_source'] ) && 'slug' == $_POST['wpt_tag_source'] ) ? 'slug' : '' ) );
101
  update_option( 'jd_max_characters', $_POST['jd_max_characters'] );
102
+ update_option( 'jd_replace_character', ( isset( $_POST['jd_replace_character'] ) ? $_POST['jd_replace_character'] : '' ) );
103
  update_option( 'jd_date_format', $_POST['jd_date_format'] );
104
  update_option( 'jd_dynamic_analytics', $_POST['jd-dynamic-analytics'] );
105
 
906
  $wpt_server_string = get_option( 'wpt_server_string' );
907
  if ( ! $wpt_server_string || isset( $_GET['refresh_wpt_server_string'] ) || true == $test ) {
908
  $server_time = date( DATE_COOKIE );
909
+ $response = wp_remote_get(
910
+ 'https://twitter.com/',
911
+ array(
912
+ 'timeout' => 30,
913
+ 'redirection' => 1,
914
+ )
915
+ );
916
 
917
  if ( is_wp_error( $response ) ) {
918
  $warning = '';
wp-to-twitter-shorteners.php CHANGED
@@ -29,7 +29,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
29
  * @return shortened URL.
30
  */
31
  function wpt_shorten_url( $url, $post_title, $post_ID, $testmode = false, $store_urls = true ) {
32
- wpt_mail( 'Initial Link', "$url, $post_title, $post_ID, $testmode" ); // DEBUG.
33
  // filter link before sending to shortener or adding analytics.
34
  $shortener = get_option( 'jd_shortener' );
35
  // if the URL already exists, return it without processing.
@@ -65,11 +65,14 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
65
  }
66
  $medium = urlencode( trim( apply_filters( 'wpt_utm_medium', 'twitter' ) ) );
67
  $source = urlencode( trim( apply_filters( 'wpt_utm_source', 'twitter' ) ) );
68
- $url = add_query_arg( array(
69
- 'utm_campaign' => $campaign,
70
- 'utm_medium' => $medium,
71
- 'utm_source' => $source,
72
- ), $url );
 
 
 
73
  }
74
  $url = urldecode( trim( $url ) ); // prevent double-encoding.
75
  $encoded = urlencode( $url );
@@ -169,7 +172,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
169
  $api_url = add_query_arg( $args, $yourlsurl );
170
 
171
  $json = wpt_remote_json( $api_url, false );
172
- wpt_mail( 'YOURLS JSON Response', print_r( $json, 1 ) ); // DEBUG YOURLS response.
173
  if ( is_object( $json ) ) {
174
  $shrink = $json->shorturl;
175
  } else {
29
  * @return shortened URL.
30
  */
31
  function wpt_shorten_url( $url, $post_title, $post_ID, $testmode = false, $store_urls = true ) {
32
+ wpt_mail( 'Initial Link', "$url, $post_title, $post_ID, $testmode", $post_ID ); // DEBUG.
33
  // filter link before sending to shortener or adding analytics.
34
  $shortener = get_option( 'jd_shortener' );
35
  // if the URL already exists, return it without processing.
65
  }
66
  $medium = urlencode( trim( apply_filters( 'wpt_utm_medium', 'twitter' ) ) );
67
  $source = urlencode( trim( apply_filters( 'wpt_utm_source', 'twitter' ) ) );
68
+ $url = add_query_arg(
69
+ array(
70
+ 'utm_campaign' => $campaign,
71
+ 'utm_medium' => $medium,
72
+ 'utm_source' => $source,
73
+ ),
74
+ $url
75
+ );
76
  }
77
  $url = urldecode( trim( $url ) ); // prevent double-encoding.
78
  $encoded = urlencode( $url );
172
  $api_url = add_query_arg( $args, $yourlsurl );
173
 
174
  $json = wpt_remote_json( $api_url, false );
175
+ wpt_mail( 'YOURLS JSON Response', print_r( $json, 1 ), $post_ID ); // DEBUG YOURLS response.
176
  if ( is_object( $json ) ) {
177
  $shrink = $json->shorturl;
178
  } else {
wp-to-twitter.php CHANGED
@@ -17,7 +17,7 @@
17
  * License: GPL-2.0+
18
  * License URI: http://www.gnu.org/license/gpl-2.0.txt
19
  * Domain Path: lang
20
- * Version: 3.3.7
21
  */
22
 
23
  /*
@@ -57,7 +57,7 @@ require_once( plugin_dir_path( __FILE__ ) . 'wpt-widget.php' );
57
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
58
 
59
  global $wpt_version;
60
- $wpt_version = '3.3.7';
61
 
62
  add_action( 'init', 'wpt_load_textdomain' );
63
  /**
@@ -217,13 +217,17 @@ function wpt_link( $post_ID ) {
217
  function wpt_saves_error( $id, $auth, $twit, $error, $http_code, $ts ) {
218
  $http_code = (int) $http_code;
219
  if ( 200 != $http_code ) {
220
- add_post_meta( $id, '_wpt_failed', array(
221
- 'author' => $auth,
222
- 'sentence' => $twit,
223
- 'error' => $error,
224
- 'code' => $http_code,
225
- 'timestamp' => $ts,
226
- ) );
 
 
 
 
227
  } else {
228
  if ( 1 == get_option( 'wpt_rate_limiting' ) ) {
229
  wpt_log_success( $auth, $ts, $id );
@@ -256,7 +260,7 @@ function wpt_check_recent_tweet( $id, $auth ) {
256
  $expire = apply_filters( 'wpt_recent_tweet_threshold', 30 );
257
  // if expiration is 0, don't set the transient. We don't want permanent transients.
258
  if ( 0 !== $expire ) {
259
- wpt_mail( 'Tweet transient set', "$expire / $auth / $id" );
260
  if ( false == $auth ) {
261
  set_transient( "_wpt_most_recent_tweet_$id", true, $expire );
262
  } else {
@@ -306,14 +310,14 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
306
  $check = ( ! $auth ) ? get_option( 'jd_last_tweet' ) : get_user_meta( $auth, 'wpt_last_tweet', true ); // get user's last tweet.
307
  // prevent duplicate Tweets.
308
  if ( $check == $twit ) {
309
- wpt_mail( 'Matched: tweet identical', "This Tweet: $twit; Check Tweet: $check; $auth, $id, $media" ); // DEBUG.
310
  $error = __( 'This tweet is identical to another Tweet recently sent to this account.', 'wp-to-twitter' ) . ' ' . __( 'Twitter requires all Tweets to be unique.', 'wp-to-twitter' );
311
  wpt_saves_error( $id, $auth, $twit, $error, '403-1', time() );
312
  wpt_set_log( 'wpt_status_message', $id, $error );
313
 
314
  return false;
315
  } elseif ( '' == $twit || ! $twit ) {
316
- wpt_mail( 'Tweet check: empty sentence', "$twit, $auth, $id, $media" ); // DEBUG.
317
  $error = __( 'This tweet was blank and could not be sent to Twitter.', 'wp-tweets-pro' );
318
  wpt_saves_error( $id, $auth, $twit, $error, '403-2', time() );
319
  wpt_set_log( 'wpt_status_message', $id, $error );
@@ -324,10 +328,10 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
324
  // must be designated as media and have a valid attachment.
325
  $attachment = ( $media ) ? wpt_post_attachment( $id ) : false;
326
  if ( $attachment ) {
327
- wpt_mail( 'Post has upload', "$auth, $attachment" );
328
  $meta = wp_get_attachment_metadata( $attachment );
329
  if ( ! isset( $meta['width'], $meta['height'] ) ) {
330
- wpt_mail( "Image Data Does not Exist for #$attachment", print_r( $meta, 1 ) );
331
  $attachment = false;
332
  }
333
  }
@@ -343,11 +347,14 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
343
  $connection = wpt_oauth_connection( $auth );
344
  if ( $connection ) {
345
  if ( $media && $attachment && ! $media_id ) {
346
- $media_id = $connection->media( $upload_api, array(
347
- 'auth' => $auth,
348
- 'media' => $attachment,
349
- ) );
350
- wpt_mail( 'Media Uploaded', "$auth, $media_id, $attachment" );
 
 
 
351
  if ( $media_id ) {
352
  $status['media_ids'] = $media_id;
353
  /**
@@ -383,7 +390,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
383
  $notice = '';
384
  }
385
  }
386
- wpt_mail( 'Twitter Connection', print_r( $connection, 1 ) . " - $twit, $auth, $id, $media" );
387
  if ( $connection ) {
388
  if ( isset( $connection->http_header['x-access-level'] ) && 'read' == $connection->http_header['x-access-level'] ) {
389
  // Translators: Twitter App editing URL.
@@ -449,7 +456,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
449
  $error_supplement = ( '' != $error_code ) ? ' (Error Code: ' . $error_code . ': ' . $error_message . ')' : '';
450
  $error .= ( '' != $supplement ) ? " $supplement" : '';
451
  $error .= $error_supplement;
452
- wpt_mail( "Twitter Response: $http_code", "$error" ); // DEBUG.
453
  // only save last Tweet if successful.
454
  if ( 200 == $http_code ) {
455
  if ( ! $auth ) {
@@ -750,7 +757,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
750
  } else {
751
  $default = ( 'yes' == $tweet_this ) ? true : false;
752
  }
753
- wpt_mail( '1: Tweet Template', "$tweet_this / (Original: " . get_option( 'jd_tweet_default' ) . ") / $type" ); // DEBUG.
754
  if ( $default ) { // default switch: depend on default settings.
755
  $post_info = wpt_post_info( $post_ID );
756
  $media = wpt_post_with_media( $post_ID, $post_info );
@@ -759,11 +766,11 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
759
  } else {
760
  $auth = $post_info['authId'];
761
  }
762
- wpt_mail( '2: POST Debug Data', 'Post_Info: ' . print_r( $post_info, 1 ) . " / $type" ); // DEBUG.
763
  if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() && function_exists( 'wpt_filter_post_info' ) ) {
764
  $filter = wpt_filter_post_info( $post_info );
765
  if ( true == $filter ) {
766
- wpt_mail( '3: Post caught by wpt_filter_post_info', print_r( $post_info, 1 ) . " / $type" );
767
 
768
  return false;
769
  }
@@ -776,12 +783,12 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
776
  $post_type = $post_info['postType'];
777
  if ( 'future' == $type || 'future' == get_post_meta( $post_ID, 'wpt_publishing' ) ) {
778
  $new = 1; // if this is a future action, then it should be published regardless of relationship.
779
- wpt_mail( '4a: Is a future post', print_r( $post_info, 1 ) . " / $type" );
780
  delete_post_meta( $post_ID, 'wpt_publishing' );
781
  } else {
782
  // if the post modified date and the post date are the same, this is new.
783
  // true if first date before or equal to last date.
784
- $new = wpt_date_compare( $post_info['_postModified'], $post_info['_postDate'] );
785
  }
786
  // post is not previously published but has been backdated.
787
  // (post date is edited, but save option is 'publish').
@@ -812,13 +819,13 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
812
  return false;
813
  }
814
  }
815
- wpt_mail( '4b: Is edited post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type" ); // DEBUG.
816
  if ( '1' == $post_type_settings[ $post_type ]['post-edited-update'] ) {
817
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-edited-text'] );
818
  $oldpost = true;
819
  }
820
  } else {
821
- wpt_mail( '4c: Is new post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type" ); // DEBUG.
822
  if ( '1' == $post_type_settings[ $post_type ]['post-published-update'] ) {
823
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-published-text'] );
824
  $newpost = true;
@@ -827,7 +834,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
827
  if ( $newpost || $oldpost ) {
828
  $template = ( '' != $custom_tweet ) ? $custom_tweet : $nptext;
829
  $sentence = jd_truncate_tweet( $template, $post_info, $post_ID );
830
- wpt_mail( '5: Tweet Truncated', "Truncated Tweet: $sentence / $template / $type" ); // DEBUG.
831
  if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
832
  $sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth );
833
  }
@@ -858,25 +865,37 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
858
  $offset = ( $auth != $acct ) ? apply_filters( 'wpt_random_delay', rand( 60, 480 ) ) : 0;
859
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
860
  $time = apply_filters( 'wpt_schedule_delay', ( (int) $post_info['wpt_delay_tweet'] ) * 60, $acct );
861
- wp_schedule_single_event( time() + $time + $offset, 'wpt_schedule_tweet_action', array(
862
- 'id' => $acct,
863
- 'sentence' => $sentence,
864
- 'rt' => 0,
865
- 'post_id' => $post_ID,
866
- ) );
 
 
 
 
867
  if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
868
  $author_id = ( $acct ) ? "#$acct" : 'Main';
869
- wpt_mail( "7a: Tweet Scheduled for author $author_id", print_r( array(
870
- 'id' => $acct,
871
- 'sentence' => $sentence,
872
- 'rt' => 0,
873
- 'post_id' => $post_ID,
874
- 'timestamp' => time() + $time + $offset,
875
- 'current_time' => time(),
876
- 'timezone' => get_option( 'gmt_offset' ),
877
- 'timestamp_string' => date( 'Y-m-d H:i:s', time() + $time + $offset ),
878
- 'current_ts' => date( 'Y-m-d H:i:s', time() ),
879
- ), 1 ) ); // DEBUG.
 
 
 
 
 
 
 
 
880
  }
881
  }
882
  }
@@ -897,26 +916,37 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
897
  // Don't delay the first Tweet of the group.
898
  $offset = ( true == $first ) ? 0 : rand( 60, 240 ); // delay each co-tweet by 1-4 minutes.
899
  $time = apply_filters( 'wpt_schedule_retweet', ( $post_info['wpt_retweet_after'] ) * ( 60 * 60 ) * $i, $acct, $i, $post_info );
900
- wp_schedule_single_event( time() + $time + $offset + $delay, 'wpt_schedule_tweet_action', array(
901
- 'id' => $acct,
902
- 'sentence' => $retweet,
903
- 'rt' => $i,
904
- 'post_id' => $post_ID,
905
- ) );
 
 
 
 
906
  if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
907
  if ( $acct ) {
908
  $author_id = "#$acct";
909
  } else {
910
  $author_id = 'Main';
911
  }
912
- wpt_mail( "7b: Retweet Scheduled for author $author_id", print_r( array(
913
- 'id' => $acct,
914
- 'sentence' => array( $retweet, $i, $post_ID ),
915
- 'timestamp' => time() + $time + $offset + $delay,
916
- 'time' => array( $time, $offset, $delay, get_option( 'gmt_offset' ), time() ),
917
- 'timestring' => date( 'Y-m-d H:i:s', time() + $time + $offset + $delay ),
918
- 'current_ts' => date( 'Y-m-d H:i:s', time() ),
919
- ), 1 ), true ); // DEBUG.
 
 
 
 
 
 
 
920
  }
921
  $tweet_limit = apply_filters( 'wpt_tweet_repeat_limit', 4, $post_ID );
922
  if ( $i == $tweet_limit ) {
@@ -935,7 +965,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
935
  }
936
  } else {
937
  if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
938
- wpt_mail( '3c: Not a Tweeted post type', 'Post_Info: ' . print_r( $post_info, 1 ) . " / $type" );
939
  }
940
 
941
  return $post_ID;
@@ -1402,11 +1432,15 @@ function wpt_admin_scripts() {
1402
  }
1403
  if ( 'post' == $current_screen->base && isset( $_GET['post'] ) && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1404
  wp_enqueue_script( 'wpt.ajax', plugins_url( 'js/ajax.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1405
- wp_localize_script( 'wpt.ajax', 'wpt_data', array(
1406
- 'post_ID' => (int) $_GET['post'],
1407
- 'action' => 'wpt_tweet',
1408
- 'security' => wp_create_nonce( 'wpt-tweet-nonce' ),
1409
- ) );
 
 
 
 
1410
  }
1411
  if ( 'settings_page_wp-to-twitter/wp-to-twitter' == $current_screen->id || 'toplevel_page_wp-tweets-pro' == $current_screen->id ) {
1412
  wp_enqueue_script( 'wpt.tabs', plugins_url( 'js/tabs.js', __FILE__ ), array( 'jquery' ), $wpt_version );
@@ -1468,12 +1502,16 @@ function wpt_ajax_tweet() {
1468
  wpt_post_to_twitter( $sentence, $auth, $post_ID, $media );
1469
  break;
1470
  case 'schedule':
1471
- wp_schedule_single_event( $schedule, 'wpt_schedule_tweet_action', array(
1472
- 'id' => $auth,
1473
- 'sentence' => $sentence,
1474
- 'rt' => 0,
1475
- 'post_id' => $post_ID,
1476
- ) );
 
 
 
 
1477
  break;
1478
  }
1479
  // Translators: Full text of Tweet, time scheduled for.
@@ -1514,12 +1552,16 @@ function wpt_admin_script() {
1514
  }
1515
  wp_register_script( 'wpt-base-js', plugins_url( 'js/base.js', __FILE__ ), array( 'jquery' ) );
1516
  wp_enqueue_script( 'wpt-base-js' );
1517
- wp_localize_script( 'wpt-base-js', 'wptSettings', array(
1518
- 'allowed' => $allowed,
1519
- 'first' => $first,
1520
- 'is_ssl' => ( wpt_is_ssl( home_url() ) ) ? 'true' : 'false',
1521
- 'text' => __( 'Characters left: ', 'wp-to-twitter' ),
1522
- ) );
 
 
 
 
1523
  echo "
1524
  <style type='text/css'>
1525
  #wp2t h3 span, #wp2t h2 span { padding-left: 30px; background: url(" . plugins_url( 'wp-to-twitter/images/twitter-bird-light-bgs.png' ) . ') left 50% no-repeat; }
@@ -1570,7 +1612,7 @@ function wpt_save_post( $id ) {
1570
  // WPT PRO.
1571
  // only send debug data if post meta is updated.
1572
  if ( true == $update || is_int( $update ) ) {
1573
- wpt_mail( 'Post Meta Inserted', print_r( $_POST, 1 ) ); // DEBUG.
1574
  }
1575
  if ( isset( $_POST['wpt-delete-debug'] ) && 'true' == $_POST['wpt-delete-debug'] ) {
1576
  delete_post_meta( $id, '_wpt_debug_log' );
17
  * License: GPL-2.0+
18
  * License URI: http://www.gnu.org/license/gpl-2.0.txt
19
  * Domain Path: lang
20
+ * Version: 3.3.8
21
  */
22
 
23
  /*
57
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
58
 
59
  global $wpt_version;
60
+ $wpt_version = '3.3.8';
61
 
62
  add_action( 'init', 'wpt_load_textdomain' );
63
  /**
217
  function wpt_saves_error( $id, $auth, $twit, $error, $http_code, $ts ) {
218
  $http_code = (int) $http_code;
219
  if ( 200 != $http_code ) {
220
+ add_post_meta(
221
+ $id,
222
+ '_wpt_failed',
223
+ array(
224
+ 'author' => $auth,
225
+ 'sentence' => $twit,
226
+ 'error' => $error,
227
+ 'code' => $http_code,
228
+ 'timestamp' => $ts,
229
+ )
230
+ );
231
  } else {
232
  if ( 1 == get_option( 'wpt_rate_limiting' ) ) {
233
  wpt_log_success( $auth, $ts, $id );
260
  $expire = apply_filters( 'wpt_recent_tweet_threshold', 30 );
261
  // if expiration is 0, don't set the transient. We don't want permanent transients.
262
  if ( 0 !== $expire ) {
263
+ wpt_mail( 'Tweet transient set', "$expire / $auth / $id", $id );
264
  if ( false == $auth ) {
265
  set_transient( "_wpt_most_recent_tweet_$id", true, $expire );
266
  } else {
310
  $check = ( ! $auth ) ? get_option( 'jd_last_tweet' ) : get_user_meta( $auth, 'wpt_last_tweet', true ); // get user's last tweet.
311
  // prevent duplicate Tweets.
312
  if ( $check == $twit ) {
313
+ wpt_mail( 'Matched: tweet identical', "This Tweet: $twit; Check Tweet: $check; $auth, $id, $media", $id ); // DEBUG.
314
  $error = __( 'This tweet is identical to another Tweet recently sent to this account.', 'wp-to-twitter' ) . ' ' . __( 'Twitter requires all Tweets to be unique.', 'wp-to-twitter' );
315
  wpt_saves_error( $id, $auth, $twit, $error, '403-1', time() );
316
  wpt_set_log( 'wpt_status_message', $id, $error );
317
 
318
  return false;
319
  } elseif ( '' == $twit || ! $twit ) {
320
+ wpt_mail( 'Tweet check: empty sentence', "$twit, $auth, $id, $media", $id ); // DEBUG.
321
  $error = __( 'This tweet was blank and could not be sent to Twitter.', 'wp-tweets-pro' );
322
  wpt_saves_error( $id, $auth, $twit, $error, '403-2', time() );
323
  wpt_set_log( 'wpt_status_message', $id, $error );
328
  // must be designated as media and have a valid attachment.
329
  $attachment = ( $media ) ? wpt_post_attachment( $id ) : false;
330
  if ( $attachment ) {
331
+ wpt_mail( 'Post has upload', "$auth, $attachment", $id );
332
  $meta = wp_get_attachment_metadata( $attachment );
333
  if ( ! isset( $meta['width'], $meta['height'] ) ) {
334
+ wpt_mail( "Image Data Does not Exist for #$attachment", print_r( $meta, 1 ), $id );
335
  $attachment = false;
336
  }
337
  }
347
  $connection = wpt_oauth_connection( $auth );
348
  if ( $connection ) {
349
  if ( $media && $attachment && ! $media_id ) {
350
+ $media_id = $connection->media(
351
+ $upload_api,
352
+ array(
353
+ 'auth' => $auth,
354
+ 'media' => $attachment,
355
+ )
356
+ );
357
+ wpt_mail( 'Media Uploaded', "$auth, $media_id, $attachment", $id );
358
  if ( $media_id ) {
359
  $status['media_ids'] = $media_id;
360
  /**
390
  $notice = '';
391
  }
392
  }
393
+ wpt_mail( 'Twitter Connection', print_r( $connection, 1 ) . " - $twit, $auth, $id, $media", $id );
394
  if ( $connection ) {
395
  if ( isset( $connection->http_header['x-access-level'] ) && 'read' == $connection->http_header['x-access-level'] ) {
396
  // Translators: Twitter App editing URL.
456
  $error_supplement = ( '' != $error_code ) ? ' (Error Code: ' . $error_code . ': ' . $error_message . ')' : '';
457
  $error .= ( '' != $supplement ) ? " $supplement" : '';
458
  $error .= $error_supplement;
459
+ wpt_mail( "Twitter Response: $http_code", "$error", $id ); // DEBUG.
460
  // only save last Tweet if successful.
461
  if ( 200 == $http_code ) {
462
  if ( ! $auth ) {
757
  } else {
758
  $default = ( 'yes' == $tweet_this ) ? true : false;
759
  }
760
+ wpt_mail( '1: Tweet Template', "$tweet_this / (Original: " . get_option( 'jd_tweet_default' ) . ") / $type", $post_ID ); // DEBUG.
761
  if ( $default ) { // default switch: depend on default settings.
762
  $post_info = wpt_post_info( $post_ID );
763
  $media = wpt_post_with_media( $post_ID, $post_info );
766
  } else {
767
  $auth = $post_info['authId'];
768
  }
769
+ wpt_mail( '2: POST Debug Data', 'Post_Info: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
770
  if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() && function_exists( 'wpt_filter_post_info' ) ) {
771
  $filter = wpt_filter_post_info( $post_info );
772
  if ( true == $filter ) {
773
+ wpt_mail( '3: Post caught by wpt_filter_post_info', print_r( $post_info, 1 ) . " / $type", $post_ID );
774
 
775
  return false;
776
  }
783
  $post_type = $post_info['postType'];
784
  if ( 'future' == $type || 'future' == get_post_meta( $post_ID, 'wpt_publishing' ) ) {
785
  $new = 1; // if this is a future action, then it should be published regardless of relationship.
786
+ wpt_mail( '4a: Is a future post', print_r( $post_info, 1 ) . " / $type", $post_ID );
787
  delete_post_meta( $post_ID, 'wpt_publishing' );
788
  } else {
789
  // if the post modified date and the post date are the same, this is new.
790
  // true if first date before or equal to last date.
791
+ $new = wpt_post_is_new( $post_info['_postModified'], $post_info['_postDate'] );
792
  }
793
  // post is not previously published but has been backdated.
794
  // (post date is edited, but save option is 'publish').
819
  return false;
820
  }
821
  }
822
+ wpt_mail( '4b: Is edited post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
823
  if ( '1' == $post_type_settings[ $post_type ]['post-edited-update'] ) {
824
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-edited-text'] );
825
  $oldpost = true;
826
  }
827
  } else {
828
+ wpt_mail( '4c: Is new post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
829
  if ( '1' == $post_type_settings[ $post_type ]['post-published-update'] ) {
830
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-published-text'] );
831
  $newpost = true;
834
  if ( $newpost || $oldpost ) {
835
  $template = ( '' != $custom_tweet ) ? $custom_tweet : $nptext;
836
  $sentence = jd_truncate_tweet( $template, $post_info, $post_ID );
837
+ wpt_mail( '5: Tweet Truncated', "Truncated Tweet: $sentence / $template / $type", $post_ID ); // DEBUG.
838
  if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
839
  $sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth );
840
  }
865
  $offset = ( $auth != $acct ) ? apply_filters( 'wpt_random_delay', rand( 60, 480 ) ) : 0;
866
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
867
  $time = apply_filters( 'wpt_schedule_delay', ( (int) $post_info['wpt_delay_tweet'] ) * 60, $acct );
868
+ wp_schedule_single_event(
869
+ time() + $time + $offset,
870
+ 'wpt_schedule_tweet_action',
871
+ array(
872
+ 'id' => $acct,
873
+ 'sentence' => $sentence,
874
+ 'rt' => 0,
875
+ 'post_id' => $post_ID,
876
+ )
877
+ );
878
  if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
879
  $author_id = ( $acct ) ? "#$acct" : 'Main';
880
+ wpt_mail(
881
+ "7a: Tweet Scheduled for author $author_id",
882
+ print_r(
883
+ array(
884
+ 'id' => $acct,
885
+ 'sentence' => $sentence,
886
+ 'rt' => 0,
887
+ 'post_id' => $post_ID,
888
+ 'timestamp' => time() + $time + $offset,
889
+ 'current_time' => time(),
890
+ 'timezone' => get_option( 'gmt_offset' ),
891
+ 'timestring' => date( 'Y-m-d H:i:s', time() + $time + $offset ),
892
+ 'current_ts' => date( 'Y-m-d H:i:s', time() ),
893
+ ),
894
+ 1
895
+ ),
896
+ $post_ID
897
+ );
898
+ // DEBUG.
899
  }
900
  }
901
  }
916
  // Don't delay the first Tweet of the group.
917
  $offset = ( true == $first ) ? 0 : rand( 60, 240 ); // delay each co-tweet by 1-4 minutes.
918
  $time = apply_filters( 'wpt_schedule_retweet', ( $post_info['wpt_retweet_after'] ) * ( 60 * 60 ) * $i, $acct, $i, $post_info );
919
+ wp_schedule_single_event(
920
+ time() + $time + $offset + $delay,
921
+ 'wpt_schedule_tweet_action',
922
+ array(
923
+ 'id' => $acct,
924
+ 'sentence' => $retweet,
925
+ 'rt' => $i,
926
+ 'post_id' => $post_ID,
927
+ )
928
+ );
929
  if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
930
  if ( $acct ) {
931
  $author_id = "#$acct";
932
  } else {
933
  $author_id = 'Main';
934
  }
935
+ wpt_mail(
936
+ "7b: Retweet Scheduled for author $author_id",
937
+ print_r(
938
+ array(
939
+ 'id' => $acct,
940
+ 'sentence' => array( $retweet, $i, $post_ID ),
941
+ 'timestamp' => time() + $time + $offset + $delay,
942
+ 'time' => array( $time, $offset, $delay, get_option( 'gmt_offset' ), time() ),
943
+ 'timestring' => date( 'Y-m-d H:i:s', time() + $time + $offset + $delay ),
944
+ 'current_ts' => date( 'Y-m-d H:i:s', time() ),
945
+ ),
946
+ 1
947
+ ),
948
+ $post_ID
949
+ ); // DEBUG.
950
  }
951
  $tweet_limit = apply_filters( 'wpt_tweet_repeat_limit', 4, $post_ID );
952
  if ( $i == $tweet_limit ) {
965
  }
966
  } else {
967
  if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
968
+ wpt_mail( '3c: Not a Tweeted post type', 'Post_Info: ' . print_r( $post_info, 1 ) . " / $type", $post_ID );
969
  }
970
 
971
  return $post_ID;
1432
  }
1433
  if ( 'post' == $current_screen->base && isset( $_GET['post'] ) && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1434
  wp_enqueue_script( 'wpt.ajax', plugins_url( 'js/ajax.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1435
+ wp_localize_script(
1436
+ 'wpt.ajax',
1437
+ 'wpt_data',
1438
+ array(
1439
+ 'post_ID' => (int) $_GET['post'],
1440
+ 'action' => 'wpt_tweet',
1441
+ 'security' => wp_create_nonce( 'wpt-tweet-nonce' ),
1442
+ )
1443
+ );
1444
  }
1445
  if ( 'settings_page_wp-to-twitter/wp-to-twitter' == $current_screen->id || 'toplevel_page_wp-tweets-pro' == $current_screen->id ) {
1446
  wp_enqueue_script( 'wpt.tabs', plugins_url( 'js/tabs.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1502
  wpt_post_to_twitter( $sentence, $auth, $post_ID, $media );
1503
  break;
1504
  case 'schedule':
1505
+ wp_schedule_single_event(
1506
+ $schedule,
1507
+ 'wpt_schedule_tweet_action',
1508
+ array(
1509
+ 'id' => $auth,
1510
+ 'sentence' => $sentence,
1511
+ 'rt' => 0,
1512
+ 'post_id' => $post_ID,
1513
+ )
1514
+ );
1515
  break;
1516
  }
1517
  // Translators: Full text of Tweet, time scheduled for.
1552
  }
1553
  wp_register_script( 'wpt-base-js', plugins_url( 'js/base.js', __FILE__ ), array( 'jquery' ) );
1554
  wp_enqueue_script( 'wpt-base-js' );
1555
+ wp_localize_script(
1556
+ 'wpt-base-js',
1557
+ 'wptSettings',
1558
+ array(
1559
+ 'allowed' => $allowed,
1560
+ 'first' => $first,
1561
+ 'is_ssl' => ( wpt_is_ssl( home_url() ) ) ? 'true' : 'false',
1562
+ 'text' => __( 'Characters left: ', 'wp-to-twitter' ),
1563
+ )
1564
+ );
1565
  echo "
1566
  <style type='text/css'>
1567
  #wp2t h3 span, #wp2t h2 span { padding-left: 30px; background: url(" . plugins_url( 'wp-to-twitter/images/twitter-bird-light-bgs.png' ) . ') left 50% no-repeat; }
1612
  // WPT PRO.
1613
  // only send debug data if post meta is updated.
1614
  if ( true == $update || is_int( $update ) ) {
1615
+ wpt_mail( 'Post Meta Inserted', print_r( $_POST, 1 ), $id ); // DEBUG.
1616
  }
1617
  if ( isset( $_POST['wpt-delete-debug'] ) && 'true' == $_POST['wpt-delete-debug'] ) {
1618
  delete_post_meta( $id, '_wpt_debug_log' );
wpt-functions.php CHANGED
@@ -286,14 +286,15 @@ function wpt_cap_checkbox( $role, $cap, $name ) {
286
  *
287
  * @param string $subject Subject of error.
288
  * @param string $body Body of error.
 
289
  * @param boolean $override Send message if debug disabled.
290
  */
291
- function wpt_mail( $subject, $body, $override = false ) {
292
  if ( ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) || true == $override ) {
293
  if ( WPT_DEBUG_BY_EMAIL ) {
294
  wp_mail( WPT_DEBUG_ADDRESS, $subject, $body, WPT_FROM );
295
  } else {
296
- wpt_debug_log( $subject, $body );
297
  }
298
  }
299
  }
@@ -303,9 +304,12 @@ function wpt_mail( $subject, $body, $override = false ) {
303
  *
304
  * @param string $subject Subject of error.
305
  * @param string $body Body of error.
 
306
  */
307
- function wpt_debug_log( $subject, $body ) {
308
- global $post_ID;
 
 
309
  if ( $post_ID ) {
310
  $time = current_time( 'timestamp' );
311
  add_post_meta( $post_ID, '_wpt_debug_log', array( $time, $subject, $body ) );
@@ -366,9 +370,7 @@ function wpt_show_debug() {
366
  */
367
  function wpt_remote_json( $url, $array = true, $method = 'GET' ) {
368
  $input = wpt_fetch_url( $url, $method );
369
- wpt_mail( 'Remote JSON input', print_r( $input, 1 ) . "\n\n" . $url );
370
- $obj = json_decode( $input, $array );
371
- wpt_mail( 'Remote JSON return value', print_r( $obj, 1 ) . "\n\n" . "$url" );
372
  if ( function_exists( 'json_last_error' ) ) { // > PHP 5.3.
373
  try {
374
  if ( is_null( $obj ) ) {
@@ -432,13 +434,16 @@ function wpt_is_valid_url( $url ) {
432
  */
433
  function wpt_fetch_url( $url, $method = 'GET', $body = '', $headers = '', $return = 'body' ) {
434
  $request = new WP_Http;
435
- $result = $request->request( $url, array(
436
- 'method' => $method,
437
- 'body' => $body,
438
- 'headers' => $headers,
439
- 'sslverify' => false,
440
- 'user-agent' => 'WP to Twitter/http://www.joedolson.com/wp-to-twitter/',
441
- ) );
 
 
 
442
 
443
  if ( ! is_wp_error( $result ) && isset( $result['body'] ) ) {
444
  if ( 200 == $result['response']['code'] ) {
@@ -570,9 +575,9 @@ function wtt_option_selected( $field, $value, $type = 'checkbox' ) {
570
  * @param string $modified Date this post was modified.
571
  * @param string $postdate Date this post was published.
572
  *
573
- * @return integer 1|0
574
  */
575
- function wpt_date_compare( $modified, $postdate ) {
576
  $modifier = apply_filters( 'wpt_edit_sensitivity', 0 ); // alter time in seconds to modified date.
577
  $mod_date = strtotime( $modified );
578
  $post_date = strtotime( $postdate ) + $modifier;
@@ -781,7 +786,7 @@ $plugins_string
781
  <p>" .
782
  __( 'The following additional information will be sent with your support request:', 'wp-to-twitter' )
783
  . "</p>
784
- <div class='mc_support'>
785
  " . wpautop( $data ) . '
786
  </div>
787
  </div>
286
  *
287
  * @param string $subject Subject of error.
288
  * @param string $body Body of error.
289
+ * @param int $post_ID ID of Post being Tweeted.
290
  * @param boolean $override Send message if debug disabled.
291
  */
292
+ function wpt_mail( $subject, $body, $post_ID = false, $override = false ) {
293
  if ( ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) || true == $override ) {
294
  if ( WPT_DEBUG_BY_EMAIL ) {
295
  wp_mail( WPT_DEBUG_ADDRESS, $subject, $body, WPT_FROM );
296
  } else {
297
+ wpt_debug_log( $subject, $body, $post_ID );
298
  }
299
  }
300
  }
304
  *
305
  * @param string $subject Subject of error.
306
  * @param string $body Body of error.
307
+ * @param int $post_ID ID of post being Tweeted.
308
  */
309
+ function wpt_debug_log( $subject, $body, $post_ID ) {
310
+ if ( ! $post_ID ) {
311
+ global $post_ID;
312
+ }
313
  if ( $post_ID ) {
314
  $time = current_time( 'timestamp' );
315
  add_post_meta( $post_ID, '_wpt_debug_log', array( $time, $subject, $body ) );
370
  */
371
  function wpt_remote_json( $url, $array = true, $method = 'GET' ) {
372
  $input = wpt_fetch_url( $url, $method );
373
+ $obj = json_decode( $input, $array );
 
 
374
  if ( function_exists( 'json_last_error' ) ) { // > PHP 5.3.
375
  try {
376
  if ( is_null( $obj ) ) {
434
  */
435
  function wpt_fetch_url( $url, $method = 'GET', $body = '', $headers = '', $return = 'body' ) {
436
  $request = new WP_Http;
437
+ $result = $request->request(
438
+ $url,
439
+ array(
440
+ 'method' => $method,
441
+ 'body' => $body,
442
+ 'headers' => $headers,
443
+ 'sslverify' => false,
444
+ 'user-agent' => 'WP to Twitter/http://www.joedolson.com/wp-to-twitter/',
445
+ )
446
+ );
447
 
448
  if ( ! is_wp_error( $result ) && isset( $result['body'] ) ) {
449
  if ( 200 == $result['response']['code'] ) {
575
  * @param string $modified Date this post was modified.
576
  * @param string $postdate Date this post was published.
577
  *
578
+ * @return integer (boolean)
579
  */
580
+ function wpt_post_is_new( $modified, $postdate ) {
581
  $modifier = apply_filters( 'wpt_edit_sensitivity', 0 ); // alter time in seconds to modified date.
582
  $mod_date = strtotime( $modified );
583
  $post_date = strtotime( $postdate ) + $modifier;
786
  <p>" .
787
  __( 'The following additional information will be sent with your support request:', 'wp-to-twitter' )
788
  . "</p>
789
+ <div class='wpt_support'>
790
  " . wpautop( $data ) . '
791
  </div>
792
  </div>
wpt-rate-limiting.php CHANGED
@@ -202,6 +202,10 @@ function wpt_add_term_rate_limit( $term ) {
202
  */
203
  function wpt_view_rate_limits() {
204
  $limits = get_option( 'wpt_rate_limits' );
 
 
 
 
205
  if ( is_array( $limits ) ) {
206
  $output = '<ul>';
207
  foreach ( $limits as $auth => $term ) {
@@ -227,6 +231,7 @@ function wpt_view_rate_limits() {
227
  } else {
228
  $output = __( 'No Tweets have been sent this hour.', 'wp-to-twitter' );
229
  }
 
230
 
231
- return $output;
232
  }
202
  */
203
  function wpt_view_rate_limits() {
204
  $limits = get_option( 'wpt_rate_limits' );
205
+ if ( ! wp_next_scheduled( 'wptratelimits' ) ) {
206
+ wp_schedule_event( current_time( 'timestamp' ) + 3600, 'hourly', 'wptratelimits' );
207
+ }
208
+ $next_scheduled = human_time_diff( wp_next_scheduled( 'wptratelimits' ), time() );
209
  if ( is_array( $limits ) ) {
210
  $output = '<ul>';
211
  foreach ( $limits as $auth => $term ) {
231
  } else {
232
  $output = __( 'No Tweets have been sent this hour.', 'wp-to-twitter' );
233
  }
234
+ $next = wpautop( sprintf( __( ' Next reset in %s.', 'wp-to-twitter' ), $next_scheduled ) );
235
 
236
+ return $output . $next;
237
  }
wpt-truncate.php CHANGED
@@ -26,11 +26,13 @@ function wpt_max_length() {
26
  $config = $connection->get( 'https://api.twitter.com/1.1/help/configuration.json' );
27
  set_transient( 'wpt_twitter_config', $config, 60 * 60 * 24 );
28
  } else {
29
- $config = json_encode( array(
30
- 'http_length' => 23,
31
- 'https_length' => 23,
32
- 'reserved_chars' => 24,
33
- ) );
 
 
34
  }
35
  }
36
 
26
  $config = $connection->get( 'https://api.twitter.com/1.1/help/configuration.json' );
27
  set_transient( 'wpt_twitter_config', $config, 60 * 60 * 24 );
28
  } else {
29
+ $config = json_encode(
30
+ array(
31
+ 'http_length' => 23,
32
+ 'https_length' => 23,
33
+ 'reserved_chars' => 24,
34
+ )
35
+ );
36
  }
37
  }
38
 
wpt-widget.php CHANGED
@@ -159,20 +159,24 @@ add_shortcode( 'get_tweets', 'wpt_get_twitter_feed' );
159
  * @return Twitter feed.
160
  */
161
  function wpt_get_twitter_feed( $atts, $content ) {
162
- $atts = ( shortcode_atts( array(
163
- 'id' => false,
164
- 'num' => 10,
165
- 'duration' => 1800,
166
- 'replies' => 0,
167
- 'rts' => 1,
168
- 'links' => 1,
169
- 'mentions' => 1,
170
- 'hashtags' => 0,
171
- 'intents' => 1,
172
- 'source' => 0,
173
- 'show_images' => 1,
174
- 'hide_header' => 0,
175
- ), $atts, 'get_tweets' ) );
 
 
 
 
176
  $instance = array(
177
  'twitter_id' => $atts['id'],
178
  'twitter_num' => $atts['num'],
159
  * @return Twitter feed.
160
  */
161
  function wpt_get_twitter_feed( $atts, $content ) {
162
+ $atts = shortcode_atts(
163
+ array(
164
+ 'id' => false,
165
+ 'num' => 10,
166
+ 'duration' => 1800,
167
+ 'replies' => 0,
168
+ 'rts' => 1,
169
+ 'links' => 1,
170
+ 'mentions' => 1,
171
+ 'hashtags' => 0,
172
+ 'intents' => 1,
173
+ 'source' => 0,
174
+ 'show_images' => 1,
175
+ 'hide_header' => 0,
176
+ ),
177
+ $atts,
178
+ 'get_tweets'
179
+ );
180
  $instance = array(
181
  'twitter_id' => $atts['id'],
182
  'twitter_num' => $atts['num'],