Version Description
- Bug fix: Changed rules for differentiating between new and edited posts.
- Bug fix: Bit.ly supporting plug-in changed function name.
- Bug fix: Variable types different between default settings & saved settings.
- Bug fix: Prevent scheduled Tweets (Pro) if post has been deleted.
- Update debugging messages & data for better clarity.
Download this release
Release Info
Developer | joedolson |
Plugin | WP to Twitter |
Version | 3.4.7 |
Comparing to | |
See all releases |
Code changes from version 3.4.4 to 3.4.7
- classes/class-tmhoauth.php +5 -5
- classes/class-wp-oauth.php +5 -5
- classes/class-wpt-normalizer.php +4 -4
- classes/class-wpt-twitterfeed.php +2 -2
- classes/class-wpt-twitteroauth.php +3 -3
- readme.txt +22 -3
- wp-to-twitter-manager.php +19 -38
- wp-to-twitter-oauth.php +9 -9
- wp-to-twitter-shorteners.php +111 -151
- wp-to-twitter-users.php +2 -2
- wp-to-twitter.php +79 -81
- wpt-functions.php +11 -10
- wpt-rate-limiting.php +4 -4
- wpt-widget.php +8 -8
classes/class-tmhoauth.php
CHANGED
@@ -102,7 +102,7 @@ class TmhOAuth {
|
|
102 |
$config
|
103 |
);
|
104 |
$this->set_user_agent();
|
105 |
-
date_default_timezone_set( $this->config['timezone'] );
|
106 |
}
|
107 |
|
108 |
/**
|
@@ -137,7 +137,7 @@ class TmhOAuth {
|
|
137 |
* @return void value is stored to the config array class variable
|
138 |
*/
|
139 |
private function create_nonce( $length = 12, $include_time = true ) {
|
140 |
-
if ( false
|
141 |
$sequence = array_merge( range( 0, 9 ), range( 'A', 'Z' ), range( 'a', 'z' ) );
|
142 |
$length = $length > count( $sequence ) ? count( $sequence ) : $length;
|
143 |
shuffle( $sequence );
|
@@ -154,7 +154,7 @@ class TmhOAuth {
|
|
154 |
* @return void value is stored to the config array class variable
|
155 |
*/
|
156 |
private function create_timestamp() {
|
157 |
-
$this->config['timestamp'] = ( false
|
158 |
}
|
159 |
|
160 |
/**
|
@@ -278,7 +278,7 @@ class TmhOAuth {
|
|
278 |
$port = ( 'https' === $scheme ) ? '443' : '80';
|
279 |
}
|
280 |
|
281 |
-
if ( ( 'https' === $scheme && '443'
|
282 |
$host = "$host:$port";
|
283 |
}
|
284 |
|
@@ -748,7 +748,7 @@ class TmhOAuth {
|
|
748 |
curl_setopt( $c, CURLOPT_HTTPHEADER, $headers );
|
749 |
}
|
750 |
|
751 |
-
if ( isset( $this->config['prevent_request'] ) && ( true
|
752 |
return 0;
|
753 |
}
|
754 |
|
102 |
$config
|
103 |
);
|
104 |
$this->set_user_agent();
|
105 |
+
date_default_timezone_set( $this->config['timezone'] ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
|
106 |
}
|
107 |
|
108 |
/**
|
137 |
* @return void value is stored to the config array class variable
|
138 |
*/
|
139 |
private function create_nonce( $length = 12, $include_time = true ) {
|
140 |
+
if ( false === $this->config['force_nonce'] ) {
|
141 |
$sequence = array_merge( range( 0, 9 ), range( 'A', 'Z' ), range( 'a', 'z' ) );
|
142 |
$length = $length > count( $sequence ) ? count( $sequence ) : $length;
|
143 |
shuffle( $sequence );
|
154 |
* @return void value is stored to the config array class variable
|
155 |
*/
|
156 |
private function create_timestamp() {
|
157 |
+
$this->config['timestamp'] = ( false === $this->config['force_timestamp'] ? time() : $this->config['timestamp'] );
|
158 |
}
|
159 |
|
160 |
/**
|
278 |
$port = ( 'https' === $scheme ) ? '443' : '80';
|
279 |
}
|
280 |
|
281 |
+
if ( ( 'https' === $scheme && '443' !== (string) $port ) || ( 'http' === $scheme && '80' !== (string) $port ) ) {
|
282 |
$host = "$host:$port";
|
283 |
}
|
284 |
|
748 |
curl_setopt( $c, CURLOPT_HTTPHEADER, $headers );
|
749 |
}
|
750 |
|
751 |
+
if ( isset( $this->config['prevent_request'] ) && ( true === $this->config['prevent_request'] ) ) {
|
752 |
return 0;
|
753 |
}
|
754 |
|
classes/class-wp-oauth.php
CHANGED
@@ -574,7 +574,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
|
|
574 |
$port = ( 'https' === $scheme ) ? '443' : '80';
|
575 |
}
|
576 |
|
577 |
-
if ( ( 'https' === $scheme && '443'
|
578 |
) {
|
579 |
$host = "$host:$port";
|
580 |
}
|
@@ -621,7 +621,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
|
|
621 |
|
622 |
$total = array();
|
623 |
foreach ( $this->parameters as $k => $v ) {
|
624 |
-
if ( 'oauth'
|
625 |
continue;
|
626 |
}
|
627 |
if ( is_array( $v ) ) {
|
@@ -683,7 +683,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
|
|
683 |
*/
|
684 |
private static function generate_timestamp() {
|
685 |
// make sure that timestamp is in UTC.
|
686 |
-
date_default_timezone_set( 'UTC' );
|
687 |
|
688 |
return time();
|
689 |
}
|
@@ -852,7 +852,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
|
|
852 |
throw new WPOAuthException( 'No signature method parameter. This parameter is required' );
|
853 |
}
|
854 |
|
855 |
-
if ( ! in_array( $signature_method, array_keys( $this->signature_methods ) ) ) {
|
856 |
throw new WPOAuthException(
|
857 |
"Signature method '$signature_method' not supported " .
|
858 |
'try one of the following: ' .
|
@@ -1150,7 +1150,7 @@ if ( ! class_exists( 'WPOAuthException' ) ) {
|
|
1150 |
}
|
1151 |
|
1152 |
foreach ( $_SERVER as $key => $value ) {
|
1153 |
-
if ( substr( $key, 0, 5 )
|
1154 |
// this is chaos, basically it is just there to capitalize the first.
|
1155 |
// letter of every word that is not an initial HTTP and strip HTTP.
|
1156 |
// code from przemek.
|
574 |
$port = ( 'https' === $scheme ) ? '443' : '80';
|
575 |
}
|
576 |
|
577 |
+
if ( ( 'https' === $scheme && '443' !== (string) $port ) || ( 'http' === $scheme && '80' !== (string) $port )
|
578 |
) {
|
579 |
$host = "$host:$port";
|
580 |
}
|
621 |
|
622 |
$total = array();
|
623 |
foreach ( $this->parameters as $k => $v ) {
|
624 |
+
if ( 'oauth' !== substr( $k, 0, 5 ) ) {
|
625 |
continue;
|
626 |
}
|
627 |
if ( is_array( $v ) ) {
|
683 |
*/
|
684 |
private static function generate_timestamp() {
|
685 |
// make sure that timestamp is in UTC.
|
686 |
+
date_default_timezone_set( 'UTC' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
|
687 |
|
688 |
return time();
|
689 |
}
|
852 |
throw new WPOAuthException( 'No signature method parameter. This parameter is required' );
|
853 |
}
|
854 |
|
855 |
+
if ( ! in_array( $signature_method, array_keys( $this->signature_methods ), true ) ) {
|
856 |
throw new WPOAuthException(
|
857 |
"Signature method '$signature_method' not supported " .
|
858 |
'try one of the following: ' .
|
1150 |
}
|
1151 |
|
1152 |
foreach ( $_SERVER as $key => $value ) {
|
1153 |
+
if ( substr( $key, 0, 5 ) === 'HTTP_' ) {
|
1154 |
// this is chaos, basically it is just there to capitalize the first.
|
1155 |
// letter of every word that is not an initial HTTP and strip HTTP.
|
1156 |
// code from przemek.
|
classes/class-wpt-normalizer.php
CHANGED
@@ -200,7 +200,7 @@ class WPT_Normalizer {
|
|
200 |
|
201 |
if ( isset( $comp_map[ $last_uchr . $uchr ] ) && ( ! $last_ucls || $last_ucls < $ucls ) ) {
|
202 |
$last_uchr = $comp_map[ $last_uchr . $uchr ];
|
203 |
-
} elseif ( $last_ucls
|
204 |
$tail .= $uchr;
|
205 |
} else {
|
206 |
if ( $tail ) {
|
@@ -293,13 +293,13 @@ class WPT_Normalizer {
|
|
293 |
// Table lookup.
|
294 |
$j = isset( $compat_map[ $uchr ] ) ? $compat_map[ $uchr ] : ( isset( $decomp_map[ $uchr ] ) ? $decomp_map[ $uchr ] : $uchr );
|
295 |
|
296 |
-
if ( $uchr
|
297 |
$uchr = $j;
|
298 |
|
299 |
$j = strlen( $uchr );
|
300 |
$ulen = $uchr[0] < "\x80" ? 1 : $ulen_mask[ $uchr[0] & "\xF0" ];
|
301 |
|
302 |
-
if ( $ulen
|
303 |
// Put trailing chars in $s.
|
304 |
$j -= $ulen;
|
305 |
$i -= $j;
|
@@ -324,7 +324,7 @@ class WPT_Normalizer {
|
|
324 |
|
325 |
$uchr = "\xE1\x84" . chr( 0x80 + (int) ( $j / 588 ) ) . "\xE1\x85" . chr( 0xA1 + (int) ( ( $j % 588 ) / 28 ) );
|
326 |
|
327 |
-
if ( $j %= 28 ) {
|
328 |
$uchr .= $j < 25 ? ( "\xE1\x86" . chr( 0xA7 + $j ) ) : ( "\xE1\x87" . chr( 0x67 + $j ) );
|
329 |
}
|
330 |
}
|
200 |
|
201 |
if ( isset( $comp_map[ $last_uchr . $uchr ] ) && ( ! $last_ucls || $last_ucls < $ucls ) ) {
|
202 |
$last_uchr = $comp_map[ $last_uchr . $uchr ];
|
203 |
+
} elseif ( $last_ucls === $ucls ) {
|
204 |
$tail .= $uchr;
|
205 |
} else {
|
206 |
if ( $tail ) {
|
293 |
// Table lookup.
|
294 |
$j = isset( $compat_map[ $uchr ] ) ? $compat_map[ $uchr ] : ( isset( $decomp_map[ $uchr ] ) ? $decomp_map[ $uchr ] : $uchr );
|
295 |
|
296 |
+
if ( $uchr !== $j ) {
|
297 |
$uchr = $j;
|
298 |
|
299 |
$j = strlen( $uchr );
|
300 |
$ulen = $uchr[0] < "\x80" ? 1 : $ulen_mask[ $uchr[0] & "\xF0" ];
|
301 |
|
302 |
+
if ( $ulen !== $j ) {
|
303 |
// Put trailing chars in $s.
|
304 |
$j -= $ulen;
|
305 |
$i -= $j;
|
324 |
|
325 |
$uchr = "\xE1\x84" . chr( 0x80 + (int) ( $j / 588 ) ) . "\xE1\x85" . chr( 0xA1 + (int) ( ( $j % 588 ) / 28 ) );
|
326 |
|
327 |
+
if ( $j %= 28 ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
|
328 |
$uchr .= $j < 25 ? ( "\xE1\x86" . chr( 0xA7 + $j ) ) : ( "\xE1\x87" . chr( 0x67 + $j ) );
|
329 |
}
|
330 |
}
|
classes/class-wpt-twitterfeed.php
CHANGED
@@ -320,10 +320,10 @@ class WPT_TwitterFeed {
|
|
320 |
} else {
|
321 |
if ( is_array( $result ) && isset( $result['errors'][0] ) && isset( $result['errors'][0]['message'] ) ) {
|
322 |
// Translators: Error message.
|
323 |
-
$last_error = '[' .
|
324 |
$this->st_last_error = $last_error;
|
325 |
} else {
|
326 |
-
$last_error = '[' .
|
327 |
$this->st_last_error = $last_error;
|
328 |
}
|
329 |
}
|
320 |
} else {
|
321 |
if ( is_array( $result ) && isset( $result['errors'][0] ) && isset( $result['errors'][0]['message'] ) ) {
|
322 |
// Translators: Error message.
|
323 |
+
$last_error = '[' . gmdate( 'r' ) . '] ' . sprintf( __( 'Twitter error: %s', 'wp-to-twitter' ), $result['errors'][0]['message'] );
|
324 |
$this->st_last_error = $last_error;
|
325 |
} else {
|
326 |
+
$last_error = '[' . gmdate( 'r' ) . ']' . __( 'Twitter returned an invalid response. It is probably down.', 'wp-to-twitter' );
|
327 |
$this->st_last_error = $last_error;
|
328 |
}
|
329 |
}
|
classes/class-wpt-twitteroauth.php
CHANGED
@@ -169,7 +169,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
|
|
169 |
$r = array();
|
170 |
foreach ( explode( '&', $response_string ) as $param ) {
|
171 |
$pair = explode( '=', $param, 2 );
|
172 |
-
if ( count( $pair )
|
173 |
continue;
|
174 |
}
|
175 |
$r[ urldecode( $pair[0] ) ] = urldecode( $pair[1] );
|
@@ -315,7 +315,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
|
|
315 |
$attachment = $args['media'];
|
316 |
|
317 |
$image_sizes = get_intermediate_image_sizes();
|
318 |
-
if ( in_array( 'large', $image_sizes ) ) {
|
319 |
$size = 'large';
|
320 |
} else {
|
321 |
$size = array_pop( $image_sizes );
|
@@ -332,7 +332,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
|
|
332 |
$transport = 'wp_http';
|
333 |
$binary = wp_remote_retrieve_body( $remote );
|
334 |
}
|
335 |
-
wpt_mail( '
|
336 |
if ( ! $binary ) {
|
337 |
return;
|
338 |
}
|
169 |
$r = array();
|
170 |
foreach ( explode( '&', $response_string ) as $param ) {
|
171 |
$pair = explode( '=', $param, 2 );
|
172 |
+
if ( count( $pair ) !== 2 ) {
|
173 |
continue;
|
174 |
}
|
175 |
$r[ urldecode( $pair[0] ) ] = urldecode( $pair[1] );
|
315 |
$attachment = $args['media'];
|
316 |
|
317 |
$image_sizes = get_intermediate_image_sizes();
|
318 |
+
if ( in_array( 'large', $image_sizes, true ) ) {
|
319 |
$size = 'large';
|
320 |
} else {
|
321 |
$size = array_pop( $image_sizes );
|
332 |
$transport = 'wp_http';
|
333 |
$binary = wp_remote_retrieve_body( $remote );
|
334 |
}
|
335 |
+
wpt_mail( 'WP to Twitter: media binary fetched', 'Url: ' . $image_url . 'Transport: ' . $transport . print_r( $remote, 1 ), $parent );
|
336 |
if ( ! $binary ) {
|
337 |
return;
|
338 |
}
|
readme.txt
CHANGED
@@ -3,11 +3,11 @@ 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.
|
7 |
-
Requires PHP: 5.
|
8 |
License: GPLv2 or later
|
9 |
Text Domain: wp-to-twitter
|
10 |
-
Stable tag: 3.4.
|
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,25 @@ Check out my <a href="https://github.com/joedolson/plugin-extensions/tree/master
|
|
63 |
|
64 |
== Changelog ==
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
= 3.4.4 =
|
67 |
|
68 |
* Bug fix: Due to external add-ons, need to test URL shortener settings as strings, not integers.
|
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.4
|
7 |
+
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
Text Domain: wp-to-twitter
|
10 |
+
Stable tag: 3.4.7
|
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.7 =
|
67 |
+
|
68 |
+
* Bug fix: Changed rules for differentiating between new and edited posts.
|
69 |
+
* Bug fix: Bit.ly supporting plug-in changed function name.
|
70 |
+
* Bug fix: Variable types different between default settings & saved settings.
|
71 |
+
* Bug fix: Prevent scheduled Tweets (Pro) if post has been deleted.
|
72 |
+
* Update debugging messages & data for better clarity.
|
73 |
+
|
74 |
+
= 3.4.6 =
|
75 |
+
|
76 |
+
* Bug fix: YOURLS queries not executing.
|
77 |
+
|
78 |
+
= 3.4.5 =
|
79 |
+
|
80 |
+
* Add support for @ references on tags.
|
81 |
+
* Add support for <a href="https://wordpress.org/support/plugin/codehaveli-bitly-url-shortener/">Codehaveli Bitly URL Shortener</a>
|
82 |
+
* Remove deprecated category filters. (UI disabled in 2014.)
|
83 |
+
* Don't query shorteners if they are enabled but settings are missing.
|
84 |
+
|
85 |
= 3.4.4 =
|
86 |
|
87 |
* Bug fix: Due to external add-ons, need to test URL shortener settings as strings, not integers.
|
wp-to-twitter-manager.php
CHANGED
@@ -77,9 +77,9 @@ function wpt_updated_settings() {
|
|
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 |
|
80 |
-
if ( isset( $_POST['wpt_rate_limiting'] ) && 1
|
81 |
$extend = __( 'Rate Limiting is enabled. Default rate limits are set at 10 posts per category/term per hour. <a href="#special_cases">Edit global default</a> or edit individual terms to customize limits for each category or taxonomy term.', 'wp-to-twitter' );
|
82 |
-
wp_schedule_event(
|
83 |
} else {
|
84 |
$extend = '';
|
85 |
wp_clear_scheduled_hook( 'wptratelimits' );
|
@@ -104,11 +104,11 @@ function wpt_updated_settings() {
|
|
104 |
update_option( 'jd_dynamic_analytics', $_POST['jd-dynamic-analytics'] );
|
105 |
|
106 |
$twitter_analytics = ( isset( $_POST['twitter-analytics'] ) ) ? $_POST['twitter-analytics'] : 0;
|
107 |
-
if ( 1
|
108 |
update_option( 'use_dynamic_analytics', 0 );
|
109 |
update_option( 'use-twitter-analytics', 1 );
|
110 |
update_option( 'no-analytics', 0 );
|
111 |
-
} elseif ( 2
|
112 |
update_option( 'use_dynamic_analytics', 1 );
|
113 |
update_option( 'use-twitter-analytics', 0 );
|
114 |
update_option( 'no-analytics', 0 );
|
@@ -199,7 +199,7 @@ function wpt_update_settings() {
|
|
199 |
?>
|
200 |
<div class="wrap" id="wp-to-twitter">
|
201 |
<?php
|
202 |
-
if ( defined( 'WPT_STAGING_MODE' ) && true
|
203 |
echo "<div class='updated notice'><p>" . __( 'WP to Twitter is in staging mode. Tweets will be reported as if successfully sent to Twitter but will not be sent.', 'wp-to-twitter' ) . '</p></div>';
|
204 |
}
|
205 |
wpt_updated_settings();
|
@@ -217,7 +217,7 @@ function wpt_update_settings() {
|
|
217 |
<div class="metabox-holder">
|
218 |
|
219 |
<?php
|
220 |
-
$default = ( ''
|
221 |
$current = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $default;
|
222 |
if ( 'connection' === $current ) {
|
223 |
if ( function_exists( 'wtt_connect_oauth' ) ) {
|
@@ -311,7 +311,7 @@ function wpt_update_settings() {
|
|
311 |
$tabs = "<ul class='tabs' role='tablist'>";
|
312 |
foreach ( $post_types as $type ) {
|
313 |
// If post type is both private & has no UI, don't show.
|
314 |
-
if ( false
|
315 |
continue;
|
316 |
}
|
317 |
$name = $type->labels->name;
|
@@ -324,7 +324,7 @@ function wpt_update_settings() {
|
|
324 |
$tabs .= "<li><a href='#wpt_links' id='tab_wpt_links' aria-controls='wpt_links'>" . __( 'Links', 'wp-to-twitter' ) . '</a></li></ul>';
|
325 |
echo $tabs;
|
326 |
foreach ( $post_types as $type ) {
|
327 |
-
if ( false
|
328 |
continue;
|
329 |
}
|
330 |
$name = $type->labels->name;
|
@@ -336,28 +336,9 @@ function wpt_update_settings() {
|
|
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 (
|
340 |
-
|
341 |
-
|
342 |
-
if ( 1 == $falseness ) {
|
343 |
-
echo '<p>' . __( 'These categories are currently <strong>excluded</strong> by the deprecated WP to Twitter category filters.', 'wp-to-twitter' ) . '</p>';
|
344 |
-
} else {
|
345 |
-
echo '<p>' . __( 'These categories are currently <strong>allowed</strong> by the deprecated WP to Twitter category filters.', 'wp-to-twitter' ) . '</p>';
|
346 |
-
}
|
347 |
-
echo '<ul>';
|
348 |
-
if ( is_array( $categories ) ) {
|
349 |
-
foreach ( $categories as $cat ) {
|
350 |
-
$category = get_the_category_by_ID( $cat );
|
351 |
-
echo "<li>$category</li>";
|
352 |
-
}
|
353 |
-
}
|
354 |
-
echo '</ul>';
|
355 |
-
if ( ! function_exists( 'wpt_pro_exists' ) ) {
|
356 |
-
// Translators: Link to sales page.
|
357 |
-
printf( __( '<a href="%s">Upgrade to WP Tweets PRO</a> to filter posts in all custom post types on any taxonomy.', 'wp-to-twitter' ), 'http://www.wptweetspro.com/wp-tweets-pro' );
|
358 |
-
} else {
|
359 |
-
_e( 'Updating the WP Tweets PRO taxonomy filters will overwrite your old category filters.', 'wp-to-twitter' );
|
360 |
-
}
|
361 |
}
|
362 |
?>
|
363 |
<fieldset>
|
@@ -446,7 +427,7 @@ function wpt_update_settings() {
|
|
446 |
<li><?php _e( '<code>#@#</code>: the twitter @reference for the author or blank, if not set', 'wp-to-twitter' ); ?></li>
|
447 |
<li><?php _e( '<code>#tags#</code>: your tags modified into hashtags.', 'wp-to-twitter' ); ?></li>
|
448 |
<?php
|
449 |
-
if ( function_exists( 'wpt_pro_exists' ) && true
|
450 |
?>
|
451 |
<li><?php _e( '<code>#reference#</code>: Used only in co-tweeting. @reference to main account when posted to author account, @reference to author account in post to main account.', 'wp-to-twitter' ); ?></li>
|
452 |
<?php
|
@@ -542,7 +523,7 @@ function wpt_update_settings() {
|
|
542 |
?>
|
543 |
"/>
|
544 |
<?php
|
545 |
-
if ( ''
|
546 |
echo date_i18n( get_option( 'jd_date_format' ) );
|
547 |
} else {
|
548 |
echo '<em>' . date_i18n( get_option( 'date_format' ) ) . '</em>';
|
@@ -583,7 +564,7 @@ function wpt_update_settings() {
|
|
583 |
<input type="checkbox" name="wpt_rate_limiting" id="wpt_rate_limiting" value="1" <?php echo wpt_checkbox( 'wpt_rate_limiting' ); ?> />
|
584 |
<label for="wpt_rate_limiting"><?php _e( 'Enable Rate Limiting', 'wp-to-twitter' ); ?></label><br/>
|
585 |
<?php
|
586 |
-
if ( get_option( 'wpt_rate_limiting' )
|
587 |
?>
|
588 |
<input type="number" name="wpt_default_rate_limit" min="1" id="wpt_default_rate_limit" value="<?php echo wpt_default_rate_limit(); ?>" />
|
589 |
<label for="wpt_default_rate_limit"><?php _e( 'Default Rate Limit per category per hour', 'wp-to-twitter' ); ?></label><br/>
|
@@ -815,7 +796,7 @@ function wpt_sidebar() {
|
|
815 |
?>
|
816 |
<div class="inside resources">
|
817 |
<?php
|
818 |
-
if ( 1
|
819 |
?>
|
820 |
<p class='cta'><?php _e( '<a href="http://www.wptweetspro.com/wp-tweets-pro">Get WP Tweets Pro</a>', 'wp-to-twitter' ); ?></p>
|
821 |
<?php
|
@@ -885,7 +866,7 @@ function wpt_sidebar() {
|
|
885 |
</div>
|
886 |
|
887 |
<?php
|
888 |
-
if ( 1
|
889 |
?>
|
890 |
<div class="ui-sortable meta-box-sortables">
|
891 |
<div class="postbox">
|
@@ -910,8 +891,8 @@ function wpt_sidebar() {
|
|
910 |
*/
|
911 |
function wpt_do_server_check( $test = false ) {
|
912 |
$wpt_server_string = get_option( 'wpt_server_string' );
|
913 |
-
if ( ! $wpt_server_string || isset( $_GET['refresh_wpt_server_string'] ) || true
|
914 |
-
$server_time =
|
915 |
$response = wp_remote_get(
|
916 |
'https://twitter.com/',
|
917 |
array(
|
@@ -934,7 +915,7 @@ function wpt_do_server_check( $test = false ) {
|
|
934 |
}
|
935 |
$errors = '<li>' . $ssl . $warning . '</li>';
|
936 |
} else {
|
937 |
-
$date =
|
938 |
$errors = '';
|
939 |
}
|
940 |
|
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 |
|
80 |
+
if ( isset( $_POST['wpt_rate_limiting'] ) && '1' !== get_option( 'wpt_rate_limiting' ) ) {
|
81 |
$extend = __( 'Rate Limiting is enabled. Default rate limits are set at 10 posts per category/term per hour. <a href="#special_cases">Edit global default</a> or edit individual terms to customize limits for each category or taxonomy term.', 'wp-to-twitter' );
|
82 |
+
wp_schedule_event( time() + 3600, 'hourly', 'wptratelimits' );
|
83 |
} else {
|
84 |
$extend = '';
|
85 |
wp_clear_scheduled_hook( 'wptratelimits' );
|
104 |
update_option( 'jd_dynamic_analytics', $_POST['jd-dynamic-analytics'] );
|
105 |
|
106 |
$twitter_analytics = ( isset( $_POST['twitter-analytics'] ) ) ? $_POST['twitter-analytics'] : 0;
|
107 |
+
if ( 1 === (int) $twitter_analytics ) {
|
108 |
update_option( 'use_dynamic_analytics', 0 );
|
109 |
update_option( 'use-twitter-analytics', 1 );
|
110 |
update_option( 'no-analytics', 0 );
|
111 |
+
} elseif ( 2 === (int) $twitter_analytics ) {
|
112 |
update_option( 'use_dynamic_analytics', 1 );
|
113 |
update_option( 'use-twitter-analytics', 0 );
|
114 |
update_option( 'no-analytics', 0 );
|
199 |
?>
|
200 |
<div class="wrap" id="wp-to-twitter">
|
201 |
<?php
|
202 |
+
if ( defined( 'WPT_STAGING_MODE' ) && true === WPT_STAGING_MODE ) {
|
203 |
echo "<div class='updated notice'><p>" . __( 'WP to Twitter is in staging mode. Tweets will be reported as if successfully sent to Twitter but will not be sent.', 'wp-to-twitter' ) . '</p></div>';
|
204 |
}
|
205 |
wpt_updated_settings();
|
217 |
<div class="metabox-holder">
|
218 |
|
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' ) ) {
|
311 |
$tabs = "<ul class='tabs' role='tablist'>";
|
312 |
foreach ( $post_types as $type ) {
|
313 |
// If post type is both private & has no UI, don't show.
|
314 |
+
if ( false === $type->public && false === $type->show_ui ) {
|
315 |
continue;
|
316 |
}
|
317 |
$name = $type->labels->name;
|
324 |
$tabs .= "<li><a href='#wpt_links' id='tab_wpt_links' aria-controls='wpt_links'>" . __( 'Links', 'wp-to-twitter' ) . '</a></li></ul>';
|
325 |
echo $tabs;
|
326 |
foreach ( $post_types as $type ) {
|
327 |
+
if ( false === $type->public && false === $type->show_ui ) {
|
328 |
continue;
|
329 |
}
|
330 |
$name = $type->labels->name;
|
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 ( ! function_exists( 'wpt_pro_exists' ) ) {
|
340 |
+
// Translators: Link to sales page.
|
341 |
+
printf( __( '<a href="%s">Upgrade to WP Tweets PRO</a> to filter posts in all custom post types on any taxonomy.', 'wp-to-twitter' ), 'http://www.wptweetspro.com/wp-tweets-pro' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
}
|
343 |
?>
|
344 |
<fieldset>
|
427 |
<li><?php _e( '<code>#@#</code>: the twitter @reference for the author or blank, if not set', 'wp-to-twitter' ); ?></li>
|
428 |
<li><?php _e( '<code>#tags#</code>: your tags modified into hashtags.', 'wp-to-twitter' ); ?></li>
|
429 |
<?php
|
430 |
+
if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
|
431 |
?>
|
432 |
<li><?php _e( '<code>#reference#</code>: Used only in co-tweeting. @reference to main account when posted to author account, @reference to author account in post to main account.', 'wp-to-twitter' ); ?></li>
|
433 |
<?php
|
523 |
?>
|
524 |
"/>
|
525 |
<?php
|
526 |
+
if ( '' !== get_option( 'jd_date_format', '' ) ) {
|
527 |
echo date_i18n( get_option( 'jd_date_format' ) );
|
528 |
} else {
|
529 |
echo '<em>' . date_i18n( get_option( 'date_format' ) ) . '</em>';
|
564 |
<input type="checkbox" name="wpt_rate_limiting" id="wpt_rate_limiting" value="1" <?php echo wpt_checkbox( 'wpt_rate_limiting' ); ?> />
|
565 |
<label for="wpt_rate_limiting"><?php _e( 'Enable Rate Limiting', 'wp-to-twitter' ); ?></label><br/>
|
566 |
<?php
|
567 |
+
if ( '1' === get_option( 'wpt_rate_limiting' ) ) {
|
568 |
?>
|
569 |
<input type="number" name="wpt_default_rate_limit" min="1" id="wpt_default_rate_limit" value="<?php echo wpt_default_rate_limit(); ?>" />
|
570 |
<label for="wpt_default_rate_limit"><?php _e( 'Default Rate Limit per category per hour', 'wp-to-twitter' ); ?></label><br/>
|
796 |
?>
|
797 |
<div class="inside resources">
|
798 |
<?php
|
799 |
+
if ( '1' !== get_option( 'jd_donations' ) && ! function_exists( 'wpt_pro_exists' ) ) {
|
800 |
?>
|
801 |
<p class='cta'><?php _e( '<a href="http://www.wptweetspro.com/wp-tweets-pro">Get WP Tweets Pro</a>', 'wp-to-twitter' ); ?></p>
|
802 |
<?php
|
866 |
</div>
|
867 |
|
868 |
<?php
|
869 |
+
if ( '1' === get_option( 'wpt_rate_limiting' ) ) {
|
870 |
?>
|
871 |
<div class="ui-sortable meta-box-sortables">
|
872 |
<div class="postbox">
|
891 |
*/
|
892 |
function wpt_do_server_check( $test = false ) {
|
893 |
$wpt_server_string = get_option( 'wpt_server_string' );
|
894 |
+
if ( ! $wpt_server_string || isset( $_GET['refresh_wpt_server_string'] ) || true === $test ) {
|
895 |
+
$server_time = gmdate( DATE_COOKIE );
|
896 |
$response = wp_remote_get(
|
897 |
'https://twitter.com/',
|
898 |
array(
|
915 |
}
|
916 |
$errors = '<li>' . $ssl . $warning . '</li>';
|
917 |
} else {
|
918 |
+
$date = gmdate( DATE_COOKIE, strtotime( $response['headers']['date'] ) );
|
919 |
$errors = '';
|
920 |
}
|
921 |
|
wp-to-twitter-oauth.php
CHANGED
@@ -23,11 +23,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
23 |
*/
|
24 |
function wtt_oauth_test( $auth = false, $context = '' ) {
|
25 |
if ( ! $auth ) {
|
26 |
-
return ( wtt_oauth_credentials_to_hash()
|
27 |
} else {
|
28 |
-
$return = ( wtt_oauth_credentials_to_hash( $auth )
|
29 |
-
if ( ! $return && 'verify'
|
30 |
-
return ( wtt_oauth_credentials_to_hash()
|
31 |
} else {
|
32 |
return $return;
|
33 |
}
|
@@ -42,7 +42,7 @@ function wtt_oauth_test( $auth = false, $context = '' ) {
|
|
42 |
* @return author hash.
|
43 |
*/
|
44 |
function wpt_get_user_verification( $auth ) {
|
45 |
-
if ( get_option( 'jd_individual_twitter_users' )
|
46 |
return false;
|
47 |
} else {
|
48 |
$auth = get_user_meta( $auth, 'wtt_oauth_hash', true );
|
@@ -135,7 +135,7 @@ function wpt_update_oauth_settings( $auth = false, $post = false ) {
|
|
135 |
$connection = wpt_oauth_connection( $auth );
|
136 |
if ( $connection ) {
|
137 |
$data = $connection->get( 'https://api.twitter.com/1.1/account/verify_credentials.json' );
|
138 |
-
if ( '200'
|
139 |
$data = json_decode( $data );
|
140 |
$code = "<a href='https://dev.twitter.com/docs/error-codes-responses'>" . $data->errors[0]->code . '</a>';
|
141 |
$error = $data->errors[0]->message;
|
@@ -143,7 +143,7 @@ function wpt_update_oauth_settings( $auth = false, $post = false ) {
|
|
143 |
} else {
|
144 |
delete_option( 'wpt_error' );
|
145 |
}
|
146 |
-
if ( '200'
|
147 |
$error_information = '';
|
148 |
$decode = json_decode( $data );
|
149 |
if ( ! $auth ) {
|
@@ -159,7 +159,7 @@ function wpt_update_oauth_settings( $auth = false, $post = false ) {
|
|
159 |
}
|
160 |
$message = 'success';
|
161 |
delete_option( 'wpt_curl_error' );
|
162 |
-
} elseif ( 0
|
163 |
$error_information = __( 'WP to Twitter was unable to establish a connection to Twitter.', 'wp-to-twitter' );
|
164 |
update_option( 'wpt_curl_error', "$error_information" );
|
165 |
} else {
|
@@ -172,7 +172,7 @@ function wpt_update_oauth_settings( $auth = false, $post = false ) {
|
|
172 |
$error_code = sprintf( __( 'Twitter response: http_code %s', 'wp-to-twitter' ), "$error_information[http_code] - $error_information[status]" );
|
173 |
update_option( 'wpt_curl_error', $error_code );
|
174 |
}
|
175 |
-
if ( '1'
|
176 |
echo '<pre><strong>Summary Connection Response:</strong><br />';
|
177 |
print_r( $error_information );
|
178 |
echo '<br /><strong>Account Verification Data:</strong><br />';
|
23 |
*/
|
24 |
function wtt_oauth_test( $auth = false, $context = '' ) {
|
25 |
if ( ! $auth ) {
|
26 |
+
return ( wtt_oauth_credentials_to_hash() === get_option( 'wtt_oauth_hash' ) );
|
27 |
} else {
|
28 |
+
$return = ( wtt_oauth_credentials_to_hash( $auth ) === wpt_get_user_verification( $auth ) );
|
29 |
+
if ( ! $return && 'verify' !== $context ) {
|
30 |
+
return ( wtt_oauth_credentials_to_hash() === get_option( 'wtt_oauth_hash' ) );
|
31 |
} else {
|
32 |
return $return;
|
33 |
}
|
42 |
* @return author hash.
|
43 |
*/
|
44 |
function wpt_get_user_verification( $auth ) {
|
45 |
+
if ( get_option( 'jd_individual_twitter_users' ) !== '1' ) {
|
46 |
return false;
|
47 |
} else {
|
48 |
$auth = get_user_meta( $auth, 'wtt_oauth_hash', true );
|
135 |
$connection = wpt_oauth_connection( $auth );
|
136 |
if ( $connection ) {
|
137 |
$data = $connection->get( 'https://api.twitter.com/1.1/account/verify_credentials.json' );
|
138 |
+
if ( '200' !== (string) $connection->http_code ) {
|
139 |
$data = json_decode( $data );
|
140 |
$code = "<a href='https://dev.twitter.com/docs/error-codes-responses'>" . $data->errors[0]->code . '</a>';
|
141 |
$error = $data->errors[0]->message;
|
143 |
} else {
|
144 |
delete_option( 'wpt_error' );
|
145 |
}
|
146 |
+
if ( '200' === (string) $connection->http_code ) {
|
147 |
$error_information = '';
|
148 |
$decode = json_decode( $data );
|
149 |
if ( ! $auth ) {
|
159 |
}
|
160 |
$message = 'success';
|
161 |
delete_option( 'wpt_curl_error' );
|
162 |
+
} elseif ( '0' === (string) $connection->http_code ) {
|
163 |
$error_information = __( 'WP to Twitter was unable to establish a connection to Twitter.', 'wp-to-twitter' );
|
164 |
update_option( 'wpt_curl_error', "$error_information" );
|
165 |
} else {
|
172 |
$error_code = sprintf( __( 'Twitter response: http_code %s', 'wp-to-twitter' ), "$error_information[http_code] - $error_information[status]" );
|
173 |
update_option( 'wpt_curl_error', $error_code );
|
174 |
}
|
175 |
+
if ( '1' === get_option( 'wp_debug_oauth' ) ) {
|
176 |
echo '<pre><strong>Summary Connection Response:</strong><br />';
|
177 |
print_r( $error_information );
|
178 |
echo '<br /><strong>Account Verification Data:</strong><br />';
|
wp-to-twitter-shorteners.php
CHANGED
@@ -29,7 +29,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
29 |
* @return shortened URL.
|
30 |
*/
|
31 |
function wpt_shorten_url( $url, $post_title, $post_ID, $testmode = false, $store_urls = true ) {
|
32 |
-
wpt_mail( '
|
33 |
// filter link before sending to shortener or adding analytics.
|
34 |
$shortener = get_option( 'jd_shortener' );
|
35 |
// if the URL already exists, return it without processing.
|
@@ -39,9 +39,9 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
39 |
return $shrink;
|
40 |
}
|
41 |
$url = apply_filters( 'wpt_shorten_link', $url, $shortener, $post_ID );
|
42 |
-
if ( false
|
43 |
-
if ( 1
|
44 |
-
if ( '1'
|
45 |
$campaign_type = get_option( 'jd_dynamic_analytics' );
|
46 |
if ( 'post_category' === $campaign_type && 'link' !== $testmode ) {
|
47 |
$category = get_the_category( $post_ID );
|
@@ -82,8 +82,8 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
82 |
}
|
83 |
|
84 |
// custom word setting.
|
85 |
-
$keyword_format = ( '1'
|
86 |
-
$keyword_format = ( '2'
|
87 |
// Generate and grab the short url.
|
88 |
$shrink = apply_filters( 'wpt_do_shortening', false, $shortener, $url, $post_title, $post_ID, $testmode );
|
89 |
// if an add-on has shortened the link, skip shortening.
|
@@ -95,27 +95,22 @@ if ( ! function_exists( 'wpt_shorten_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 |
-
$
|
99 |
-
|
100 |
-
|
101 |
-
if ( $decoded && isset( $decoded['status_code'] ) ) {
|
102 |
-
if ( 200 != $decoded['status_code'] ) {
|
103 |
-
$shrink = $url;
|
104 |
-
$error = $decoded['status_txt'];
|
105 |
-
} else {
|
106 |
-
$shrink = $decoded['data']['url'];
|
107 |
-
}
|
108 |
} else {
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
$shrink
|
|
|
|
|
113 |
}
|
114 |
break;
|
115 |
case 4:
|
116 |
if ( function_exists( 'wp_get_shortlink' ) ) {
|
117 |
// wp_get_shortlink doesn't natively support custom post types; but don't return an error in that case.
|
118 |
-
$shrink = ( false
|
119 |
}
|
120 |
if ( ! $shrink ) {
|
121 |
$shrink = $url;
|
@@ -144,41 +139,42 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
144 |
break;
|
145 |
case 6:
|
146 |
// remote YOURLS installation.
|
|
|
147 |
$yourlslogin = trim( get_option( 'yourlslogin' ) );
|
148 |
-
$
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
$
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
$api_url = add_query_arg( $args, $yourlsurl );
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
182 |
}
|
183 |
break;
|
184 |
case 7:
|
@@ -191,38 +187,40 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
191 |
break;
|
192 |
case 10:
|
193 |
// jotURL, added: 2013-04-10.
|
194 |
-
$joturlapi
|
195 |
-
$joturllogin
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
if (
|
200 |
-
$
|
201 |
-
} else {
|
202 |
-
$ct = '&';
|
203 |
-
}
|
204 |
-
$url .= $ct . $joturl_longurl_params;
|
205 |
-
$encoded = urlencode( urldecode( trim( $url ) ) ); // prevent double-encoding.
|
206 |
-
}
|
207 |
-
$domain = ( $domain ) ? '&domain=' . $domain : '';
|
208 |
-
$decoded = wpt_fetch_url( 'https://api.joturl.com/a/v1/shorten?url=' . $encoded . '&login=' . $joturllogin . '&key=' . $joturlapi . '&format=plain' . $domain );
|
209 |
-
if ( false !== $decoded ) {
|
210 |
-
$shrink = $decoded;
|
211 |
-
$joturl_shorturl_params = trim( get_option( 'joturl_shorturl_params' ) );
|
212 |
-
if ( '' != $joturl_shorturl_params ) {
|
213 |
-
if ( false === strpos( $shrink, '%3F' ) && false === strpos( $shrink, '?' ) ) {
|
214 |
$ct = '?';
|
215 |
} else {
|
216 |
$ct = '&';
|
217 |
}
|
218 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
}
|
220 |
-
} else {
|
221 |
-
$error = $decoded;
|
222 |
-
$shrink = false;
|
223 |
-
}
|
224 |
-
if ( ! wpt_is_valid_url( $shrink ) ) {
|
225 |
-
$shrink = false;
|
226 |
}
|
227 |
break;
|
228 |
default:
|
@@ -258,7 +256,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
258 |
$store_urls = apply_filters( 'wpt_store_urls', true, $post_ID, $url );
|
259 |
if ( function_exists( 'wpt_shorten_url' ) && $store_urls ) {
|
260 |
$shortener = get_option( 'jd_shortener' );
|
261 |
-
if ( wpt_short_url( $post_ID )
|
262 |
update_post_meta( $post_ID, '_wpt_short_url', $url );
|
263 |
}
|
264 |
switch ( $shortener ) {
|
@@ -284,14 +282,14 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
284 |
* @return long url.
|
285 |
*/
|
286 |
function wpt_expand_yourl( $short_url, $remote ) {
|
287 |
-
if ( 6
|
288 |
$short_url = urlencode( $short_url );
|
289 |
$yourl_api = get_option( 'yourlsurl' );
|
290 |
$user = get_option( 'yourlslogin' );
|
291 |
$pass = stripslashes( get_option( 'yourlsapi' ) );
|
292 |
$token = get_option( 'yourlstoken' );
|
293 |
if ( $token ) {
|
294 |
-
$decoded = wpt_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&signature=$token
|
295 |
} else {
|
296 |
$decoded = wpt_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&username=$user&password=$pass" );
|
297 |
}
|
@@ -344,30 +342,17 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
344 |
|
345 |
<div class="inside">
|
346 |
<?php
|
347 |
-
if ( 7
|
348 |
echo '<p>' . __( 'The Su.pr URL shortener was shut down when Stumbleupon closed doors in June 2018.', 'wp-to-twitter' ) . '</p>';
|
349 |
-
} elseif ( 2
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
<
|
354 |
-
|
355 |
-
|
356 |
-
<p>
|
357 |
-
<label for="bitlyapi"><?php _e( "Your Bit.ly <abbr title='application programming interface'>API</abbr> Key:", 'wp-to-twitter' ); ?></label>
|
358 |
-
<input type="text" name="bitlyapi" id="bitlyapi" size="40" value="<?php echo esc_attr( get_option( 'bitlyapi' ) ); ?>"/>
|
359 |
-
</p>
|
360 |
-
<p>
|
361 |
-
<a href="http://bitly.com/a/your_api_key"><?php _e( 'View your Bit.ly username and API key', 'wp-to-twitter' ); ?></a>
|
362 |
-
</p>
|
363 |
-
<div>
|
364 |
-
<input type="hidden" name="submit-type" value="bitlyapi"/>
|
365 |
-
</div>
|
366 |
-
<?php
|
367 |
-
echo $form_end;
|
368 |
-
} elseif ( 5 == $shortener || 6 == $shortener ) {
|
369 |
echo $form_start;
|
370 |
-
if ( 5
|
371 |
?>
|
372 |
<p>
|
373 |
<label for="yourlspath"><?php _e( 'Path to your YOURLS config file', 'wp-to-twitter' ); ?></label><br/>
|
@@ -377,7 +362,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
377 |
</p>
|
378 |
<?php
|
379 |
}
|
380 |
-
if ( 6
|
381 |
?>
|
382 |
<p>
|
383 |
<label for="yourlsurl"><?php _e( 'URI to the YOURLS API', 'wp-to-twitter' ); ?></label><br/>
|
@@ -414,9 +399,9 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
414 |
</div>
|
415 |
<?php
|
416 |
echo $form_end;
|
417 |
-
} elseif ( 8
|
418 |
echo '<p>' . __( 'The Goo.gl URL shortener was shut down by Google in March 2019.', 'wp-to-twitter' ) . '</p>';
|
419 |
-
} elseif ( 10
|
420 |
echo $form_start;
|
421 |
?>
|
422 |
<p>
|
@@ -428,7 +413,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
428 |
<input type="text" name="joturlapi" id="joturlapi" size="40" value="<?php echo esc_attr( get_option( 'joturlapi' ) ); ?>"/>
|
429 |
</p>
|
430 |
<p>
|
431 |
-
<label for="joturl_domain"><?php _e(
|
432 |
<input type="text" name="joturl_domain" id="joturl_domain" size="40" value="<?php echo esc_attr( get_option( 'joturl_domain' ) ); ?>"/>
|
433 |
</p>
|
434 |
<p>
|
@@ -448,7 +433,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
448 |
echo $form_end;
|
449 |
} else {
|
450 |
$form = apply_filters( 'wpt_shortener_settings', '', $shortener );
|
451 |
-
if ( ''
|
452 |
echo $form_start . $form . $form_end;
|
453 |
} else {
|
454 |
_e( 'Your shortener does not require any account settings.', 'wp-to-twitter' );
|
@@ -470,7 +455,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
470 |
$message = '';
|
471 |
if ( isset( $post['submit-type'] ) && 'yourlsapi' === $post['submit-type'] ) {
|
472 |
$message = '';
|
473 |
-
if ( ''
|
474 |
update_option( 'yourlstoken', trim( $post['yourlstoken'] ) );
|
475 |
delete_option( 'yourlsapi' );
|
476 |
delete_option( 'yourlslogin' );
|
@@ -478,7 +463,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
478 |
}
|
479 |
update_option( 'yourlsurl', trim( $post['yourlsurl'] ) );
|
480 |
// yourls path is deprecated.
|
481 |
-
if ( isset( $post['yourlspath'] ) && ''
|
482 |
update_option( 'yourlspath', trim( $post['yourlspath'] ) );
|
483 |
if ( file_exists( $post['yourlspath'] ) ) {
|
484 |
$message .= ' ' . __( 'YOURLS local server path added. ', 'wp-to-twitter' );
|
@@ -486,11 +471,11 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
486 |
$message .= ' ' . __( 'The path to your YOURLS installation is not correct. ', 'wp-to-twitter' );
|
487 |
}
|
488 |
}
|
489 |
-
if ( ''
|
490 |
update_option( 'jd_keyword_format', $post['jd_keyword_format'] );
|
491 |
-
if ( 1
|
492 |
$message .= ' ' . __( 'YOURLS will use Post ID for short URL slug.', 'wp-to-twitter' );
|
493 |
-
} elseif ( 0
|
494 |
$message .= ' ' . __( 'YOURLS will use default URL structures.', 'wp-to-twitter' );
|
495 |
} else {
|
496 |
$message .= ' ' . __( 'YOURLS will use your custom keyword for short URL slug.', 'wp-to-twitter' );
|
@@ -507,29 +492,8 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
507 |
}
|
508 |
}
|
509 |
|
510 |
-
if ( isset( $post['submit-type'] ) && 'bitlyapi' === $post['submit-type'] ) {
|
511 |
-
if ( '' != $post['bitlyapi'] && isset( $post['submit'] ) ) {
|
512 |
-
update_option( 'bitlyapi', trim( $post['bitlyapi'] ) );
|
513 |
-
$message = __( 'Bit.ly API Key Updated.', 'wp-to-twitter' );
|
514 |
-
} elseif ( isset( $post['clear'] ) ) {
|
515 |
-
update_option( 'bitlyapi', '' );
|
516 |
-
$message = __( 'Bit.ly API Key deleted. You cannot use the Bit.ly API without an API key.', 'wp-to-twitter' );
|
517 |
-
} else {
|
518 |
-
$message = __( "Bit.ly API Key not added - <a href='http://bit.ly/account/'>get one here</a>! An API key is required to use the Bit.ly URL shortening service.", 'wp-to-twitter' );
|
519 |
-
}
|
520 |
-
if ( '' != $post['bitlylogin'] && isset( $post['submit'] ) ) {
|
521 |
-
update_option( 'bitlylogin', trim( $post['bitlylogin'] ) );
|
522 |
-
$message .= __( 'Bit.ly User Login Updated.', 'wp-to-twitter' );
|
523 |
-
} elseif ( isset( $post['clear'] ) ) {
|
524 |
-
update_option( 'bitlylogin', '' );
|
525 |
-
$message = __( 'Bit.ly User Login deleted. You cannot use the Bit.ly API without providing your username.', 'wp-to-twitter' );
|
526 |
-
} else {
|
527 |
-
$message = __( "Bit.ly Login not added - <a href='http://bit.ly/account/'>get one here</a>!", 'wp-to-twitter' );
|
528 |
-
}
|
529 |
-
}
|
530 |
-
|
531 |
if ( isset( $post['submit-type'] ) && 'joturlapi' === $post['submit-type'] ) {
|
532 |
-
if ( ''
|
533 |
update_option( 'joturlapi', trim( $post['joturlapi'] ) );
|
534 |
$message = __( 'jotURL private API Key Updated.', 'wp-to-twitter' );
|
535 |
} elseif ( isset( $post['clear'] ) ) {
|
@@ -538,7 +502,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
538 |
} else {
|
539 |
$message = __( "jotURL private API Key not added - <a href='https://www.joturl.com/reserved/api.html'>get one here</a>! A private API key is required to use the jotURL URL shortening service. ", 'wp-to-twitter' );
|
540 |
}
|
541 |
-
if ( ''
|
542 |
update_option( 'joturllogin', trim( $post['joturllogin'] ) );
|
543 |
$message .= __( 'jotURL public API Key Updated.', 'wp-to-twitter' );
|
544 |
} elseif ( isset( $post['clear'] ) ) {
|
@@ -547,9 +511,9 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
547 |
} else {
|
548 |
$message = __( "jotURL public API Key not added - <a href='https://www.joturl.com/reserved/settings.html#tools-api'>get one here</a>! ", 'wp-to-twitter' );
|
549 |
}
|
550 |
-
if ( ''
|
551 |
$v = trim( $post['joturl_longurl_params'] );
|
552 |
-
if ( substr( $v, 0, 1 )
|
553 |
$v = substr( $v, 1 );
|
554 |
}
|
555 |
update_option( 'joturl_longurl_params', $v );
|
@@ -558,16 +522,16 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
558 |
update_option( 'joturl_longurl_params', '' );
|
559 |
$message = __( 'Long URL parameters deleted.', 'wp-to-twitter' );
|
560 |
}
|
561 |
-
if ( ''
|
562 |
update_option( 'joturl_domain', $post['joturl_domain'] );
|
563 |
$message .= __( 'Custom jotURL domain saved.', 'wp-to-twitter' );
|
564 |
} elseif ( isset( $post['clear'] ) ) {
|
565 |
update_option( 'joturl_domain', '' );
|
566 |
$message = __( 'Custom jotURL domain deleted.', 'wp-to-twitter' );
|
567 |
}
|
568 |
-
if ( ''
|
569 |
$v = trim( $post['joturl_shorturl_params'] );
|
570 |
-
if ( substr( $v, 0, 1 )
|
571 |
$v = substr( $v, 1 );
|
572 |
}
|
573 |
update_option( 'joturl_shorturl_params', $v );
|
@@ -621,8 +585,8 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
621 |
*/
|
622 |
function wpt_pick_shortener() {
|
623 |
$shortener = (string) get_option( 'jd_shortener' );
|
624 |
-
if ( '2' === $shortener ) {
|
625 |
-
echo '<p>' . __( '
|
626 |
}
|
627 |
?>
|
628 |
<p>
|
@@ -630,12 +594,8 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
630 |
<select name="jd_shortener" id="jd_shortener">
|
631 |
<option value="3" <?php selected( $shortener, '3' ); ?>><?php _e( "Don't shorten URLs.", 'wp-to-twitter' ); ?></option>
|
632 |
<option value="4" <?php selected( $shortener, '4' ); ?>>WordPress</option>
|
633 |
-
<?php
|
634 |
-
if ( '2' === $shortener ) { // If Bit.ly is currently enabled, leave available.
|
635 |
-
?>
|
636 |
<option value="2" <?php selected( $shortener, '2' ); ?>>Bit.ly</option>
|
637 |
-
|
638 |
-
}
|
639 |
if ( '5' === $shortener ) { // if the user has already selected local server, leave available.
|
640 |
?>
|
641 |
<option value="5" <?php selected( $shortener, '5' ); ?>><?php _e( 'YOURLS (this server)', 'wp-to-twitter' ); ?></option>
|
29 |
* @return shortened URL.
|
30 |
*/
|
31 |
function wpt_shorten_url( $url, $post_title, $post_ID, $testmode = false, $store_urls = true ) {
|
32 |
+
wpt_mail( 'Shortener running: initial link', "Url: $url, Title: $post_title, Post ID: $post_ID, Test mode: $testmode", $post_ID ); // DEBUG.
|
33 |
// filter link before sending to shortener or adding analytics.
|
34 |
$shortener = get_option( 'jd_shortener' );
|
35 |
// if the URL already exists, return it without processing.
|
39 |
return $shrink;
|
40 |
}
|
41 |
$url = apply_filters( 'wpt_shorten_link', $url, $shortener, $post_ID );
|
42 |
+
if ( false === $testmode ) {
|
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 );
|
82 |
}
|
83 |
|
84 |
// custom word setting.
|
85 |
+
$keyword_format = ( '1' === get_option( 'jd_keyword_format' ) ) ? $post_ID : '';
|
86 |
+
$keyword_format = ( '2' === get_option( 'jd_keyword_format' ) ) ? get_post_meta( $post_ID, '_yourls_keyword', true ) : $keyword_format;
|
87 |
// Generate and grab the short url.
|
88 |
$shrink = apply_filters( 'wpt_do_shortening', false, $shortener, $url, $post_title, $post_ID, $testmode );
|
89 |
// if an add-on has shortened the link, skip shortening.
|
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 |
+
$bitlyurl = get_post_meta( $post_ID, '_wbitly_shorturl', true );
|
99 |
+
if ( ! empty( $bitlyurl ) ) {
|
100 |
+
$shrink = $bitlyurl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
} else {
|
102 |
+
if ( function_exists( 'wbitly_generate_shorten_url' ) ) {
|
103 |
+
$shrink = wbitly_generate_shorten_url( $url );
|
104 |
+
}
|
105 |
+
if ( function_exists( 'wbitly_shorten_url' ) && ! $shrink ) {
|
106 |
+
$shrink = wbitly_shorten_url( $url );
|
107 |
+
}
|
108 |
}
|
109 |
break;
|
110 |
case 4:
|
111 |
if ( function_exists( 'wp_get_shortlink' ) ) {
|
112 |
// wp_get_shortlink doesn't natively support custom post types; but don't return an error in that case.
|
113 |
+
$shrink = ( false !== $post_ID ) ? wp_get_shortlink( $post_ID, 'post' ) : $url;
|
114 |
}
|
115 |
if ( ! $shrink ) {
|
116 |
$shrink = $url;
|
139 |
break;
|
140 |
case 6:
|
141 |
// remote YOURLS installation.
|
142 |
+
$yourlstoken = trim( get_option( 'yourlstoken' ) );
|
143 |
$yourlslogin = trim( get_option( 'yourlslogin' ) );
|
144 |
+
$yourlsurl = stripcslashes( get_option( 'yourlsurl' ) );
|
145 |
+
if ( $yourlstoken && $yourlsurl ) {
|
146 |
+
$token = stripcslashes( $yourlstoken );
|
147 |
+
$yourlsurl = esc_url( $yourlsurl );
|
148 |
+
if ( $token ) {
|
149 |
+
$args = array(
|
150 |
+
'signature' => $token,
|
151 |
+
'url' => $encoded,
|
152 |
+
'action' => 'shorturl',
|
153 |
+
'format' => 'json',
|
154 |
+
'title' => urlencode( $post_title ),
|
155 |
+
);
|
156 |
+
} else {
|
157 |
+
$args = array(
|
158 |
+
'username' => $yourlslogin,
|
159 |
+
'password' => $yourlsurl,
|
160 |
+
'url' => $encoded,
|
161 |
+
'action' => 'shorturl',
|
162 |
+
'format' => 'json',
|
163 |
+
'title' => urlencode( $post_title ),
|
164 |
+
);
|
165 |
+
}
|
166 |
+
if ( $keyword_format ) {
|
167 |
+
$args['keyword'] = $keyword_format;
|
168 |
+
}
|
|
|
169 |
|
170 |
+
$api_url = add_query_arg( $args, $yourlsurl );
|
171 |
+
$json = wpt_remote_json( $api_url, false );
|
172 |
+
if ( is_object( $json ) ) {
|
173 |
+
$shrink = $json->shorturl;
|
174 |
+
} else {
|
175 |
+
$error = 'Error code: YOURLS response is not an object';
|
176 |
+
$shrink = false;
|
177 |
+
}
|
178 |
}
|
179 |
break;
|
180 |
case 7:
|
187 |
break;
|
188 |
case 10:
|
189 |
// jotURL, added: 2013-04-10.
|
190 |
+
$joturlapi = trim( get_option( 'joturlapi' ) );
|
191 |
+
$joturllogin = trim( get_option( 'joturllogin' ) );
|
192 |
+
if ( ! empty( $joturlapi ) && ! empty( $joturllogin ) ) {
|
193 |
+
$joturl_longurl_params = trim( get_option( 'joturl_longurl_params' ) );
|
194 |
+
$domain = trim( get_option( 'joturl_domain', false ) );
|
195 |
+
if ( '' !== $joturl_longurl_params ) {
|
196 |
+
if ( false === strpos( $url, '%3F' ) && false === strpos( $url, '?' ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
$ct = '?';
|
198 |
} else {
|
199 |
$ct = '&';
|
200 |
}
|
201 |
+
$url .= $ct . $joturl_longurl_params;
|
202 |
+
$encoded = urlencode( urldecode( trim( $url ) ) ); // prevent double-encoding.
|
203 |
+
}
|
204 |
+
$domain = ( $domain ) ? '&domain=' . $domain : '';
|
205 |
+
$decoded = wpt_fetch_url( 'https://api.joturl.com/a/v1/shorten?url=' . $encoded . '&login=' . $joturllogin . '&key=' . $joturlapi . '&format=plain' . $domain );
|
206 |
+
if ( false !== $decoded ) {
|
207 |
+
$shrink = $decoded;
|
208 |
+
$joturl_shorturl_params = trim( get_option( 'joturl_shorturl_params' ) );
|
209 |
+
if ( '' !== $joturl_shorturl_params ) {
|
210 |
+
if ( false === strpos( $shrink, '%3F' ) && false === strpos( $shrink, '?' ) ) {
|
211 |
+
$ct = '?';
|
212 |
+
} else {
|
213 |
+
$ct = '&';
|
214 |
+
}
|
215 |
+
$shrink .= $ct . $joturl_shorturl_params;
|
216 |
+
}
|
217 |
+
} else {
|
218 |
+
$error = $decoded;
|
219 |
+
$shrink = false;
|
220 |
+
}
|
221 |
+
if ( ! wpt_is_valid_url( $shrink ) ) {
|
222 |
+
$shrink = false;
|
223 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
}
|
225 |
break;
|
226 |
default:
|
256 |
$store_urls = apply_filters( 'wpt_store_urls', true, $post_ID, $url );
|
257 |
if ( function_exists( 'wpt_shorten_url' ) && $store_urls ) {
|
258 |
$shortener = get_option( 'jd_shortener' );
|
259 |
+
if ( wpt_short_url( $post_ID ) !== $url && wpt_is_valid_url( $url ) ) {
|
260 |
update_post_meta( $post_ID, '_wpt_short_url', $url );
|
261 |
}
|
262 |
switch ( $shortener ) {
|
282 |
* @return long url.
|
283 |
*/
|
284 |
function wpt_expand_yourl( $short_url, $remote ) {
|
285 |
+
if ( 6 === (int) $remote ) {
|
286 |
$short_url = urlencode( $short_url );
|
287 |
$yourl_api = get_option( 'yourlsurl' );
|
288 |
$user = get_option( 'yourlslogin' );
|
289 |
$pass = stripslashes( get_option( 'yourlsapi' ) );
|
290 |
$token = get_option( 'yourlstoken' );
|
291 |
if ( $token ) {
|
292 |
+
$decoded = wpt_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&signature=$token" );
|
293 |
} else {
|
294 |
$decoded = wpt_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&username=$user&password=$pass" );
|
295 |
}
|
342 |
|
343 |
<div class="inside">
|
344 |
<?php
|
345 |
+
if ( 7 === (int) $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 === (int) $shortener ) {
|
348 |
+
if ( function_exists( 'wbitly_shorten_url' ) ) {
|
349 |
+
echo '<p>' . __( 'WP to Twitter supports Bit.ly shortened links via <a href="https://wordpress.org/plugins/codehaveli-bitly-url-shortener/">Codehaveli Bitly URL Shortener</a>. If you are having issues with Bit.ly URLs, please request support from <a href="https://wordpress.org/support/plugin/codehaveli-bitly-url-shortener/">the plugin support forums</a>.', 'wp-to-twitter' ) . '</p>';
|
350 |
+
} else {
|
351 |
+
echo '<p>' . __( 'WP to Twitter supports Bit.ly shortened links via <a href="https://wordpress.org/plugins/codehaveli-bitly-url-shortener/">Codehaveli Bitly URL Shortener</a>. Install that plug-in to use Bit.ly', 'wp-to-twitter' ) . '</p>';
|
352 |
+
}
|
353 |
+
} elseif ( 5 === (int) $shortener || 6 === (int) $shortener ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
echo $form_start;
|
355 |
+
if ( 5 === (int) $shortener ) {
|
356 |
?>
|
357 |
<p>
|
358 |
<label for="yourlspath"><?php _e( 'Path to your YOURLS config file', 'wp-to-twitter' ); ?></label><br/>
|
362 |
</p>
|
363 |
<?php
|
364 |
}
|
365 |
+
if ( 6 === (int) $shortener ) {
|
366 |
?>
|
367 |
<p>
|
368 |
<label for="yourlsurl"><?php _e( 'URI to the YOURLS API', 'wp-to-twitter' ); ?></label><br/>
|
399 |
</div>
|
400 |
<?php
|
401 |
echo $form_end;
|
402 |
+
} elseif ( 8 === (int) $shortener ) {
|
403 |
echo '<p>' . __( 'The Goo.gl URL shortener was shut down by Google in March 2019.', 'wp-to-twitter' ) . '</p>';
|
404 |
+
} elseif ( 10 === (int) $shortener ) {
|
405 |
echo $form_start;
|
406 |
?>
|
407 |
<p>
|
413 |
<input type="text" name="joturlapi" id="joturlapi" size="40" value="<?php echo esc_attr( get_option( 'joturlapi' ) ); ?>"/>
|
414 |
</p>
|
415 |
<p>
|
416 |
+
<label for="joturl_domain"><?php _e( 'Your jotURL custom domain:', 'wp-to-twitter' ); ?></label>
|
417 |
<input type="text" name="joturl_domain" id="joturl_domain" size="40" value="<?php echo esc_attr( get_option( 'joturl_domain' ) ); ?>"/>
|
418 |
</p>
|
419 |
<p>
|
433 |
echo $form_end;
|
434 |
} else {
|
435 |
$form = apply_filters( 'wpt_shortener_settings', '', $shortener );
|
436 |
+
if ( '' !== $form ) {
|
437 |
echo $form_start . $form . $form_end;
|
438 |
} else {
|
439 |
_e( 'Your shortener does not require any account settings.', 'wp-to-twitter' );
|
455 |
$message = '';
|
456 |
if ( isset( $post['submit-type'] ) && 'yourlsapi' === $post['submit-type'] ) {
|
457 |
$message = '';
|
458 |
+
if ( '' !== $post['yourlstoken'] && isset( $post['submit'] ) ) {
|
459 |
update_option( 'yourlstoken', trim( $post['yourlstoken'] ) );
|
460 |
delete_option( 'yourlsapi' );
|
461 |
delete_option( 'yourlslogin' );
|
463 |
}
|
464 |
update_option( 'yourlsurl', trim( $post['yourlsurl'] ) );
|
465 |
// yourls path is deprecated.
|
466 |
+
if ( isset( $post['yourlspath'] ) && '' !== $post['yourlspath'] ) {
|
467 |
update_option( 'yourlspath', trim( $post['yourlspath'] ) );
|
468 |
if ( file_exists( $post['yourlspath'] ) ) {
|
469 |
$message .= ' ' . __( 'YOURLS local server path added. ', 'wp-to-twitter' );
|
471 |
$message .= ' ' . __( 'The path to your YOURLS installation is not correct. ', 'wp-to-twitter' );
|
472 |
}
|
473 |
}
|
474 |
+
if ( '' !== $post['jd_keyword_format'] ) {
|
475 |
update_option( 'jd_keyword_format', $post['jd_keyword_format'] );
|
476 |
+
if ( '1' === $post['jd_keyword_format'] ) {
|
477 |
$message .= ' ' . __( 'YOURLS will use Post ID for short URL slug.', 'wp-to-twitter' );
|
478 |
+
} elseif ( '0' === $post['jd_keyword_format'] ) {
|
479 |
$message .= ' ' . __( 'YOURLS will use default URL structures.', 'wp-to-twitter' );
|
480 |
} else {
|
481 |
$message .= ' ' . __( 'YOURLS will use your custom keyword for short URL slug.', 'wp-to-twitter' );
|
492 |
}
|
493 |
}
|
494 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
495 |
if ( isset( $post['submit-type'] ) && 'joturlapi' === $post['submit-type'] ) {
|
496 |
+
if ( '' !== $post['joturlapi'] && isset( $post['submit'] ) ) {
|
497 |
update_option( 'joturlapi', trim( $post['joturlapi'] ) );
|
498 |
$message = __( 'jotURL private API Key Updated.', 'wp-to-twitter' );
|
499 |
} elseif ( isset( $post['clear'] ) ) {
|
502 |
} else {
|
503 |
$message = __( "jotURL private API Key not added - <a href='https://www.joturl.com/reserved/api.html'>get one here</a>! A private API key is required to use the jotURL URL shortening service. ", 'wp-to-twitter' );
|
504 |
}
|
505 |
+
if ( '' !== $post['joturllogin'] && isset( $post['submit'] ) ) {
|
506 |
update_option( 'joturllogin', trim( $post['joturllogin'] ) );
|
507 |
$message .= __( 'jotURL public API Key Updated.', 'wp-to-twitter' );
|
508 |
} elseif ( isset( $post['clear'] ) ) {
|
511 |
} else {
|
512 |
$message = __( "jotURL public API Key not added - <a href='https://www.joturl.com/reserved/settings.html#tools-api'>get one here</a>! ", 'wp-to-twitter' );
|
513 |
}
|
514 |
+
if ( '' !== $post['joturl_longurl_params'] && isset( $post['submit'] ) ) {
|
515 |
$v = trim( $post['joturl_longurl_params'] );
|
516 |
+
if ( substr( $v, 0, 1 ) === '&' || substr( $v, 0, 1 ) === '?' ) {
|
517 |
$v = substr( $v, 1 );
|
518 |
}
|
519 |
update_option( 'joturl_longurl_params', $v );
|
522 |
update_option( 'joturl_longurl_params', '' );
|
523 |
$message = __( 'Long URL parameters deleted.', 'wp-to-twitter' );
|
524 |
}
|
525 |
+
if ( '' !== $post['joturl_domain'] && isset( $post['submit'] ) ) {
|
526 |
update_option( 'joturl_domain', $post['joturl_domain'] );
|
527 |
$message .= __( 'Custom jotURL domain saved.', 'wp-to-twitter' );
|
528 |
} elseif ( isset( $post['clear'] ) ) {
|
529 |
update_option( 'joturl_domain', '' );
|
530 |
$message = __( 'Custom jotURL domain deleted.', 'wp-to-twitter' );
|
531 |
}
|
532 |
+
if ( '' !== $post['joturl_shorturl_params'] && isset( $post['submit'] ) ) {
|
533 |
$v = trim( $post['joturl_shorturl_params'] );
|
534 |
+
if ( substr( $v, 0, 1 ) === '&' || substr( $v, 0, 1 ) === '?' ) {
|
535 |
$v = substr( $v, 1 );
|
536 |
}
|
537 |
update_option( 'joturl_shorturl_params', $v );
|
585 |
*/
|
586 |
function wpt_pick_shortener() {
|
587 |
$shortener = (string) get_option( 'jd_shortener' );
|
588 |
+
if ( '2' === $shortener && ! function_exists( 'wbitly_shorten_url' ) ) {
|
589 |
+
echo '<p>' . __( 'Bit.ly support is provided via the <a href="https://wordpress.org/plugins/codehaveli-bitly-url-shortener/">Codehaveli Bitly URL Shortener</a> plug-in, available from WordPress.org', 'wp-to-twitter' ) . '</p>';
|
590 |
}
|
591 |
?>
|
592 |
<p>
|
594 |
<select name="jd_shortener" id="jd_shortener">
|
595 |
<option value="3" <?php selected( $shortener, '3' ); ?>><?php _e( "Don't shorten URLs.", 'wp-to-twitter' ); ?></option>
|
596 |
<option value="4" <?php selected( $shortener, '4' ); ?>>WordPress</option>
|
|
|
|
|
|
|
597 |
<option value="2" <?php selected( $shortener, '2' ); ?>>Bit.ly</option>
|
598 |
+
<?php
|
|
|
599 |
if ( '5' === $shortener ) { // if the user has already selected local server, leave available.
|
600 |
?>
|
601 |
<option value="5" <?php selected( $shortener, '5' ); ?>><?php _e( 'YOURLS (this server)', 'wp-to-twitter' ); ?></option>
|
wp-to-twitter-users.php
CHANGED
@@ -9,7 +9,7 @@
|
|
9 |
* @link https://www.joedolson.com/wp-to-twitter/
|
10 |
*/
|
11 |
|
12 |
-
if ( '1'
|
13 |
add_action( 'show_user_profile', 'wpt_twitter_profile' );
|
14 |
add_action( 'edit_user_profile', 'wpt_twitter_profile' );
|
15 |
add_action( 'profile_update', 'wpt_twitter_save_profile' );
|
@@ -30,7 +30,7 @@ function wpt_twitter_profile() {
|
|
30 |
$is_enabled = get_user_meta( $user_edit, 'wp-to-twitter-enable-user', true );
|
31 |
$twitter_username = get_user_meta( $user_edit, 'wp-to-twitter-user-username', true );
|
32 |
$wpt_remove = get_user_meta( $user_edit, 'wpt-remove', true );
|
33 |
-
if ( $current_user->ID
|
34 |
?>
|
35 |
<h3><?php _e( 'WP Tweets User Settings', 'wp-to-twitter' ); ?></h3>
|
36 |
<?php
|
9 |
* @link https://www.joedolson.com/wp-to-twitter/
|
10 |
*/
|
11 |
|
12 |
+
if ( '1' === get_option( 'jd_individual_twitter_users' ) ) {
|
13 |
add_action( 'show_user_profile', 'wpt_twitter_profile' );
|
14 |
add_action( 'edit_user_profile', 'wpt_twitter_profile' );
|
15 |
add_action( 'profile_update', 'wpt_twitter_save_profile' );
|
30 |
$is_enabled = get_user_meta( $user_edit, 'wp-to-twitter-enable-user', true );
|
31 |
$twitter_username = get_user_meta( $user_edit, 'wp-to-twitter-user-username', true );
|
32 |
$wpt_remove = get_user_meta( $user_edit, 'wpt-remove', true );
|
33 |
+
if ( $current_user->ID === $user_ID || current_user_can( 'manage_options' ) ) {
|
34 |
?>
|
35 |
<h3><?php _e( 'WP Tweets User Settings', 'wp-to-twitter' ); ?></h3>
|
36 |
<?php
|
wp-to-twitter.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
*
|
5 |
* @package WP to Twitter
|
6 |
* @author Joe Dolson
|
7 |
-
* @copyright 2008-
|
8 |
* @license GPL-2.0+
|
9 |
*
|
10 |
* @wordpress-plugin
|
@@ -17,11 +17,11 @@
|
|
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.
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
-
Copyright 2008-
|
25 |
|
26 |
This program is free software; you can redistribute it and/or modify
|
27 |
it under the terms of the GNU General Public License as published by
|
@@ -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.
|
61 |
|
62 |
add_action( 'init', 'wpt_load_textdomain' );
|
63 |
/**
|
@@ -113,15 +113,15 @@ function wptotwitter_activate() {
|
|
113 |
if ( $new_install ) {
|
114 |
$initial_settings = array(
|
115 |
'post' => array(
|
116 |
-
'post-published-update' => 1,
|
117 |
'post-published-text' => 'New post: #title# #url#',
|
118 |
-
'post-edited-update' => 0,
|
119 |
'post-edited-text' => 'Post Edited: #title# #url#',
|
120 |
),
|
121 |
'page' => array(
|
122 |
-
'post-published-update' => 0,
|
123 |
'post-published-text' => 'New page: #title# #url#',
|
124 |
-
'post-edited-update' => 0,
|
125 |
'post-edited-text' => 'Page edited: #title# #url#',
|
126 |
),
|
127 |
);
|
@@ -182,6 +182,11 @@ function wptotwitter_activate() {
|
|
182 |
if ( $upgrade ) {
|
183 |
$administrator->add_cap( 'wpt_tweet_now' );
|
184 |
}
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
update_option( 'wp_to_twitter_version', $wpt_version );
|
187 |
}
|
@@ -284,18 +289,33 @@ function wpt_check_recent_tweet( $id, $auth ) {
|
|
284 |
* @return boolean Success of query.
|
285 |
*/
|
286 |
function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false ) {
|
287 |
-
$
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 ) {
|
|
|
|
|
293 |
return false;
|
294 |
}
|
295 |
}
|
296 |
|
297 |
-
$
|
298 |
if ( $recent ) {
|
|
|
|
|
299 |
return false;
|
300 |
}
|
301 |
|
@@ -303,6 +323,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
|
|
303 |
$error = __( 'This account is not authorized to post to Twitter.', 'wp-to-twitter' );
|
304 |
wpt_saves_error( $id, $auth, $twit, $error, '401', time() );
|
305 |
wpt_set_log( 'wpt_status_message', $id, $error );
|
|
|
306 |
|
307 |
return false;
|
308 |
} // exit silently if not authorized.
|
@@ -536,28 +557,6 @@ function wpt_is_ssl( $url ) {
|
|
536 |
}
|
537 |
}
|
538 |
|
539 |
-
/**
|
540 |
-
* Deprecated; still used if configured.
|
541 |
-
* Uses old option 'tweet_categories' and verifies whether category of current post allows it to be Tweeted.
|
542 |
-
*
|
543 |
-
* @param array $array Array of categories for post.
|
544 |
-
*
|
545 |
-
* @return boolean.
|
546 |
-
*/
|
547 |
-
function wpt_in_allowed_category( $array ) {
|
548 |
-
$allowed_categories = get_option( 'tweet_categories' );
|
549 |
-
if ( is_array( $array ) && is_array( $allowed_categories ) ) {
|
550 |
-
$common = array_intersect( $array, $allowed_categories );
|
551 |
-
if ( count( $common ) >= 1 ) {
|
552 |
-
return true;
|
553 |
-
} else {
|
554 |
-
return false;
|
555 |
-
}
|
556 |
-
} else {
|
557 |
-
return true;
|
558 |
-
}
|
559 |
-
}
|
560 |
-
|
561 |
/**
|
562 |
* Builds array of post info for use in Tweet functions.
|
563 |
*
|
@@ -698,22 +697,9 @@ function wpt_post_with_media( $post_ID, $post_info = array() ) {
|
|
698 |
* @param string $post_type Type of post.
|
699 |
* @param array $post_info Post info.
|
700 |
* @param int $post_ID Post ID.
|
701 |
-
*
|
702 |
-
* @deprecated
|
703 |
*/
|
704 |
function wpt_category_limit( $post_type, $post_info, $post_ID ) {
|
705 |
-
$
|
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,
|
@@ -754,11 +740,13 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
754 |
}
|
755 |
}
|
756 |
if ( '0' === get_option( 'jd_tweet_default' ) ) {
|
757 |
-
$default
|
|
|
758 |
} else {
|
759 |
-
$default
|
|
|
760 |
}
|
761 |
-
wpt_mail( '1: Tweet
|
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 );
|
@@ -767,11 +755,14 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
767 |
} else {
|
768 |
$auth = $post_info['authId'];
|
769 |
}
|
770 |
-
|
|
|
|
|
|
|
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
|
775 |
|
776 |
return false;
|
777 |
}
|
@@ -784,7 +775,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
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:
|
788 |
delete_post_meta( $post_ID, 'wpt_publishing' );
|
789 |
} else {
|
790 |
// if the post modified date and the post date are the same, this is new.
|
@@ -803,7 +794,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
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
|
807 |
return false;
|
808 |
}
|
809 |
// create Tweet and ID whether current action is edit or new.
|
@@ -821,14 +812,14 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
821 |
return false;
|
822 |
}
|
823 |
}
|
824 |
-
wpt_mail( '4b:
|
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:
|
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 |
}
|
@@ -836,7 +827,7 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
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
|
840 |
if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
|
841 |
$sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth );
|
842 |
}
|
@@ -890,9 +881,9 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
890 |
'timestamp' => time() + $time + $offset,
|
891 |
'current_time' => time(),
|
892 |
'timezone' => get_option( 'gmt_offset' ),
|
893 |
-
'timestring' =>
|
894 |
-
'current_ts' =>
|
895 |
-
'users'
|
896 |
),
|
897 |
1
|
898 |
),
|
@@ -947,8 +938,8 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
947 |
'sentence' => array( $retweet, $i, $post_ID ),
|
948 |
'timestamp' => time() + $time + $offset + $delay,
|
949 |
'time' => array( $time, $offset, $delay, get_option( 'gmt_offset' ), time() ),
|
950 |
-
'timestring' =>
|
951 |
-
'current_ts' =>
|
952 |
),
|
953 |
1
|
954 |
),
|
@@ -970,12 +961,6 @@ function wpt_tweet( $post_ID, $type = 'instant' ) {
|
|
970 |
}
|
971 |
// END WPT PRO.
|
972 |
}
|
973 |
-
} else {
|
974 |
-
if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
|
975 |
-
wpt_mail( '3c: Not a Tweeted post type', 'Post_Info: ' . print_r( $post_info, 1 ) . " / $type", $post_ID );
|
976 |
-
}
|
977 |
-
|
978 |
-
return $post_ID;
|
979 |
}
|
980 |
}
|
981 |
|
@@ -1083,6 +1068,9 @@ function wpt_generate_hash_tags( $post_ID ) {
|
|
1083 |
case 4:
|
1084 |
$newtag = $tag;
|
1085 |
break;
|
|
|
|
|
|
|
1086 |
default:
|
1087 |
$newtag = apply_filters( 'wpt_tag_default', '#', $t_id ) . $tag;
|
1088 |
}
|
@@ -1110,7 +1098,7 @@ function wpt_add_twitter_outer_box() {
|
|
1110 |
$wpt_post_types = get_option( 'wpt_post_types' );
|
1111 |
if ( is_array( $wpt_post_types ) ) {
|
1112 |
foreach ( $wpt_post_types as $key => $value ) {
|
1113 |
-
if ( '1' === $value['post-published-update'] || '1' === $value['post-edited-update'] ) {
|
1114 |
add_meta_box( 'wp2t', 'WP to Twitter', 'wpt_add_twitter_inner_box', $key, 'side' );
|
1115 |
}
|
1116 |
}
|
@@ -1128,7 +1116,7 @@ function wpt_add_twitter_debug_box() {
|
|
1128 |
$wpt_post_types = get_option( 'wpt_post_types' );
|
1129 |
if ( is_array( $wpt_post_types ) ) {
|
1130 |
foreach ( $wpt_post_types as $key => $value ) {
|
1131 |
-
if ( '1' === $value['post-published-update'] || '1' === $value['post-edited-update'] ) {
|
1132 |
add_meta_box( 'wp2t-debug', 'WP to Twitter Debugging', 'wpt_show_debug', $key, 'advanced' );
|
1133 |
}
|
1134 |
}
|
@@ -1190,10 +1178,14 @@ function wpt_add_twitter_inner_box( $post ) {
|
|
1190 |
<span class="dashicons dashicons-clock" aria-hidden="true"></span><span class="screen-reader-text"><?php _e( 'Set Date/Time', 'wp-to-twitter' ); ?></span>
|
1191 |
</button>
|
1192 |
<div id="jts">
|
|
|
|
|
|
|
|
|
1193 |
<label for='wpt_date'><?php _e( 'Date', 'wp-to-twitter' ); ?></label>
|
1194 |
-
<input type='date' value='' class='wpt_date date' name='wpt_datetime' id='wpt_date' data-value='<?php echo
|
1195 |
<label for='wpt_time'><?php _e( 'Time', 'wp-to-twitter' ); ?></label>
|
1196 |
-
<input type='text' value='<?php echo
|
1197 |
</div>
|
1198 |
<?php
|
1199 |
}
|
@@ -1467,8 +1459,8 @@ function wpt_ajax_tweet() {
|
|
1467 |
die;
|
1468 |
}
|
1469 |
$action = ( 'tweet' === $_REQUEST['tweet_action'] ) ? 'tweet' : 'schedule';
|
1470 |
-
$authors = ( isset( $_REQUEST['tweet_auth'] ) && null
|
1471 |
-
$upload = ( isset( $_REQUEST['tweet_upload'] ) && null
|
1472 |
$current_user = wp_get_current_user();
|
1473 |
if ( function_exists( 'wpt_pro_exists' ) && wpt_pro_exists() ) {
|
1474 |
if ( wtt_oauth_test( $current_user->ID, 'verify' ) ) {
|
@@ -1619,7 +1611,7 @@ function wpt_save_post( $id ) {
|
|
1619 |
// WPT PRO.
|
1620 |
// only send debug data if post meta is updated.
|
1621 |
if ( true === $update || is_int( $update ) ) {
|
1622 |
-
wpt_mail( 'Post Meta Inserted',
|
1623 |
}
|
1624 |
if ( isset( $_POST['wpt-delete-debug'] ) && 'true' === $_POST['wpt-delete-debug'] ) {
|
1625 |
delete_post_meta( $id, '_wpt_debug_log' );
|
@@ -1720,6 +1712,9 @@ function wpt_in_post_type( $id ) {
|
|
1720 |
if ( in_array( $type, $post_types, true ) ) {
|
1721 |
return true;
|
1722 |
}
|
|
|
|
|
|
|
1723 |
|
1724 |
return false;
|
1725 |
}
|
@@ -1734,7 +1729,7 @@ function wpt_allowed_post_types() {
|
|
1734 |
$allowed_types = array();
|
1735 |
if ( is_array( $post_type_settings ) && ! empty( $post_type_settings ) ) {
|
1736 |
foreach ( $post_type_settings as $type => $settings ) {
|
1737 |
-
if ( '1'
|
1738 |
$allowed_types[] = $type;
|
1739 |
}
|
1740 |
}
|
@@ -1754,6 +1749,7 @@ function wpt_future_to_publish( $post ) {
|
|
1754 |
if ( wp_is_post_autosave( $id ) || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
|
1755 |
return;
|
1756 |
}
|
|
|
1757 |
wpt_twit_future( $id );
|
1758 |
}
|
1759 |
|
@@ -1773,6 +1769,7 @@ function wpt_twit( $id ) {
|
|
1773 |
// is there any reason to accept any other status?
|
1774 |
// This is an issue only until the release of WP 4.7.
|
1775 |
remove_action( 'save_post', 'wpt_twit', 15 );
|
|
|
1776 |
wpt_twit_instant( $id );
|
1777 |
add_action( 'save_post', 'wpt_twit', 15 );
|
1778 |
}
|
@@ -1788,7 +1785,7 @@ add_action( 'publish_phone', 'wpt_twit_xmlrpc' );
|
|
1788 |
function wpt_twit_future( $id ) {
|
1789 |
set_transient( '_wpt_twit_future', $id, 10 );
|
1790 |
// instant action has already run for this post. // prevent running actions twice (need both for older WP).
|
1791 |
-
if ( get_transient( '_wpt_twit_instant' ) && get_transient( '_wpt_twit_instant' )
|
1792 |
delete_transient( '_wpt_twit_instant' );
|
1793 |
|
1794 |
return;
|
@@ -1805,13 +1802,13 @@ function wpt_twit_future( $id ) {
|
|
1805 |
function wpt_twit_instant( $id ) {
|
1806 |
set_transient( '_wpt_twit_instant', $id, 10 );
|
1807 |
// future action has already run for this post.
|
1808 |
-
if ( get_transient( '_wpt_twit_future' ) && get_transient( '_wpt_twit_future' )
|
1809 |
delete_transient( '_wpt_twit_future' );
|
1810 |
|
1811 |
return;
|
1812 |
}
|
1813 |
// xmlrpc action has already run for this post.
|
1814 |
-
if ( get_transient( '_wpt_twit_xmlrpc' ) && get_transient( '_wpt_twit_xmlrpc' )
|
1815 |
delete_transient( '_wpt_twit_xmlrpc' );
|
1816 |
|
1817 |
return;
|
@@ -1831,6 +1828,7 @@ function wpt_twit_xmlrpc( $id ) {
|
|
1831 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
|
1832 |
return $id;
|
1833 |
}
|
|
|
1834 |
wpt_tweet( $id, 'xmlrpc' );
|
1835 |
return $id;
|
1836 |
}
|
4 |
*
|
5 |
* @package WP to Twitter
|
6 |
* @author Joe Dolson
|
7 |
+
* @copyright 2008-2020 Joe Dolson
|
8 |
* @license GPL-2.0+
|
9 |
*
|
10 |
* @wordpress-plugin
|
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.7
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
+
Copyright 2008-2020 Joe Dolson (email : joe@joedolson.com)
|
25 |
|
26 |
This program is free software; you can redistribute it and/or modify
|
27 |
it under the terms of the GNU General Public License as published by
|
57 |
require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
|
58 |
|
59 |
global $wpt_version;
|
60 |
+
$wpt_version = '3.4.7';
|
61 |
|
62 |
add_action( 'init', 'wpt_load_textdomain' );
|
63 |
/**
|
113 |
if ( $new_install ) {
|
114 |
$initial_settings = array(
|
115 |
'post' => array(
|
116 |
+
'post-published-update' => '1',
|
117 |
'post-published-text' => 'New post: #title# #url#',
|
118 |
+
'post-edited-update' => '0',
|
119 |
'post-edited-text' => 'Post Edited: #title# #url#',
|
120 |
),
|
121 |
'page' => array(
|
122 |
+
'post-published-update' => '0',
|
123 |
'post-published-text' => 'New page: #title# #url#',
|
124 |
+
'post-edited-update' => '0',
|
125 |
'post-edited-text' => 'Page edited: #title# #url#',
|
126 |
),
|
127 |
);
|
182 |
if ( $upgrade ) {
|
183 |
$administrator->add_cap( 'wpt_tweet_now' );
|
184 |
}
|
185 |
+
$upgrade = version_compare( $prev_version, '3.4.4', '<' );
|
186 |
+
if ( $upgrade ) {
|
187 |
+
delete_option( 'bitlyapi' );
|
188 |
+
delete_option( 'bitlylogin' );
|
189 |
+
}
|
190 |
|
191 |
update_option( 'wp_to_twitter_version', $wpt_version );
|
192 |
}
|
289 |
* @return boolean Success of query.
|
290 |
*/
|
291 |
function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false ) {
|
292 |
+
$http_code = 0;
|
293 |
+
// If an ID is set but the post is not currently present or published, ignore.
|
294 |
+
if ( $id ) {
|
295 |
+
$status = get_post_status( $id );
|
296 |
+
if ( ! $status || 'publish' !== $status ) {
|
297 |
+
$error = __( 'This post is no longer published or has been deleted', 'wp-to-twitter' );
|
298 |
+
wpt_saves_error( $id, $auth, $twit, $error, '404', time() );
|
299 |
+
wpt_set_log( 'wpt_status_message', $id, $error );
|
300 |
+
|
301 |
+
return false;
|
302 |
+
}
|
303 |
+
}
|
304 |
+
$error = false;
|
305 |
if ( '1' === get_option( 'wpt_rate_limiting' ) ) {
|
306 |
// check whether this post needs to be rate limited.
|
307 |
$continue = wpt_test_rate_limit( $id, $auth );
|
308 |
if ( ! $continue ) {
|
309 |
+
wpt_mail( 'This post was blocked by WP to Twitter rate limiting.', 'Post ID: ' . $id . '; Account: ' . $auth );
|
310 |
+
|
311 |
return false;
|
312 |
}
|
313 |
}
|
314 |
|
315 |
+
$recent = wpt_check_recent_tweet( $id, $auth );
|
316 |
if ( $recent ) {
|
317 |
+
wpt_mail( 'This post was just Tweeted, and this is a duplicate.', 'Post ID: ' . $id . '; Account: ' . $auth );
|
318 |
+
|
319 |
return false;
|
320 |
}
|
321 |
|
323 |
$error = __( 'This account is not authorized to post to Twitter.', 'wp-to-twitter' );
|
324 |
wpt_saves_error( $id, $auth, $twit, $error, '401', time() );
|
325 |
wpt_set_log( 'wpt_status_message', $id, $error );
|
326 |
+
wpt_mail( 'Account not authorized with Twitter', 'Post ID: ' . $id );
|
327 |
|
328 |
return false;
|
329 |
} // exit silently if not authorized.
|
557 |
}
|
558 |
}
|
559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
/**
|
561 |
* Builds array of post info for use in Tweet functions.
|
562 |
*
|
697 |
* @param string $post_type Type of post.
|
698 |
* @param array $post_info Post info.
|
699 |
* @param int $post_ID Post ID.
|
|
|
|
|
700 |
*/
|
701 |
function wpt_category_limit( $post_type, $post_info, $post_ID ) {
|
702 |
+
$continue = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
703 |
$args = array(
|
704 |
'type' => $post_type,
|
705 |
'info' => $post_info,
|
740 |
}
|
741 |
}
|
742 |
if ( '0' === get_option( 'jd_tweet_default' ) ) {
|
743 |
+
$default = ( 'no' !== $tweet_this ) ? true : false;
|
744 |
+
$text_default = 'no';
|
745 |
} else {
|
746 |
+
$default = ( 'yes' === $tweet_this ) ? true : false;
|
747 |
+
$text_default = 'yes';
|
748 |
}
|
749 |
+
wpt_mail( '1: Tweet Status', "Should tweet: $tweet_this; Setting: $text_default; Publication method: $type", $post_ID ); // DEBUG.
|
750 |
if ( $default ) { // default switch: depend on default settings.
|
751 |
$post_info = wpt_post_info( $post_ID );
|
752 |
$media = wpt_post_with_media( $post_ID, $post_info );
|
755 |
} else {
|
756 |
$auth = $post_info['authId'];
|
757 |
}
|
758 |
+
$debug_post_info = $post_info;
|
759 |
+
unset( $debug_post_info['post_content'] );
|
760 |
+
unset( $debug_post_info['postContent'] );
|
761 |
+
wpt_mail( '2: WP to Twitter Post Info (post content omitted)', print_r( $debug_post_info, 1 ), $post_ID ); // DEBUG.
|
762 |
if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() && function_exists( 'wpt_filter_post_info' ) ) {
|
763 |
$filter = wpt_filter_post_info( $post_info );
|
764 |
if ( true === $filter ) {
|
765 |
+
wpt_mail( '3: Post blocked by WP Tweets Pro custom filters', 'No additional data available', $post_ID );
|
766 |
|
767 |
return false;
|
768 |
}
|
775 |
$post_type = $post_info['postType'];
|
776 |
if ( 'future' === $type || 'future' === get_post_meta( $post_ID, 'wpt_publishing', true ) ) {
|
777 |
$new = 1; // if this is a future action, then it should be published regardless of relationship.
|
778 |
+
wpt_mail( '4a: Post is a scheduled post', 'See Post Info data', $post_ID );
|
779 |
delete_post_meta( $post_ID, 'wpt_publishing' );
|
780 |
} else {
|
781 |
// if the post modified date and the post date are the same, this is new.
|
794 |
// identify whether limited by category/taxonomy.
|
795 |
$continue = wpt_category_limit( $post_type, $post_info, $post_ID );
|
796 |
if ( false === $continue ) {
|
797 |
+
wpt_mail( '4b: WP Tweets Pro: Limited by term filters', 'This post was rejected by a taxonomy/term filter', $post_ID );
|
798 |
return false;
|
799 |
}
|
800 |
// create Tweet and ID whether current action is edit or new.
|
812 |
return false;
|
813 |
}
|
814 |
}
|
815 |
+
wpt_mail( '4b: Post action is edit', 'This event was a post edit action, not a post publication.' . "\n" . 'Modified Date: ' . $post_info['post_modified'] . "\n\n" . 'Publication date:' . $post_info['post_date'], $post_ID ); // DEBUG.
|
816 |
+
if ( '1' === (string) $post_type_settings[ $post_type ]['post-edited-update'] ) {
|
817 |
$nptext = stripcslashes( $post_type_settings[ $post_type ]['post-edited-text'] );
|
818 |
$oldpost = true;
|
819 |
}
|
820 |
} else {
|
821 |
+
wpt_mail( '4c: Post action is publish', 'This event was a post publish action.' . "\n" . 'Modified Date: ' . $post_info['post_modified'] . "\n\n" . 'Publication date:' . $post_info['post_date'], $post_ID ); // DEBUG.
|
822 |
+
if ( '1' === (string) $post_type_settings[ $post_type ]['post-published-update'] ) {
|
823 |
$nptext = stripcslashes( $post_type_settings[ $post_type ]['post-published-text'] );
|
824 |
$newpost = true;
|
825 |
}
|
827 |
if ( $newpost || $oldpost ) {
|
828 |
$template = ( '' !== $custom_tweet ) ? $custom_tweet : $nptext;
|
829 |
$sentence = jd_truncate_tweet( $template, $post_info, $post_ID );
|
830 |
+
wpt_mail( '5: Tweet Template Processed', "Template: $template; Tweet: $sentence", $post_ID ); // DEBUG.
|
831 |
if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
|
832 |
$sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth );
|
833 |
}
|
881 |
'timestamp' => time() + $time + $offset,
|
882 |
'current_time' => time(),
|
883 |
'timezone' => get_option( 'gmt_offset' ),
|
884 |
+
'timestring' => gmdate( 'Y-m-d H:i:s', time() + $time + $offset ),
|
885 |
+
'current_ts' => gmdate( 'Y-m-d H:i:s', time() ),
|
886 |
+
'users' => $wpt_selected_users,
|
887 |
),
|
888 |
1
|
889 |
),
|
938 |
'sentence' => array( $retweet, $i, $post_ID ),
|
939 |
'timestamp' => time() + $time + $offset + $delay,
|
940 |
'time' => array( $time, $offset, $delay, get_option( 'gmt_offset' ), time() ),
|
941 |
+
'timestring' => gmdate( 'Y-m-d H:i:s', time() + $time + $offset + $delay ),
|
942 |
+
'current_ts' => gmdate( 'Y-m-d H:i:s', time() ),
|
943 |
),
|
944 |
1
|
945 |
),
|
961 |
}
|
962 |
// END WPT PRO.
|
963 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
964 |
}
|
965 |
}
|
966 |
|
1068 |
case 4:
|
1069 |
$newtag = $tag;
|
1070 |
break;
|
1071 |
+
case 5:
|
1072 |
+
$newtag = "@$tag";
|
1073 |
+
break;
|
1074 |
default:
|
1075 |
$newtag = apply_filters( 'wpt_tag_default', '#', $t_id ) . $tag;
|
1076 |
}
|
1098 |
$wpt_post_types = get_option( 'wpt_post_types' );
|
1099 |
if ( is_array( $wpt_post_types ) ) {
|
1100 |
foreach ( $wpt_post_types as $key => $value ) {
|
1101 |
+
if ( '1' === (string) $value['post-published-update'] || '1' === (string) $value['post-edited-update'] ) {
|
1102 |
add_meta_box( 'wp2t', 'WP to Twitter', 'wpt_add_twitter_inner_box', $key, 'side' );
|
1103 |
}
|
1104 |
}
|
1116 |
$wpt_post_types = get_option( 'wpt_post_types' );
|
1117 |
if ( is_array( $wpt_post_types ) ) {
|
1118 |
foreach ( $wpt_post_types as $key => $value ) {
|
1119 |
+
if ( '1' === (string) $value['post-published-update'] || '1' === (string) $value['post-edited-update'] ) {
|
1120 |
add_meta_box( 'wp2t-debug', 'WP to Twitter Debugging', 'wpt_show_debug', $key, 'advanced' );
|
1121 |
}
|
1122 |
}
|
1178 |
<span class="dashicons dashicons-clock" aria-hidden="true"></span><span class="screen-reader-text"><?php _e( 'Set Date/Time', 'wp-to-twitter' ); ?></span>
|
1179 |
</button>
|
1180 |
<div id="jts">
|
1181 |
+
<?php
|
1182 |
+
$datavalue = gmdate( 'Y-m-d', current_time( 'timestamp' ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
|
1183 |
+
$timevalue = date_i18n( 'h:s a', current_time( 'timestamp' ) + 3600 ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
|
1184 |
+
?>
|
1185 |
<label for='wpt_date'><?php _e( 'Date', 'wp-to-twitter' ); ?></label>
|
1186 |
+
<input type='date' value='' class='wpt_date date' name='wpt_datetime' id='wpt_date' data-value='<?php echo $datavalue; ?>' /><br/>
|
1187 |
<label for='wpt_time'><?php _e( 'Time', 'wp-to-twitter' ); ?></label>
|
1188 |
+
<input type='text' value='<?php echo $timevalue; ?>' class='wpt_time time' name='wpt_datetime' id='wpt_time'/>
|
1189 |
</div>
|
1190 |
<?php
|
1191 |
}
|
1459 |
die;
|
1460 |
}
|
1461 |
$action = ( 'tweet' === $_REQUEST['tweet_action'] ) ? 'tweet' : 'schedule';
|
1462 |
+
$authors = ( isset( $_REQUEST['tweet_auth'] ) && null !== $_REQUEST['tweet_auth'] ) ? $_REQUEST['tweet_auth'] : false;
|
1463 |
+
$upload = ( isset( $_REQUEST['tweet_upload'] ) && null !== $_REQUEST['tweet_upload'] ) ? $_REQUEST['tweet_upload'] : '1';
|
1464 |
$current_user = wp_get_current_user();
|
1465 |
if ( function_exists( 'wpt_pro_exists' ) && wpt_pro_exists() ) {
|
1466 |
if ( wtt_oauth_test( $current_user->ID, 'verify' ) ) {
|
1611 |
// WPT PRO.
|
1612 |
// only send debug data if post meta is updated.
|
1613 |
if ( true === $update || is_int( $update ) ) {
|
1614 |
+
wpt_mail( 'Post Meta Inserted', 'WP to Twitter post meta was updated', $id ); // DEBUG.
|
1615 |
}
|
1616 |
if ( isset( $_POST['wpt-delete-debug'] ) && 'true' === $_POST['wpt-delete-debug'] ) {
|
1617 |
delete_post_meta( $id, '_wpt_debug_log' );
|
1712 |
if ( in_array( $type, $post_types, true ) ) {
|
1713 |
return true;
|
1714 |
}
|
1715 |
+
if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
|
1716 |
+
wpt_mail( '0: Not a Tweeted post type', 'This post type is not enabled for Tweeting: ' . $type, $id );
|
1717 |
+
}
|
1718 |
|
1719 |
return false;
|
1720 |
}
|
1729 |
$allowed_types = array();
|
1730 |
if ( is_array( $post_type_settings ) && ! empty( $post_type_settings ) ) {
|
1731 |
foreach ( $post_type_settings as $type => $settings ) {
|
1732 |
+
if ( '1' === (string) $settings['post-edited-update'] || '1' === (string) $settings['post-published-update'] ) {
|
1733 |
$allowed_types[] = $type;
|
1734 |
}
|
1735 |
}
|
1749 |
if ( wp_is_post_autosave( $id ) || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
|
1750 |
return;
|
1751 |
}
|
1752 |
+
wpt_mail( 'Transitioning future to publish', $id );
|
1753 |
wpt_twit_future( $id );
|
1754 |
}
|
1755 |
|
1769 |
// is there any reason to accept any other status?
|
1770 |
// This is an issue only until the release of WP 4.7.
|
1771 |
remove_action( 'save_post', 'wpt_twit', 15 );
|
1772 |
+
wpt_mail( 'Tweeting published post', $id );
|
1773 |
wpt_twit_instant( $id );
|
1774 |
add_action( 'save_post', 'wpt_twit', 15 );
|
1775 |
}
|
1785 |
function wpt_twit_future( $id ) {
|
1786 |
set_transient( '_wpt_twit_future', $id, 10 );
|
1787 |
// instant action has already run for this post. // prevent running actions twice (need both for older WP).
|
1788 |
+
if ( get_transient( '_wpt_twit_instant' ) && (int) get_transient( '_wpt_twit_instant' ) === $id ) {
|
1789 |
delete_transient( '_wpt_twit_instant' );
|
1790 |
|
1791 |
return;
|
1802 |
function wpt_twit_instant( $id ) {
|
1803 |
set_transient( '_wpt_twit_instant', $id, 10 );
|
1804 |
// future action has already run for this post.
|
1805 |
+
if ( get_transient( '_wpt_twit_future' ) && (int) get_transient( '_wpt_twit_future' ) === $id ) {
|
1806 |
delete_transient( '_wpt_twit_future' );
|
1807 |
|
1808 |
return;
|
1809 |
}
|
1810 |
// xmlrpc action has already run for this post.
|
1811 |
+
if ( get_transient( '_wpt_twit_xmlrpc' ) && (int) get_transient( '_wpt_twit_xmlrpc' ) === $id ) {
|
1812 |
delete_transient( '_wpt_twit_xmlrpc' );
|
1813 |
|
1814 |
return;
|
1828 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
|
1829 |
return $id;
|
1830 |
}
|
1831 |
+
wpt_mail( 'Tweeting XMLRPC published post', $id );
|
1832 |
wpt_tweet( $id, 'xmlrpc' );
|
1833 |
return $id;
|
1834 |
}
|
wpt-functions.php
CHANGED
@@ -107,14 +107,14 @@ function wpt_check_functions() {
|
|
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 .=
|
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>';
|
115 |
}
|
116 |
} else {
|
117 |
-
$message .=
|
118 |
$message .= " <a href='$shrink'>$shrink</a></li>";
|
119 |
}
|
120 |
// check twitter credentials.
|
@@ -122,20 +122,20 @@ function wpt_check_functions() {
|
|
122 |
$rand = rand( 1000000, 9999999 );
|
123 |
$testpost = wpt_post_to_twitter( "This is a test of WP to Twitter. $shrink ($rand)" );
|
124 |
if ( $testpost ) {
|
125 |
-
$message .=
|
126 |
} else {
|
127 |
$error = wpt_log( 'wpt_status_message', 'test' );
|
128 |
-
$message .=
|
129 |
$message .= "<li class='error'>$error</li>";
|
130 |
}
|
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 .=
|
136 |
}
|
137 |
if ( $testpost && $shrink ) {
|
138 |
-
$message .=
|
139 |
}
|
140 |
$message .= '</ul>
|
141 |
</div>';
|
@@ -209,8 +209,8 @@ function wpt_handle_errors() {
|
|
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">' . __( '
|
213 |
-
'
|
214 |
<div>
|
215 |
<input type="hidden" name="submit-type" value="clear-error"/>
|
216 |
' . $nonce . '
|
@@ -283,7 +283,7 @@ function wpt_debug_log( $subject, $body, $post_ID ) {
|
|
283 |
global $post_ID;
|
284 |
}
|
285 |
if ( $post_ID ) {
|
286 |
-
$time = current_time( 'timestamp' );
|
287 |
add_post_meta( $post_ID, '_wpt_debug_log', array( $time, $subject, $body ) );
|
288 |
}
|
289 |
}
|
@@ -549,7 +549,8 @@ function wtt_option_selected( $field, $value, $type = 'checkbox' ) {
|
|
549 |
* @return integer (boolean)
|
550 |
*/
|
551 |
function wpt_post_is_new( $modified, $postdate ) {
|
552 |
-
|
|
|
553 |
$mod_date = strtotime( $modified );
|
554 |
$post_date = strtotime( $postdate ) + $modifier;
|
555 |
if ( $mod_date <= $post_date ) { // if post_modified is before or equal to post_date.
|
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.', 'wp-to-twitter' ) . '</strong></li>';
|
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>';
|
115 |
}
|
116 |
} else {
|
117 |
+
$message .= '<li><strong>' . __( "WP to Twitter successfully contacted your URL shortening service.</strong> This link should point to your site's homepage:", 'wp-to-twitter' );
|
118 |
$message .= " <a href='$shrink'>$shrink</a></li>";
|
119 |
}
|
120 |
// check twitter credentials.
|
122 |
$rand = rand( 1000000, 9999999 );
|
123 |
$testpost = wpt_post_to_twitter( "This is a test of WP to Twitter. $shrink ($rand)" );
|
124 |
if ( $testpost ) {
|
125 |
+
$message .= '<li><strong>' . __( 'WP to Twitter successfully submitted a status update to Twitter.', 'wp-to-twitter' ) . '</strong></li>';
|
126 |
} else {
|
127 |
$error = wpt_log( 'wpt_status_message', 'test' );
|
128 |
+
$message .= '<li class="error"><strong>' . __( 'WP to Twitter failed to submit an update to Twitter.', 'wp-to-twitter' ) . '</strong></li>';
|
129 |
$message .= "<li class='error'>$error</li>";
|
130 |
}
|
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.", 'wp-to-twitter' ) . '</li>';
|
136 |
}
|
137 |
if ( $testpost && $shrink ) {
|
138 |
+
$message .= '<li><strong>' . __( 'Your server should run WP to Twitter successfully.', 'wp-to-twitter' ) . '</strong></li>';
|
139 |
}
|
140 |
$message .= '</ul>
|
141 |
</div>';
|
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.', 'wp-to-twitter' ) .
|
213 |
+
'</p><form method="post" action="' . $admin_url . '">
|
214 |
<div>
|
215 |
<input type="hidden" name="submit-type" value="clear-error"/>
|
216 |
' . $nonce . '
|
283 |
global $post_ID;
|
284 |
}
|
285 |
if ( $post_ID ) {
|
286 |
+
$time = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
|
287 |
add_post_meta( $post_ID, '_wpt_debug_log', array( $time, $subject, $body ) );
|
288 |
}
|
289 |
}
|
549 |
* @return integer (boolean)
|
550 |
*/
|
551 |
function wpt_post_is_new( $modified, $postdate ) {
|
552 |
+
// Default allows up to a 10 second discrepancy for slow processing.
|
553 |
+
$modifier = apply_filters( 'wpt_edit_sensitivity', 10 ); // alter time in seconds to modified date.
|
554 |
$mod_date = strtotime( $modified );
|
555 |
$post_date = strtotime( $postdate ) + $modifier;
|
556 |
if ( $mod_date <= $post_date ) { // if post_modified is before or equal to post_date.
|
wpt-rate-limiting.php
CHANGED
@@ -100,8 +100,8 @@ function wpt_test_rate_limit( $post_ID, $auth ) {
|
|
100 |
* @return integer Default rate limit
|
101 |
*/
|
102 |
function wpt_default_rate_limit( $term = false ) {
|
103 |
-
$limit = ( ''
|
104 |
-
$limit = ( 0
|
105 |
|
106 |
return apply_filters( 'wpt_default_rate_limit', $limit, $term );
|
107 |
}
|
@@ -203,13 +203,13 @@ function wpt_add_term_rate_limit( $term ) {
|
|
203 |
function wpt_view_rate_limits() {
|
204 |
$limits = get_option( 'wpt_rate_limits' );
|
205 |
if ( ! wp_next_scheduled( 'wptratelimits' ) ) {
|
206 |
-
wp_schedule_event(
|
207 |
}
|
208 |
$next_scheduled = human_time_diff( wp_next_scheduled( 'wptratelimits' ), time() );
|
209 |
if ( is_array( $limits ) ) {
|
210 |
$output = '<ul>';
|
211 |
foreach ( $limits as $auth => $term ) {
|
212 |
-
$author = ( 0
|
213 |
$output .= "<li><h4><a href='https://twitter.com/$author'>@$author</a>:</h4><ul>";
|
214 |
foreach ( $term as $id => $value ) {
|
215 |
$count = count( $value );
|
100 |
* @return integer Default rate limit
|
101 |
*/
|
102 |
function wpt_default_rate_limit( $term = false ) {
|
103 |
+
$limit = ( '' !== get_option( 'wpt_default_rate_limit' ) ) ? get_option( 'wpt_default_rate_limit' ) : 10;
|
104 |
+
$limit = ( '0' === (string) $limit ) ? 1 : $limit;
|
105 |
|
106 |
return apply_filters( 'wpt_default_rate_limit', $limit, $term );
|
107 |
}
|
203 |
function wpt_view_rate_limits() {
|
204 |
$limits = get_option( 'wpt_rate_limits' );
|
205 |
if ( ! wp_next_scheduled( 'wptratelimits' ) ) {
|
206 |
+
wp_schedule_event( time() + 3600, 'hourly', 'wptratelimits' );
|
207 |
}
|
208 |
$next_scheduled = human_time_diff( wp_next_scheduled( 'wptratelimits' ), time() );
|
209 |
if ( is_array( $limits ) ) {
|
210 |
$output = '<ul>';
|
211 |
foreach ( $limits as $auth => $term ) {
|
212 |
+
$author = ( 0 === (int) $auth ) ? get_option( 'wtt_twitter_username' ) : get_user_meta( $auth, 'wtt_twitter_username', true );
|
213 |
$output .= "<li><h4><a href='https://twitter.com/$author'>@$author</a>:</h4><ul>";
|
214 |
foreach ( $term as $id => $value ) {
|
215 |
$count = count( $value );
|
wpt-widget.php
CHANGED
@@ -34,7 +34,7 @@ require_once( dirname( __FILE__ ) . '/classes/class-wpt-search-tweets-widget.php
|
|
34 |
* @return string Linkified tweet content
|
35 |
*/
|
36 |
function wpt_tweet_linkify( $text, $opts, $tweet ) {
|
37 |
-
if ( true
|
38 |
$media = isset( $tweet['entities']['media'] ) ? $tweet['entities']['media'] : false;
|
39 |
if ( $media ) {
|
40 |
$media_urls = array();
|
@@ -58,17 +58,17 @@ function wpt_tweet_linkify( $text, $opts, $tweet ) {
|
|
58 |
$text = str_replace( '…', ' ______ ', $text );
|
59 |
$restore = true;
|
60 |
}
|
61 |
-
$text = ( true
|
62 |
-
$text = ( true
|
63 |
-
$text = ( true
|
64 |
-
$text = ( true
|
65 |
$urls = $tweet['entities']['urls'];
|
66 |
if ( is_array( $urls ) ) {
|
67 |
foreach ( $urls as $url ) {
|
68 |
$text = str_replace( ">$url[url]<", ">$url[display_url]<", $text );
|
69 |
}
|
70 |
}
|
71 |
-
if ( true
|
72 |
$text = str_replace( ' ______ ', '…', $text );
|
73 |
}
|
74 |
|
@@ -205,7 +205,7 @@ function wpt_get_twitter_feed( $atts, $content ) {
|
|
205 |
function wpt_twitter_feed( $instance ) {
|
206 |
$header = '';
|
207 |
if ( ! isset( $instance['search'] ) ) {
|
208 |
-
$twitter_id = ( isset( $instance['twitter_id'] ) && ''
|
209 |
$user = wpt_get_user( $twitter_id );
|
210 |
if ( empty( $user ) ) {
|
211 |
return __( 'Error: You are not connected to Twitter.', 'wp-to-twitter' );
|
@@ -232,7 +232,7 @@ function wpt_twitter_feed( $instance ) {
|
|
232 |
$twitter_id = false;
|
233 |
}
|
234 |
|
235 |
-
$hide_header = ( isset( $instance['hide_header'] ) && 1
|
236 |
|
237 |
if ( ! isset( $instance['search'] ) ) {
|
238 |
$options['exclude_replies'] = ( isset( $instance['twitter_hide_replies'] ) ) ? $instance['twitter_hide_replies'] : false;
|
34 |
* @return string Linkified tweet content
|
35 |
*/
|
36 |
function wpt_tweet_linkify( $text, $opts, $tweet ) {
|
37 |
+
if ( true === (bool) $opts['show_images'] ) {
|
38 |
$media = isset( $tweet['entities']['media'] ) ? $tweet['entities']['media'] : false;
|
39 |
if ( $media ) {
|
40 |
$media_urls = array();
|
58 |
$text = str_replace( '…', ' ______ ', $text );
|
59 |
$restore = true;
|
60 |
}
|
61 |
+
$text = ( true === (bool) $opts['links'] ) ? preg_replace( '#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#', '\\1<a href="\\2" rel="nofollow">\\2</a>', $text ) : $text;
|
62 |
+
$text = ( true === (bool) $opts['links'] ) ? preg_replace( '#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#', '\\1<a href="http://\\2" rel="nofollow">\\2</a>', $text ) : $text;
|
63 |
+
$text = ( true === (bool) $opts['mentions'] ) ? preg_replace( '/@(\w+)/', '<a href="https://twitter.com/\\1" rel="nofollow">@\\1</a>', $text ) : $text;
|
64 |
+
$text = ( true === (bool) $opts['hashtags'] ) ? preg_replace( '/#(\w+)/', '<a href="https://twitter.com/search?q=%23\\1" rel="nofollow">#\\1</a>', $text ) : $text;
|
65 |
$urls = $tweet['entities']['urls'];
|
66 |
if ( is_array( $urls ) ) {
|
67 |
foreach ( $urls as $url ) {
|
68 |
$text = str_replace( ">$url[url]<", ">$url[display_url]<", $text );
|
69 |
}
|
70 |
}
|
71 |
+
if ( true === $restore ) {
|
72 |
$text = str_replace( ' ______ ', '…', $text );
|
73 |
}
|
74 |
|
205 |
function wpt_twitter_feed( $instance ) {
|
206 |
$header = '';
|
207 |
if ( ! isset( $instance['search'] ) ) {
|
208 |
+
$twitter_id = ( isset( $instance['twitter_id'] ) && '' !== $instance['twitter_id'] ) ? $instance['twitter_id'] : get_option( 'wtt_twitter_username' );
|
209 |
$user = wpt_get_user( $twitter_id );
|
210 |
if ( empty( $user ) ) {
|
211 |
return __( 'Error: You are not connected to Twitter.', 'wp-to-twitter' );
|
232 |
$twitter_id = false;
|
233 |
}
|
234 |
|
235 |
+
$hide_header = ( isset( $instance['hide_header'] ) && 1 === (int) $instance['hide_header'] ) ? true : false;
|
236 |
|
237 |
if ( ! isset( $instance['search'] ) ) {
|
238 |
$options['exclude_replies'] = ( isset( $instance['twitter_hide_replies'] ) ) ? $instance['twitter_hide_replies'] : false;
|