WP to Twitter - Version 3.4.2

Version Description

  • Bug fix: don't parse Username settings if user is connected to Twitter (Pro)
  • Bug fix: Non-semantic text in user settings.
  • Bug fix: type error in media comparison.
  • Improve logic for exiting media handling. (Pro)
Download this release

Release Info

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

Code changes from version 3.4.0 to 3.4.2

classes/class-tmhoauth.php CHANGED
@@ -275,10 +275,10 @@ class TmhOAuth {
275
  $path = isset( $parts['path'] ) ? $parts['path'] : false;
276
 
277
  if ( ! $port ) {
278
- $port = ( 'https' == $scheme ) ? '443' : '80';
279
  }
280
 
281
- if ( ( 'https' == $scheme && '443' != $port ) || ( 'http' == $scheme && '80' != $port ) ) {
282
  $host = "$host:$port";
283
  }
284
 
275
  $path = isset( $parts['path'] ) ? $parts['path'] : false;
276
 
277
  if ( ! $port ) {
278
+ $port = ( 'https' === $scheme ) ? '443' : '80';
279
  }
280
 
281
+ if ( ( 'https' === $scheme && '443' != $port ) || ( 'http' === $scheme && '80' != $port ) ) {
282
  $host = "$host:$port";
283
  }
284
 
classes/class-wp-oauth.php CHANGED
@@ -150,7 +150,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
150
  public function check_signature( $request, $consumer, $token, $signature ) {
151
  $built = $this->build_signature( $request, $consumer, $token );
152
 
153
- return $built == $signature;
154
  }
155
  }
156
 
@@ -322,7 +322,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
322
  // Release the key resource.
323
  openssl_free_key( $publickeyid );
324
 
325
- return 1 == $ok;
326
  }
327
  }
328
 
@@ -396,7 +396,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
396
  * @return WP_Oauth_Request object.
397
  */
398
  public static function from_request( $http_method = null, $http_url = null, $parameters = null ) {
399
- $scheme = ( ! isset( $_SERVER['HTTPS'] ) || 'on' != $_SERVER['HTTPS'] ) ? 'http' : 'https';
400
  if ( null === $http_url ) {
401
  $http_url = $scheme . '://' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
402
  }
@@ -416,7 +416,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
416
  // It's a POST request of the proper content-type, so parse POST.
417
  // parameters and add those overriding any duplicates from GET.
418
  $content_type = isset( $request_headers['Content-Type'] ) ? $request_headers['Content-Type'] : '';
419
- if ( 'POST' == $http_method && strstr( $content_type, 'application/x-www-form-urlencoded' ) ) {
420
  $post_data = WPOAuthUtil::parse_parameters(
421
  file_get_contents( self::$post_input )
422
  );
@@ -426,7 +426,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
426
  // We have a Authorization-header with OAuth data. Parse the header.
427
  // and add those overriding any duplicates from GET or POST.
428
  $authorization = isset( $request_headers['Authorization'] ) ? $request_headers['Authorization'] : '';
429
- if ( 'OAuth ' == substr( $authorization, 0, 6 ) ) {
430
  $header_parameters = WPOAuthUtil::split_header(
431
  $request_headers['Authorization']
432
  );
@@ -571,10 +571,10 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
571
  $path = isset( $parts['path'] ) ? $parts['path'] : '';
572
 
573
  if ( ! $port ) {
574
- $port = ( 'https' == $scheme ) ? '443' : '80';
575
  }
576
 
577
- if ( ( 'https' == $scheme && '443' != $port ) || ( 'http' == $scheme && '80' != $port )
578
  ) {
579
  $host = "$host:$port";
580
  }
150
  public function check_signature( $request, $consumer, $token, $signature ) {
151
  $built = $this->build_signature( $request, $consumer, $token );
152
 
153
+ return $built === $signature;
154
  }
155
  }
156
 
322
  // Release the key resource.
323
  openssl_free_key( $publickeyid );
324
 
325
+ return 1 === $ok;
326
  }
327
  }
328
 
396
  * @return WP_Oauth_Request object.
397
  */
398
  public static function from_request( $http_method = null, $http_url = null, $parameters = null ) {
399
+ $scheme = ( ! isset( $_SERVER['HTTPS'] ) || 'on' !== $_SERVER['HTTPS'] ) ? 'http' : 'https';
400
  if ( null === $http_url ) {
401
  $http_url = $scheme . '://' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
402
  }
416
  // It's a POST request of the proper content-type, so parse POST.
417
  // parameters and add those overriding any duplicates from GET.
418
  $content_type = isset( $request_headers['Content-Type'] ) ? $request_headers['Content-Type'] : '';
419
+ if ( 'POST' === $http_method && strstr( $content_type, 'application/x-www-form-urlencoded' ) ) {
420
  $post_data = WPOAuthUtil::parse_parameters(
421
  file_get_contents( self::$post_input )
422
  );
426
  // We have a Authorization-header with OAuth data. Parse the header.
427
  // and add those overriding any duplicates from GET or POST.
428
  $authorization = isset( $request_headers['Authorization'] ) ? $request_headers['Authorization'] : '';
429
+ if ( 'OAuth ' === substr( $authorization, 0, 6 ) ) {
430
  $header_parameters = WPOAuthUtil::split_header(
431
  $request_headers['Authorization']
432
  );
571
  $path = isset( $parts['path'] ) ? $parts['path'] : '';
572
 
573
  if ( ! $port ) {
574
+ $port = ( 'https' === $scheme ) ? '443' : '80';
575
  }
576
 
577
+ if ( ( 'https' === $scheme && '443' != $port ) || ( 'http' === $scheme && '80' != $port )
578
  ) {
579
  $host = "$host:$port";
580
  }
classes/class-wpt-search-tweets-widget.php CHANGED
@@ -131,7 +131,7 @@ class WPT_Search_Tweets_Widget extends WP_Widget {
131
 
132
  <p>
133
  <label for="<?php echo $this->get_field_id( 'result_type' ); ?>"><?php _e( 'Type of Results', 'wp-to-twitter' ); ?></label>
134
- <select name="<?php echo $this->get_field_name( 'result_type' ); ?>" id="<?php echo $this->get_field_id( 'result_type' ); ?>"> <option value='recent'<?php echo ( 'recent' == $instance['result_type'] ) ? ' selected="selected"' : ''; ?>><?php _e( 'Recent Tweets', 'wp-to-twitter' ); ?></option> <option value='popular'<?php echo ( 'popular' == $instance['result_type'] ) ? ' selected="selected"' : ''; ?>><?php _e( 'Popular Tweets', 'wp-to-twitter' ); ?></option> <option value='mixed'<?php echo ( 'mixed' == $instance['result_type'] ) ? ' selected="selected"' : ''; ?>><?php _e( 'Mixed', 'wp-to-twitter' ); ?></option>
135
  </select>
136
  </p>
137
 
131
 
132
  <p>
133
  <label for="<?php echo $this->get_field_id( 'result_type' ); ?>"><?php _e( 'Type of Results', 'wp-to-twitter' ); ?></label>
134
+ <select name="<?php echo $this->get_field_name( 'result_type' ); ?>" id="<?php echo $this->get_field_id( 'result_type' ); ?>"> <option value='recent'<?php echo ( 'recent' === $instance['result_type'] ) ? ' selected="selected"' : ''; ?>><?php _e( 'Recent Tweets', 'wp-to-twitter' ); ?></option> <option value='popular'<?php echo ( 'popular' === $instance['result_type'] ) ? ' selected="selected"' : ''; ?>><?php _e( 'Popular Tweets', 'wp-to-twitter' ); ?></option> <option value='mixed'<?php echo ( 'mixed' === $instance['result_type'] ) ? ' selected="selected"' : ''; ?>><?php _e( 'Mixed', 'wp-to-twitter' ); ?></option>
135
  </select>
136
  </p>
137
 
classes/class-wpt-twitterfeed.php CHANGED
@@ -196,7 +196,7 @@ class WPT_TwitterFeed {
196
  $delete_cache = get_option( 'wpt_delete_cache' );
197
  $file = $this->get_cache_location();
198
 
199
- if ( 'true' == $delete_cache ) {
200
  update_option( 'wpt_delete_cache', 'false' );
201
  $this->delete_cache( $file );
202
  }
@@ -286,7 +286,7 @@ class WPT_TwitterFeed {
286
  'q' => urlencode( $options['search'] ),
287
  'result_type' => urlencode( $options['result_type'] ),
288
  );
289
- if ( '' != $options['geocode'] ) {
290
  $args['geocode'] = urlencode( $options['geocode'] );
291
  }
292
  $url = add_query_arg( $args, 'https://api.twitter.com/1.1/search/tweets.json' );
196
  $delete_cache = get_option( 'wpt_delete_cache' );
197
  $file = $this->get_cache_location();
198
 
199
+ if ( 'true' === $delete_cache ) {
200
  update_option( 'wpt_delete_cache', 'false' );
201
  $this->delete_cache( $file );
202
  }
286
  'q' => urlencode( $options['search'] ),
287
  'result_type' => urlencode( $options['result_type'] ),
288
  );
289
+ if ( '' !== $options['geocode'] ) {
290
  $args['geocode'] = urlencode( $options['geocode'] );
291
  }
292
  $url = add_query_arg( $args, 'https://api.twitter.com/1.1/search/tweets.json' );
classes/class-wpt-twitteroauth.php CHANGED
@@ -403,7 +403,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
403
  */
404
  function wp_oauth_request( $url, $args = array(), $method = null ) {
405
  // Handle media requests using tmhOAuth library.
406
- if ( 'MEDIA' == $method ) {
407
  return $this->handle_media_request( $url, $args );
408
  }
409
 
403
  */
404
  function wp_oauth_request( $url, $args = array(), $method = null ) {
405
  // Handle media requests using tmhOAuth library.
406
+ if ( 'MEDIA' === $method ) {
407
  return $this->handle_media_request( $url, $args );
408
  }
409
 
readme.txt CHANGED
@@ -1,13 +1,13 @@
1
  === WP to Twitter ===
2
  Contributors: joedolson
3
  Donate link: http://www.joedolson.com/donate/
4
- Tags: twitter, microblogging, su.pr, bitly, yourls, redirect, shortener, post, links, social, sharing, media, tweet
5
  Requires at least: 4.4
6
  Tested up to: 5.2
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
- Stable tag: 3.4.0
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
@@ -63,6 +63,20 @@ Check out my <a href="https://github.com/joedolson/plugin-extensions/tree/master
63
 
64
  == Changelog ==
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  = 3.4.0 =
67
 
68
  * New function: wpt_allowed_post_types(). Returns array of post types that can be Tweeted.
1
  === WP to Twitter ===
2
  Contributors: joedolson
3
  Donate link: http://www.joedolson.com/donate/
4
+ Tags: twitter, microblogging, bitly, yourls, redirect, shortener, post, links, social, sharing, media, tweet
5
  Requires at least: 4.4
6
  Tested up to: 5.2
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
+ Stable tag: 3.4.2
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
63
 
64
  == Changelog ==
65
 
66
+ = 3.4.2 =
67
+
68
+ * Bug fix: don't parse Username settings if user is connected to Twitter (Pro)
69
+ * Bug fix: Non-semantic text in user settings.
70
+ * Bug fix: type error in media comparison.
71
+ * Improve logic for exiting media handling. (Pro)
72
+
73
+ = 3.4.1 =
74
+
75
+ * Removed goo.gl shortener completely (disabled by Goo.gl in March 2019)
76
+ * Removed su.pr shortener completely (Stumbleupon closed down in June 2018)
77
+ * Prep for removal of Bit.ly URL shortener. (Bitly API v3 will shut down March 2020)
78
+ * Misc. markup improvements.
79
+
80
  = 3.4.0 =
81
 
82
  * New function: wpt_allowed_post_types(). Returns array of post types that can be Tweeted.
wp-to-twitter-manager.php CHANGED
@@ -38,7 +38,7 @@ function wpt_updated_settings() {
38
 
39
  // notifications from oauth connection.
40
  if ( isset( $_POST['oauth_settings'] ) ) {
41
- if ( 'success' == $oauth_message ) {
42
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro?tab=basic' );
43
 
44
  print( '
@@ -46,19 +46,19 @@ function wpt_updated_settings() {
46
  <p>' . __( 'WP to Twitter is now connected with Twitter.', 'wp-to-twitter' ) . " <a href='$admin_url'>" . __( 'Configure your Tweet templates', 'wp-to-twitter' ) . '</a></p>
47
  </div>
48
  ' );
49
- } elseif ( 'failed' == $oauth_message ) {
50
  print( '
51
  <div id="message" class="error fade">
52
  <p>' . __( 'WP to Twitter failed to connect with Twitter.', 'wp-to-twitter' ) . ' <strong>' . __( 'Error:', 'wp-to-twitter' ) . '</strong> ' . get_option( 'wpt_error' ) . '</p>
53
  </div>
54
  ' );
55
- } elseif ( 'cleared' == $oauth_message ) {
56
  print( '
57
  <div id="message" class="updated fade">
58
  <p>' . __( 'OAuth Authentication Data Cleared.', 'wp-to-twitter' ) . '</p>
59
  </div>
60
  ' );
61
- } elseif ( 'nosync' == $oauth_message ) {
62
  print( '
63
  <div id="message" class="error fade">
64
  <p>' . __( 'OAuth Authentication Failed. Your server time is not in sync with the Twitter servers. Talk to your hosting service to see what can be done.', 'wp-to-twitter' ) . '</p>
@@ -73,7 +73,7 @@ function wpt_updated_settings() {
73
  }
74
  }
75
 
76
- if ( isset( $_POST['submit-type'] ) && 'advanced' == $_POST['submit-type'] ) {
77
  update_option( 'jd_tweet_default', ( isset( $_POST['jd_tweet_default'] ) ) ? $_POST['jd_tweet_default'] : 0 );
78
  update_option( 'jd_tweet_default_edit', ( isset( $_POST['jd_tweet_default_edit'] ) ) ? $_POST['jd_tweet_default_edit'] : 0 );
79
 
@@ -97,7 +97,7 @@ function wpt_updated_settings() {
97
  update_option( 'jd_max_tags', $_POST['jd_max_tags'] );
98
  $use_cats = ( isset( $_POST['wpt_use_cats'] ) ) ? $_POST['wpt_use_cats'] : 0;
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'] );
@@ -146,7 +146,7 @@ function wpt_updated_settings() {
146
  $message .= __( 'WP to Twitter Advanced Options Updated', 'wp-to-twitter' ) . '. ' . $extend;
147
  }
148
 
149
- if ( isset( $_POST['submit-type'] ) && 'options' == $_POST['submit-type'] ) {
150
  // UPDATE OPTIONS.
151
  $wpt_settings = get_option( 'wpt_post_types' );
152
  if ( ! is_array( $wpt_settings ) ) {
@@ -178,12 +178,12 @@ function wpt_updated_settings() {
178
  $message = apply_filters( 'wpt_settings', $message, $_POST );
179
  }
180
 
181
- if ( isset( $_POST['wpt_shortener_update'] ) && 'true' == $_POST['wpt_shortener_update'] ) {
182
  $message = wpt_shortener_update( $_POST );
183
  }
184
 
185
  // Check whether the server has supported for needed functions.
186
- if ( isset( $_POST['submit-type'] ) && 'check-support' == $_POST['submit-type'] ) {
187
  $message = wpt_check_functions();
188
  }
189
 
@@ -219,12 +219,12 @@ function wpt_update_settings() {
219
  <?php
220
  $default = ( '' == get_option( 'wtt_twitter_username' ) ) ? 'connection' : 'basic';
221
  $current = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $default;
222
- if ( 'connection' == $current ) {
223
  if ( function_exists( 'wtt_connect_oauth' ) ) {
224
  wtt_connect_oauth();
225
  }
226
  }
227
- if ( 'pro' == $current ) {
228
  if ( function_exists( 'wpt_pro_functions' ) ) {
229
  wpt_pro_functions();
230
  if ( function_exists( 'wpt_notes' ) ) {
@@ -290,7 +290,7 @@ function wpt_update_settings() {
290
  }
291
  }
292
  }
293
- if ( 'basic' == $current ) {
294
  ?>
295
  <div class="ui-sortable meta-box-sortables">
296
  <div class="postbox">
@@ -316,7 +316,7 @@ function wpt_update_settings() {
316
  }
317
  $name = $type->labels->name;
318
  $slug = $type->name;
319
- if ( 'attachment' == $slug || 'nav_menu_item' == $slug || 'revision' == $slug ) {
320
  } else {
321
  $tabs .= "<li><a href='#wpt_$slug' role='tab' id='tab_wpt_$slug' aria-controls='wpt_$slug'>$name</a></li>";
322
  }
@@ -329,14 +329,14 @@ function wpt_update_settings() {
329
  }
330
  $name = $type->labels->name;
331
  $slug = $type->name;
332
- if ( 'attachment' == $slug || 'nav_menu_item' == $slug || 'revision' == $slug ) {
333
  continue;
334
  } else {
335
  ?>
336
  <div class='wptab wpt_types wpt_<?php echo $slug; ?>' aria-labelledby='tab_wpt_<?php echo $slug; ?>' role="tabpanel" id='wpt_<?php echo $slug; ?>'>
337
  <?php
338
  // share information about any usage of pre 2.8 category filters.
339
- if ( '0' != get_option( 'limit_categories' ) && 'post' == $slug ) {
340
  $falseness = get_option( 'jd_twit_cats' );
341
  $categories = get_option( 'tweet_categories' );
342
  if ( 1 == $falseness ) {
@@ -468,11 +468,11 @@ function wpt_update_settings() {
468
  </div>
469
  <?php
470
  }
471
- if ( 'shortener' == $current ) {
472
  echo apply_filters( 'wpt_shortener_controls', '' );
473
  }
474
 
475
- if ( 'advanced' == $current ) {
476
  ?>
477
  <form method="post" action="">
478
  <div class="ui-sortable meta-box-sortables">
@@ -499,7 +499,7 @@ function wpt_update_settings() {
499
  <label for="wpt_use_cats"><?php _e( 'Use categories instead of tags', 'wp-to-twitter' ); ?></label><br/>
500
  </p>
501
  <?php
502
- if ( ! ( '[ ]' == get_option( 'jd_replace_character' ) || '' == get_option( 'jd_replace_character' ) ) ) {
503
  ?>
504
  <p>
505
  <label for="jd_replace_character"><?php _e( 'Spaces in tags replaced with:', 'wp-to-twitter' ); ?></label>
@@ -534,7 +534,7 @@ function wpt_update_settings() {
534
  <label for="jd_date_format"><?php _e( 'Date Format (#date#):', 'wp-to-twitter' ); ?></label>
535
  <input type="text" aria-describedby="date_format_label" name="jd_date_format" id="jd_date_format" size="12" maxlength="12" value="
536
  <?php
537
- if ( '' == get_option( 'jd_date_format' ) ) {
538
  echo( esc_attr( stripslashes( get_option( 'date_format' ) ) ) );
539
  } else {
540
  echo( esc_attr( get_option( 'jd_date_format' ) ) );
@@ -601,7 +601,6 @@ function wpt_update_settings() {
601
  <div class="inside">
602
  <fieldset>
603
  <legend class='screen-reader-text'><?php _e( 'Google Analytics Settings', 'wp-to-twitter' ); ?></legend>
604
-
605
  <p>
606
  <input type="radio" name="twitter-analytics" id="use-twitter-analytics" value="1" <?php echo wpt_checkbox( 'use-twitter-analytics' ); ?> />
607
  <label for="use-twitter-analytics"><?php _e( 'Use a Static Identifier', 'wp-to-twitter' ); ?></label><br/>
@@ -652,7 +651,7 @@ function wpt_update_settings() {
652
  $role_tabs = '';
653
  $role_container = '';
654
  foreach ( $roles as $role => $rolename ) {
655
- if ( 'administrator' == $role ) {
656
  continue;
657
  }
658
  $role_tabs .= "<li><a href='#wpt_" . sanitize_title( $role ) . "'>$rolename</a></li>\n";
@@ -704,9 +703,9 @@ function wpt_update_settings() {
704
  }
705
  asort( $default_order );
706
  foreach ( $default_order as $k => $v ) {
707
- if ( 'blogname' == $k ) {
708
  $label = '<code>#blog#</code>';
709
- } elseif ( 'excerpt' == $k ) {
710
  $label = '<code>#post#</code>';
711
  } else {
712
  $label = '<code>#' . $k . '#</code>';
@@ -759,7 +758,7 @@ function wpt_update_settings() {
759
  </div>
760
  <?php
761
  }
762
- if ( 'support' == $current ) {
763
  ?>
764
  <div class="postbox" id="get-support">
765
  <h3><span><?php _e( 'Get Plug-in Support', 'wp-to-twitter' ); ?></span></h3>
@@ -804,7 +803,7 @@ function wpt_sidebar() {
804
  <div class="ui-sortable meta-box-sortables<?php echo ' ' . $context; ?>">
805
  <div class="postbox">
806
  <?php
807
- if ( 'free' == $context ) {
808
  ?>
809
  <h3><span><strong><?php _e( 'Support WP to Twitter', 'wp-to-twitter' ); ?></strong></span></h3>
810
  <?php
@@ -835,7 +834,7 @@ function wpt_sidebar() {
835
  }(document, "script", "twitter-wjs");</script>
836
  </p>
837
  <?php
838
- if ( 'premium' == $context ) {
839
  $support_url = admin_url( 'admin.php?page=wp-tweets-pro' );
840
  $support = '<a href="' . esc_url( add_query_arg( 'tab', 'support', $support_url ) ) . '#get-support">' . __( 'Get Support', 'wp-to-twitter' ) . '</a> &bull;';
841
  } else {
38
 
39
  // notifications from oauth connection.
40
  if ( isset( $_POST['oauth_settings'] ) ) {
41
+ if ( 'success' === $oauth_message ) {
42
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro?tab=basic' );
43
 
44
  print( '
46
  <p>' . __( 'WP to Twitter is now connected with Twitter.', 'wp-to-twitter' ) . " <a href='$admin_url'>" . __( 'Configure your Tweet templates', 'wp-to-twitter' ) . '</a></p>
47
  </div>
48
  ' );
49
+ } elseif ( 'failed' === $oauth_message ) {
50
  print( '
51
  <div id="message" class="error fade">
52
  <p>' . __( 'WP to Twitter failed to connect with Twitter.', 'wp-to-twitter' ) . ' <strong>' . __( 'Error:', 'wp-to-twitter' ) . '</strong> ' . get_option( 'wpt_error' ) . '</p>
53
  </div>
54
  ' );
55
+ } elseif ( 'cleared' === $oauth_message ) {
56
  print( '
57
  <div id="message" class="updated fade">
58
  <p>' . __( 'OAuth Authentication Data Cleared.', 'wp-to-twitter' ) . '</p>
59
  </div>
60
  ' );
61
+ } elseif ( 'nosync' === $oauth_message ) {
62
  print( '
63
  <div id="message" class="error fade">
64
  <p>' . __( 'OAuth Authentication Failed. Your server time is not in sync with the Twitter servers. Talk to your hosting service to see what can be done.', 'wp-to-twitter' ) . '</p>
73
  }
74
  }
75
 
76
+ if ( isset( $_POST['submit-type'] ) && 'advanced' === $_POST['submit-type'] ) {
77
  update_option( 'jd_tweet_default', ( isset( $_POST['jd_tweet_default'] ) ) ? $_POST['jd_tweet_default'] : 0 );
78
  update_option( 'jd_tweet_default_edit', ( isset( $_POST['jd_tweet_default_edit'] ) ) ? $_POST['jd_tweet_default_edit'] : 0 );
79
 
97
  update_option( 'jd_max_tags', $_POST['jd_max_tags'] );
98
  $use_cats = ( isset( $_POST['wpt_use_cats'] ) ) ? $_POST['wpt_use_cats'] : 0;
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'] );
146
  $message .= __( 'WP to Twitter Advanced Options Updated', 'wp-to-twitter' ) . '. ' . $extend;
147
  }
148
 
149
+ if ( isset( $_POST['submit-type'] ) && 'options' === $_POST['submit-type'] ) {
150
  // UPDATE OPTIONS.
151
  $wpt_settings = get_option( 'wpt_post_types' );
152
  if ( ! is_array( $wpt_settings ) ) {
178
  $message = apply_filters( 'wpt_settings', $message, $_POST );
179
  }
180
 
181
+ if ( isset( $_POST['wpt_shortener_update'] ) && 'true' === $_POST['wpt_shortener_update'] ) {
182
  $message = wpt_shortener_update( $_POST );
183
  }
184
 
185
  // Check whether the server has supported for needed functions.
186
+ if ( isset( $_POST['submit-type'] ) && 'check-support' === $_POST['submit-type'] ) {
187
  $message = wpt_check_functions();
188
  }
189
 
219
  <?php
220
  $default = ( '' == get_option( 'wtt_twitter_username' ) ) ? 'connection' : 'basic';
221
  $current = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $default;
222
+ if ( 'connection' === $current ) {
223
  if ( function_exists( 'wtt_connect_oauth' ) ) {
224
  wtt_connect_oauth();
225
  }
226
  }
227
+ if ( 'pro' === $current ) {
228
  if ( function_exists( 'wpt_pro_functions' ) ) {
229
  wpt_pro_functions();
230
  if ( function_exists( 'wpt_notes' ) ) {
290
  }
291
  }
292
  }
293
+ if ( 'basic' === $current ) {
294
  ?>
295
  <div class="ui-sortable meta-box-sortables">
296
  <div class="postbox">
316
  }
317
  $name = $type->labels->name;
318
  $slug = $type->name;
319
+ if ( 'attachment' === $slug || 'nav_menu_item' === $slug || 'revision' === $slug ) {
320
  } else {
321
  $tabs .= "<li><a href='#wpt_$slug' role='tab' id='tab_wpt_$slug' aria-controls='wpt_$slug'>$name</a></li>";
322
  }
329
  }
330
  $name = $type->labels->name;
331
  $slug = $type->name;
332
+ if ( 'attachment' === $slug || 'nav_menu_item' === $slug || 'revision' === $slug ) {
333
  continue;
334
  } else {
335
  ?>
336
  <div class='wptab wpt_types wpt_<?php echo $slug; ?>' aria-labelledby='tab_wpt_<?php echo $slug; ?>' role="tabpanel" id='wpt_<?php echo $slug; ?>'>
337
  <?php
338
  // share information about any usage of pre 2.8 category filters.
339
+ if ( '0' != get_option( 'limit_categories' ) && 'post' === $slug ) {
340
  $falseness = get_option( 'jd_twit_cats' );
341
  $categories = get_option( 'tweet_categories' );
342
  if ( 1 == $falseness ) {
468
  </div>
469
  <?php
470
  }
471
+ if ( 'shortener' === $current ) {
472
  echo apply_filters( 'wpt_shortener_controls', '' );
473
  }
474
 
475
+ if ( 'advanced' === $current ) {
476
  ?>
477
  <form method="post" action="">
478
  <div class="ui-sortable meta-box-sortables">
499
  <label for="wpt_use_cats"><?php _e( 'Use categories instead of tags', 'wp-to-twitter' ); ?></label><br/>
500
  </p>
501
  <?php
502
+ if ( ! ( '[ ]' === get_option( 'jd_replace_character' ) || '' === get_option( 'jd_replace_character', '' ) ) ) {
503
  ?>
504
  <p>
505
  <label for="jd_replace_character"><?php _e( 'Spaces in tags replaced with:', 'wp-to-twitter' ); ?></label>
534
  <label for="jd_date_format"><?php _e( 'Date Format (#date#):', 'wp-to-twitter' ); ?></label>
535
  <input type="text" aria-describedby="date_format_label" name="jd_date_format" id="jd_date_format" size="12" maxlength="12" value="
536
  <?php
537
+ if ( '' === get_option( 'jd_date_format', '' ) ) {
538
  echo( esc_attr( stripslashes( get_option( 'date_format' ) ) ) );
539
  } else {
540
  echo( esc_attr( get_option( 'jd_date_format' ) ) );
601
  <div class="inside">
602
  <fieldset>
603
  <legend class='screen-reader-text'><?php _e( 'Google Analytics Settings', 'wp-to-twitter' ); ?></legend>
 
604
  <p>
605
  <input type="radio" name="twitter-analytics" id="use-twitter-analytics" value="1" <?php echo wpt_checkbox( 'use-twitter-analytics' ); ?> />
606
  <label for="use-twitter-analytics"><?php _e( 'Use a Static Identifier', 'wp-to-twitter' ); ?></label><br/>
651
  $role_tabs = '';
652
  $role_container = '';
653
  foreach ( $roles as $role => $rolename ) {
654
+ if ( 'administrator' === $role ) {
655
  continue;
656
  }
657
  $role_tabs .= "<li><a href='#wpt_" . sanitize_title( $role ) . "'>$rolename</a></li>\n";
703
  }
704
  asort( $default_order );
705
  foreach ( $default_order as $k => $v ) {
706
+ if ( 'blogname' === $k ) {
707
  $label = '<code>#blog#</code>';
708
+ } elseif ( 'excerpt' === $k ) {
709
  $label = '<code>#post#</code>';
710
  } else {
711
  $label = '<code>#' . $k . '#</code>';
758
  </div>
759
  <?php
760
  }
761
+ if ( 'support' === $current ) {
762
  ?>
763
  <div class="postbox" id="get-support">
764
  <h3><span><?php _e( 'Get Plug-in Support', 'wp-to-twitter' ); ?></span></h3>
803
  <div class="ui-sortable meta-box-sortables<?php echo ' ' . $context; ?>">
804
  <div class="postbox">
805
  <?php
806
+ if ( 'free' === $context ) {
807
  ?>
808
  <h3><span><strong><?php _e( 'Support WP to Twitter', 'wp-to-twitter' ); ?></strong></span></h3>
809
  <?php
834
  }(document, "script", "twitter-wjs");</script>
835
  </p>
836
  <?php
837
+ if ( 'premium' === $context ) {
838
  $support_url = admin_url( 'admin.php?page=wp-tweets-pro' );
839
  $support = '<a href="' . esc_url( add_query_arg( 'tab', 'support', $support_url ) ) . '#get-support">' . __( 'Get Support', 'wp-to-twitter' ) . '</a> &bull;';
840
  } else {
wp-to-twitter-oauth.php CHANGED
@@ -185,7 +185,7 @@ function wpt_update_oauth_settings( $auth = false, $post = false ) {
185
  } else {
186
  $message = 'nodata';
187
  }
188
- if ( 'failed' == $message && ( time() < strtotime( $connection->http_header['date'] ) - 300 || time() > strtotime( $connection->http_header['date'] ) + 300 ) ) {
189
  $message = 'nosync';
190
  }
191
 
185
  } else {
186
  $message = 'nodata';
187
  }
188
+ if ( 'failed' === $message && ( time() < strtotime( $connection->http_header['date'] ) - 300 || time() > strtotime( $connection->http_header['date'] ) + 300 ) ) {
189
  $message = 'nosync';
190
  }
191
 
wp-to-twitter-shorteners.php CHANGED
@@ -43,16 +43,16 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
43
  if ( 1 == get_option( 'use-twitter-analytics' ) || 1 == get_option( 'use_dynamic_analytics' ) ) {
44
  if ( '1' == get_option( 'use_dynamic_analytics' ) ) {
45
  $campaign_type = get_option( 'jd_dynamic_analytics' );
46
- if ( 'post_category' == $campaign_type && 'link' != $testmode ) {
47
  $category = get_the_category( $post_ID );
48
  $campaign = sanitize_title( $category[0]->cat_name );
49
- } elseif ( 'post_ID' == $campaign_type ) {
50
  $campaign = $post_ID;
51
- } elseif ( 'post_title' == $campaign_type && 'link' != $testmode ) {
52
  $post = get_post( $post_ID );
53
  $campaign = sanitize_title( $post->post_title );
54
  } else {
55
- if ( 'link' != $testmode ) {
56
  $post = get_post( $post_ID );
57
  $post_author = $post->post_author;
58
  $campaign = urlencode( get_the_author_meta( 'user_login', $post_author ) );
@@ -94,6 +94,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
94
  $shrink = $url;
95
  break;
96
  case 2: // updated to v3 3/31/2010.
 
97
  $bitlyapi = trim( get_option( 'bitlyapi' ) );
98
  $bitlylogin = trim( strtolower( get_option( 'bitlylogin' ) ) );
99
  $decoded = wpt_remote_json( 'https://api-ssl.bitly.com/v3/shorten?longUrl=' . $encoded . '&login=' . $bitlylogin . '&apiKey=' . $bitlyapi . '&format=json' );
@@ -181,42 +182,9 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
181
  }
182
  break;
183
  case 7:
184
- $suprapi = trim( get_option( 'suprapi' ) );
185
- $suprlogin = trim( get_option( 'suprlogin' ) );
186
- if ( '' != $suprapi ) {
187
- $decoded = wpt_remote_json( 'http://su.pr/api/shorten?longUrl=' . $encoded . '&login=' . $suprlogin . '&apiKey=' . $suprapi );
188
- } else {
189
- $decoded = wpt_remote_json( 'http://su.pr/api/shorten?longUrl=' . $encoded );
190
- }
191
- if ( $decoded && isset( $decoded['statusCode'] ) ) {
192
- if ( 'OK' == $decoded['statusCode'] ) {
193
- $page = str_replace( '&', '&#38;', urldecode( $url ) );
194
- $shrink = $decoded['results'][ $page ]['shortUrl'];
195
- $error = $decoded['errorMessage'];
196
- } else {
197
- $shrink = false;
198
- $error = $decoded['errorMessage'];
199
- }
200
- } else {
201
- $shrink = false;
202
- $error = __( 'Su.pr query returned invalid data.', 'wp-to-twitter' );
203
- }
204
- if ( ! wpt_is_valid_url( $shrink ) ) {
205
- $shrink = false;
206
- }
207
- break;
208
  case 8:
209
- // Goo.gl.
210
- $googl_api_key = ( '' == get_option( 'googl_api_key' ) ) ? 'AIzaSyBSnqQOg3vX1gwR7y2l-40yEG9SZiaYPUQ' : get_option( 'googl_api_key' );
211
- $target = "https://www.googleapis.com/urlshortener/v1/url?key=$googl_api_key";
212
- $body = "{'longUrl':'$url'}";
213
- $json = wpt_fetch_url( $target, 'POST', $body, 'Content-Type: application/json' );
214
- $decoded = json_decode( $json );
215
- $shrink = $decoded->id;
216
- if ( ! wpt_is_valid_url( $shrink ) ) {
217
- $shrink = false;
218
- }
219
- break;
220
  case 9:
221
  // Twitter Friendly Links. This plugin not updated in 8 years.
222
  $shrink = $url;
@@ -375,25 +343,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
375
  <div class="inside">
376
  <?php
377
  if ( 7 == $shortener ) {
378
- ?>
379
- <?php echo $form_start; ?>
380
- <p>
381
- <label
382
- for="suprlogin"><?php _e( 'Your Su.pr Username:', 'wp-to-twitter' ); ?></label>
383
- <input type="text" name="suprlogin" id="suprlogin" size="40" value="<?php echo esc_attr( get_option( 'suprlogin' ) ); ?> "/>
384
- </p>
385
- <p>
386
- <label
387
- for="suprapi"><?php _e( "Your Su.pr <abbr title='application programming interface'>API</abbr> Key:", 'wp-to-twitter' ); ?></label>
388
- <input type="text" name="suprapi" id="suprapi" size="40" value="<?php echo esc_attr( get_option( 'suprapi' ) ); ?> "/>
389
- </p>
390
-
391
- <div>
392
- <input type="hidden" name="submit-type" value="suprapi"/>
393
- </div>
394
- <p><small><?php _e( "Don't have a Su.pr account or API key? <a href='http://su.pr/'>Get one here!</a> You'll need an API key in order to associate the URLs you create with your Su.pr account.", 'wp-to-twitter' ); ?></small></p>
395
- <?php echo $form_end; ?>
396
- <?php
397
  } elseif ( 2 == $shortener ) {
398
  echo $form_start;
399
  ?>
@@ -463,16 +413,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
463
  <?php
464
  echo $form_end;
465
  } elseif ( 8 == $shortener ) {
466
- echo '<p>' . __( 'The Goo.gl URL shortener will be shut down by Google on March 30th, 2019, and will be removed from WP to Twitter in the near future.', 'wp-to-twitter' ) . '</p>';
467
- echo $form_start;
468
- ?>
469
- <p>
470
- <label for="googl_api_key"><?php _e( 'Goo.gl API Key:', 'wp-to-twitter' ); ?></label>
471
- <input type="text" name="googl_api_key" id="googl_api_key" value="<?php echo esc_attr( get_option( 'googl_api_key' ) ); ?>"/>
472
- </p>
473
- <div><input type="hidden" name="submit-type" value="googlapi" /></div>
474
- <?php
475
- echo $form_end;
476
  } elseif ( 10 == $shortener ) {
477
  echo $form_start;
478
  ?>
@@ -521,7 +462,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
521
  */
522
  function wpt_shortener_update( $post ) {
523
  $message = '';
524
- if ( isset( $post['submit-type'] ) && 'yourlsapi' == $post['submit-type'] ) {
525
  $message = '';
526
  if ( '' != $post['yourlstoken'] && isset( $post['submit'] ) ) {
527
  update_option( 'yourlstoken', trim( $post['yourlstoken'] ) );
@@ -560,21 +501,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
560
  }
561
  }
562
 
563
- if ( isset( $post['submit-type'] ) && 'suprapi' == $post['submit-type'] ) {
564
- if ( '' != $post['suprapi'] && isset( $post['submit'] ) ) {
565
- update_option( 'suprapi', trim( $post['suprapi'] ) );
566
- update_option( 'suprlogin', trim( $post['suprlogin'] ) );
567
- $message = __( 'Su.pr API Key and Username Updated', 'wp-to-twitter' );
568
- } elseif ( isset( $post['clear'] ) ) {
569
- update_option( 'suprapi', '' );
570
- update_option( 'suprlogin', '' );
571
- $message = __( 'Su.pr API Key and username deleted. Su.pr URLs created by WP to Twitter will no longer be associated with your account.', 'wp-to-twitter' );
572
- } else {
573
- $message = __( "Su.pr API Key not added - <a href='http://su.pr/'>get one here</a>!", 'wp-to-twitter' );
574
- }
575
- }
576
-
577
- if ( isset( $post['submit-type'] ) && 'bitlyapi' == $post['submit-type'] ) {
578
  if ( '' != $post['bitlyapi'] && isset( $post['submit'] ) ) {
579
  update_option( 'bitlyapi', trim( $post['bitlyapi'] ) );
580
  $message = __( 'Bit.ly API Key Updated.', 'wp-to-twitter' );
@@ -594,16 +521,8 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
594
  $message = __( "Bit.ly Login not added - <a href='http://bit.ly/account/'>get one here</a>!", 'wp-to-twitter' );
595
  }
596
  }
597
- if ( isset( $post['submit-type'] ) && 'googlapi' == $post['submit-type'] ) {
598
- if ( '' != $post['googl_api_key'] && isset( $post['submit'] ) ) {
599
- update_option( 'googl_api_key', trim( $post['googl_api_key'] ) );
600
- $message .= __( 'Goo.gl API Key Updated.', 'wp-to-twitter' );
601
- } else {
602
- $message = __( "Goo.gl API Key not added - <a href='https://developers.google.com/url-shortener/v1/getting_started'>get one here</a>! ", 'wp-to-twitter' );
603
- }
604
- }
605
 
606
- if ( isset( $post['submit-type'] ) && 'joturlapi' == $post['submit-type'] ) {
607
  if ( '' != $post['joturlapi'] && isset( $post['submit'] ) ) {
608
  update_option( 'joturlapi', trim( $post['joturlapi'] ) );
609
  $message = __( 'jotURL private API Key Updated.', 'wp-to-twitter' );
@@ -662,21 +581,21 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
662
  // don't return a message if unchanged.
663
  $stored = ( isset( $_POST['wpt_use_stored_urls'] ) ) ? 'false' : 'true';
664
  update_option( 'wpt_use_stored_urls', $stored );
665
- if ( get_option( 'jd_shortener' ) == $post['jd_shortener'] ) {
666
  return;
667
  }
668
  update_option( 'jd_shortener', sanitize_key( $post['jd_shortener'] ) );
669
- $short = get_option( 'jd_shortener' );
670
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
671
  $admin_url = add_query_arg( 'tab', 'shortener', $admin_url );
672
 
673
  // these are the URL shorteners which require settings.
674
- if ( 2 == $short || 10 == $short || 6 == $short ) {
675
  // Translators: Settings URL for shortener configuration.
676
  $message .= sprintf( __( 'You must <a href="%s">configure your URL shortener settings</a>.', 'wp-to-twitter' ), $admin_url );
677
  }
678
 
679
- if ( '' != $message ) {
680
  $message .= '<br />';
681
  }
682
 
@@ -688,9 +607,9 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
688
  * Form to select your shortener.
689
  */
690
  function wpt_pick_shortener() {
691
- $shortener = get_option( 'jd_shortener' );
692
- if ( 8 == $shortener ) {
693
- echo '<p>' . __( 'The Goo.gl URL shortener will be shut down by Google on March 30th, 2019, and will be removed from WP to Twitter in the near future.', 'wp-to-twitter' ) . '</p>';
694
  }
695
  ?>
696
  <p>
@@ -698,17 +617,13 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
698
  <select name="jd_shortener" id="jd_shortener">
699
  <option value="3" <?php selected( $shortener, '3' ); ?>><?php _e( "Don't shorten URLs.", 'wp-to-twitter' ); ?></option>
700
  <option value="4" <?php selected( $shortener, '4' ); ?>>WordPress</option>
701
- <option value="2" <?php selected( $shortener, '2' ); ?>>Bit.ly</option>
702
  <?php
703
- if ( 8 == $shortener ) { // if already selected, leave available.
704
  ?>
705
- <option value="8" <?php selected( $shortener, '8' ); ?>>Goo.gl</option>
706
  <?php
707
  }
708
- ?>
709
- <option value="7" <?php selected( $shortener, '7' ); ?>>Su.pr</option>
710
- <?php
711
- if ( 5 == $shortener ) { // if the user has already selected local server, leave available.
712
  ?>
713
  <option value="5" <?php selected( $shortener, '5' ); ?>><?php _e( 'YOURLS (this server)', 'wp-to-twitter' ); ?></option>
714
  <?php
@@ -722,7 +637,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
722
  ?>
723
  </select>
724
  <?php
725
- if ( 3 != $shortener ) {
726
  ?>
727
  <input type='checkbox' value='false' name='wpt_use_stored_urls' id='wpt_use_stored_urls' <?php checked( get_option( 'wpt_use_stored_urls' ), 'false' ); ?>> <label for='wpt_use_stored_urls'><?php _e( 'Always request a new short URL for Tweets', 'wp-to-twitter' ); ?></label>
728
  <?php
43
  if ( 1 == get_option( 'use-twitter-analytics' ) || 1 == get_option( 'use_dynamic_analytics' ) ) {
44
  if ( '1' == get_option( 'use_dynamic_analytics' ) ) {
45
  $campaign_type = get_option( 'jd_dynamic_analytics' );
46
+ if ( 'post_category' === $campaign_type && 'link' !== $testmode ) {
47
  $category = get_the_category( $post_ID );
48
  $campaign = sanitize_title( $category[0]->cat_name );
49
+ } elseif ( 'post_ID' === $campaign_type ) {
50
  $campaign = $post_ID;
51
+ } elseif ( 'post_title' === $campaign_type && 'link' !== $testmode ) {
52
  $post = get_post( $post_ID );
53
  $campaign = sanitize_title( $post->post_title );
54
  } else {
55
+ if ( 'link' !== $testmode ) {
56
  $post = get_post( $post_ID );
57
  $post_author = $post->post_author;
58
  $campaign = urlencode( get_the_author_meta( 'user_login', $post_author ) );
94
  $shrink = $url;
95
  break;
96
  case 2: // updated to v3 3/31/2010.
97
+ // v3 is being sunsetted 3/31/2020. Option to enable removed 7/4/2019.
98
  $bitlyapi = trim( get_option( 'bitlyapi' ) );
99
  $bitlylogin = trim( strtolower( get_option( 'bitlylogin' ) ) );
100
  $decoded = wpt_remote_json( 'https://api-ssl.bitly.com/v3/shorten?longUrl=' . $encoded . '&login=' . $bitlylogin . '&apiKey=' . $bitlyapi . '&format=json' );
182
  }
183
  break;
184
  case 7:
185
+ // Su.pr. Stumbleupon closed doors in June 2018.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  case 8:
187
+ // Goo.gl. Service disabled March 2019.
 
 
 
 
 
 
 
 
 
 
188
  case 9:
189
  // Twitter Friendly Links. This plugin not updated in 8 years.
190
  $shrink = $url;
343
  <div class="inside">
344
  <?php
345
  if ( 7 == $shortener ) {
346
+ echo '<p>' . __( 'The Su.pr URL shortener was shut down when Stumbleupon closed doors in June 2018.', 'wp-to-twitter' ) . '</p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  } elseif ( 2 == $shortener ) {
348
  echo $form_start;
349
  ?>
413
  <?php
414
  echo $form_end;
415
  } elseif ( 8 == $shortener ) {
416
+ echo '<p>' . __( 'The Goo.gl URL shortener was shut down by Google in March 2019.', 'wp-to-twitter' ) . '</p>';
 
 
 
 
 
 
 
 
 
417
  } elseif ( 10 == $shortener ) {
418
  echo $form_start;
419
  ?>
462
  */
463
  function wpt_shortener_update( $post ) {
464
  $message = '';
465
+ if ( isset( $post['submit-type'] ) && 'yourlsapi' === $post['submit-type'] ) {
466
  $message = '';
467
  if ( '' != $post['yourlstoken'] && isset( $post['submit'] ) ) {
468
  update_option( 'yourlstoken', trim( $post['yourlstoken'] ) );
501
  }
502
  }
503
 
504
+ if ( isset( $post['submit-type'] ) && 'bitlyapi' === $post['submit-type'] ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
505
  if ( '' != $post['bitlyapi'] && isset( $post['submit'] ) ) {
506
  update_option( 'bitlyapi', trim( $post['bitlyapi'] ) );
507
  $message = __( 'Bit.ly API Key Updated.', 'wp-to-twitter' );
521
  $message = __( "Bit.ly Login not added - <a href='http://bit.ly/account/'>get one here</a>!", 'wp-to-twitter' );
522
  }
523
  }
 
 
 
 
 
 
 
 
524
 
525
+ if ( isset( $post['submit-type'] ) && 'joturlapi' === $post['submit-type'] ) {
526
  if ( '' != $post['joturlapi'] && isset( $post['submit'] ) ) {
527
  update_option( 'joturlapi', trim( $post['joturlapi'] ) );
528
  $message = __( 'jotURL private API Key Updated.', 'wp-to-twitter' );
581
  // don't return a message if unchanged.
582
  $stored = ( isset( $_POST['wpt_use_stored_urls'] ) ) ? 'false' : 'true';
583
  update_option( 'wpt_use_stored_urls', $stored );
584
+ if ( get_option( 'jd_shortener' ) === $post['jd_shortener'] ) {
585
  return;
586
  }
587
  update_option( 'jd_shortener', sanitize_key( $post['jd_shortener'] ) );
588
+ $short = absint( get_option( 'jd_shortener' ) );
589
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
590
  $admin_url = add_query_arg( 'tab', 'shortener', $admin_url );
591
 
592
  // these are the URL shorteners which require settings.
593
+ if ( 2 === $short || 10 === $short || 6 === $short ) {
594
  // Translators: Settings URL for shortener configuration.
595
  $message .= sprintf( __( 'You must <a href="%s">configure your URL shortener settings</a>.', 'wp-to-twitter' ), $admin_url );
596
  }
597
 
598
+ if ( '' !== $message ) {
599
  $message .= '<br />';
600
  }
601
 
607
  * Form to select your shortener.
608
  */
609
  function wpt_pick_shortener() {
610
+ $shortener = absint( get_option( 'jd_shortener' ) );
611
+ if ( 2 === $shortener ) {
612
+ echo '<p>' . __( 'The Bit.ly URL shortener API will be removed from WP to Twitter in March 2020. The version 3 API will be shut down on March 1st, and the plug-in will not be updated to version 4.', 'wp-to-twitter' ) . '</p>';
613
  }
614
  ?>
615
  <p>
617
  <select name="jd_shortener" id="jd_shortener">
618
  <option value="3" <?php selected( $shortener, '3' ); ?>><?php _e( "Don't shorten URLs.", 'wp-to-twitter' ); ?></option>
619
  <option value="4" <?php selected( $shortener, '4' ); ?>>WordPress</option>
 
620
  <?php
621
+ if ( 2 === $shortener ) { // If Bit.ly is currently enabled, leave available.
622
  ?>
623
+ <option value="2" <?php selected( $shortener, '2' ); ?>>Bit.ly</option>
624
  <?php
625
  }
626
+ if ( 5 === $shortener ) { // if the user has already selected local server, leave available.
 
 
 
627
  ?>
628
  <option value="5" <?php selected( $shortener, '5' ); ?>><?php _e( 'YOURLS (this server)', 'wp-to-twitter' ); ?></option>
629
  <?php
637
  ?>
638
  </select>
639
  <?php
640
+ if ( 3 !== $shortener ) {
641
  ?>
642
  <input type='checkbox' value='false' name='wpt_use_stored_urls' id='wpt_use_stored_urls' <?php checked( get_option( 'wpt_use_stored_urls' ), 'false' ); ?>> <label for='wpt_use_stored_urls'><?php _e( 'Always request a new short URL for Tweets', 'wp-to-twitter' ); ?></label>
643
  <?php
wp-to-twitter-users.php CHANGED
@@ -42,23 +42,23 @@ function wpt_twitter_profile() {
42
  <tr>
43
  <th scope="row"><?php _e( 'Use My Twitter Username', 'wp-to-twitter' ); ?></th>
44
  <td>
45
- <input type="radio" name="wp-to-twitter-enable-user" id="wp-to-twitter-enable-user-3" value="mainAtTwitter"<?php checked( $is_enabled, 'mainAtTwitter' ); ?> /> <label for="wp-to-twitter-enable-user-3"><?php _e( 'Tweet my posts with an @ reference to my username.', 'wp-to-twitter' ); ?></label><br/>
46
- <input type="radio" name="wp-to-twitter-enable-user" id="wp-to-twitter-enable-user-4" value="mainAtTwitterPlus"<?php checked( $is_enabled, 'mainAtTwitterPlus' ); ?> /> <label for="wp-to-twitter-enable-user-4"><?php _e( 'Tweet my posts with an @ reference to both my username and to the main site username.', 'wp-to-twitter' ); ?></label>
47
  </td>
48
  </tr>
49
  <tr>
50
  <th scope="row">
51
- <label for="wp-to-twitter-user-username"><?php _e( 'Your Twitter Username', 'wp-to-twitter' ); ?></label>
52
  </th>
53
  <td>
54
- <input type="text" name="wp-to-twitter-user-username" id="wp-to-twitter-user-username" value="<?php echo esc_attr( $twitter_username ); ?>"/> <?php _e( 'Enter your own Twitter username.', 'wp-to-twitter' ); ?>
55
  </td>
56
  </tr>
57
  <tr>
58
  <th scope="row">
59
  <label for="wpt-remove"><?php _e( 'Hide account name in Tweets', 'wp-to-twitter' ); ?></label></th>
60
  <td>
61
- <input type="checkbox" name="wpt-remove" id="wpt-remove" value="on"<?php checked( 'on', $wpt_remove ); ?>/> <?php _e( 'Do not display my account in the #account# template tag.', 'wp-to-twitter' ); ?>
62
  </td>
63
  </tr>
64
  <?php echo apply_filters( 'wpt_twitter_user_fields', $user_edit ); ?>
@@ -110,8 +110,8 @@ function wpt_twitter_save_profile() {
110
  $edit_id = $user_ID;
111
  }
112
  if ( current_user_can( 'wpt_twitter_oauth' ) || current_user_can( 'manage_options' ) ) {
113
- $enable = ( isset( $_POST['wp-to-twitter-enable-user'] ) ) ? $_POST['wp-to-twitter-enable-user'] : '';
114
- $username = ( isset( $_POST['wp-to-twitter-user-username'] ) ) ? $_POST['wp-to-twitter-user-username'] : '';
115
  $wpt_remove = ( isset( $_POST['wpt-remove'] ) ) ? 'on' : '';
116
  update_user_meta( $edit_id, 'wp-to-twitter-enable-user', $enable );
117
  update_user_meta( $edit_id, 'wp-to-twitter-user-username', $username );
42
  <tr>
43
  <th scope="row"><?php _e( 'Use My Twitter Username', 'wp-to-twitter' ); ?></th>
44
  <td>
45
+ <input type="radio" name="wpt-enable-user" id="wpt-enable-user-3" value="mainAtTwitter"<?php checked( $is_enabled, 'mainAtTwitter' ); ?> /> <label for="wpt-enable-user-3"><?php _e( 'Tweet my posts with an @ reference to my username.', 'wp-to-twitter' ); ?></label><br/>
46
+ <input type="radio" name="wpt-enable-user" id="wpt-enable-user-4" value="mainAtTwitterPlus"<?php checked( $is_enabled, 'mainAtTwitterPlus' ); ?> /> <label for="wpt-enable-user-4"><?php _e( 'Tweet my posts with an @ reference to both my username and to the main site username.', 'wp-to-twitter' ); ?></label>
47
  </td>
48
  </tr>
49
  <tr>
50
  <th scope="row">
51
+ <label for="wpt-username"><?php _e( 'Your Twitter Username', 'wp-to-twitter' ); ?></label>
52
  </th>
53
  <td>
54
+ <input type="text" name="wpt-username" id="wpt-username" value="<?php echo esc_attr( $twitter_username ); ?>"/>
55
  </td>
56
  </tr>
57
  <tr>
58
  <th scope="row">
59
  <label for="wpt-remove"><?php _e( 'Hide account name in Tweets', 'wp-to-twitter' ); ?></label></th>
60
  <td>
61
+ <input type="checkbox" name="wpt-remove" id="wpt-remove" aria-describedby="wpt-remove-desc" value="on"<?php checked( 'on', $wpt_remove ); ?> /> <span id="wpt-remove-desc"><?php _e( 'Do not display my account in the #account# template tag.', 'wp-to-twitter' ); ?></span>
62
  </td>
63
  </tr>
64
  <?php echo apply_filters( 'wpt_twitter_user_fields', $user_edit ); ?>
110
  $edit_id = $user_ID;
111
  }
112
  if ( current_user_can( 'wpt_twitter_oauth' ) || current_user_can( 'manage_options' ) ) {
113
+ $enable = ( isset( $_POST['wpt-enable-user'] ) ) ? $_POST['wpt-enable-user'] : '';
114
+ $username = ( isset( $_POST['wpt-username'] ) ) ? $_POST['wpt-username'] : '';
115
  $wpt_remove = ( isset( $_POST['wpt-remove'] ) ) ? 'on' : '';
116
  update_user_meta( $edit_id, 'wp-to-twitter-enable-user', $enable );
117
  update_user_meta( $edit_id, 'wp-to-twitter-user-username', $username );
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.4.0
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.4.0';
61
 
62
  add_action( 'init', 'wpt_load_textdomain' );
63
  /**
@@ -98,7 +98,7 @@ function wpt_check_oauth( $auth = false ) {
98
  */
99
  function wpt_check_version() {
100
  global $wpt_version;
101
- $prev_version = ( '' != get_option( 'wp_to_twitter_version' ) ) ? get_option( 'wp_to_twitter_version' ) : '1.0.0';
102
  if ( version_compare( $prev_version, $wpt_version, '<' ) ) {
103
  wptotwitter_activate();
104
  }
@@ -109,7 +109,7 @@ function wpt_check_version() {
109
  */
110
  function wptotwitter_activate() {
111
  // If this has never run before, do the initial setup.
112
- $new_install = ( 1 == get_option( 'wpt_twitter_setup' ) || 1 == get_option( 'twitterInitialised' ) ) ? false : true;
113
  if ( $new_install ) {
114
  $initial_settings = array(
115
  'post' => array(
@@ -195,9 +195,9 @@ function wptotwitter_activate() {
195
  */
196
  function wpt_link( $post_ID ) {
197
  $ex_link = false;
198
- $external_link = get_option( 'jd_twit_custom_url' );
199
  $permalink = get_permalink( $post_ID );
200
- if ( '' != $external_link ) {
201
  $ex_link = get_post_meta( $post_ID, $external_link, true );
202
  }
203
 
@@ -216,7 +216,7 @@ function wpt_link( $post_ID ) {
216
  */
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',
@@ -229,7 +229,7 @@ function wpt_saves_error( $id, $auth, $twit, $error, $http_code, $ts ) {
229
  )
230
  );
231
  } else {
232
- if ( 1 == get_option( 'wpt_rate_limiting' ) ) {
233
  wpt_log_success( $auth, $ts, $id );
234
  }
235
  }
@@ -249,7 +249,7 @@ function wpt_check_recent_tweet( $id, $auth ) {
249
  if ( ! $id ) {
250
  return false;
251
  } else {
252
- if ( false == $auth ) {
253
  $transient = get_transient( "_wpt_most_recent_tweet_$id" );
254
  } else {
255
  $transient = get_transient( '_wpt_' . $auth . "_most_recent_tweet_$id" );
@@ -261,7 +261,7 @@ function wpt_check_recent_tweet( $id, $auth ) {
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 {
267
  set_transient( '_wpt_' . $auth . "_most_recent_tweet_$id", true, $expire );
@@ -286,7 +286,7 @@ function wpt_check_recent_tweet( $id, $auth ) {
286
  function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false ) {
287
  $recent = wpt_check_recent_tweet( $id, $auth );
288
  $error = false;
289
- if ( 1 == get_option( 'wpt_rate_limiting' ) ) {
290
  // check whether this post needs to be rate limited.
291
  $continue = wpt_test_rate_limit( $id, $auth );
292
  if ( ! $continue ) {
@@ -307,16 +307,16 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
307
  return false;
308
  } // exit silently if not authorized.
309
 
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 && '' != $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() );
@@ -365,7 +365,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
365
  $connection = array( 'connection' => 'undefined' );
366
  } else {
367
  $staging_mode = apply_filters( 'wpt_staging_mode', false, $auth, $id );
368
- if ( ( defined( 'WPT_STAGING_MODE' ) && true == WPT_STAGING_MODE ) || $staging_mode ) {
369
  // if in staging mode, we'll behave as if the Tweet succeeded, but not send it.
370
  $connection = true;
371
  $http_code = 200;
@@ -375,7 +375,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
375
  $do_tweet = apply_filters( 'wpt_do_tweet', true, $auth, $id );
376
  if ( $do_tweet ) {
377
  $connection->post( $api, $status );
378
- $http_code = ( $connection ) ? $connection->http_code : 'failed';
379
  $notice = '';
380
  } else {
381
  $http_code = '000';
@@ -385,7 +385,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
385
  }
386
  wpt_mail( 'Twitter Connection', print_r( $connection, 1 ) . " - $twit, $auth, $id, $media", $id );
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.
390
  $supplement = sprintf( __( 'Your Twitter application does not have read and write permissions. Go to <a href="%s">your Twitter apps</a> to modify these settings.', 'wp-to-twitter' ), 'https://dev.twitter.com/apps/' );
391
  } else {
@@ -396,49 +396,49 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
396
  case '000':
397
  $error = '';
398
  break;
399
- case '100':
400
  $error = __( '100 Continue: Twitter received the header of your submission, but your server did not follow through by sending the body of the data.', 'wp-to-twitter' );
401
  break;
402
- case '200':
403
  $return = true;
404
  $error = __( '200 OK: Success!', 'wp-to-twitter' );
405
  update_option( 'wpt_authentication_missing', false );
406
  break;
407
- case '304':
408
  $error = __( '304 Not Modified: There was no new data to return', 'wp-to-twitter' );
409
  break;
410
- case '400':
411
  $error = __( '400 Bad Request: The request was invalid. This is the status code returned during rate limiting.', 'wp-to-twitter' );
412
  break;
413
- case '401':
414
  $error = __( '401 Unauthorized: Authentication credentials were missing or incorrect.', 'wp-to-twitter' );
415
  update_option( 'wpt_authentication_missing', "$auth" );
416
  break;
417
- case '403':
418
  $error = __( '403 Forbidden: The request is understood, but has been refused by Twitter.', 'wp-to-twitter' );
419
  break;
420
- case '404':
421
  $error = __( '404 Not Found: The URI requested is invalid or the resource requested does not exist.', 'wp-to-twitter' );
422
  break;
423
- case '406':
424
  $error = __( '406 Not Acceptable: Invalid Format Specified.', 'wp-to-twitter' );
425
  break;
426
- case '422':
427
  $error = __( '422 Unprocessable Entity: The image uploaded could not be processed.', 'wp-to-twitter' );
428
  break;
429
- case '429':
430
  $error = __( '429 Too Many Requests: You have exceeded your rate limits.', 'wp-to-twitter' );
431
  break;
432
- case '500':
433
  $error = __( '500 Internal Server Error: Something is broken at Twitter.', 'wp-to-twitter' );
434
  break;
435
- case '502':
436
  $error = __( '502 Bad Gateway: Twitter is down or being upgraded.', 'wp-to-twitter' );
437
  break;
438
- case '503':
439
  $error = __( '503 Service Unavailable: The Twitter servers are up, but overloaded with requests - Please try again later.', 'wp-to-twitter' );
440
  break;
441
- case '504':
442
  $error = __( "504 Gateway Timeout: The Twitter servers are up, but the request couldn't be serviced due to some failure within our stack. Try again later.", 'wp-to-twitter' );
443
  break;
444
  default:
@@ -447,14 +447,14 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
447
  break;
448
  }
449
  $body = $connection->body;
450
- $error_code = ( 200 != $http_code ) ? $body->errors[0]->code : '';
451
- $error_message = ( 200 != $http_code ) ? $body->errors[0]->message : '';
452
- $error_supplement = ( '' != $error_code ) ? ' (Error Code: ' . $error_code . ': ' . $error_message . ')' : '';
453
- $error .= ( '' != $supplement ) ? " $supplement" : '';
454
  $error .= $error_supplement;
455
  wpt_mail( "Twitter Response: $http_code", "$error", $id ); // DEBUG.
456
  // only save last Tweet if successful.
457
- if ( 200 == $http_code ) {
458
  if ( ! $auth ) {
459
  update_option( 'jd_last_tweet', $twit );
460
  } else {
@@ -462,7 +462,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
462
  }
463
  }
464
  wpt_saves_error( $id, $auth, $twit, $error, $http_code, time() );
465
- if ( 200 == $http_code ) {
466
  $jwt = get_post_meta( $id, '_jd_wp_twitter', true );
467
  if ( ! is_array( $jwt ) ) {
468
  $jwt = array();
@@ -475,7 +475,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
475
  update_post_meta( $id, '_jd_wp_twitter', $jwt );
476
  if ( ! function_exists( 'wpt_pro_exists' ) ) {
477
  // schedule a one-time promotional box for 4 weeks after first successful Tweet.
478
- if ( false == get_option( 'wpt_promotion_scheduled' ) ) {
479
  wp_schedule_single_event( time() + ( 60 * 60 * 24 * 7 * 4 ), 'wpt_schedule_promotion_action' );
480
  update_option( 'wpt_promotion_scheduled', 1 );
481
  }
@@ -566,8 +566,8 @@ function wpt_in_allowed_category( $array ) {
566
  * @return array Post data used in Tweet functions.
567
  */
568
  function wpt_post_info( $post_ID ) {
569
- $encoding = get_option( 'blog_charset' );
570
- if ( '' == $encoding ) {
571
  $encoding = 'UTF-8';
572
  }
573
  $post = get_post( $post_ID );
@@ -579,7 +579,7 @@ function wpt_post_info( $post_ID ) {
579
  $values['postContent'] = $post->post_content;
580
  $values['authId'] = $post->post_author;
581
  $postdate = $post->post_date;
582
- $dateformat = ( '' == get_option( 'jd_date_format' ) ) ? get_option( 'date_format' ) : get_option( 'jd_date_format' );
583
  $thisdate = mysql2date( $dateformat, $postdate );
584
  $altdate = mysql2date( 'Y-m-d H:i:s', $postdate );
585
  $values['_postDate'] = $altdate;
@@ -616,10 +616,10 @@ function wpt_post_info( $post_ID ) {
616
  $values['category'] = html_entity_decode( $category, ENT_COMPAT, $encoding );
617
  $values['cat_desc'] = html_entity_decode( $cat_desc, ENT_COMPAT, $encoding );
618
  $excerpt_length = get_option( 'jd_post_excerpt' );
619
- $post_excerpt = ( '' == trim( $post->post_excerpt ) ) ? mb_substr( strip_tags( strip_shortcodes( $post->post_content ) ), 0, $excerpt_length ) : mb_substr( strip_tags( strip_shortcodes( $post->post_excerpt ) ), 0, $excerpt_length );
620
  $values['postExcerpt'] = html_entity_decode( $post_excerpt, ENT_COMPAT, $encoding );
621
  $thisposttitle = $post->post_title;
622
- if ( '' == $thisposttitle && isset( $_POST['title'] ) ) {
623
  $thisposttitle = $_POST['title'];
624
  }
625
  $thisposttitle = strip_tags( apply_filters( 'the_title', stripcslashes( $thisposttitle ), $post_ID ) );
@@ -657,8 +657,9 @@ function wpt_short_url( $post_id ) {
657
  if ( ! $post_id ) {
658
  $post_id = $post_ID;
659
  }
660
- $use_urls = ( get_option( 'wpt_use_stored_urls' ) == 'false' ) ? false : true;
661
  $short = ( $use_urls ) ? get_post_meta( $post_id, '_wpt_short_url', true ) : false;
 
662
 
663
  return $short;
664
  }
@@ -672,11 +673,15 @@ function wpt_short_url( $post_id ) {
672
  */
673
  function wpt_post_with_media( $post_ID, $post_info = array() ) {
674
  $return = false;
675
- if ( isset( $post_info['wpt_image'] ) && 1 == $post_info['wpt_image'] ) {
676
  return $return;
677
  }
678
-
679
- if ( ! function_exists( 'wpt_pro_exists' ) || '1' != get_option( 'wpt_media' ) ) {
 
 
 
 
680
  $return = false;
681
  } else {
682
  if ( has_post_thumbnail( $post_ID ) || wpt_post_attachment( $post_ID ) ) {
@@ -699,16 +704,16 @@ function wpt_post_with_media( $post_ID, $post_info = array() ) {
699
  function wpt_category_limit( $post_type, $post_info, $post_ID ) {
700
  $post_type_cats = get_object_taxonomies( $post_type );
701
  $continue = true;
702
- if ( in_array( 'category', $post_type_cats ) ) {
703
  // 'category' is assigned to this post type, so apply filters.
704
- if ( '1' == get_option( 'jd_twit_cats' ) ) {
705
  $continue = ( ! wpt_in_allowed_category( $post_info['categoryIds'] ) ) ? true : false;
706
  } else {
707
  $continue = ( wpt_in_allowed_category( $post_info['categoryIds'] ) ) ? true : false;
708
  }
709
  }
710
 
711
- $continue = ( '0' == get_option( 'limit_categories' ) ) ? true : $continue;
712
  $args = array(
713
  'type' => $post_type,
714
  'info' => $post_info,
@@ -739,7 +744,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
739
  $sentence = '';
740
  $template = '';
741
  $nptext = '';
742
- if ( 1 != get_option( 'wpt_inline_edits' ) ) {
743
  if ( isset( $_POST['_inline_edit'] ) || isset( $_REQUEST['bulk_edit'] ) ) {
744
  return false;
745
  }
@@ -748,24 +753,24 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
748
  $is_inline_edit = true;
749
  }
750
  }
751
- if ( 0 == get_option( 'jd_tweet_default' ) ) {
752
- $default = ( 'no' != $tweet_this ) ? true : false;
753
  } else {
754
- $default = ( 'yes' == $tweet_this ) ? true : false;
755
  }
756
  wpt_mail( '1: Tweet Template', "$tweet_this / (Original: " . get_option( 'jd_tweet_default' ) . ") / $type", $post_ID ); // DEBUG.
757
  if ( $default ) { // default switch: depend on default settings.
758
  $post_info = wpt_post_info( $post_ID );
759
  $media = wpt_post_with_media( $post_ID, $post_info );
760
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
761
- $auth = ( 'false' == get_option( 'wpt_cotweet_lock' ) || ! get_option( 'wpt_cotweet_lock' ) ) ? $post_info['authId'] : get_option( 'wpt_cotweet_lock' );
762
  } else {
763
  $auth = $post_info['authId'];
764
  }
765
  wpt_mail( '2: POST Debug Data', 'Post_Info: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
766
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() && function_exists( 'wpt_filter_post_info' ) ) {
767
  $filter = wpt_filter_post_info( $post_info );
768
- if ( true == $filter ) {
769
  wpt_mail( '3: Post caught by wpt_filter_post_info', print_r( $post_info, 1 ) . " / $type", $post_ID );
770
 
771
  return false;
@@ -777,7 +782,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
777
  return false;
778
  }
779
  $post_type = $post_info['postType'];
780
- if ( 'future' == $type || 'future' == get_post_meta( $post_ID, 'wpt_publishing' ) ) {
781
  $new = 1; // if this is a future action, then it should be published regardless of relationship.
782
  wpt_mail( '4a: Is a future post', print_r( $post_info, 1 ) . " / $type", $post_ID );
783
  delete_post_meta( $post_ID, 'wpt_publishing' );
@@ -788,69 +793,69 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
788
  }
789
  // post is not previously published but has been backdated.
790
  // (post date is edited, but save option is 'publish').
791
- if ( 0 == $new && ( isset( $_POST['edit_date'] ) && 1 == $_POST['edit_date'] && ! isset( $_POST['save'] ) ) ) {
792
  $new = 1;
793
  }
794
  // can't catch posts that were set to a past date as a draft, then published.
795
  $post_type_settings = get_option( 'wpt_post_types' );
796
  $post_types = array_keys( $post_type_settings );
797
- if ( in_array( $post_type, $post_types ) ) {
798
  // identify whether limited by category/taxonomy.
799
  $continue = wpt_category_limit( $post_type, $post_info, $post_ID );
800
- if ( false == $continue ) {
801
  wpt_mail( '4b: Limited by category filters', print_r( $post_info, 1 ), $post_ID );
802
  return false;
803
  }
804
  // create Tweet and ID whether current action is edit or new.
805
  $ct = get_post_meta( $post_ID, '_jd_twitter', true );
806
- if ( isset( $_POST['_jd_twitter'] ) && '' != $_POST['_jd_twitter'] ) {
807
  $ct = $_POST['_jd_twitter'];
808
  }
809
- $custom_tweet = ( '' != $ct ) ? stripcslashes( trim( $ct ) ) : '';
810
  // if ops is set and equals 'publish', this is being edited. Otherwise, it's a new post.
811
- if ( 0 == $new || true == $is_inline_edit ) {
812
  // if this is an old post and editing updates are enabled.
813
- if ( 1 == get_option( 'jd_tweet_default_edit' ) ) {
814
  $tweet_this = apply_filters( 'wpt_tweet_this_edit', $tweet_this, $_POST );
815
- if ( 'yes' != $tweet_this ) {
816
  return false;
817
  }
818
  }
819
  wpt_mail( '4b: Is edited post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
820
- if ( '1' == $post_type_settings[ $post_type ]['post-edited-update'] ) {
821
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-edited-text'] );
822
  $oldpost = true;
823
  }
824
  } else {
825
  wpt_mail( '4c: Is new post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
826
- if ( '1' == $post_type_settings[ $post_type ]['post-published-update'] ) {
827
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-published-text'] );
828
  $newpost = true;
829
  }
830
  }
831
  if ( $newpost || $oldpost ) {
832
- $template = ( '' != $custom_tweet ) ? $custom_tweet : $nptext;
833
  $sentence = jd_truncate_tweet( $template, $post_info, $post_ID );
834
  wpt_mail( '5: Tweet Truncated', "Truncated Tweet: $sentence / $template / $type", $post_ID ); // DEBUG.
835
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
836
  $sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth );
837
  }
838
  }
839
- if ( '' != $sentence ) {
840
  // WPT PRO.
841
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
842
  $wpt_selected_users = $post_info['wpt_authorized_users'];
843
  // set up basic author/main account values.
844
  $auth_verified = wtt_oauth_test( $auth, 'verify' );
845
- if ( empty( $wpt_selected_users ) && 1 == get_option( 'jd_individual_twitter_users' ) ) {
846
  $wpt_selected_users = ( $auth_verified ) ? array( $auth ) : array( false );
847
  }
848
- if ( 1 == $post_info['wpt_cotweet'] || 1 != get_option( 'jd_individual_twitter_users' ) || in_array( 'main', $wpt_selected_users ) ) {
849
  $wpt_selected_users['main'] = false;
850
  }
851
  // filter selected users before using.
852
  $wpt_selected_users = apply_filters( 'wpt_filter_users', $wpt_selected_users, $post_info );
853
- if ( 0 == $post_info['wpt_delay_tweet'] || '' == $post_info['wpt_delay_tweet'] || 'on' == $post_info['wpt_no_delay'] ) {
854
  foreach ( $wpt_selected_users as $acct ) {
855
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
856
  wpt_post_to_twitter( $sentence2, $acct, $post_ID, $media );
@@ -858,8 +863,8 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
858
  }
859
  } else {
860
  foreach ( $wpt_selected_users as $acct ) {
861
- $acct = ( 'main' == $acct ) ? false : $acct;
862
- $offset = ( $auth != $acct ) ? apply_filters( 'wpt_random_delay', rand( 60, 480 ) ) : 0;
863
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
864
  $time = apply_filters( 'wpt_schedule_delay', ( (int) $post_info['wpt_delay_tweet'] ) * 60, $acct );
865
  wp_schedule_single_event(
@@ -898,7 +903,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
898
  }
899
  }
900
  // This cycle handles scheduling the automatic retweets.
901
- if ( 0 != $post_info['wpt_retweet_after'] && 'on' != $post_info['wpt_no_repost'] ) {
902
  $repeat = $post_info['wpt_retweet_repeat'];
903
  $first = true;
904
  foreach ( $wpt_selected_users as $acct ) {
@@ -908,14 +913,14 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
908
  if ( $continue ) {
909
  $retweet = apply_filters( 'wpt_set_retweet_text', $template, $i, $post_ID );
910
  $retweet = jd_truncate_tweet( $retweet, $post_info, $post_ID, true, $acct );
911
- if ( '' == $retweet ) {
912
  // If a filter sets this value to empty, exit without scheduling.
913
  return $post_ID;
914
  }
915
  // add original delay to schedule.
916
  $delay = ( isset( $post_info['wpt_delay_tweet'] ) ) ? ( (int) $post_info['wpt_delay_tweet'] ) * 60 : 0;
917
  // Don't delay the first Tweet of the group.
918
- $offset = ( true == $first ) ? 0 : rand( 60, 240 ); // delay each co-tweet by 1-4 minutes.
919
  $time = apply_filters( 'wpt_schedule_retweet', ( $post_info['wpt_retweet_after'] ) * ( 60 * 60 ) * $i, $acct, $i, $post_info );
920
  wp_schedule_single_event(
921
  time() + $time + $offset + $delay,
@@ -949,8 +954,8 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
949
  $post_ID
950
  ); // DEBUG.
951
  }
952
- $tweet_limit = apply_filters( 'wpt_tweet_repeat_limit', 4, $post_ID );
953
- if ( $i == $tweet_limit ) {
954
  break;
955
  }
956
  }
@@ -986,7 +991,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
986
  function wpt_twit_link( $link_id ) {
987
  wpt_check_version();
988
  $thislinkprivate = $_POST['link_visible'];
989
- if ( 'N' != $thislinkprivate ) {
990
  $thislinkname = stripslashes( $_POST['link_name'] );
991
  $thispostlink = $_POST['link_url'];
992
  $thislinkdescription = stripcslashes( $_POST['link_description'] );
@@ -1010,7 +1015,7 @@ function wpt_twit_link( $link_id ) {
1010
  $sentence = str_ireplace( '#longurl#', $thispostlink, $sentence );
1011
  }
1012
 
1013
- if ( '' != $sentence ) {
1014
  wpt_post_to_twitter( $sentence, false, $link_id );
1015
  }
1016
 
@@ -1031,14 +1036,14 @@ function wpt_generate_hash_tags( $post_ID ) {
1031
  $hashtags = '';
1032
  $term_meta = false;
1033
  $t_id = false;
1034
- $max_tags = get_option( 'jd_max_tags' );
1035
- $max_characters = get_option( 'jd_max_characters' );
1036
- $max_characters = ( 0 == $max_characters || '' == $max_characters ) ? 100 : $max_characters + 1;
1037
- if ( 0 == $max_tags || '' == $max_tags ) {
1038
  $max_tags = 100;
1039
  }
1040
- $use_cats = ( '1' == get_option( 'wpt_use_cats' ) ) ? true : false;
1041
- $tags = ( true == $use_cats ) ? wp_get_post_categories( $post_ID, array( 'fields' => 'all' ) ) : get_the_tags( $post_ID );
1042
  $tags = apply_filters( 'wpt_hash_source', $tags, $post_ID );
1043
  if ( $tags && count( $tags ) > 0 ) {
1044
  $i = 1;
@@ -1047,7 +1052,7 @@ function wpt_generate_hash_tags( $post_ID ) {
1047
  $t_id = $value->term_id;
1048
  $term_meta = get_option( "wpt_taxonomy_$t_id" );
1049
  }
1050
- if ( 'slug' == get_option( 'wpt_tag_source' ) ) {
1051
  $tag = $value->slug;
1052
  } else {
1053
  $tag = $value->name;
@@ -1055,14 +1060,14 @@ function wpt_generate_hash_tags( $post_ID ) {
1055
  $strip = get_option( 'jd_strip_nonan' );
1056
  $search = '/[^\p{L}\p{N}\s]/u';
1057
  $replace = get_option( 'jd_replace_character' );
1058
- $replace = ( '[ ]' == $replace || '' == $replace ) ? '' : $replace;
1059
  if ( false !== strpos( $tag, ' ' ) ) {
1060
  // If multiple words, camelcase tag.
1061
  $tag = ucwords( $tag );
1062
  }
1063
  $tag = str_ireplace( ' ', $replace, trim( $tag ) );
1064
  $tag = preg_replace( '/[\/]/', $replace, $tag ); // remove forward slashes.
1065
- $tag = ( '1' == $strip ) ? preg_replace( $search, $replace, $tag ) : $tag;
1066
 
1067
  switch ( $term_meta ) {
1068
  case 1:
@@ -1104,7 +1109,7 @@ function wpt_add_twitter_outer_box() {
1104
  $wpt_post_types = get_option( 'wpt_post_types' );
1105
  if ( is_array( $wpt_post_types ) ) {
1106
  foreach ( $wpt_post_types as $key => $value ) {
1107
- if ( 1 == $value['post-published-update'] || 1 == $value['post-edited-update'] ) {
1108
  add_meta_box( 'wp2t', 'WP to Twitter', 'wpt_add_twitter_inner_box', $key, 'side' );
1109
  }
1110
  }
@@ -1122,7 +1127,7 @@ function wpt_add_twitter_debug_box() {
1122
  $wpt_post_types = get_option( 'wpt_post_types' );
1123
  if ( is_array( $wpt_post_types ) ) {
1124
  foreach ( $wpt_post_types as $key => $value ) {
1125
- if ( 1 == $value['post-published-update'] || 1 == $value['post-edited-update'] ) {
1126
  add_meta_box( 'wp2t-debug', 'WP to Twitter Debugging', 'wpt_show_debug', $key, 'advanced' );
1127
  }
1128
  }
@@ -1148,31 +1153,31 @@ function wpt_add_twitter_inner_box( $post ) {
1148
  $post_id = $post->ID;
1149
  $tweet_this = get_post_meta( $post_id, '_jd_tweet_this', true );
1150
  if ( ! $tweet_this ) {
1151
- $tweet_this = ( '1' == get_option( 'jd_tweet_default' ) ) ? 'no' : 'yes';
1152
  }
1153
- if ( isset( $_GET['action'] ) && 'edit' == $_GET['action'] && '1' == get_option( 'jd_tweet_default_edit' ) && 'publish' == $status ) {
1154
  $tweet_this = 'no';
1155
  }
1156
- if ( isset( $_REQUEST['message'] ) && 10 != $_REQUEST['message'] ) {
1157
  // don't display when draft is updated or if no message.
1158
- if ( ! ( ( 1 == $_REQUEST['message'] ) && ( 'publish' == $status && 1 != $options[ $type ]['post-edited-update'] ) ) && 'no' != $tweet_this ) {
1159
  $log = wpt_log( 'wpt_status_message', $post_id );
1160
- $class = ( __( 'Tweet sent successfully.', 'wp-to-twitter' ) != $log ) ? 'error' : 'updated';
1161
- if ( '' != $log ) {
1162
  echo "<div class='$class'><p>$log</p></div>";
1163
  }
1164
  }
1165
  }
1166
  $tweet = esc_attr( stripcslashes( get_post_meta( $post_id, '_jd_twitter', true ) ) );
1167
  $tweet = apply_filters( 'wpt_user_text', $tweet, $status );
1168
- $template = ( 'publish' == $status ) ? $options[ $type ]['post-edited-text'] : $options[ $type ]['post-published-text'];
1169
 
1170
- if ( 'publish' == $status && 1 != $options[ $type ]['post-edited-update'] ) {
1171
  // Translators: post type.
1172
  $tweet_status = sprintf( __( '%s will not be Tweeted on update.', 'wp-to-twitter' ), ucfirst( $type ) );
1173
  }
1174
 
1175
- if ( 'publish' == $status && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1176
  ?>
1177
  <div class='tweet-buttons'>
1178
  <button type='button' class='tweet button-primary' data-action='tweet'><span class='dashicons dashicons-twitter' aria-hidden='true'></span><?php _e( 'Tweet Now', 'wp-to-twitter' ); ?></button>
@@ -1205,10 +1210,10 @@ function wpt_add_twitter_inner_box( $post ) {
1205
  </p>
1206
  <?php
1207
  $expanded = $template;
1208
- if ( '' != get_option( 'jd_twit_prepend' ) ) {
1209
  $expanded = "<span title='" . __( 'Your prepended Tweet text; not part of your template.', 'wp-to-twitter' ) . "'>" . stripslashes( get_option( 'jd_twit_prepend' ) ) . '</span> ' . $expanded;
1210
  }
1211
- if ( '' != get_option( 'jd_twit_append' ) ) {
1212
  $expanded = $expanded . " <span title='" . __( 'Your appended Tweet text; not part of your template.', 'wp-to-twitter' ) . "'>" . stripslashes( get_option( 'jd_twit_append' ) ) . '</span>';
1213
  }
1214
  ?>
@@ -1219,7 +1224,7 @@ function wpt_add_twitter_inner_box( $post ) {
1219
  </p>
1220
  <?php
1221
  echo apply_filters( 'wpt_custom_retweet_fields', '', $post_id );
1222
- if ( get_option( 'jd_keyword_format' ) == 2 ) {
1223
  $custom_keyword = get_post_meta( $post_id, '_yourls_keyword', true );
1224
  echo "<label for='yourls_keyword'>" . __( 'YOURLS Custom Keyword', 'wp-to-twitter' ) . "</label> <input type='text' name='_yourls_keyword' id='yourls_keyword' value='$custom_keyword' />";
1225
  }
@@ -1231,7 +1236,7 @@ function wpt_add_twitter_inner_box( $post ) {
1231
  ?>
1232
  <div class='wpt-options'>
1233
  <?php
1234
- if ( 'pro' == $is_pro ) {
1235
  $pro_active = " class='active'";
1236
  $free_active = '';
1237
  } else {
@@ -1240,7 +1245,7 @@ function wpt_add_twitter_inner_box( $post ) {
1240
  }
1241
  ?>
1242
  <ul class='tabs' role="tablist">
1243
- <?php if ( get_option( 'jd_individual_twitter_users' ) == 1 ) { ?>
1244
  <li><a href='#authors'<?php echo $pro_active; ?> aria-controls="authors" role="tab" id="tab_authors"><?php _e( 'Tweet to', 'wp-to-twitter' ); ?></a></li>
1245
  <?php } ?>
1246
  <li><a href='#custom' aria-controls="custom" role="tab" id="tab_custom"><?php _e( 'Options', 'wp-to-twitter' ); ?></a></li>
@@ -1249,7 +1254,7 @@ function wpt_add_twitter_inner_box( $post ) {
1249
  <?php
1250
  // WPT PRO OPTIONS.
1251
  if ( current_user_can( 'edit_others_posts' ) ) {
1252
- if ( 1 == get_option( 'jd_individual_twitter_users' ) ) {
1253
  echo "<div class='wptab' id='authors' aria-labelledby='tab_authors' role='tabpanel'>";
1254
  $selected = ( get_post_meta( $post_id, '_wpt_authorized_users', true ) ) ? get_post_meta( $post_id, '_wpt_authorized_users', true ) : array();
1255
  if ( function_exists( 'wpt_authorized_users' ) ) {
@@ -1272,7 +1277,7 @@ function wpt_add_twitter_inner_box( $post ) {
1272
  ?>
1273
  <div class='wptab' id='custom' aria-labelledby='tab_custom' role='tabpanel'>
1274
  <?php
1275
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() && ( current_user_can( 'wpt_twitter_custom' ) || current_user_can( 'manage_options' ) ) ) {
1276
  wpt_schedule_values( $post_id );
1277
  do_action( 'wpt_custom_tab', $post_id, 'visible' );
1278
  } else {
@@ -1290,7 +1295,7 @@ function wpt_add_twitter_inner_box( $post ) {
1290
  <div class='wptab' id='custom' aria-labelledby='tab_custom' role='tabpanel'>
1291
  <p><?php _e( 'Access to customizing WP to Twitter values is not allowed for your user role.', 'wp-to-twitter' ); ?></p>
1292
  <?php
1293
- if ( function_exists( 'wpt_pro_exists' ) && wpt_pro_exists() == true ) {
1294
  wpt_schedule_values( $post_id, 'hidden' );
1295
  do_action( 'wpt_custom_tab', $post_id, 'hidden' );
1296
  }
@@ -1315,8 +1320,8 @@ function wpt_add_twitter_inner_box( $post ) {
1315
  <?php
1316
  if ( current_user_can( 'wpt_twitter_switch' ) || current_user_can( 'manage_options' ) ) {
1317
  // "no" means 'Don't Tweet' (is checked)
1318
- $nochecked = ( 'no' == $tweet_this ) ? ' checked="checked"' : '';
1319
- $yeschecked = ( 'yes' == $tweet_this ) ? ' checked="checked"' : '';
1320
  ?>
1321
  <p class='toggle-btn-group'>
1322
  <input type="radio" name="_jd_tweet_this" value="no" id="jtn"<?php echo $nochecked; ?> /><label for="jtn"><?php _e( "Don't Tweet", 'wp-to-twitter' ); ?></label>
@@ -1344,7 +1349,7 @@ function wpt_add_twitter_inner_box( $post ) {
1344
  ?>
1345
  </p>
1346
  <?php
1347
- if ( '' != $tweet_status ) {
1348
  echo "<p class='disabled'>$tweet_status</p>";
1349
  }
1350
  ?>
@@ -1368,7 +1373,7 @@ function wpt_show_tweets( $post_id ) {
1368
  $previous_tweets = get_post_meta( $post_id, '_jd_wp_twitter', true );
1369
  $failed_tweets = get_post_meta( $post_id, '_wpt_failed' );
1370
 
1371
- if ( ! is_array( $previous_tweets ) && '' != $previous_tweets ) {
1372
  $previous_tweets = array( 0 => $previous_tweets );
1373
  }
1374
  if ( ! empty( $previous_tweets ) || ! empty( $failed_tweets ) ) {
@@ -1385,7 +1390,7 @@ function wpt_show_tweets( $post_id ) {
1385
  $hidden_fields = '';
1386
  if ( is_array( $previous_tweets ) ) {
1387
  foreach ( $previous_tweets as $previous_tweet ) {
1388
- if ( '' != $previous_tweet ) {
1389
  $has_history = true;
1390
  $hidden_fields .= "<input type='hidden' name='_jd_wp_twitter[]' value='" . esc_attr( $previous_tweet ) . "' />";
1391
  echo "<li>$previous_tweet <a href='http://twitter.com/intent/tweet?text=" . urlencode( $previous_tweet ) . "'>Retweet this</a></li>";
@@ -1407,7 +1412,7 @@ function wpt_show_tweets( $post_id ) {
1407
  $error_list .= "<li> <code>Error: $reason</code> $ft <a href='http://twitter.com/intent/tweet?text=" . urlencode( $ft ) . "'>Tweet this</a><br /><em>$error</em></li>";
1408
  }
1409
  }
1410
- if ( true == $list ) {
1411
  echo "<p class='error'><em>" . __( 'Failed Tweets', 'wp-to-twitter' ) . ":</em></p>
1412
  <ul>$error_list</ul>";
1413
  }
@@ -1428,10 +1433,10 @@ add_action( 'admin_enqueue_scripts', 'wpt_admin_scripts', 10, 1 );
1428
  */
1429
  function wpt_admin_scripts() {
1430
  global $current_screen, $wpt_version;
1431
- if ( 'post' == $current_screen->base || 'wp-tweets-pro_page_wp-to-twitter-schedule' == $current_screen->id ) {
1432
  wp_enqueue_script( 'charCount', plugins_url( 'wp-to-twitter/js/jquery.charcount.js' ), array( 'jquery' ), $wpt_version );
1433
  }
1434
- if ( 'post' == $current_screen->base && isset( $_GET['post'] ) && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1435
  wp_enqueue_script( 'wpt.ajax', plugins_url( 'js/ajax.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1436
  wp_localize_script(
1437
  'wpt.ajax',
@@ -1443,7 +1448,7 @@ function wpt_admin_scripts() {
1443
  )
1444
  );
1445
  }
1446
- if ( 'settings_page_wp-to-twitter/wp-to-twitter' == $current_screen->id || 'toplevel_page_wp-tweets-pro' == $current_screen->id ) {
1447
  wp_enqueue_script( 'wpt.tabs', plugins_url( 'js/tabs.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1448
  wp_localize_script( 'wpt.tabs', 'firstItem', 'wpt_post' );
1449
  wp_localize_script( 'wpt.tabs', 'firstPerm', 'wpt_editor' );
@@ -1460,9 +1465,9 @@ function wpt_ajax_tweet() {
1460
  echo 'Invalid Security Check';
1461
  die;
1462
  }
1463
- $action = ( 'tweet' == $_REQUEST['tweet_action'] ) ? 'tweet' : 'schedule';
1464
  $authors = ( isset( $_REQUEST['tweet_auth'] ) && null != $_REQUEST['tweet_auth'] ) ? $_REQUEST['tweet_auth'] : false;
1465
- $upload = ( isset( $_REQUEST['tweet_upload'] ) && null != $_REQUEST['tweet_upload'] ) ? $_REQUEST['tweet_upload'] : 1;
1466
  $current_user = wp_get_current_user();
1467
  if ( function_exists( 'wpt_pro_exists' ) && wpt_pro_exists() ) {
1468
  if ( wtt_oauth_test( $current_user->ID, 'verify' ) ) {
@@ -1484,7 +1489,7 @@ function wpt_ajax_tweet() {
1484
  $post_ID = intval( $_REQUEST['tweet_post_id'] );
1485
  $type = get_post_type( $post_ID );
1486
  $default = ( isset( $options[ $type ]['post-edited-text'] ) ) ? $options[ $type ]['post-edited-text'] : '';
1487
- $sentence = ( isset( $_REQUEST['tweet_text'] ) && '' != trim( $_REQUEST['tweet_text'] ) ) ? $_REQUEST['tweet_text'] : $default;
1488
  $sentence = stripcslashes( trim( $sentence ) );
1489
  $post_info = wpt_post_info( $post_ID );
1490
  $sentence = jd_truncate_tweet( $sentence, $post_info, $post_ID, false, $user_ID );
@@ -1492,11 +1497,11 @@ function wpt_ajax_tweet() {
1492
  $print_schedule = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), $schedule );
1493
  $offset = ( 60 * 60 * get_option( 'gmt_offset' ) );
1494
  $schedule = $schedule - $offset;
1495
- $media = ( 1 == $upload ) ? false : true; // this is correct; the boolean logic is reversed. Blah.
1496
 
1497
  foreach ( $authors as $auth ) {
1498
 
1499
- $auth = ( 'main' == $auth ) ? false : $auth;
1500
 
1501
  switch ( $action ) {
1502
  case 'tweet':
@@ -1516,7 +1521,7 @@ function wpt_ajax_tweet() {
1516
  break;
1517
  }
1518
  // Translators: Full text of Tweet, time scheduled for.
1519
- $return = ( 'tweet' == $action ) ? wpt_log( 'wpt_status_message', $post_ID ) : sprintf( __( 'Tweet scheduled: %1$s for %2$s', 'wp-tweets-pro' ), '"' . $sentence . '"', $print_schedule );
1520
  echo $return;
1521
  if ( count( $authors ) > 1 ) {
1522
  echo '<br />';
@@ -1534,17 +1539,17 @@ add_action( 'admin_head', 'wpt_admin_script' );
1534
  */
1535
  function wpt_admin_script() {
1536
  global $current_screen;
1537
- if ( 'post' == $current_screen->base || 'wp-tweets-pro_page_wp-to-twitter-schedule' == $current_screen->id ) {
1538
  wp_register_style( 'wpt-post-styles', plugins_url( 'css/post-styles.css', __FILE__ ) );
1539
  wp_enqueue_style( 'wpt-post-styles' );
1540
  $config = wpt_max_length();
1541
  // add one; character count starts from 1.
1542
- if ( 'post' == $current_screen->base ) {
1543
  $allowed = $config['base_length'] - mb_strlen( stripslashes( get_option( 'jd_twit_prepend' ) . get_option( 'jd_twit_append' ) ) ) + 1;
1544
  } else {
1545
  $allowed = $config['base_length'] + 1;
1546
  }
1547
- if ( function_exists( 'wpt_pro_exists' ) && 1 == get_option( 'jd_individual_twitter_users' ) ) {
1548
  $first = '#authors';
1549
  } elseif ( function_exists( 'wpt_pro_exists' ) ) {
1550
  $first = '#custom';
@@ -1583,26 +1588,26 @@ function wpt_save_post( $id ) {
1583
  $yourls = $_POST['_yourls_keyword'];
1584
  $update = update_post_meta( $id, '_yourls_keyword', $yourls );
1585
  }
1586
- if ( isset( $_POST['_jd_twitter'] ) && '' != $_POST['_jd_twitter'] ) {
1587
  $twitter = $_POST['_jd_twitter'];
1588
  $update = update_post_meta( $id, '_jd_twitter', $twitter );
1589
- } elseif ( isset( $_POST['_jd_twitter'] ) && '' == $_POST['_jd_twitter'] ) {
1590
  delete_post_meta( $id, '_jd_twitter' );
1591
  }
1592
- if ( isset( $_POST['_jd_wp_twitter'] ) && '' != $_POST['_jd_wp_twitter'] ) {
1593
  $wp_twitter = $_POST['_jd_wp_twitter'];
1594
  $update = update_post_meta( $id, '_jd_wp_twitter', $wp_twitter );
1595
  }
1596
  if ( isset( $_POST['_jd_tweet_this'] ) ) {
1597
- $tweet_this = ( 'no' == $_POST['_jd_tweet_this'] ) ? 'no' : 'yes';
1598
  $update = update_post_meta( $id, '_jd_tweet_this', $tweet_this );
1599
  } else {
1600
  if ( isset( $_POST['_wpnonce'] ) ) {
1601
- $tweet_default = ( 1 == get_option( 'jd_tweet_default' ) ) ? 'no' : 'yes';
1602
  $update = update_post_meta( $id, '_jd_tweet_this', $tweet_default );
1603
  }
1604
  }
1605
- if ( isset( $_POST['wpt_clear_history'] ) && 'clear' == $_POST['wpt_clear_history'] ) {
1606
  delete_post_meta( $id, '_wpt_failed' );
1607
  delete_post_meta( $id, '_jd_wp_twitter' );
1608
  delete_post_meta( $id, '_wpt_short_url' );
@@ -1612,13 +1617,13 @@ function wpt_save_post( $id ) {
1612
  $update = apply_filters( 'wpt_insert_post', $_POST, $id );
1613
  // WPT PRO.
1614
  // only send debug data if post meta is updated.
1615
- if ( true == $update || is_int( $update ) ) {
1616
  wpt_mail( 'Post Meta Inserted', print_r( $_POST, 1 ), $id ); // DEBUG.
1617
  }
1618
- if ( isset( $_POST['wpt-delete-debug'] ) && 'true' == $_POST['wpt-delete-debug'] ) {
1619
  delete_post_meta( $id, '_wpt_debug_log' );
1620
  }
1621
- if ( isset( $_POST['wpt-delete-all-debug'] ) && 'true' == $_POST['wpt-delete-all-debug'] ) {
1622
  delete_post_meta_by_key( '_wpt_debug_log' );
1623
  }
1624
  }
@@ -1628,7 +1633,7 @@ add_action( 'init', 'wpt_old_admin_redirect' );
1628
  * Send links to old admin to new admin page
1629
  */
1630
  function wpt_old_admin_redirect() {
1631
- if ( is_admin() && isset( $_GET['page'] ) && 'wp-to-twitter/wp-to-twitter.php' == $_GET['page'] ) {
1632
  wp_safe_redirect( admin_url( 'admin.php?page=wp-tweets-pro' ) );
1633
  exit;
1634
  }
@@ -1650,7 +1655,7 @@ add_action( 'admin_head', 'wpt_admin_style' );
1650
  * Add stylesheets to WP to Twitter pages.
1651
  */
1652
  function wpt_admin_style() {
1653
- if ( isset( $_GET['page'] ) && ( 'wp-to-twitter' == $_GET['page'] || 'wp-tweets-pro' == $_GET['page'] || 'wp-to-twitter-schedule' == $_GET['page'] || 'wp-to-twitter-tweets' == $_GET['page'] || 'wp-to-twitter-errors' == $_GET['page'] ) ) {
1654
  wp_enqueue_style( 'wpt-styles', plugins_url( 'css/styles.css', __FILE__ ) );
1655
  }
1656
  }
@@ -1664,7 +1669,7 @@ function wpt_admin_style() {
1664
  * @return link new array.
1665
  */
1666
  function wpt_plugin_action( $links, $file ) {
1667
- if ( plugin_basename( dirname( __FILE__ ) . '/wp-to-twitter.php' ) == $file ) {
1668
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
1669
  $links[] = "<a href='$admin_url'>" . __( 'WP to Twitter Settings', 'wp-to-twitter' ) . '</a>';
1670
  if ( ! function_exists( 'wpt_pro_exists' ) ) {
@@ -1695,7 +1700,7 @@ function wpt_plugin_update_message() {
1695
  echo $note;
1696
  }
1697
 
1698
- if ( '1' == get_option( 'jd_twit_blogroll' ) ) {
1699
  add_action( 'add_link', 'wpt_twit_link' );
1700
  }
1701
 
@@ -1711,7 +1716,7 @@ add_action( 'save_post', 'wpt_save_post', 10 );
1711
  function wpt_in_post_type( $id ) {
1712
  $post_types = wpt_allowed_post_types();
1713
  $type = get_post_type( $id );
1714
- if ( in_array( $type, $post_types ) ) {
1715
  return true;
1716
  }
1717
 
@@ -1761,7 +1766,7 @@ function wpt_twit( $id ) {
1761
  return;
1762
  }
1763
  $post = get_post( $id );
1764
- if ( 'publish' != $post->post_status ) {
1765
  return;
1766
  }
1767
  // is there any reason to accept any other status?
@@ -1834,7 +1839,7 @@ add_action( 'wpt_schedule_promotion_action', 'wpt_schedule_promotion' );
1834
  * Set an option indicating that a job has been scheduled for promoting WP Tweets PRO.
1835
  */
1836
  function wpt_schedule_promotion() {
1837
- if ( ! function_exists( 'wpt_pro_exists' ) && 1 == get_option( 'wpt_promotion_scheduled' ) ) {
1838
  update_option( 'wpt_promotion_scheduled', 2 );
1839
  }
1840
  }
@@ -1843,7 +1848,7 @@ function wpt_schedule_promotion() {
1843
  * Dismiss promotion notice.
1844
  */
1845
  function wpt_dismiss_promotion() {
1846
- if ( isset( $_GET['dismiss'] ) && 'promotion' == $_GET['dismiss'] ) {
1847
  update_option( 'wpt_promotion_scheduled', 3 );
1848
  }
1849
  }
@@ -1864,7 +1869,7 @@ function wpt_debugging_enabled() {
1864
  * Display promotion notice to admin users who have not donated or purchased WP Tweets PRO.
1865
  */
1866
  function wpt_promotion_notice() {
1867
- if ( current_user_can( 'activate_plugins' ) && 2 == get_option( 'wpt_promotion_scheduled' ) && 1 != get_option( 'jd_donations' ) ) {
1868
  $upgrade = 'http://www.wptweetspro.com/wp-tweets-pro/';
1869
  $dismiss = admin_url( 'admin.php?page=wp-tweets-pro&dismiss=promotion' );
1870
  // Translators: URL to upgrade.
@@ -1894,7 +1899,7 @@ add_filter( 'wpt_enqueue_feed_styles', 'wpt_permit_feed_styles' );
1894
  * @return boolean $value False if settings disable styles.
1895
  */
1896
  function wpt_permit_feed_styles( $value ) {
1897
- if ( 1 == get_option( 'wpt_permit_feed_styles' ) ) {
1898
  $value = false;
1899
  }
1900
 
17
  * License: GPL-2.0+
18
  * License URI: http://www.gnu.org/license/gpl-2.0.txt
19
  * Domain Path: lang
20
+ * Version: 3.4.2
21
  */
22
 
23
  /*
57
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
58
 
59
  global $wpt_version;
60
+ $wpt_version = '3.4.2';
61
 
62
  add_action( 'init', 'wpt_load_textdomain' );
63
  /**
98
  */
99
  function wpt_check_version() {
100
  global $wpt_version;
101
+ $prev_version = ( '' !== get_option( 'wp_to_twitter_version', '' ) ) ? get_option( 'wp_to_twitter_version' ) : '1.0.0';
102
  if ( version_compare( $prev_version, $wpt_version, '<' ) ) {
103
  wptotwitter_activate();
104
  }
109
  */
110
  function wptotwitter_activate() {
111
  // If this has never run before, do the initial setup.
112
+ $new_install = ( '1' === get_option( 'wpt_twitter_setup' ) || '1' === get_option( 'twitterInitialised' ) ) ? false : true;
113
  if ( $new_install ) {
114
  $initial_settings = array(
115
  'post' => array(
195
  */
196
  function wpt_link( $post_ID ) {
197
  $ex_link = false;
198
+ $external_link = get_option( 'jd_twit_custom_url', '' );
199
  $permalink = get_permalink( $post_ID );
200
+ if ( '' !== $external_link ) {
201
  $ex_link = get_post_meta( $post_ID, $external_link, true );
202
  }
203
 
216
  */
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',
229
  )
230
  );
231
  } else {
232
+ if ( '1' === get_option( 'wpt_rate_limiting' ) ) {
233
  wpt_log_success( $auth, $ts, $id );
234
  }
235
  }
249
  if ( ! $id ) {
250
  return false;
251
  } else {
252
+ if ( false === $auth ) {
253
  $transient = get_transient( "_wpt_most_recent_tweet_$id" );
254
  } else {
255
  $transient = get_transient( '_wpt_' . $auth . "_most_recent_tweet_$id" );
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 {
267
  set_transient( '_wpt_' . $auth . "_most_recent_tweet_$id", true, $expire );
286
  function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false ) {
287
  $recent = wpt_check_recent_tweet( $id, $auth );
288
  $error = false;
289
+ if ( '1' === get_option( 'wpt_rate_limiting' ) ) {
290
  // check whether this post needs to be rate limited.
291
  $continue = wpt_test_rate_limit( $id, $auth );
292
  if ( ! $continue ) {
307
  return false;
308
  } // exit silently if not authorized.
309
 
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 && '' !== $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() );
365
  $connection = array( 'connection' => 'undefined' );
366
  } else {
367
  $staging_mode = apply_filters( 'wpt_staging_mode', false, $auth, $id );
368
+ if ( ( defined( 'WPT_STAGING_MODE' ) && true === WPT_STAGING_MODE ) || $staging_mode ) {
369
  // if in staging mode, we'll behave as if the Tweet succeeded, but not send it.
370
  $connection = true;
371
  $http_code = 200;
375
  $do_tweet = apply_filters( 'wpt_do_tweet', true, $auth, $id );
376
  if ( $do_tweet ) {
377
  $connection->post( $api, $status );
378
+ $http_code = ( $connection ) ? (int) $connection->http_code : 'failed';
379
  $notice = '';
380
  } else {
381
  $http_code = '000';
385
  }
386
  wpt_mail( 'Twitter Connection', print_r( $connection, 1 ) . " - $twit, $auth, $id, $media", $id );
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.
390
  $supplement = sprintf( __( 'Your Twitter application does not have read and write permissions. Go to <a href="%s">your Twitter apps</a> to modify these settings.', 'wp-to-twitter' ), 'https://dev.twitter.com/apps/' );
391
  } else {
396
  case '000':
397
  $error = '';
398
  break;
399
+ case 100:
400
  $error = __( '100 Continue: Twitter received the header of your submission, but your server did not follow through by sending the body of the data.', 'wp-to-twitter' );
401
  break;
402
+ case 200:
403
  $return = true;
404
  $error = __( '200 OK: Success!', 'wp-to-twitter' );
405
  update_option( 'wpt_authentication_missing', false );
406
  break;
407
+ case 304:
408
  $error = __( '304 Not Modified: There was no new data to return', 'wp-to-twitter' );
409
  break;
410
+ case 400:
411
  $error = __( '400 Bad Request: The request was invalid. This is the status code returned during rate limiting.', 'wp-to-twitter' );
412
  break;
413
+ case 401:
414
  $error = __( '401 Unauthorized: Authentication credentials were missing or incorrect.', 'wp-to-twitter' );
415
  update_option( 'wpt_authentication_missing', "$auth" );
416
  break;
417
+ case 403:
418
  $error = __( '403 Forbidden: The request is understood, but has been refused by Twitter.', 'wp-to-twitter' );
419
  break;
420
+ case 404:
421
  $error = __( '404 Not Found: The URI requested is invalid or the resource requested does not exist.', 'wp-to-twitter' );
422
  break;
423
+ case 406:
424
  $error = __( '406 Not Acceptable: Invalid Format Specified.', 'wp-to-twitter' );
425
  break;
426
+ case 422:
427
  $error = __( '422 Unprocessable Entity: The image uploaded could not be processed.', 'wp-to-twitter' );
428
  break;
429
+ case 429:
430
  $error = __( '429 Too Many Requests: You have exceeded your rate limits.', 'wp-to-twitter' );
431
  break;
432
+ case 500:
433
  $error = __( '500 Internal Server Error: Something is broken at Twitter.', 'wp-to-twitter' );
434
  break;
435
+ case 502:
436
  $error = __( '502 Bad Gateway: Twitter is down or being upgraded.', 'wp-to-twitter' );
437
  break;
438
+ case 503:
439
  $error = __( '503 Service Unavailable: The Twitter servers are up, but overloaded with requests - Please try again later.', 'wp-to-twitter' );
440
  break;
441
+ case 504:
442
  $error = __( "504 Gateway Timeout: The Twitter servers are up, but the request couldn't be serviced due to some failure within our stack. Try again later.", 'wp-to-twitter' );
443
  break;
444
  default:
447
  break;
448
  }
449
  $body = $connection->body;
450
+ $error_code = ( 200 !== $http_code ) ? $body->errors[0]->code : '';
451
+ $error_message = ( 200 !== $http_code ) ? $body->errors[0]->message : '';
452
+ $error_supplement = ( '' !== (string) $error_code ) ? ' (Error Code: ' . $error_code . ': ' . $error_message . ')' : '';
453
+ $error .= ( '' !== $supplement ) ? " $supplement" : '';
454
  $error .= $error_supplement;
455
  wpt_mail( "Twitter Response: $http_code", "$error", $id ); // DEBUG.
456
  // only save last Tweet if successful.
457
+ if ( 200 === $http_code ) {
458
  if ( ! $auth ) {
459
  update_option( 'jd_last_tweet', $twit );
460
  } else {
462
  }
463
  }
464
  wpt_saves_error( $id, $auth, $twit, $error, $http_code, time() );
465
+ if ( 200 === $http_code ) {
466
  $jwt = get_post_meta( $id, '_jd_wp_twitter', true );
467
  if ( ! is_array( $jwt ) ) {
468
  $jwt = array();
475
  update_post_meta( $id, '_jd_wp_twitter', $jwt );
476
  if ( ! function_exists( 'wpt_pro_exists' ) ) {
477
  // schedule a one-time promotional box for 4 weeks after first successful Tweet.
478
+ if ( false === get_option( 'wpt_promotion_scheduled', false ) ) {
479
  wp_schedule_single_event( time() + ( 60 * 60 * 24 * 7 * 4 ), 'wpt_schedule_promotion_action' );
480
  update_option( 'wpt_promotion_scheduled', 1 );
481
  }
566
  * @return array Post data used in Tweet functions.
567
  */
568
  function wpt_post_info( $post_ID ) {
569
+ $encoding = get_option( 'blog_charset', '' );
570
+ if ( '' === $encoding ) {
571
  $encoding = 'UTF-8';
572
  }
573
  $post = get_post( $post_ID );
579
  $values['postContent'] = $post->post_content;
580
  $values['authId'] = $post->post_author;
581
  $postdate = $post->post_date;
582
+ $dateformat = ( '' === get_option( 'jd_date_format', '' ) ) ? get_option( 'date_format' ) : get_option( 'jd_date_format' );
583
  $thisdate = mysql2date( $dateformat, $postdate );
584
  $altdate = mysql2date( 'Y-m-d H:i:s', $postdate );
585
  $values['_postDate'] = $altdate;
616
  $values['category'] = html_entity_decode( $category, ENT_COMPAT, $encoding );
617
  $values['cat_desc'] = html_entity_decode( $cat_desc, ENT_COMPAT, $encoding );
618
  $excerpt_length = get_option( 'jd_post_excerpt' );
619
+ $post_excerpt = ( '' === trim( $post->post_excerpt ) ) ? mb_substr( strip_tags( strip_shortcodes( $post->post_content ) ), 0, $excerpt_length ) : mb_substr( strip_tags( strip_shortcodes( $post->post_excerpt ) ), 0, $excerpt_length );
620
  $values['postExcerpt'] = html_entity_decode( $post_excerpt, ENT_COMPAT, $encoding );
621
  $thisposttitle = $post->post_title;
622
+ if ( '' === $thisposttitle && isset( $_POST['title'] ) ) {
623
  $thisposttitle = $_POST['title'];
624
  }
625
  $thisposttitle = strip_tags( apply_filters( 'the_title', stripcslashes( $thisposttitle ), $post_ID ) );
657
  if ( ! $post_id ) {
658
  $post_id = $post_ID;
659
  }
660
+ $use_urls = ( get_option( 'wpt_use_stored_urls' ) === 'false' ) ? false : true;
661
  $short = ( $use_urls ) ? get_post_meta( $post_id, '_wpt_short_url', true ) : false;
662
+ $short = ( '' === $short ) ? false : $short;
663
 
664
  return $short;
665
  }
673
  */
674
  function wpt_post_with_media( $post_ID, $post_info = array() ) {
675
  $return = false;
676
+ if ( ! function_exists( 'wpt_pro_exists' ) ) {
677
  return $return;
678
  }
679
+ if ( isset( $post_info['wpt_image'] ) && 1 === (int) $post_info['wpt_image'] ) {
680
+ // Post settings win over filters.
681
+ return $return;
682
+ }
683
+ if ( ! get_option( 'wpt_media' ) ) {
684
+ // Don't return immediately, this needs to be overrideable for posts.
685
  $return = false;
686
  } else {
687
  if ( has_post_thumbnail( $post_ID ) || wpt_post_attachment( $post_ID ) ) {
704
  function wpt_category_limit( $post_type, $post_info, $post_ID ) {
705
  $post_type_cats = get_object_taxonomies( $post_type );
706
  $continue = true;
707
+ if ( in_array( 'category', $post_type_cats, true ) ) {
708
  // 'category' is assigned to this post type, so apply filters.
709
+ if ( '1' === get_option( 'jd_twit_cats' ) ) {
710
  $continue = ( ! wpt_in_allowed_category( $post_info['categoryIds'] ) ) ? true : false;
711
  } else {
712
  $continue = ( wpt_in_allowed_category( $post_info['categoryIds'] ) ) ? true : false;
713
  }
714
  }
715
 
716
+ $continue = ( '0' === get_option( 'limit_categories' ) ) ? true : $continue;
717
  $args = array(
718
  'type' => $post_type,
719
  'info' => $post_info,
744
  $sentence = '';
745
  $template = '';
746
  $nptext = '';
747
+ if ( '1' !== get_option( 'wpt_inline_edits' ) ) {
748
  if ( isset( $_POST['_inline_edit'] ) || isset( $_REQUEST['bulk_edit'] ) ) {
749
  return false;
750
  }
753
  $is_inline_edit = true;
754
  }
755
  }
756
+ if ( '0' === get_option( 'jd_tweet_default' ) ) {
757
+ $default = ( 'no' !== $tweet_this ) ? true : false;
758
  } else {
759
+ $default = ( 'yes' === $tweet_this ) ? true : false;
760
  }
761
  wpt_mail( '1: Tweet Template', "$tweet_this / (Original: " . get_option( 'jd_tweet_default' ) . ") / $type", $post_ID ); // DEBUG.
762
  if ( $default ) { // default switch: depend on default settings.
763
  $post_info = wpt_post_info( $post_ID );
764
  $media = wpt_post_with_media( $post_ID, $post_info );
765
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
766
+ $auth = ( 'false' === get_option( 'wpt_cotweet_lock' ) || ! get_option( 'wpt_cotweet_lock' ) ) ? $post_info['authId'] : get_option( 'wpt_cotweet_lock' );
767
  } else {
768
  $auth = $post_info['authId'];
769
  }
770
  wpt_mail( '2: POST Debug Data', 'Post_Info: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
771
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() && function_exists( 'wpt_filter_post_info' ) ) {
772
  $filter = wpt_filter_post_info( $post_info );
773
+ if ( true === $filter ) {
774
  wpt_mail( '3: Post caught by wpt_filter_post_info', print_r( $post_info, 1 ) . " / $type", $post_ID );
775
 
776
  return false;
782
  return false;
783
  }
784
  $post_type = $post_info['postType'];
785
+ if ( 'future' === $type || 'future' === get_post_meta( $post_ID, 'wpt_publishing', true ) ) {
786
  $new = 1; // if this is a future action, then it should be published regardless of relationship.
787
  wpt_mail( '4a: Is a future post', print_r( $post_info, 1 ) . " / $type", $post_ID );
788
  delete_post_meta( $post_ID, 'wpt_publishing' );
793
  }
794
  // post is not previously published but has been backdated.
795
  // (post date is edited, but save option is 'publish').
796
+ if ( 0 === $new && ( isset( $_POST['edit_date'] ) && '1' === $_POST['edit_date'] && ! isset( $_POST['save'] ) ) ) {
797
  $new = 1;
798
  }
799
  // can't catch posts that were set to a past date as a draft, then published.
800
  $post_type_settings = get_option( 'wpt_post_types' );
801
  $post_types = array_keys( $post_type_settings );
802
+ if ( in_array( $post_type, $post_types, true ) ) {
803
  // identify whether limited by category/taxonomy.
804
  $continue = wpt_category_limit( $post_type, $post_info, $post_ID );
805
+ if ( false === $continue ) {
806
  wpt_mail( '4b: Limited by category filters', print_r( $post_info, 1 ), $post_ID );
807
  return false;
808
  }
809
  // create Tweet and ID whether current action is edit or new.
810
  $ct = get_post_meta( $post_ID, '_jd_twitter', true );
811
+ if ( isset( $_POST['_jd_twitter'] ) && '' !== trim( $_POST['_jd_twitter'] ) ) {
812
  $ct = $_POST['_jd_twitter'];
813
  }
814
+ $custom_tweet = ( '' !== $ct ) ? stripcslashes( trim( $ct ) ) : '';
815
  // if ops is set and equals 'publish', this is being edited. Otherwise, it's a new post.
816
+ if ( 0 === $new || true === $is_inline_edit ) {
817
  // if this is an old post and editing updates are enabled.
818
+ if ( '1' === get_option( 'jd_tweet_default_edit' ) ) {
819
  $tweet_this = apply_filters( 'wpt_tweet_this_edit', $tweet_this, $_POST );
820
+ if ( 'yes' !== $tweet_this ) {
821
  return false;
822
  }
823
  }
824
  wpt_mail( '4b: Is edited post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
825
+ if ( '1' === $post_type_settings[ $post_type ]['post-edited-update'] ) {
826
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-edited-text'] );
827
  $oldpost = true;
828
  }
829
  } else {
830
  wpt_mail( '4c: Is new post', 'Tweet this: ' . print_r( $post_info, 1 ) . " / $type", $post_ID ); // DEBUG.
831
+ if ( '1' === $post_type_settings[ $post_type ]['post-published-update'] ) {
832
  $nptext = stripcslashes( $post_type_settings[ $post_type ]['post-published-text'] );
833
  $newpost = true;
834
  }
835
  }
836
  if ( $newpost || $oldpost ) {
837
+ $template = ( '' !== $custom_tweet ) ? $custom_tweet : $nptext;
838
  $sentence = jd_truncate_tweet( $template, $post_info, $post_ID );
839
  wpt_mail( '5: Tweet Truncated', "Truncated Tweet: $sentence / $template / $type", $post_ID ); // DEBUG.
840
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
841
  $sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth );
842
  }
843
  }
844
+ if ( '' !== $sentence ) {
845
  // WPT PRO.
846
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
847
  $wpt_selected_users = $post_info['wpt_authorized_users'];
848
  // set up basic author/main account values.
849
  $auth_verified = wtt_oauth_test( $auth, 'verify' );
850
+ if ( empty( $wpt_selected_users ) && '1' === get_option( 'jd_individual_twitter_users' ) ) {
851
  $wpt_selected_users = ( $auth_verified ) ? array( $auth ) : array( false );
852
  }
853
+ if ( 1 === (int) $post_info['wpt_cotweet'] || '1' !== get_option( 'jd_individual_twitter_users' ) || in_array( 'main', $wpt_selected_users, true ) ) {
854
  $wpt_selected_users['main'] = false;
855
  }
856
  // filter selected users before using.
857
  $wpt_selected_users = apply_filters( 'wpt_filter_users', $wpt_selected_users, $post_info );
858
+ if ( 0 === $post_info['wpt_delay_tweet'] || '' === $post_info['wpt_delay_tweet'] || 'on' === $post_info['wpt_no_delay'] ) {
859
  foreach ( $wpt_selected_users as $acct ) {
860
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
861
  wpt_post_to_twitter( $sentence2, $acct, $post_ID, $media );
863
  }
864
  } else {
865
  foreach ( $wpt_selected_users as $acct ) {
866
+ $acct = ( 'main' === $acct ) ? false : $acct;
867
+ $offset = ( $auth !== $acct ) ? apply_filters( 'wpt_random_delay', rand( 60, 480 ) ) : 0;
868
  if ( wtt_oauth_test( $acct, 'verify' ) ) {
869
  $time = apply_filters( 'wpt_schedule_delay', ( (int) $post_info['wpt_delay_tweet'] ) * 60, $acct );
870
  wp_schedule_single_event(
903
  }
904
  }
905
  // This cycle handles scheduling the automatic retweets.
906
+ if ( 0 !== (int) $post_info['wpt_retweet_after'] && 'on' !== $post_info['wpt_no_repost'] ) {
907
  $repeat = $post_info['wpt_retweet_repeat'];
908
  $first = true;
909
  foreach ( $wpt_selected_users as $acct ) {
913
  if ( $continue ) {
914
  $retweet = apply_filters( 'wpt_set_retweet_text', $template, $i, $post_ID );
915
  $retweet = jd_truncate_tweet( $retweet, $post_info, $post_ID, true, $acct );
916
+ if ( '' === $retweet ) {
917
  // If a filter sets this value to empty, exit without scheduling.
918
  return $post_ID;
919
  }
920
  // add original delay to schedule.
921
  $delay = ( isset( $post_info['wpt_delay_tweet'] ) ) ? ( (int) $post_info['wpt_delay_tweet'] ) * 60 : 0;
922
  // Don't delay the first Tweet of the group.
923
+ $offset = ( true === $first ) ? 0 : rand( 60, 240 ); // delay each co-tweet by 1-4 minutes.
924
  $time = apply_filters( 'wpt_schedule_retweet', ( $post_info['wpt_retweet_after'] ) * ( 60 * 60 ) * $i, $acct, $i, $post_info );
925
  wp_schedule_single_event(
926
  time() + $time + $offset + $delay,
954
  $post_ID
955
  ); // DEBUG.
956
  }
957
+ $tweet_limit = (int) apply_filters( 'wpt_tweet_repeat_limit', 4, $post_ID );
958
+ if ( $i === $tweet_limit ) {
959
  break;
960
  }
961
  }
991
  function wpt_twit_link( $link_id ) {
992
  wpt_check_version();
993
  $thislinkprivate = $_POST['link_visible'];
994
+ if ( 'N' !== $thislinkprivate ) {
995
  $thislinkname = stripslashes( $_POST['link_name'] );
996
  $thispostlink = $_POST['link_url'];
997
  $thislinkdescription = stripcslashes( $_POST['link_description'] );
1015
  $sentence = str_ireplace( '#longurl#', $thispostlink, $sentence );
1016
  }
1017
 
1018
+ if ( '' !== $sentence ) {
1019
  wpt_post_to_twitter( $sentence, false, $link_id );
1020
  }
1021
 
1036
  $hashtags = '';
1037
  $term_meta = false;
1038
  $t_id = false;
1039
+ $max_tags = get_option( 'jd_max_tags', '3' );
1040
+ $max_characters = get_option( 'jd_max_characters', '20' );
1041
+ $max_characters = ( '0' === $max_characters || '' === $max_characters ) ? 100 : $max_characters + 1;
1042
+ if ( '0' === $max_tags || '' === $max_tags ) {
1043
  $max_tags = 100;
1044
  }
1045
+ $use_cats = ( '1' === get_option( 'wpt_use_cats' ) ) ? true : false;
1046
+ $tags = ( true === $use_cats ) ? wp_get_post_categories( $post_ID, array( 'fields' => 'all' ) ) : get_the_tags( $post_ID );
1047
  $tags = apply_filters( 'wpt_hash_source', $tags, $post_ID );
1048
  if ( $tags && count( $tags ) > 0 ) {
1049
  $i = 1;
1052
  $t_id = $value->term_id;
1053
  $term_meta = get_option( "wpt_taxonomy_$t_id" );
1054
  }
1055
+ if ( 'slug' === get_option( 'wpt_tag_source' ) ) {
1056
  $tag = $value->slug;
1057
  } else {
1058
  $tag = $value->name;
1060
  $strip = get_option( 'jd_strip_nonan' );
1061
  $search = '/[^\p{L}\p{N}\s]/u';
1062
  $replace = get_option( 'jd_replace_character' );
1063
+ $replace = ( '[ ]' === $replace || '' === $replace ) ? '' : $replace;
1064
  if ( false !== strpos( $tag, ' ' ) ) {
1065
  // If multiple words, camelcase tag.
1066
  $tag = ucwords( $tag );
1067
  }
1068
  $tag = str_ireplace( ' ', $replace, trim( $tag ) );
1069
  $tag = preg_replace( '/[\/]/', $replace, $tag ); // remove forward slashes.
1070
+ $tag = ( '1' === $strip ) ? preg_replace( $search, $replace, $tag ) : $tag;
1071
 
1072
  switch ( $term_meta ) {
1073
  case 1:
1109
  $wpt_post_types = get_option( 'wpt_post_types' );
1110
  if ( is_array( $wpt_post_types ) ) {
1111
  foreach ( $wpt_post_types as $key => $value ) {
1112
+ if ( '1' === $value['post-published-update'] || '1' === $value['post-edited-update'] ) {
1113
  add_meta_box( 'wp2t', 'WP to Twitter', 'wpt_add_twitter_inner_box', $key, 'side' );
1114
  }
1115
  }
1127
  $wpt_post_types = get_option( 'wpt_post_types' );
1128
  if ( is_array( $wpt_post_types ) ) {
1129
  foreach ( $wpt_post_types as $key => $value ) {
1130
+ if ( '1' === $value['post-published-update'] || '1' === $value['post-edited-update'] ) {
1131
  add_meta_box( 'wp2t-debug', 'WP to Twitter Debugging', 'wpt_show_debug', $key, 'advanced' );
1132
  }
1133
  }
1153
  $post_id = $post->ID;
1154
  $tweet_this = get_post_meta( $post_id, '_jd_tweet_this', true );
1155
  if ( ! $tweet_this ) {
1156
+ $tweet_this = ( '1' === get_option( 'jd_tweet_default' ) ) ? 'no' : 'yes';
1157
  }
1158
+ if ( isset( $_GET['action'] ) && 'edit' === $_GET['action'] && '1' === get_option( 'jd_tweet_default_edit' ) && 'publish' === $status ) {
1159
  $tweet_this = 'no';
1160
  }
1161
+ if ( isset( $_REQUEST['message'] ) && '10' !== $_REQUEST['message'] ) {
1162
  // don't display when draft is updated or if no message.
1163
+ if ( ! ( ( '1' === $_REQUEST['message'] ) && ( 'publish' === $status && '1' !== $options[ $type ]['post-edited-update'] ) ) && 'no' !== $tweet_this ) {
1164
  $log = wpt_log( 'wpt_status_message', $post_id );
1165
+ $class = ( __( 'Tweet sent successfully.', 'wp-to-twitter' ) !== $log ) ? 'error' : 'updated';
1166
+ if ( '' !== trim( $log ) ) {
1167
  echo "<div class='$class'><p>$log</p></div>";
1168
  }
1169
  }
1170
  }
1171
  $tweet = esc_attr( stripcslashes( get_post_meta( $post_id, '_jd_twitter', true ) ) );
1172
  $tweet = apply_filters( 'wpt_user_text', $tweet, $status );
1173
+ $template = ( 'publish' === $status ) ? $options[ $type ]['post-edited-text'] : $options[ $type ]['post-published-text'];
1174
 
1175
+ if ( 'publish' === $status && '1' !== $options[ $type ]['post-edited-update'] ) {
1176
  // Translators: post type.
1177
  $tweet_status = sprintf( __( '%s will not be Tweeted on update.', 'wp-to-twitter' ), ucfirst( $type ) );
1178
  }
1179
 
1180
+ if ( 'publish' === $status && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1181
  ?>
1182
  <div class='tweet-buttons'>
1183
  <button type='button' class='tweet button-primary' data-action='tweet'><span class='dashicons dashicons-twitter' aria-hidden='true'></span><?php _e( 'Tweet Now', 'wp-to-twitter' ); ?></button>
1210
  </p>
1211
  <?php
1212
  $expanded = $template;
1213
+ if ( '' !== get_option( 'jd_twit_prepend', '' ) ) {
1214
  $expanded = "<span title='" . __( 'Your prepended Tweet text; not part of your template.', 'wp-to-twitter' ) . "'>" . stripslashes( get_option( 'jd_twit_prepend' ) ) . '</span> ' . $expanded;
1215
  }
1216
+ if ( '' !== get_option( 'jd_twit_append', '' ) ) {
1217
  $expanded = $expanded . " <span title='" . __( 'Your appended Tweet text; not part of your template.', 'wp-to-twitter' ) . "'>" . stripslashes( get_option( 'jd_twit_append' ) ) . '</span>';
1218
  }
1219
  ?>
1224
  </p>
1225
  <?php
1226
  echo apply_filters( 'wpt_custom_retweet_fields', '', $post_id );
1227
+ if ( get_option( 'jd_keyword_format' ) === '2' ) {
1228
  $custom_keyword = get_post_meta( $post_id, '_yourls_keyword', true );
1229
  echo "<label for='yourls_keyword'>" . __( 'YOURLS Custom Keyword', 'wp-to-twitter' ) . "</label> <input type='text' name='_yourls_keyword' id='yourls_keyword' value='$custom_keyword' />";
1230
  }
1236
  ?>
1237
  <div class='wpt-options'>
1238
  <?php
1239
+ if ( 'pro' === $is_pro ) {
1240
  $pro_active = " class='active'";
1241
  $free_active = '';
1242
  } else {
1245
  }
1246
  ?>
1247
  <ul class='tabs' role="tablist">
1248
+ <?php if ( get_option( 'jd_individual_twitter_users' ) === '1' ) { ?>
1249
  <li><a href='#authors'<?php echo $pro_active; ?> aria-controls="authors" role="tab" id="tab_authors"><?php _e( 'Tweet to', 'wp-to-twitter' ); ?></a></li>
1250
  <?php } ?>
1251
  <li><a href='#custom' aria-controls="custom" role="tab" id="tab_custom"><?php _e( 'Options', 'wp-to-twitter' ); ?></a></li>
1254
  <?php
1255
  // WPT PRO OPTIONS.
1256
  if ( current_user_can( 'edit_others_posts' ) ) {
1257
+ if ( '1' === get_option( 'jd_individual_twitter_users' ) ) {
1258
  echo "<div class='wptab' id='authors' aria-labelledby='tab_authors' role='tabpanel'>";
1259
  $selected = ( get_post_meta( $post_id, '_wpt_authorized_users', true ) ) ? get_post_meta( $post_id, '_wpt_authorized_users', true ) : array();
1260
  if ( function_exists( 'wpt_authorized_users' ) ) {
1277
  ?>
1278
  <div class='wptab' id='custom' aria-labelledby='tab_custom' role='tabpanel'>
1279
  <?php
1280
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() && ( current_user_can( 'wpt_twitter_custom' ) || current_user_can( 'manage_options' ) ) ) {
1281
  wpt_schedule_values( $post_id );
1282
  do_action( 'wpt_custom_tab', $post_id, 'visible' );
1283
  } else {
1295
  <div class='wptab' id='custom' aria-labelledby='tab_custom' role='tabpanel'>
1296
  <p><?php _e( 'Access to customizing WP to Twitter values is not allowed for your user role.', 'wp-to-twitter' ); ?></p>
1297
  <?php
1298
+ if ( function_exists( 'wpt_pro_exists' ) && wpt_pro_exists() === true ) {
1299
  wpt_schedule_values( $post_id, 'hidden' );
1300
  do_action( 'wpt_custom_tab', $post_id, 'hidden' );
1301
  }
1320
  <?php
1321
  if ( current_user_can( 'wpt_twitter_switch' ) || current_user_can( 'manage_options' ) ) {
1322
  // "no" means 'Don't Tweet' (is checked)
1323
+ $nochecked = ( 'no' === $tweet_this ) ? ' checked="checked"' : '';
1324
+ $yeschecked = ( 'yes' === $tweet_this ) ? ' checked="checked"' : '';
1325
  ?>
1326
  <p class='toggle-btn-group'>
1327
  <input type="radio" name="_jd_tweet_this" value="no" id="jtn"<?php echo $nochecked; ?> /><label for="jtn"><?php _e( "Don't Tweet", 'wp-to-twitter' ); ?></label>
1349
  ?>
1350
  </p>
1351
  <?php
1352
+ if ( '' !== $tweet_status ) {
1353
  echo "<p class='disabled'>$tweet_status</p>";
1354
  }
1355
  ?>
1373
  $previous_tweets = get_post_meta( $post_id, '_jd_wp_twitter', true );
1374
  $failed_tweets = get_post_meta( $post_id, '_wpt_failed' );
1375
 
1376
+ if ( ! is_array( $previous_tweets ) && '' !== $previous_tweets ) {
1377
  $previous_tweets = array( 0 => $previous_tweets );
1378
  }
1379
  if ( ! empty( $previous_tweets ) || ! empty( $failed_tweets ) ) {
1390
  $hidden_fields = '';
1391
  if ( is_array( $previous_tweets ) ) {
1392
  foreach ( $previous_tweets as $previous_tweet ) {
1393
+ if ( '' !== $previous_tweet ) {
1394
  $has_history = true;
1395
  $hidden_fields .= "<input type='hidden' name='_jd_wp_twitter[]' value='" . esc_attr( $previous_tweet ) . "' />";
1396
  echo "<li>$previous_tweet <a href='http://twitter.com/intent/tweet?text=" . urlencode( $previous_tweet ) . "'>Retweet this</a></li>";
1412
  $error_list .= "<li> <code>Error: $reason</code> $ft <a href='http://twitter.com/intent/tweet?text=" . urlencode( $ft ) . "'>Tweet this</a><br /><em>$error</em></li>";
1413
  }
1414
  }
1415
+ if ( true === $list ) {
1416
  echo "<p class='error'><em>" . __( 'Failed Tweets', 'wp-to-twitter' ) . ":</em></p>
1417
  <ul>$error_list</ul>";
1418
  }
1433
  */
1434
  function wpt_admin_scripts() {
1435
  global $current_screen, $wpt_version;
1436
+ if ( 'post' === $current_screen->base || 'wp-tweets-pro_page_wp-to-twitter-schedule' === $current_screen->id ) {
1437
  wp_enqueue_script( 'charCount', plugins_url( 'wp-to-twitter/js/jquery.charcount.js' ), array( 'jquery' ), $wpt_version );
1438
  }
1439
+ if ( 'post' === $current_screen->base && isset( $_GET['post'] ) && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1440
  wp_enqueue_script( 'wpt.ajax', plugins_url( 'js/ajax.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1441
  wp_localize_script(
1442
  'wpt.ajax',
1448
  )
1449
  );
1450
  }
1451
+ if ( 'settings_page_wp-to-twitter/wp-to-twitter' === $current_screen->id || 'toplevel_page_wp-tweets-pro' === $current_screen->id ) {
1452
  wp_enqueue_script( 'wpt.tabs', plugins_url( 'js/tabs.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1453
  wp_localize_script( 'wpt.tabs', 'firstItem', 'wpt_post' );
1454
  wp_localize_script( 'wpt.tabs', 'firstPerm', 'wpt_editor' );
1465
  echo 'Invalid Security Check';
1466
  die;
1467
  }
1468
+ $action = ( 'tweet' === $_REQUEST['tweet_action'] ) ? 'tweet' : 'schedule';
1469
  $authors = ( isset( $_REQUEST['tweet_auth'] ) && null != $_REQUEST['tweet_auth'] ) ? $_REQUEST['tweet_auth'] : false;
1470
+ $upload = ( isset( $_REQUEST['tweet_upload'] ) && null != $_REQUEST['tweet_upload'] ) ? $_REQUEST['tweet_upload'] : '1';
1471
  $current_user = wp_get_current_user();
1472
  if ( function_exists( 'wpt_pro_exists' ) && wpt_pro_exists() ) {
1473
  if ( wtt_oauth_test( $current_user->ID, 'verify' ) ) {
1489
  $post_ID = intval( $_REQUEST['tweet_post_id'] );
1490
  $type = get_post_type( $post_ID );
1491
  $default = ( isset( $options[ $type ]['post-edited-text'] ) ) ? $options[ $type ]['post-edited-text'] : '';
1492
+ $sentence = ( isset( $_REQUEST['tweet_text'] ) && '' !== trim( $_REQUEST['tweet_text'] ) ) ? $_REQUEST['tweet_text'] : $default;
1493
  $sentence = stripcslashes( trim( $sentence ) );
1494
  $post_info = wpt_post_info( $post_ID );
1495
  $sentence = jd_truncate_tweet( $sentence, $post_info, $post_ID, false, $user_ID );
1497
  $print_schedule = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), $schedule );
1498
  $offset = ( 60 * 60 * get_option( 'gmt_offset' ) );
1499
  $schedule = $schedule - $offset;
1500
+ $media = ( '1' === $upload ) ? false : true; // this is correct; the boolean logic is reversed. Blah.
1501
 
1502
  foreach ( $authors as $auth ) {
1503
 
1504
+ $auth = ( 'main' === $auth ) ? false : $auth;
1505
 
1506
  switch ( $action ) {
1507
  case 'tweet':
1521
  break;
1522
  }
1523
  // Translators: Full text of Tweet, time scheduled for.
1524
+ $return = ( 'tweet' === $action ) ? wpt_log( 'wpt_status_message', $post_ID ) : sprintf( __( 'Tweet scheduled: %1$s for %2$s', 'wp-tweets-pro' ), '"' . $sentence . '"', $print_schedule );
1525
  echo $return;
1526
  if ( count( $authors ) > 1 ) {
1527
  echo '<br />';
1539
  */
1540
  function wpt_admin_script() {
1541
  global $current_screen;
1542
+ if ( 'post' === $current_screen->base || 'wp-tweets-pro_page_wp-to-twitter-schedule' === $current_screen->id ) {
1543
  wp_register_style( 'wpt-post-styles', plugins_url( 'css/post-styles.css', __FILE__ ) );
1544
  wp_enqueue_style( 'wpt-post-styles' );
1545
  $config = wpt_max_length();
1546
  // add one; character count starts from 1.
1547
+ if ( 'post' === $current_screen->base ) {
1548
  $allowed = $config['base_length'] - mb_strlen( stripslashes( get_option( 'jd_twit_prepend' ) . get_option( 'jd_twit_append' ) ) ) + 1;
1549
  } else {
1550
  $allowed = $config['base_length'] + 1;
1551
  }
1552
+ if ( function_exists( 'wpt_pro_exists' ) && '1' === get_option( 'jd_individual_twitter_users' ) ) {
1553
  $first = '#authors';
1554
  } elseif ( function_exists( 'wpt_pro_exists' ) ) {
1555
  $first = '#custom';
1588
  $yourls = $_POST['_yourls_keyword'];
1589
  $update = update_post_meta( $id, '_yourls_keyword', $yourls );
1590
  }
1591
+ if ( isset( $_POST['_jd_twitter'] ) && '' !== $_POST['_jd_twitter'] ) {
1592
  $twitter = $_POST['_jd_twitter'];
1593
  $update = update_post_meta( $id, '_jd_twitter', $twitter );
1594
+ } elseif ( isset( $_POST['_jd_twitter'] ) && '' === $_POST['_jd_twitter'] ) {
1595
  delete_post_meta( $id, '_jd_twitter' );
1596
  }
1597
+ if ( isset( $_POST['_jd_wp_twitter'] ) && '' !== $_POST['_jd_wp_twitter'] ) {
1598
  $wp_twitter = $_POST['_jd_wp_twitter'];
1599
  $update = update_post_meta( $id, '_jd_wp_twitter', $wp_twitter );
1600
  }
1601
  if ( isset( $_POST['_jd_tweet_this'] ) ) {
1602
+ $tweet_this = ( 'no' === $_POST['_jd_tweet_this'] ) ? 'no' : 'yes';
1603
  $update = update_post_meta( $id, '_jd_tweet_this', $tweet_this );
1604
  } else {
1605
  if ( isset( $_POST['_wpnonce'] ) ) {
1606
+ $tweet_default = ( '1' === get_option( 'jd_tweet_default' ) ) ? 'no' : 'yes';
1607
  $update = update_post_meta( $id, '_jd_tweet_this', $tweet_default );
1608
  }
1609
  }
1610
+ if ( isset( $_POST['wpt_clear_history'] ) && 'clear' === $_POST['wpt_clear_history'] ) {
1611
  delete_post_meta( $id, '_wpt_failed' );
1612
  delete_post_meta( $id, '_jd_wp_twitter' );
1613
  delete_post_meta( $id, '_wpt_short_url' );
1617
  $update = apply_filters( 'wpt_insert_post', $_POST, $id );
1618
  // WPT PRO.
1619
  // only send debug data if post meta is updated.
1620
+ if ( true === $update || is_int( $update ) ) {
1621
  wpt_mail( 'Post Meta Inserted', print_r( $_POST, 1 ), $id ); // DEBUG.
1622
  }
1623
+ if ( isset( $_POST['wpt-delete-debug'] ) && 'true' === $_POST['wpt-delete-debug'] ) {
1624
  delete_post_meta( $id, '_wpt_debug_log' );
1625
  }
1626
+ if ( isset( $_POST['wpt-delete-all-debug'] ) && 'true' === $_POST['wpt-delete-all-debug'] ) {
1627
  delete_post_meta_by_key( '_wpt_debug_log' );
1628
  }
1629
  }
1633
  * Send links to old admin to new admin page
1634
  */
1635
  function wpt_old_admin_redirect() {
1636
+ if ( is_admin() && isset( $_GET['page'] ) && 'wp-to-twitter/wp-to-twitter.php' === $_GET['page'] ) {
1637
  wp_safe_redirect( admin_url( 'admin.php?page=wp-tweets-pro' ) );
1638
  exit;
1639
  }
1655
  * Add stylesheets to WP to Twitter pages.
1656
  */
1657
  function wpt_admin_style() {
1658
+ if ( isset( $_GET['page'] ) && ( 'wp-to-twitter' === $_GET['page'] || 'wp-tweets-pro' === $_GET['page'] || 'wp-to-twitter-schedule' === $_GET['page'] || 'wp-to-twitter-tweets' === $_GET['page'] || 'wp-to-twitter-errors' === $_GET['page'] ) ) {
1659
  wp_enqueue_style( 'wpt-styles', plugins_url( 'css/styles.css', __FILE__ ) );
1660
  }
1661
  }
1669
  * @return link new array.
1670
  */
1671
  function wpt_plugin_action( $links, $file ) {
1672
+ if ( plugin_basename( dirname( __FILE__ ) . '/wp-to-twitter.php' ) === $file ) {
1673
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
1674
  $links[] = "<a href='$admin_url'>" . __( 'WP to Twitter Settings', 'wp-to-twitter' ) . '</a>';
1675
  if ( ! function_exists( 'wpt_pro_exists' ) ) {
1700
  echo $note;
1701
  }
1702
 
1703
+ if ( '1' === get_option( 'jd_twit_blogroll' ) ) {
1704
  add_action( 'add_link', 'wpt_twit_link' );
1705
  }
1706
 
1716
  function wpt_in_post_type( $id ) {
1717
  $post_types = wpt_allowed_post_types();
1718
  $type = get_post_type( $id );
1719
+ if ( in_array( $type, $post_types, true ) ) {
1720
  return true;
1721
  }
1722
 
1766
  return;
1767
  }
1768
  $post = get_post( $id );
1769
+ if ( 'publish' !== $post->post_status ) {
1770
  return;
1771
  }
1772
  // is there any reason to accept any other status?
1839
  * Set an option indicating that a job has been scheduled for promoting WP Tweets PRO.
1840
  */
1841
  function wpt_schedule_promotion() {
1842
+ if ( ! function_exists( 'wpt_pro_exists' ) && '1' === get_option( 'wpt_promotion_scheduled' ) ) {
1843
  update_option( 'wpt_promotion_scheduled', 2 );
1844
  }
1845
  }
1848
  * Dismiss promotion notice.
1849
  */
1850
  function wpt_dismiss_promotion() {
1851
+ if ( isset( $_GET['dismiss'] ) && 'promotion' === $_GET['dismiss'] ) {
1852
  update_option( 'wpt_promotion_scheduled', 3 );
1853
  }
1854
  }
1869
  * Display promotion notice to admin users who have not donated or purchased WP Tweets PRO.
1870
  */
1871
  function wpt_promotion_notice() {
1872
+ if ( current_user_can( 'activate_plugins' ) && '2' === get_option( 'wpt_promotion_scheduled' ) && '1' !== get_option( 'jd_donations' ) ) {
1873
  $upgrade = 'http://www.wptweetspro.com/wp-tweets-pro/';
1874
  $dismiss = admin_url( 'admin.php?page=wp-tweets-pro&dismiss=promotion' );
1875
  // Translators: URL to upgrade.
1899
  * @return boolean $value False if settings disable styles.
1900
  */
1901
  function wpt_permit_feed_styles( $value ) {
1902
+ if ( '1' === get_option( 'wpt_permit_feed_styles' ) ) {
1903
  $value = false;
1904
  }
1905
 
wpt-functions.php CHANGED
@@ -28,32 +28,33 @@ function wpt_checkbox( $field, $sub1 = false, $sub2 = '' ) {
28
  if ( $sub1 ) {
29
  $setting = get_option( $field );
30
  if ( isset( $setting[ $sub1 ] ) ) {
31
- $value = ( '' != $sub2 ) ? $setting[ $sub1 ][ $sub2 ] : $setting[ $sub1 ];
32
  } else {
33
  $value = 0;
34
  }
35
- if ( 1 == $value ) {
36
  return 'checked="checked"';
37
  }
38
  }
39
- if ( '1' == get_option( $field ) ) {
40
  return 'checked="checked"';
41
  }
 
42
  return '';
43
  }
44
 
45
  /**
46
- * See if options should be selected
47
  *
48
  * @param string $field Option name to check.
49
  * @param string $value Value to verify against.
50
  * @param string $type Select or checkbox.
51
  *
52
- * @return Selected or unselected/ checked or unchecked..
53
  */
54
  function wpt_selected( $field, $value, $type = 'select' ) {
55
- if ( get_option( $field ) == $value ) {
56
- return ( 'select' == $type ) ? 'selected="selected"' : 'checked="checked"';
57
  }
58
  return '';
59
  }
@@ -66,7 +67,7 @@ function wpt_selected( $field, $value, $type = 'select' ) {
66
  * @param string $message Log message.
67
  */
68
  function wpt_set_log( $data, $id, $message ) {
69
- if ( 'test' == $id ) {
70
  update_option( $data, $message );
71
  } else {
72
  update_post_meta( $id, '_' . $data, $message );
@@ -104,10 +105,10 @@ function wpt_check_functions() {
104
  $testpost = false;
105
  $title = urlencode( 'Your blog home' );
106
  $shrink = apply_filters( 'wptt_shorten_link', $testurl, $title, false, true );
107
- if ( false == $shrink ) {
108
  $error = htmlentities( get_option( 'wpt_shortener_status' ) );
109
  $message .= __( '<li class="error"><strong>WP to Twitter was unable to contact your selected URL shortening service.</strong></li>', 'wp-to-twitter' );
110
- if ( '' != $error ) {
111
  $message .= "<li><code>$error</code></li>";
112
  } else {
113
  $message .= '<li><code>' . __( 'No error message was returned.', 'wp-to-twitter' ) . '</code></li>';
@@ -130,7 +131,7 @@ function wpt_check_functions() {
130
  } else {
131
  $message .= '<strong>' . __( 'You have not connected WordPress to Twitter.', 'wp-to-twitter' ) . '</strong> ';
132
  }
133
- if ( false == $testpost && false == $shrink ) {
134
  $message .= __( "<li class=\"error\"><strong>Your server does not appear to support the required methods for WP to Twitter to function.</strong> You can try it anyway - these tests aren't perfect.</li>", 'wp-to-twitter' );
135
  }
136
  if ( $testpost && $shrink ) {
@@ -147,7 +148,8 @@ function wpt_check_functions() {
147
  */
148
  function wpt_settings_tabs() {
149
  $output = '';
150
- $default = ( '' == get_option( 'wtt_twitter_username' ) ) ? 'connection' : 'basic';
 
151
  $current = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $default;
152
  $pro_text = ( function_exists( 'wpt_pro_exists' ) ) ? __( 'Pro Settings', 'wp-to-twitter' ) : __( 'Get WP Tweets PRO', 'wp-to-twitter' );
153
  $pages = array(
@@ -158,7 +160,7 @@ function wpt_settings_tabs() {
158
  'support' => __( 'Get Help', 'wp-to-twitter' ),
159
  'pro' => $pro_text,
160
  );
161
- if ( '1' == get_option( 'jd_donations' ) && ! function_exists( 'wpt_pro_exists' ) ) {
162
  unset( $pages['pro'] );
163
  }
164
 
@@ -166,9 +168,9 @@ function wpt_settings_tabs() {
166
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
167
 
168
  foreach ( $pages as $key => $value ) {
169
- $selected = ( $key == $current ) ? ' nav-tab-active' : '';
170
  $url = esc_url( add_query_arg( 'tab', $key, $admin_url ) );
171
- if ( 'pro' == $key ) {
172
  $output .= "<a class='wpt-pro-tab nav-tab$selected' href='$url'>$value</a>";
173
  } else {
174
  $output .= "<a class='nav-tab$selected' href='$url'>$value</a>";
@@ -201,10 +203,10 @@ function wpt_show_last_tweet() {
201
  * Handle Tweet & URL shortener errors.
202
  */
203
  function wpt_handle_errors() {
204
- if ( isset( $_POST['submit-type'] ) && 'clear-error' == $_POST['submit-type'] ) {
205
  delete_option( 'wp_url_failure' );
206
  }
207
- if ( '1' == get_option( 'wp_url_failure' ) ) {
208
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
209
  $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
210
  $error = '<div class="error">' . __( '<p>The query to the URL shortener API failed, and your URL was not shrunk. The full post URL was attached to your Tweet. Check with your URL shortening provider to see if there are any known issues.</p>', 'wp-to-twitter' ) .
@@ -260,7 +262,7 @@ function wpt_cap_checkbox( $role, $cap, $name ) {
260
  * @param boolean $override Send message if debug disabled.
261
  */
262
  function wpt_mail( $subject, $body, $post_ID = false, $override = false ) {
263
- if ( ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) || true == $override ) {
264
  if ( WPT_DEBUG_BY_EMAIL ) {
265
  wp_mail( WPT_DEBUG_ADDRESS, $subject, $body, WPT_FROM );
266
  } else {
@@ -324,7 +326,7 @@ function wpt_show_debug() {
324
  <li><input type='checkbox' name='wpt-delete-all-debug' value='true' id='wpt-delete-all-debug'> <label for='wpt-delete-all-debug'>" . __( 'Delete debugging logs for all posts', 'wp-to-twitter' ) . '</label></li>
325
  </ul>';
326
 
327
- echo ( '' != $records ) ? "$script<div class='wpt-debug-log'><h3>Debugging Log:</h3><ul>$records</ul></div>$delete" : '';
328
  }
329
  }
330
 
@@ -415,8 +417,8 @@ function wpt_fetch_url( $url, $method = 'GET', $body = '', $headers = '', $retur
415
  );
416
 
417
  if ( ! is_wp_error( $result ) && isset( $result['body'] ) ) {
418
- if ( 200 == $result['response']['code'] ) {
419
- if ( 'body' == $return ) {
420
  return $result['body'];
421
  } else {
422
  return $result;
@@ -440,7 +442,7 @@ if ( ! function_exists( 'mb_substr_split_unicode' ) ) {
440
  * @return split output.
441
  */
442
  function mb_substr_split_unicode( $str, $split_pos ) {
443
- if ( 0 == $split_pos ) {
444
  return 0;
445
  }
446
  $byte_len = strlen( $str );
@@ -529,7 +531,7 @@ function wtt_option_selected( $field, $value, $type = 'checkbox' ) {
529
  default:
530
  $result = ' selected="selected"';
531
  }
532
- if ( $field == $value ) {
533
  $output = $result;
534
  } else {
535
  $output = '';
@@ -600,9 +602,9 @@ function wpt_get_support_form() {
600
  $request = '';
601
  $response_email = $current_user->user_email;
602
  // send fields for WP to Twitter.
603
- $license = ( '' != get_option( 'wpt_license_key' ) ) ? get_option( 'wpt_license_key' ) : 'none';
604
- if ( 'none' != $license ) {
605
- $valid = ( ( 'true' == get_option( 'wpt_license_valid' ) ) || ( 'active' == get_option( 'wpt_license_valid' ) ) || ( 'valid' == get_option( 'wpt_license_valid' ) ) ) ? ' (active)' : ' (inactive)';
606
  } else {
607
  $valid = '';
608
  }
@@ -678,7 +680,7 @@ $plugins_string
678
  $request = ( ! empty( $_POST['support_request'] ) ) ? stripslashes( $_POST['support_request'] ) : false;
679
  $has_donated = ( isset( $_POST['has_donated'] ) ) ? 'Donor' : 'No donation';
680
  $has_read_faq = ( isset( $_POST['has_read_faq'] ) ) ? 'Read FAQ' : false;
681
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
682
  $pro = ' PRO';
683
  } else {
684
  $pro = '';
@@ -687,12 +689,12 @@ $plugins_string
687
  $message = $request . "\n\n" . $data;
688
  // Get the site domain and get rid of www. from pluggable.php.
689
  $sitename = strtolower( $_SERVER['SERVER_NAME'] );
690
- if ( 'www.' == substr( $sitename, 0, 4 ) ) {
691
  $sitename = substr( $sitename, 4 );
692
  }
693
  $response_email = ( isset( $_POST['response_email'] ) ) ? $_POST['response_email'] : false;
694
  $from_email = 'wordpress@' . $sitename;
695
- $from = "From: \"$current_user->display_name\" <$response_email>\r\nReply-to: \"$current_user->display_name\" <$response_email>\r\n";
696
 
697
  if ( ! $has_read_faq ) {
698
  echo "<div class='notice error'><p>" . __( 'Please read the FAQ and other Help documents before making a support request.', 'wp-to-twitter' ) . '</p></div>';
@@ -703,7 +705,7 @@ $plugins_string
703
  } else {
704
  $sent = wp_mail( 'plugins@joedolson.com', $subject, $message, $from );
705
  if ( $sent ) {
706
- if ( 'Donor' == $has_donated ) {
707
  // Translators: Email address.
708
  echo "<div class='notice updated'><p>" . sprintf( __( 'Thank you for supporting WP to Twitter! I\'ll get back to you as soon as I can. Please make sure you can receive email at <code>%s</code>.', 'wp-to-twitter' ), $response_email ) . '</p></div>';
709
  } else {
@@ -716,7 +718,7 @@ $plugins_string
716
  }
717
  }
718
  }
719
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
720
  $checked = 'checked="checked"';
721
  } else {
722
  $checked = '';
@@ -781,7 +783,9 @@ function wpt_is_writable( $file ) {
781
 
782
  add_action( 'load-post.php', 'wpt_migrate_url_meta' );
783
  /**
784
- * Migrates post meta to new format when post is called in editor.
 
 
785
  */
786
  function wpt_migrate_url_meta() {
787
  $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : false;
@@ -797,47 +801,47 @@ function wpt_migrate_url_meta() {
797
  }
798
 
799
  $short = wpt_short_url( $post_id );
800
- if ( '' != $short ) {
801
  return;
802
  }
803
- if ( '' == $short ) {
804
  $short = get_post_meta( $post_id, '_wp_jd_goo', true );
805
  delete_post_meta( $post_id, '_wp_jd_goo' );
806
  }
807
- if ( '' == $short ) {
808
  $short = get_post_meta( $post_id, '_wp_jd_supr', true );
809
  delete_post_meta( $post_id, '_wp_jd_supr' );
810
  }
811
- if ( '' == $short ) {
812
  $short = get_post_meta( $post_id, '_wp_jd_wp', true );
813
  delete_post_meta( $post_id, '_wp_jd_wp' );
814
  }
815
- if ( '' == $short ) {
816
  $short = get_post_meta( $post_id, '_wp_jd_ind', true );
817
  delete_post_meta( $post_id, '_wp_jd_ind' );
818
  }
819
- if ( '' == $short ) {
820
  $short = get_post_meta( $post_id, '_wp_jd_yourls', true );
821
  delete_post_meta( $post_id, '_wp_jd_yourls' );
822
  }
823
- if ( '' == $short ) {
824
  $short = get_post_meta( $post_id, '_wp_jd_url', true );
825
  delete_post_meta( $post_id, '_wp_jd_url' );
826
  }
827
- if ( '' == $short ) {
828
  $short = get_post_meta( $post_id, '_wp_jd_joturl', true );
829
  delete_post_meta( $post_id, '_wp_jd_joturl' );
830
  }
831
- if ( '' == $short ) {
832
  // don't delete target link.
833
  $short = get_post_meta( $post_id, '_wp_jd_target', true );
834
  }
835
- if ( '' == $short ) {
836
  $short = get_post_meta( $post_id, '_wp_jd_clig', true );
837
  delete_post_meta( $post_id, '_wp_jd_clig' );
838
  }
839
 
840
- if ( '' != $short ) {
841
  update_post_meta( $post_id, '_wpt_short_url', $short );
842
  }
843
  }
28
  if ( $sub1 ) {
29
  $setting = get_option( $field );
30
  if ( isset( $setting[ $sub1 ] ) ) {
31
+ $value = ( '' !== $sub2 ) ? $setting[ $sub1 ][ $sub2 ] : $setting[ $sub1 ];
32
  } else {
33
  $value = 0;
34
  }
35
+ if ( 1 === (int) $value ) {
36
  return 'checked="checked"';
37
  }
38
  }
39
+ if ( '1' === get_option( $field ) ) {
40
  return 'checked="checked"';
41
  }
42
+
43
  return '';
44
  }
45
 
46
  /**
47
+ * See if options should be selected. Note: does not appear to be in use as of 7/14/2019.
48
  *
49
  * @param string $field Option name to check.
50
  * @param string $value Value to verify against.
51
  * @param string $type Select or checkbox.
52
  *
53
+ * @return Selected or unselected/ checked or unchecked.
54
  */
55
  function wpt_selected( $field, $value, $type = 'select' ) {
56
+ if ( get_option( $field ) === $value ) {
57
+ return ( 'select' === $type ) ? 'selected="selected"' : 'checked="checked"';
58
  }
59
  return '';
60
  }
67
  * @param string $message Log message.
68
  */
69
  function wpt_set_log( $data, $id, $message ) {
70
+ if ( 'test' === $id ) {
71
  update_option( $data, $message );
72
  } else {
73
  update_post_meta( $id, '_' . $data, $message );
105
  $testpost = false;
106
  $title = urlencode( 'Your blog home' );
107
  $shrink = apply_filters( 'wptt_shorten_link', $testurl, $title, false, true );
108
+ if ( false === $shrink ) {
109
  $error = htmlentities( get_option( 'wpt_shortener_status' ) );
110
  $message .= __( '<li class="error"><strong>WP to Twitter was unable to contact your selected URL shortening service.</strong></li>', 'wp-to-twitter' );
111
+ if ( is_string( $error ) && strlen( trim( $error ) ) > 0 ) {
112
  $message .= "<li><code>$error</code></li>";
113
  } else {
114
  $message .= '<li><code>' . __( 'No error message was returned.', 'wp-to-twitter' ) . '</code></li>';
131
  } else {
132
  $message .= '<strong>' . __( 'You have not connected WordPress to Twitter.', 'wp-to-twitter' ) . '</strong> ';
133
  }
134
+ if ( false === $testpost && false === $shrink ) {
135
  $message .= __( "<li class=\"error\"><strong>Your server does not appear to support the required methods for WP to Twitter to function.</strong> You can try it anyway - these tests aren't perfect.</li>", 'wp-to-twitter' );
136
  }
137
  if ( $testpost && $shrink ) {
148
  */
149
  function wpt_settings_tabs() {
150
  $output = '';
151
+ $username = get_option( 'wtt_twitter_username' );
152
+ $default = ( '' === $username || false === $username ) ? 'connection' : 'basic';
153
  $current = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $default;
154
  $pro_text = ( function_exists( 'wpt_pro_exists' ) ) ? __( 'Pro Settings', 'wp-to-twitter' ) : __( 'Get WP Tweets PRO', 'wp-to-twitter' );
155
  $pages = array(
160
  'support' => __( 'Get Help', 'wp-to-twitter' ),
161
  'pro' => $pro_text,
162
  );
163
+ if ( '1' === get_option( 'jd_donations' ) && ! function_exists( 'wpt_pro_exists' ) ) {
164
  unset( $pages['pro'] );
165
  }
166
 
168
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
169
 
170
  foreach ( $pages as $key => $value ) {
171
+ $selected = ( $key === $current ) ? ' nav-tab-active' : '';
172
  $url = esc_url( add_query_arg( 'tab', $key, $admin_url ) );
173
+ if ( 'pro' === $key ) {
174
  $output .= "<a class='wpt-pro-tab nav-tab$selected' href='$url'>$value</a>";
175
  } else {
176
  $output .= "<a class='nav-tab$selected' href='$url'>$value</a>";
203
  * Handle Tweet & URL shortener errors.
204
  */
205
  function wpt_handle_errors() {
206
+ if ( isset( $_POST['submit-type'] ) && 'clear-error' === $_POST['submit-type'] ) {
207
  delete_option( 'wp_url_failure' );
208
  }
209
+ if ( '1' === get_option( 'wp_url_failure' ) ) {
210
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
211
  $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
212
  $error = '<div class="error">' . __( '<p>The query to the URL shortener API failed, and your URL was not shrunk. The full post URL was attached to your Tweet. Check with your URL shortening provider to see if there are any known issues.</p>', 'wp-to-twitter' ) .
262
  * @param boolean $override Send message if debug disabled.
263
  */
264
  function wpt_mail( $subject, $body, $post_ID = false, $override = false ) {
265
+ if ( ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) || true === $override ) {
266
  if ( WPT_DEBUG_BY_EMAIL ) {
267
  wp_mail( WPT_DEBUG_ADDRESS, $subject, $body, WPT_FROM );
268
  } else {
326
  <li><input type='checkbox' name='wpt-delete-all-debug' value='true' id='wpt-delete-all-debug'> <label for='wpt-delete-all-debug'>" . __( 'Delete debugging logs for all posts', 'wp-to-twitter' ) . '</label></li>
327
  </ul>';
328
 
329
+ echo ( '' !== $records ) ? "$script<div class='wpt-debug-log'><h3>Debugging Log:</h3><ul>$records</ul></div>$delete" : '';
330
  }
331
  }
332
 
417
  );
418
 
419
  if ( ! is_wp_error( $result ) && isset( $result['body'] ) ) {
420
+ if ( 200 === absint( $result['response']['code'] ) ) {
421
+ if ( 'body' === $return ) {
422
  return $result['body'];
423
  } else {
424
  return $result;
442
  * @return split output.
443
  */
444
  function mb_substr_split_unicode( $str, $split_pos ) {
445
+ if ( 0 === $split_pos ) {
446
  return 0;
447
  }
448
  $byte_len = strlen( $str );
531
  default:
532
  $result = ' selected="selected"';
533
  }
534
+ if ( $field === $value ) {
535
  $output = $result;
536
  } else {
537
  $output = '';
602
  $request = '';
603
  $response_email = $current_user->user_email;
604
  // send fields for WP to Twitter.
605
+ $license = ( get_option( 'wpt_license_key' ) ) ? get_option( 'wpt_license_key' ) : 'none';
606
+ if ( 'none' !== $license ) {
607
+ $valid = ( ( 'true' === get_option( 'wpt_license_valid' ) ) || ( 'active' === get_option( 'wpt_license_valid' ) ) || ( 'valid' === get_option( 'wpt_license_valid' ) ) ) ? ' (active)' : ' (inactive)';
608
  } else {
609
  $valid = '';
610
  }
680
  $request = ( ! empty( $_POST['support_request'] ) ) ? stripslashes( $_POST['support_request'] ) : false;
681
  $has_donated = ( isset( $_POST['has_donated'] ) ) ? 'Donor' : 'No donation';
682
  $has_read_faq = ( isset( $_POST['has_read_faq'] ) ) ? 'Read FAQ' : false;
683
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
684
  $pro = ' PRO';
685
  } else {
686
  $pro = '';
689
  $message = $request . "\n\n" . $data;
690
  // Get the site domain and get rid of www. from pluggable.php.
691
  $sitename = strtolower( $_SERVER['SERVER_NAME'] );
692
+ if ( 'www.' === substr( $sitename, 0, 4 ) ) {
693
  $sitename = substr( $sitename, 4 );
694
  }
695
  $response_email = ( isset( $_POST['response_email'] ) ) ? $_POST['response_email'] : false;
696
  $from_email = 'wordpress@' . $sitename;
697
+ $from = "From: $current_user->display_name <$response_email>\r\nReply-to: $current_user->display_name <$response_email>\r\n";
698
 
699
  if ( ! $has_read_faq ) {
700
  echo "<div class='notice error'><p>" . __( 'Please read the FAQ and other Help documents before making a support request.', 'wp-to-twitter' ) . '</p></div>';
705
  } else {
706
  $sent = wp_mail( 'plugins@joedolson.com', $subject, $message, $from );
707
  if ( $sent ) {
708
+ if ( 'Donor' === $has_donated ) {
709
  // Translators: Email address.
710
  echo "<div class='notice updated'><p>" . sprintf( __( 'Thank you for supporting WP to Twitter! I\'ll get back to you as soon as I can. Please make sure you can receive email at <code>%s</code>.', 'wp-to-twitter' ), $response_email ) . '</p></div>';
711
  } else {
718
  }
719
  }
720
  }
721
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
722
  $checked = 'checked="checked"';
723
  } else {
724
  $checked = '';
783
 
784
  add_action( 'load-post.php', 'wpt_migrate_url_meta' );
785
  /**
786
+ * Migrates post meta to new format when post is called in editor.
787
+ *
788
+ * Migration started 12/10/2015. This can probably be removed soon.
789
  */
790
  function wpt_migrate_url_meta() {
791
  $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : false;
801
  }
802
 
803
  $short = wpt_short_url( $post_id );
804
+ if ( false !== $short ) {
805
  return;
806
  }
807
+ if ( false === $short ) {
808
  $short = get_post_meta( $post_id, '_wp_jd_goo', true );
809
  delete_post_meta( $post_id, '_wp_jd_goo' );
810
  }
811
+ if ( false === $short || '' === $short ) {
812
  $short = get_post_meta( $post_id, '_wp_jd_supr', true );
813
  delete_post_meta( $post_id, '_wp_jd_supr' );
814
  }
815
+ if ( false === $short || '' === $short ) {
816
  $short = get_post_meta( $post_id, '_wp_jd_wp', true );
817
  delete_post_meta( $post_id, '_wp_jd_wp' );
818
  }
819
+ if ( false === $short || '' === $short ) {
820
  $short = get_post_meta( $post_id, '_wp_jd_ind', true );
821
  delete_post_meta( $post_id, '_wp_jd_ind' );
822
  }
823
+ if ( false === $short || '' === $short ) {
824
  $short = get_post_meta( $post_id, '_wp_jd_yourls', true );
825
  delete_post_meta( $post_id, '_wp_jd_yourls' );
826
  }
827
+ if ( false === $short || '' === $short ) {
828
  $short = get_post_meta( $post_id, '_wp_jd_url', true );
829
  delete_post_meta( $post_id, '_wp_jd_url' );
830
  }
831
+ if ( false === $short || '' === $short ) {
832
  $short = get_post_meta( $post_id, '_wp_jd_joturl', true );
833
  delete_post_meta( $post_id, '_wp_jd_joturl' );
834
  }
835
+ if ( false === $short || '' === $short ) {
836
  // don't delete target link.
837
  $short = get_post_meta( $post_id, '_wp_jd_target', true );
838
  }
839
+ if ( false === $short || '' === $short ) {
840
  $short = get_post_meta( $post_id, '_wp_jd_clig', true );
841
  delete_post_meta( $post_id, '_wp_jd_clig' );
842
  }
843
 
844
+ if ( false !== $short && '' !== $short ) {
845
  update_post_meta( $post_id, '_wpt_short_url', $short );
846
  }
847
  }
wpt-truncate.php CHANGED
@@ -108,14 +108,14 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
108
  $tweet = apply_filters( 'wpt_tweet_sentence', $tweet, $post_ID );
109
  $tweet = trim( wpt_custom_shortcodes( $tweet, $post_ID ) );
110
  $tweet = trim( wpt_user_meta_shortcodes( $tweet, $post['authId'] ) );
111
- $encoding = ( 'UTF-8' != get_option( 'blog_charset' ) && '' != get_option( 'blog_charset' ) ) ? get_option( 'blog_charset' ) : 'UTF-8';
112
  $diff = 0;
113
 
114
  // Add custom append/prepend fields to Tweet text.
115
- if ( '' != get_option( 'jd_twit_prepend' ) && '' != $tweet ) {
116
  $tweet = stripslashes( get_option( 'jd_twit_prepend' ) ) . ' ' . $tweet;
117
  }
118
- if ( '' != get_option( 'jd_twit_append' ) && '' != $tweet ) {
119
  $tweet = $tweet . ' ' . stripslashes( get_option( 'jd_twit_append' ) );
120
  }
121
 
@@ -160,10 +160,10 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
160
  asort( $order );
161
  $preferred = array();
162
  foreach ( $order as $k => $v ) {
163
- if ( 'excerpt' == $k ) {
164
  $k = 'post';
165
  $value = $length_array['post'];
166
- } elseif ( 'blogname' == $k ) {
167
  $k = 'blog';
168
  $value = $length_array['blog'];
169
  } else {
@@ -183,7 +183,7 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
183
  if ( $str_length > ( $length + 1 + $diff ) ) {
184
  foreach ( $preferred as $key => $value ) {
185
  // don't truncate content of post excerpt or title if those tags not in use.
186
- if ( ! ( 'excerpt' == $key && ! $has_excerpt_tag ) && ! ( 'title' == $key && ! $has_title_tag ) ) {
187
  $str_length = mb_strlen( urldecode( wpt_normalize( trim( $post_tweet ) ) ), $encoding );
188
  if ( $str_length > ( $length + 1 + $diff ) ) {
189
  $trim = $str_length - ( $length + 1 + $diff );
@@ -195,7 +195,7 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
195
  if ( wpt_remove_tag( $key ) ) {
196
  $new_value = '';
197
  // These tag fields should have stray characters removed on word boundaries.
198
- } elseif ( 'tags' == $key ) {
199
  // remove any stray hash characters due to string truncation.
200
  if ( mb_strlen( $old_value ) - $trim <= 2 ) {
201
  $new_value = '';
@@ -244,7 +244,7 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
244
 
245
  if ( ! $tweet ) {
246
  $temp = str_ireplace( $url, $tag, $post_tweet );
247
- if ( mb_strlen( wpt_normalize( $temp ) ) > ( ( $length + 1 ) - ( $tco - strlen( $tag ) ) ) && $temp != $post_tweet ) {
248
  if ( false === stripos( $temp, '#url#' ) && false === stripos( $temp, '#longurl#' ) ) {
249
  $post_tweet = trim( mb_substr( $temp, 0, $length, $encoding ) );
250
  } else {
@@ -351,7 +351,7 @@ function wpt_make_tag( $value ) {
351
  * @return array of values.
352
  */
353
  function wpt_create_values( $post, $post_ID, $ref ) {
354
- $shrink = ( '' != $post['shortUrl'] ) ? $post['shortUrl'] : apply_filters( 'wptt_shorten_link', $post['postLink'], $post['postTitle'], $post_ID, false );
355
  // generate template variable values.
356
  $auth = $post['authId'];
357
  $title = trim( apply_filters( 'wpt_status', $post['postTitle'], $post_ID, 'title' ) );
@@ -363,37 +363,41 @@ function wpt_create_values( $post, $post_ID, $ref ) {
363
  $cat_desc = trim( $post['cat_desc'] );
364
  $user_account = get_user_meta( $auth, 'wtt_twitter_username', true );
365
  $tags = wpt_generate_hash_tags( $post_ID );
366
- $account = get_option( 'wtt_twitter_username' );
367
  $date = trim( $post['postDate'] );
368
  $modified = trim( $post['postModified'] );
369
- if ( 1 == get_option( 'jd_individual_twitter_users' ) ) {
370
- if ( '' == $user_account ) {
371
- if ( 'mainAtTwitter' == get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
372
- $user_account = stripcslashes( get_user_meta( $auth, 'wp-to-twitter-user-username', true ) );
 
 
 
 
373
  $account = $user_account;
374
- } elseif ( 'mainAtTwitterPlus' == get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
375
- $user_account = stripcslashes( get_user_meta( $auth, 'wp-to-twitter-user-username', true ) . ' @' . get_option( 'wtt_twitter_username' ) );
376
  $account = $user_account;
377
  }
378
- } else {
379
- $account = "$user_account";
380
  }
381
  }
382
- $display_name = get_the_author_meta( 'display_name', $auth );
383
- $author = ( '' != $user_account ) ? "@$user_account" : $display_name; // value of #author#.
384
- $account = ( '' != $account ) ? "@$account" : ''; // value of #account#.
385
- $uaccount = ( '' != $user_account ) ? "@$user_account" : "$account"; // value of #@#.
386
- // clean up data if extra @ included in user data.
387
- $account = str_ireplace( '@@', '@', $account );
388
  $uaccount = str_ireplace( '@@', '@', $uaccount );
389
- $author = str_ireplace( '@@', '@', $author );
390
 
391
- if ( 'on' == get_user_meta( $auth, 'wpt-remove', true ) ) {
 
 
 
 
392
  $account = '';
393
  }
394
 
395
- if ( function_exists( 'wpt_pro_exists' ) && true == wpt_pro_exists() ) {
396
- $reference = ( $ref ) ? $account : '@' . get_option( 'wtt_twitter_username' );
397
  } else {
398
  $reference = '';
399
  }
108
  $tweet = apply_filters( 'wpt_tweet_sentence', $tweet, $post_ID );
109
  $tweet = trim( wpt_custom_shortcodes( $tweet, $post_ID ) );
110
  $tweet = trim( wpt_user_meta_shortcodes( $tweet, $post['authId'] ) );
111
+ $encoding = ( 'UTF-8' !== get_option( 'blog_charset' ) && '' !== get_option( 'blog_charset', '' ) ) ? get_option( 'blog_charset' ) : 'UTF-8';
112
  $diff = 0;
113
 
114
  // Add custom append/prepend fields to Tweet text.
115
+ if ( '' !== get_option( 'jd_twit_prepend', '' ) && '' !== $tweet ) {
116
  $tweet = stripslashes( get_option( 'jd_twit_prepend' ) ) . ' ' . $tweet;
117
  }
118
+ if ( '' !== get_option( 'jd_twit_append', '' ) && '' !== $tweet ) {
119
  $tweet = $tweet . ' ' . stripslashes( get_option( 'jd_twit_append' ) );
120
  }
121
 
160
  asort( $order );
161
  $preferred = array();
162
  foreach ( $order as $k => $v ) {
163
+ if ( 'excerpt' === $k ) {
164
  $k = 'post';
165
  $value = $length_array['post'];
166
+ } elseif ( 'blogname' === $k ) {
167
  $k = 'blog';
168
  $value = $length_array['blog'];
169
  } else {
183
  if ( $str_length > ( $length + 1 + $diff ) ) {
184
  foreach ( $preferred as $key => $value ) {
185
  // don't truncate content of post excerpt or title if those tags not in use.
186
+ if ( ! ( 'excerpt' === $key && ! $has_excerpt_tag ) && ! ( 'title' === $key && ! $has_title_tag ) ) {
187
  $str_length = mb_strlen( urldecode( wpt_normalize( trim( $post_tweet ) ) ), $encoding );
188
  if ( $str_length > ( $length + 1 + $diff ) ) {
189
  $trim = $str_length - ( $length + 1 + $diff );
195
  if ( wpt_remove_tag( $key ) ) {
196
  $new_value = '';
197
  // These tag fields should have stray characters removed on word boundaries.
198
+ } elseif ( 'tags' === $key ) {
199
  // remove any stray hash characters due to string truncation.
200
  if ( mb_strlen( $old_value ) - $trim <= 2 ) {
201
  $new_value = '';
244
 
245
  if ( ! $tweet ) {
246
  $temp = str_ireplace( $url, $tag, $post_tweet );
247
+ if ( mb_strlen( wpt_normalize( $temp ) ) > ( ( $length + 1 ) - ( $tco - strlen( $tag ) ) ) && $temp !== $post_tweet ) {
248
  if ( false === stripos( $temp, '#url#' ) && false === stripos( $temp, '#longurl#' ) ) {
249
  $post_tweet = trim( mb_substr( $temp, 0, $length, $encoding ) );
250
  } else {
351
  * @return array of values.
352
  */
353
  function wpt_create_values( $post, $post_ID, $ref ) {
354
+ $shrink = ( '' !== $post['shortUrl'] ) ? $post['shortUrl'] : apply_filters( 'wptt_shorten_link', $post['postLink'], $post['postTitle'], $post_ID, false );
355
  // generate template variable values.
356
  $auth = $post['authId'];
357
  $title = trim( apply_filters( 'wpt_status', $post['postTitle'], $post_ID, 'title' ) );
363
  $cat_desc = trim( $post['cat_desc'] );
364
  $user_account = get_user_meta( $auth, 'wtt_twitter_username', true );
365
  $tags = wpt_generate_hash_tags( $post_ID );
 
366
  $date = trim( $post['postDate'] );
367
  $modified = trim( $post['postModified'] );
368
+
369
+ $account = get_option( 'wtt_twitter_username', '' );
370
+ if ( '1' === get_option( 'jd_individual_twitter_users' ) ) {
371
+ // Only execute these changes if the user is not connected to Twitter and does have a username entered.
372
+ $user_meta = get_user_meta( $auth, 'wp-to-twitter-user-username', true );
373
+ if ( '' === $user_account && '' !== trim( $user_meta ) ) {
374
+ if ( 'mainAtTwitter' === get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
375
+ $user_account = stripcslashes( $user_meta );
376
  $account = $user_account;
377
+ } elseif ( 'mainAtTwitterPlus' === get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
378
+ $user_account = stripcslashes( $user_meta . ' @' . get_option( 'wtt_twitter_username' ) );
379
  $account = $user_account;
380
  }
381
+ } elseif ( '' !== $user_account ) {
382
+ $account = $user_account;
383
  }
384
  }
385
+ $account = ( '' !== $account ) ? "@$account" : ''; // value of #account#.
386
+ $account = str_ireplace( '@@', '@', $account );
387
+
388
+ $uaccount = ( '' !== $user_account ) ? "@$user_account" : "$account"; // value of #@#.
 
 
389
  $uaccount = str_ireplace( '@@', '@', $uaccount );
 
390
 
391
+ $display_name = get_the_author_meta( 'display_name', $auth );
392
+ $author = ( '' !== $user_account ) ? "@$user_account" : $display_name; // value of #author#.
393
+ $author = str_ireplace( '@@', '@', $author );
394
+
395
+ if ( 'on' === get_user_meta( $auth, 'wpt-remove', true ) ) {
396
  $account = '';
397
  }
398
 
399
+ if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
400
+ $reference = ( $ref ) ? $uaccount : '@' . get_option( 'wtt_twitter_username' );
401
  } else {
402
  $reference = '';
403
  }