WP to Twitter - Version 3.5.3

Version Description

  • Bug fix: Query to Twitter config endpoint should never run more than once a day.
Download this release

Release Info

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

Code changes from version 3.5.2 to 3.5.3

Files changed (3) hide show
  1. readme.txt +5 -1
  2. wp-to-twitter.php +2 -2
  3. wpt-truncate.php +9 -5
readme.txt CHANGED
@@ -7,7 +7,7 @@ Tested up to: 5.7
7
  Requires PHP: 5.6
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
- Stable tag: 3.5.2
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
@@ -64,6 +64,10 @@ Check out my <a href="https://github.com/joedolson/plugin-extensions/tree/master
64
 
65
  == Changelog ==
66
 
 
 
 
 
67
  = 3.5.2 =
68
 
69
  * Bug fix: missing CSS for headings.
7
  Requires PHP: 5.6
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
+ Stable tag: 3.5.3
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
64
 
65
  == Changelog ==
66
 
67
+ = 3.5.3 =
68
+
69
+ * Bug fix: Query to Twitter config endpoint should never run more than once a day.
70
+
71
  = 3.5.2 =
72
 
73
  * Bug fix: missing CSS for headings.
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.5.2
21
  */
22
 
23
  /*
@@ -64,7 +64,7 @@ require_once( plugin_dir_path( __FILE__ ) . 'wpt-widget.php' );
64
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
65
 
66
  global $wpt_version;
67
- $wpt_version = '3.5.2';
68
 
69
  add_action( 'init', 'wpt_load_textdomain' );
70
  /**
17
  * License: GPL-2.0+
18
  * License URI: http://www.gnu.org/license/gpl-2.0.txt
19
  * Domain Path: lang
20
+ * Version: 3.5.3
21
  */
22
 
23
  /*
64
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
65
 
66
  global $wpt_version;
67
+ $wpt_version = '3.5.3';
68
 
69
  add_action( 'init', 'wpt_load_textdomain' );
70
  /**
wpt-truncate.php CHANGED
@@ -19,12 +19,13 @@ if ( ! defined( 'ABSPATH' ) ) {
19
  * @return array of URL lengths and params.
20
  */
21
  function wpt_max_length() {
22
- $config = get_transient( 'wpt_twitter_config' );
 
23
  if ( ! $config ) {
24
- $connection = wpt_oauth_connection();
 
25
  if ( $connection ) {
26
  $config = $connection->get( 'https://api.twitter.com/1.1/help/configuration.json' );
27
- set_transient( 'wpt_twitter_config', $config, 60 * 60 * 24 );
28
  } else {
29
  $config = json_encode(
30
  array(
@@ -35,8 +36,7 @@ function wpt_max_length() {
35
  );
36
  }
37
  }
38
-
39
- $decoded = json_decode( $config );
40
 
41
  if ( is_object( $decoded ) && isset( $decoded->short_url_length ) ) {
42
  $short_url_length = $decoded->short_url_length;
@@ -56,6 +56,10 @@ function wpt_max_length() {
56
  'reserved_chars' => 24,
57
  );
58
  }
 
 
 
 
59
 
60
  $values['base_length'] = intval( ( get_option( 'wpt_tweet_length' ) ) ? get_option( 'wpt_tweet_length' ) : 140 ) - 1;
61
 
19
  * @return array of URL lengths and params.
20
  */
21
  function wpt_max_length() {
22
+ $config = get_transient( 'wpt_twitter_config' );
23
+ $set_transient = false;
24
  if ( ! $config ) {
25
+ $set_transient = true;
26
+ $connection = wpt_oauth_connection();
27
  if ( $connection ) {
28
  $config = $connection->get( 'https://api.twitter.com/1.1/help/configuration.json' );
 
29
  } else {
30
  $config = json_encode(
31
  array(
36
  );
37
  }
38
  }
39
+ $decoded = ( is_string( $config ) ) ? json_decode( $config ) : $config;
 
40
 
41
  if ( is_object( $decoded ) && isset( $decoded->short_url_length ) ) {
42
  $short_url_length = $decoded->short_url_length;
56
  'reserved_chars' => 24,
57
  );
58
  }
59
+ if ( $set_transient ) {
60
+ // Only set the transient after confirming valid values.
61
+ set_transient( 'wpt_twitter_config', $values, 60 * 60 * 24 );
62
+ }
63
 
64
  $values['base_length'] = intval( ( get_option( 'wpt_tweet_length' ) ) ? get_option( 'wpt_tweet_length' ) : 140 ) - 1;
65