Version Description
- Bug fix: Fix incorrect textdomains.
- Security: Missing nonce verification in metabox.
- Change: New filter
wpt_postpone_rendering
to allow Pro to delay template rendering. - Docs: Start adding hook docs - https://joedolson.github.io/wp-to-twitter/. Work in progress.
Download this release
Release Info
Developer | joedolson |
Plugin | WP to Twitter |
Version | 3.6.0 |
Comparing to | |
See all releases |
Code changes from version 3.5.6 to 3.6.0
- classes/class-wpt-twitterfeed.php +9 -1
- readme.txt +8 -1
- wp-to-twitter-manager.php +8 -9
- wp-to-twitter-shorteners.php +10 -10
- wp-to-twitter.php +183 -12
- wpt-functions.php +2 -2
- wpt-rate-limiting.php +3 -3
- wpt-truncate.php +70 -8
classes/class-wpt-twitterfeed.php
CHANGED
@@ -326,7 +326,15 @@ class WPT_TwitterFeed {
|
|
326 |
$this->st_last_error = $last_error;
|
327 |
}
|
328 |
}
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
do_action( 'wpt_process_tweets', $result, $screenname, $options );
|
331 |
|
332 |
return $result;
|
326 |
$this->st_last_error = $last_error;
|
327 |
}
|
328 |
}
|
329 |
+
/**
|
330 |
+
* Run an action on the results output from the Twitter widget query.
|
331 |
+
*
|
332 |
+
* @hook wpt_process_tweets
|
333 |
+
*
|
334 |
+
* @param {array} $result Array of data received from Twitter's API.
|
335 |
+
* @param {string} $screenname Twitter user's screen name.
|
336 |
+
* @param {array} $options Array of options passed to this widget.
|
337 |
+
*/
|
338 |
do_action( 'wpt_process_tweets', $result, $screenname, $options );
|
339 |
|
340 |
return $result;
|
readme.txt
CHANGED
@@ -7,7 +7,7 @@ Tested up to: 6.0
|
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
Text Domain: wp-to-twitter
|
10 |
-
Stable tag: 3.
|
11 |
|
12 |
Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
|
13 |
|
@@ -64,6 +64,13 @@ Check out my <a href="https://github.com/joedolson/plugin-extensions/tree/master
|
|
64 |
|
65 |
== Changelog ==
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
= 3.5.6 =
|
68 |
|
69 |
* Bug fix: Change in link to Twitter API error codes.
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
Text Domain: wp-to-twitter
|
10 |
+
Stable tag: 3.6.0
|
11 |
|
12 |
Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
|
13 |
|
64 |
|
65 |
== Changelog ==
|
66 |
|
67 |
+
= 3.6.0 =
|
68 |
+
|
69 |
+
* Bug fix: Fix incorrect textdomains.
|
70 |
+
* Security: Missing nonce verification in metabox.
|
71 |
+
* Change: New filter `wpt_postpone_rendering` to allow Pro to delay template rendering.
|
72 |
+
* Docs: Start adding hook docs - https://joedolson.github.io/wp-to-twitter/. Work in progress.
|
73 |
+
|
74 |
= 3.5.6 =
|
75 |
|
76 |
* Bug fix: Change in link to Twitter API error codes.
|
wp-to-twitter-manager.php
CHANGED
@@ -27,9 +27,9 @@ function wpt_updated_settings() {
|
|
27 |
if ( ! wp_verify_nonce( $nonce, 'wp-to-twitter-nonce' ) ) {
|
28 |
die( 'Security check failed' );
|
29 |
}
|
30 |
-
|
31 |
if ( isset( $_POST['oauth_settings'] ) ) {
|
32 |
-
$
|
|
|
33 |
} else {
|
34 |
$oauth_message = '';
|
35 |
}
|
@@ -110,7 +110,7 @@ function wpt_updated_settings() {
|
|
110 |
update_option( 'jd_date_format', sanitize_text_field( $_POST['jd_date_format'] ) );
|
111 |
update_option( 'jd_dynamic_analytics', sanitize_text_field( $_POST['jd-dynamic-analytics'] ) );
|
112 |
|
113 |
-
$twitter_analytics = ( isset( $_POST['twitter-analytics'] ) ) ? $_POST['twitter-analytics'] : 0;
|
114 |
if ( 1 === (int) $twitter_analytics ) {
|
115 |
update_option( 'use_dynamic_analytics', 0 );
|
116 |
update_option( 'use-twitter-analytics', 1 );
|
@@ -129,7 +129,7 @@ function wpt_updated_settings() {
|
|
129 |
update_option( 'jd_individual_twitter_users', ( isset( $_POST['jd_individual_twitter_users'] ) ? 1 : 0 ) );
|
130 |
|
131 |
if ( isset( $_POST['wpt_caps'] ) ) {
|
132 |
-
$perms = $_POST['wpt_caps'];
|
133 |
$caps = array( 'wpt_twitter_oauth', 'wpt_twitter_custom', 'wpt_twitter_switch', 'wpt_can_tweet', 'wpt_tweet_now' );
|
134 |
foreach ( $perms as $key => $value ) {
|
135 |
$role = get_role( $key );
|
@@ -148,8 +148,8 @@ function wpt_updated_settings() {
|
|
148 |
update_option( 'wpt_permit_feed_styles', ( isset( $_POST['wpt_permit_feed_styles'] ) ) ? 1 : 0 );
|
149 |
update_option( 'wp_debug_oauth', ( isset( $_POST['wp_debug_oauth'] ) ) ? 1 : 0 );
|
150 |
update_option( 'wpt_debug_tweets', ( isset( $_POST['wpt_debug_tweets'] ) ) ? 1 : 0 );
|
151 |
-
$wpt_truncation_order = $_POST['wpt_truncation_order'];
|
152 |
-
update_option( 'wpt_truncation_order',
|
153 |
$message .= __( 'WP to Twitter Advanced Options Updated', 'wp-to-twitter' ) . '. ' . $extend;
|
154 |
}
|
155 |
|
@@ -181,13 +181,13 @@ function wpt_updated_settings() {
|
|
181 |
update_option( 'wpt_post_types', $wpt_settings );
|
182 |
update_option( 'newlink-published-text', sanitize_text_field( $_POST['newlink-published-text'] ) );
|
183 |
update_option( 'jd_twit_blogroll', ( isset( $_POST['jd_twit_blogroll'] ) ) ? 1 : '' );
|
184 |
-
$message = wpt_select_shortener( $_POST );
|
185 |
$message .= __( 'WP to Twitter Options Updated', 'wp-to-twitter' );
|
186 |
$message = apply_filters( 'wpt_settings', $message, $_POST );
|
187 |
}
|
188 |
|
189 |
if ( isset( $_POST['wpt_shortener_update'] ) && 'true' === $_POST['wpt_shortener_update'] ) {
|
190 |
-
$message = wpt_shortener_update( $_POST );
|
191 |
}
|
192 |
|
193 |
// Check whether the server has supported for needed functions.
|
@@ -377,7 +377,6 @@ function wpt_update_settings() {
|
|
377 |
</label><br/>
|
378 |
<textarea class="wpt-template" name="wpt_post_types[<?php echo esc_attr( $slug ); ?>][post-published-text]" id="<?php echo esc_attr( $slug ); ?>-post-published-text" cols="60" rows="3"><?php echo ( isset( $wpt_settings[ $slug ] ) ) ? esc_attr( stripslashes( $wpt_settings[ $slug ]['post-published-text'] ) ) : ''; ?></textarea>
|
379 |
</p>
|
380 |
-
|
381 |
<p>
|
382 |
<input type="checkbox" name="wpt_post_types[<?php echo esc_attr( $slug ); ?>][post-edited-update]" id="<?php echo esc_attr( $slug ); ?>-post-edited-update" value="1" <?php echo wpt_checkbox( 'wpt_post_types', $slug, 'post-edited-update' ); ?> />
|
383 |
<label for="<?php echo esc_attr( $slug ); ?>-post-edited-update"><strong>
|
27 |
if ( ! wp_verify_nonce( $nonce, 'wp-to-twitter-nonce' ) ) {
|
28 |
die( 'Security check failed' );
|
29 |
}
|
|
|
30 |
if ( isset( $_POST['oauth_settings'] ) ) {
|
31 |
+
$post = map_deep( $_POST, 'sanitize_text_field' );
|
32 |
+
$oauth_message = wpt_update_oauth_settings( false, $post );
|
33 |
} else {
|
34 |
$oauth_message = '';
|
35 |
}
|
110 |
update_option( 'jd_date_format', sanitize_text_field( $_POST['jd_date_format'] ) );
|
111 |
update_option( 'jd_dynamic_analytics', sanitize_text_field( $_POST['jd-dynamic-analytics'] ) );
|
112 |
|
113 |
+
$twitter_analytics = ( isset( $_POST['twitter-analytics'] ) ) ? absint( $_POST['twitter-analytics'] ) : 0;
|
114 |
if ( 1 === (int) $twitter_analytics ) {
|
115 |
update_option( 'use_dynamic_analytics', 0 );
|
116 |
update_option( 'use-twitter-analytics', 1 );
|
129 |
update_option( 'jd_individual_twitter_users', ( isset( $_POST['jd_individual_twitter_users'] ) ? 1 : 0 ) );
|
130 |
|
131 |
if ( isset( $_POST['wpt_caps'] ) ) {
|
132 |
+
$perms = map_deep( $_POST['wpt_caps'], 'sanitize_text_field' );
|
133 |
$caps = array( 'wpt_twitter_oauth', 'wpt_twitter_custom', 'wpt_twitter_switch', 'wpt_can_tweet', 'wpt_tweet_now' );
|
134 |
foreach ( $perms as $key => $value ) {
|
135 |
$role = get_role( $key );
|
148 |
update_option( 'wpt_permit_feed_styles', ( isset( $_POST['wpt_permit_feed_styles'] ) ) ? 1 : 0 );
|
149 |
update_option( 'wp_debug_oauth', ( isset( $_POST['wp_debug_oauth'] ) ) ? 1 : 0 );
|
150 |
update_option( 'wpt_debug_tweets', ( isset( $_POST['wpt_debug_tweets'] ) ) ? 1 : 0 );
|
151 |
+
$wpt_truncation_order = map_deep( $_POST['wpt_truncation_order'], 'sanitize_text_field' );
|
152 |
+
update_option( 'wpt_truncation_order', $wpt_truncation_order );
|
153 |
$message .= __( 'WP to Twitter Advanced Options Updated', 'wp-to-twitter' ) . '. ' . $extend;
|
154 |
}
|
155 |
|
181 |
update_option( 'wpt_post_types', $wpt_settings );
|
182 |
update_option( 'newlink-published-text', sanitize_text_field( $_POST['newlink-published-text'] ) );
|
183 |
update_option( 'jd_twit_blogroll', ( isset( $_POST['jd_twit_blogroll'] ) ) ? 1 : '' );
|
184 |
+
$message = wpt_select_shortener( map_deep( $_POST, 'sanitize_text_field' ) );
|
185 |
$message .= __( 'WP to Twitter Options Updated', 'wp-to-twitter' );
|
186 |
$message = apply_filters( 'wpt_settings', $message, $_POST );
|
187 |
}
|
188 |
|
189 |
if ( isset( $_POST['wpt_shortener_update'] ) && 'true' === $_POST['wpt_shortener_update'] ) {
|
190 |
+
$message = wpt_shortener_update( map_deep( $_POST, 'sanitize_text_field' ) );
|
191 |
}
|
192 |
|
193 |
// Check whether the server has supported for needed functions.
|
377 |
</label><br/>
|
378 |
<textarea class="wpt-template" name="wpt_post_types[<?php echo esc_attr( $slug ); ?>][post-published-text]" id="<?php echo esc_attr( $slug ); ?>-post-published-text" cols="60" rows="3"><?php echo ( isset( $wpt_settings[ $slug ] ) ) ? esc_attr( stripslashes( $wpt_settings[ $slug ]['post-published-text'] ) ) : ''; ?></textarea>
|
379 |
</p>
|
|
|
380 |
<p>
|
381 |
<input type="checkbox" name="wpt_post_types[<?php echo esc_attr( $slug ); ?>][post-edited-update]" id="<?php echo esc_attr( $slug ); ?>-post-edited-update" value="1" <?php echo wpt_checkbox( 'wpt_post_types', $slug, 'post-edited-update' ); ?> />
|
382 |
<label for="<?php echo esc_attr( $slug ); ?>-post-edited-update"><strong>
|
wp-to-twitter-shorteners.php
CHANGED
@@ -482,15 +482,15 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
482 |
if ( isset( $post['submit-type'] ) && 'yourlsapi' === $post['submit-type'] ) {
|
483 |
$message = '';
|
484 |
if ( '' !== $post['yourlstoken'] && isset( $post['submit'] ) ) {
|
485 |
-
update_option( 'yourlstoken',
|
486 |
delete_option( 'yourlsapi' );
|
487 |
delete_option( 'yourlslogin' );
|
488 |
$message .= __( 'YOURLS signature token updated.', 'wp-to-twitter' );
|
489 |
}
|
490 |
-
update_option( 'yourlsurl',
|
491 |
// yourls path is deprecated.
|
492 |
if ( isset( $post['yourlspath'] ) && '' !== $post['yourlspath'] ) {
|
493 |
-
update_option( 'yourlspath',
|
494 |
if ( file_exists( $post['yourlspath'] ) ) {
|
495 |
$message .= ' ' . __( 'YOURLS local server path added. ', 'wp-to-twitter' );
|
496 |
} else {
|
@@ -498,7 +498,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
498 |
}
|
499 |
}
|
500 |
if ( '' !== $post['jd_keyword_format'] ) {
|
501 |
-
update_option( 'jd_keyword_format',
|
502 |
if ( '1' === $post['jd_keyword_format'] ) {
|
503 |
$message .= ' ' . __( 'YOURLS will use Post ID for short URL slug.', 'wp-to-twitter' );
|
504 |
} elseif ( '0' === $post['jd_keyword_format'] ) {
|
@@ -520,7 +520,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
520 |
|
521 |
if ( isset( $post['submit-type'] ) && 'joturlapi' === $post['submit-type'] ) {
|
522 |
if ( '' !== $post['joturlapi'] && isset( $post['submit'] ) ) {
|
523 |
-
update_option( 'joturlapi',
|
524 |
$message = __( 'jotURL private API Key Updated.', 'wp-to-twitter' );
|
525 |
} elseif ( isset( $post['clear'] ) ) {
|
526 |
update_option( 'joturlapi', '' );
|
@@ -529,7 +529,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
529 |
$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' );
|
530 |
}
|
531 |
if ( '' !== $post['joturllogin'] && isset( $post['submit'] ) ) {
|
532 |
-
update_option( 'joturllogin',
|
533 |
$message .= __( 'jotURL public API Key Updated.', 'wp-to-twitter' );
|
534 |
} elseif ( isset( $post['clear'] ) ) {
|
535 |
update_option( 'joturllogin', '' );
|
@@ -542,14 +542,14 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
542 |
if ( substr( $v, 0, 1 ) === '&' || substr( $v, 0, 1 ) === '?' ) {
|
543 |
$v = substr( $v, 1 );
|
544 |
}
|
545 |
-
update_option( 'joturl_longurl_params',
|
546 |
$message .= __( 'Long URL parameters added.', 'wp-to-twitter' );
|
547 |
} elseif ( isset( $post['clear'] ) ) {
|
548 |
update_option( 'joturl_longurl_params', '' );
|
549 |
$message = __( 'Long URL parameters deleted.', 'wp-to-twitter' );
|
550 |
}
|
551 |
if ( '' !== $post['joturl_domain'] && isset( $post['submit'] ) ) {
|
552 |
-
update_option( 'joturl_domain',
|
553 |
$message .= __( 'Custom jotURL domain saved.', 'wp-to-twitter' );
|
554 |
} elseif ( isset( $post['clear'] ) ) {
|
555 |
update_option( 'joturl_domain', '' );
|
@@ -560,7 +560,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
560 |
if ( substr( $v, 0, 1 ) === '&' || substr( $v, 0, 1 ) === '?' ) {
|
561 |
$v = substr( $v, 1 );
|
562 |
}
|
563 |
-
update_option( 'joturl_shorturl_params',
|
564 |
$message .= __( 'Short URL parameters added.', 'wp-to-twitter' );
|
565 |
} elseif ( isset( $post['clear'] ) ) {
|
566 |
update_option( 'joturl_shorturl_params', '' );
|
@@ -587,7 +587,7 @@ if ( ! function_exists( 'wpt_shorten_url' ) ) {
|
|
587 |
if ( get_option( 'jd_shortener' ) === $post['jd_shortener'] ) {
|
588 |
return;
|
589 |
}
|
590 |
-
update_option( 'jd_shortener',
|
591 |
$short = (string) get_option( 'jd_shortener' );
|
592 |
$admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
|
593 |
$admin_url = add_query_arg( 'tab', 'shortener', $admin_url );
|
482 |
if ( isset( $post['submit-type'] ) && 'yourlsapi' === $post['submit-type'] ) {
|
483 |
$message = '';
|
484 |
if ( '' !== $post['yourlstoken'] && isset( $post['submit'] ) ) {
|
485 |
+
update_option( 'yourlstoken', trim( $post['yourlstoken'] ) );
|
486 |
delete_option( 'yourlsapi' );
|
487 |
delete_option( 'yourlslogin' );
|
488 |
$message .= __( 'YOURLS signature token updated.', 'wp-to-twitter' );
|
489 |
}
|
490 |
+
update_option( 'yourlsurl', trim( $post['yourlsurl'] ) );
|
491 |
// yourls path is deprecated.
|
492 |
if ( isset( $post['yourlspath'] ) && '' !== $post['yourlspath'] ) {
|
493 |
+
update_option( 'yourlspath', trim( $post['yourlspath'] ) );
|
494 |
if ( file_exists( $post['yourlspath'] ) ) {
|
495 |
$message .= ' ' . __( 'YOURLS local server path added. ', 'wp-to-twitter' );
|
496 |
} else {
|
498 |
}
|
499 |
}
|
500 |
if ( '' !== $post['jd_keyword_format'] ) {
|
501 |
+
update_option( 'jd_keyword_format', $post['jd_keyword_format'] );
|
502 |
if ( '1' === $post['jd_keyword_format'] ) {
|
503 |
$message .= ' ' . __( 'YOURLS will use Post ID for short URL slug.', 'wp-to-twitter' );
|
504 |
} elseif ( '0' === $post['jd_keyword_format'] ) {
|
520 |
|
521 |
if ( isset( $post['submit-type'] ) && 'joturlapi' === $post['submit-type'] ) {
|
522 |
if ( '' !== $post['joturlapi'] && isset( $post['submit'] ) ) {
|
523 |
+
update_option( 'joturlapi', trim( $post['joturlapi'] ) );
|
524 |
$message = __( 'jotURL private API Key Updated.', 'wp-to-twitter' );
|
525 |
} elseif ( isset( $post['clear'] ) ) {
|
526 |
update_option( 'joturlapi', '' );
|
529 |
$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' );
|
530 |
}
|
531 |
if ( '' !== $post['joturllogin'] && isset( $post['submit'] ) ) {
|
532 |
+
update_option( 'joturllogin', trim( $post['joturllogin'] ) );
|
533 |
$message .= __( 'jotURL public API Key Updated.', 'wp-to-twitter' );
|
534 |
} elseif ( isset( $post['clear'] ) ) {
|
535 |
update_option( 'joturllogin', '' );
|
542 |
if ( substr( $v, 0, 1 ) === '&' || substr( $v, 0, 1 ) === '?' ) {
|
543 |
$v = substr( $v, 1 );
|
544 |
}
|
545 |
+
update_option( 'joturl_longurl_params', $v );
|
546 |
$message .= __( 'Long URL parameters added.', 'wp-to-twitter' );
|
547 |
} elseif ( isset( $post['clear'] ) ) {
|
548 |
update_option( 'joturl_longurl_params', '' );
|
549 |
$message = __( 'Long URL parameters deleted.', 'wp-to-twitter' );
|
550 |
}
|
551 |
if ( '' !== $post['joturl_domain'] && isset( $post['submit'] ) ) {
|
552 |
+
update_option( 'joturl_domain', $post['joturl_domain'] );
|
553 |
$message .= __( 'Custom jotURL domain saved.', 'wp-to-twitter' );
|
554 |
} elseif ( isset( $post['clear'] ) ) {
|
555 |
update_option( 'joturl_domain', '' );
|
560 |
if ( substr( $v, 0, 1 ) === '&' || substr( $v, 0, 1 ) === '?' ) {
|
561 |
$v = substr( $v, 1 );
|
562 |
}
|
563 |
+
update_option( 'joturl_shorturl_params', $v );
|
564 |
$message .= __( 'Short URL parameters added.', 'wp-to-twitter' );
|
565 |
} elseif ( isset( $post['clear'] ) ) {
|
566 |
update_option( 'joturl_shorturl_params', '' );
|
587 |
if ( get_option( 'jd_shortener' ) === $post['jd_shortener'] ) {
|
588 |
return;
|
589 |
}
|
590 |
+
update_option( 'jd_shortener', $post['jd_shortener'] );
|
591 |
$short = (string) get_option( 'jd_shortener' );
|
592 |
$admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
|
593 |
$admin_url = add_query_arg( 'tab', 'shortener', $admin_url );
|
wp-to-twitter.php
CHANGED
@@ -17,7 +17,7 @@
|
|
17 |
* License: GPL-2.0+
|
18 |
* License URI: http://www.gnu.org/license/gpl-2.0.txt
|
19 |
* Domain Path: lang
|
20 |
-
* Version: 3.
|
21 |
*/
|
22 |
|
23 |
/*
|
@@ -65,7 +65,7 @@ require_once( plugin_dir_path( __FILE__ ) . 'wpt-widget.php' );
|
|
65 |
require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
|
66 |
|
67 |
global $wpt_version;
|
68 |
-
$wpt_version = '3.
|
69 |
|
70 |
add_action( 'init', 'wpt_load_textdomain' );
|
71 |
/**
|
@@ -269,6 +269,14 @@ function wpt_check_recent_tweet( $id, $auth ) {
|
|
269 |
if ( $transient ) {
|
270 |
return true;
|
271 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
$expire = apply_filters( 'wpt_recent_tweet_threshold', 30 );
|
273 |
// if expiration is 0, don't set the transient. We don't want permanent transients.
|
274 |
if ( 0 !== $expire ) {
|
@@ -346,7 +354,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
|
|
346 |
return false;
|
347 |
} elseif ( '' === $twit || ! $twit ) {
|
348 |
wpt_mail( 'Tweet check: empty sentence', "$twit, $auth, $id, $media", $id ); // DEBUG.
|
349 |
-
$error = __( 'This tweet was blank and could not be sent to Twitter.', 'wp-
|
350 |
wpt_saves_error( $id, $auth, $twit, $error, '403-2', time() );
|
351 |
wpt_set_log( 'wpt_status_message', $id, $error );
|
352 |
|
@@ -394,6 +402,17 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
|
|
394 |
if ( empty( $connection ) ) {
|
395 |
$connection = array( 'connection' => 'undefined' );
|
396 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
$staging_mode = apply_filters( 'wpt_staging_mode', false, $auth, $id );
|
398 |
if ( ( defined( 'WPT_STAGING_MODE' ) && true === WPT_STAGING_MODE ) || $staging_mode ) {
|
399 |
// if in staging mode, we'll behave as if the Tweet succeeded, but not send it.
|
@@ -401,8 +420,18 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
|
|
401 |
$http_code = 200;
|
402 |
$notice = __( 'In Staging Mode:', 'wp-to-twitter' ) . ' ';
|
403 |
} else {
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
if ( $do_tweet ) {
|
407 |
$connection->post( $api, $status );
|
408 |
$http_code = ( $connection ) ? (int) $connection->http_code : 'failed';
|
@@ -517,8 +546,28 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
|
|
517 |
}
|
518 |
}
|
519 |
if ( ! $return ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
wpt_set_log( 'wpt_status_message', $id, $error );
|
521 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
do_action( 'wpt_tweet_posted', $connection, $id );
|
523 |
// Log the Tweet ID of the first Tweet for this post.
|
524 |
$has_tweet_id = get_post_meta( $id, '_wpt_tweet_id', true );
|
@@ -621,7 +670,23 @@ function wpt_post_info( $post_ID ) {
|
|
621 |
$cats[] = $cat->cat_name;
|
622 |
$cat_descs[] = $cat->description;
|
623 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
624 |
$cat_names = implode( ' ', apply_filters( 'wpt_twitter_category_names', $cats ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
625 |
$cat_descs = implode( ' ', apply_filters( 'wpt_twitter_category_descs', $cat_descs ) );
|
626 |
} else {
|
627 |
$category = '';
|
@@ -638,7 +703,7 @@ function wpt_post_info( $post_ID ) {
|
|
638 |
$values['postExcerpt'] = html_entity_decode( $post_excerpt, ENT_COMPAT, $encoding );
|
639 |
$thisposttitle = $post->post_title;
|
640 |
if ( '' === $thisposttitle && isset( $_POST['title'] ) ) {
|
641 |
-
$thisposttitle = $_POST['title'];
|
642 |
}
|
643 |
$thisposttitle = strip_tags( apply_filters( 'the_title', stripcslashes( $thisposttitle ), $post_ID ) );
|
644 |
// These are common sequences that may not be fixed by html_entity_decode due to double encoding.
|
@@ -687,6 +752,7 @@ function wpt_short_url( $post_id ) {
|
|
687 |
*
|
688 |
* @param int $post_ID Post ID.
|
689 |
* @param array $post_info Array of post data.
|
|
|
690 |
* @return boolean
|
691 |
*/
|
692 |
function wpt_post_with_media( $post_ID, $post_info = array() ) {
|
@@ -706,7 +772,15 @@ function wpt_post_with_media( $post_ID, $post_info = array() ) {
|
|
706 |
$return = true;
|
707 |
}
|
708 |
}
|
709 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
710 |
return apply_filters( 'wpt_upload_media', $return, $post_ID );
|
711 |
}
|
712 |
|
@@ -788,7 +862,15 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null,
|
|
788 |
return false;
|
789 |
}
|
790 |
}
|
791 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
792 |
$filter = apply_filters( 'wpt_filter_post_data', false, $_POST );
|
793 |
if ( $filter ) {
|
794 |
return false;
|
@@ -879,6 +961,19 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null,
|
|
879 |
$offset = ( $auth !== $acct ) ? apply_filters( 'wpt_random_delay', rand( 60, 480 ) ) : 0;
|
880 |
if ( wtt_oauth_test( $acct, 'verify' ) ) {
|
881 |
$time = apply_filters( 'wpt_schedule_delay', ( (int) $post_info['wpt_delay_tweet'] ) * 60, $acct );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
882 |
wp_schedule_single_event(
|
883 |
time() + $time + $offset,
|
884 |
'wpt_schedule_tweet_action',
|
@@ -923,7 +1018,21 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null,
|
|
923 |
$continue = apply_filters( 'wpt_allow_reposts', true, $i, $post_ID, $acct );
|
924 |
if ( $continue ) {
|
925 |
$retweet = apply_filters( 'wpt_set_retweet_text', $template, $i, $post_ID );
|
926 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
927 |
if ( '' === $retweet ) {
|
928 |
// If a filter sets this value to empty, exit without scheduling.
|
929 |
return $post_ID;
|
@@ -1007,6 +1116,7 @@ function wpt_twit_link( $link_id ) {
|
|
1007 |
if ( mb_strlen( $sentence ) > 118 ) {
|
1008 |
$sentence = mb_substr( $sentence, 0, 114 ) . '...';
|
1009 |
}
|
|
|
1010 |
$shrink = apply_filters( 'wptt_shorten_link', $thispostlink, $thislinkname, false, 'link' );
|
1011 |
if ( false === stripos( $sentence, '#url#' ) ) {
|
1012 |
$sentence = $sentence . ' ' . $shrink;
|
@@ -1049,7 +1159,16 @@ function wpt_generate_hash_tags( $post_ID ) {
|
|
1049 |
}
|
1050 |
$use_cats = ( '1' === get_option( 'wpt_use_cats' ) ) ? true : false;
|
1051 |
$tags = ( true === $use_cats ) ? wp_get_post_categories( $post_ID, array( 'fields' => 'all' ) ) : get_the_tags( $post_ID );
|
1052 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1053 |
if ( $tags && count( $tags ) > 0 ) {
|
1054 |
$i = 1;
|
1055 |
foreach ( $tags as $value ) {
|
@@ -1100,6 +1219,15 @@ function wpt_generate_hash_tags( $post_ID ) {
|
|
1100 |
$newtag = "@$tag";
|
1101 |
break;
|
1102 |
default:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1103 |
$newtag = apply_filters( 'wpt_tag_default', '#', $t_id ) . $tag;
|
1104 |
}
|
1105 |
if ( mb_strlen( $newtag ) > 2 && ( mb_strlen( $newtag ) <= $max_characters ) && ( $i <= $max_tags ) ) {
|
@@ -1157,8 +1285,13 @@ function wpt_add_twitter_debug_box() {
|
|
1157 |
* @param object $post Post object.
|
1158 |
*/
|
1159 |
function wpt_add_twitter_inner_box( $post ) {
|
|
|
|
|
|
|
|
|
1160 |
if ( current_user_can( 'wpt_can_tweet' ) ) {
|
1161 |
-
$is_pro = ( function_exists( 'wpt_pro_exists' ) ) ? 'pro' : 'free';
|
|
|
1162 |
<div class='wp-to-twitter <?php echo $is_pro; ?>'>
|
1163 |
<?php
|
1164 |
$tweet_status = '';
|
@@ -1516,7 +1649,7 @@ function wpt_ajax_tweet() {
|
|
1516 |
break;
|
1517 |
}
|
1518 |
// Translators: Full text of Tweet, time scheduled for.
|
1519 |
-
$return = ( 'tweet' === $action ) ? wpt_get_log( 'wpt_status_message', $post_ID ) : sprintf( __( 'Tweet scheduled: %1$s for %2$s', 'wp-
|
1520 |
echo $return;
|
1521 |
if ( count( $authors ) > 1 ) {
|
1522 |
echo '<br />';
|
@@ -1580,6 +1713,10 @@ function wpt_save_post( $id, $post ) {
|
|
1580 |
if ( empty( $_POST ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $id ) || isset( $_POST['_inline_edit'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! wpt_in_post_type( $id ) ) {
|
1581 |
return $id;
|
1582 |
}
|
|
|
|
|
|
|
|
|
1583 |
if ( isset( $_POST['_yourls_keyword'] ) ) {
|
1584 |
$yourls = sanitize_text_field( $_POST['_yourls_keyword'] );
|
1585 |
$update = update_post_meta( $id, '_yourls_keyword', $yourls );
|
@@ -1750,6 +1887,15 @@ function wpt_allowed_post_types() {
|
|
1750 |
}
|
1751 |
}
|
1752 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1753 |
return apply_filters( 'wpt_allowed_post_types', $allowed_types, $post_type_settings );
|
1754 |
}
|
1755 |
|
@@ -1779,6 +1925,15 @@ function wpt_auto_tweet_allowed( $post_id ) {
|
|
1779 |
$state = get_option( 'wpt_auto_tweet_allowed', '0' );
|
1780 |
$return = ( '0' !== $state ) ? true : false;
|
1781 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1782 |
return apply_filters( 'wpt_auto_tweet_allowed', $return, $post_id );
|
1783 |
}
|
1784 |
|
@@ -1915,8 +2070,24 @@ add_action( 'wp_enqueue_scripts', 'wpt_stylesheet' );
|
|
1915 |
* Enqueue front-end styles for Twitter Feed widget if enabled.
|
1916 |
*/
|
1917 |
function wpt_stylesheet() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1918 |
$apply = apply_filters( 'wpt_enqueue_feed_styles', true );
|
1919 |
if ( $apply ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1920 |
$file = apply_filters( 'wpt_feed_stylesheet', plugins_url( 'css/twitter-feed.css', __FILE__ ) );
|
1921 |
wp_register_style( 'wpt-twitter-feed', $file );
|
1922 |
wp_enqueue_style( 'wpt-twitter-feed' );
|
17 |
* License: GPL-2.0+
|
18 |
* License URI: http://www.gnu.org/license/gpl-2.0.txt
|
19 |
* Domain Path: lang
|
20 |
+
* Version: 3.6.0
|
21 |
*/
|
22 |
|
23 |
/*
|
65 |
require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
|
66 |
|
67 |
global $wpt_version;
|
68 |
+
$wpt_version = '3.6.0';
|
69 |
|
70 |
add_action( 'init', 'wpt_load_textdomain' );
|
71 |
/**
|
269 |
if ( $transient ) {
|
270 |
return true;
|
271 |
} else {
|
272 |
+
/**
|
273 |
+
* Modify the expiration window for recent Tweets. This value does flood control, to prevent a runaway process from sending multiple Tweets. Default `30` seconds.
|
274 |
+
*
|
275 |
+
* @hook wpt_recent_tweet_threshold
|
276 |
+
* @param {int} $expire Integer representing seconds. How long the transient will exist.
|
277 |
+
*
|
278 |
+
* @return {int}
|
279 |
+
*/
|
280 |
$expire = apply_filters( 'wpt_recent_tweet_threshold', 30 );
|
281 |
// if expiration is 0, don't set the transient. We don't want permanent transients.
|
282 |
if ( 0 !== $expire ) {
|
354 |
return false;
|
355 |
} elseif ( '' === $twit || ! $twit ) {
|
356 |
wpt_mail( 'Tweet check: empty sentence', "$twit, $auth, $id, $media", $id ); // DEBUG.
|
357 |
+
$error = __( 'This tweet was blank and could not be sent to Twitter.', 'wp-to-twitter' );
|
358 |
wpt_saves_error( $id, $auth, $twit, $error, '403-2', time() );
|
359 |
wpt_set_log( 'wpt_status_message', $id, $error );
|
360 |
|
402 |
if ( empty( $connection ) ) {
|
403 |
$connection = array( 'connection' => 'undefined' );
|
404 |
} else {
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Turn on staging mode. Staging mode is automatically turned on if WPT_STAGING_MODE constant is defined.
|
408 |
+
*
|
409 |
+
* @hook wpt_staging_mode
|
410 |
+
* @param {bool} $staging_mode True to enable staging mode.
|
411 |
+
* @param {int|bool} $auth Current author.
|
412 |
+
* @param {int} $id Post ID.
|
413 |
+
*
|
414 |
+
* @return {bool}
|
415 |
+
*/
|
416 |
$staging_mode = apply_filters( 'wpt_staging_mode', false, $auth, $id );
|
417 |
if ( ( defined( 'WPT_STAGING_MODE' ) && true === WPT_STAGING_MODE ) || $staging_mode ) {
|
418 |
// if in staging mode, we'll behave as if the Tweet succeeded, but not send it.
|
420 |
$http_code = 200;
|
421 |
$notice = __( 'In Staging Mode:', 'wp-to-twitter' ) . ' ';
|
422 |
} else {
|
423 |
+
/**
|
424 |
+
* Filter the approval to send a Tweet.
|
425 |
+
*
|
426 |
+
* @hook wpt_do_tweet
|
427 |
+
* @param {bool} $do_tweet Return false to cancel this Tweet.
|
428 |
+
* @param {int|bool} $auth Author.
|
429 |
+
* @param {int} $id Post ID.
|
430 |
+
* @param {string} $twit Tweet text.
|
431 |
+
*
|
432 |
+
* @return {bool}
|
433 |
+
*/
|
434 |
+
$do_tweet = apply_filters( 'wpt_do_tweet', true, $auth, $id, $twit );
|
435 |
if ( $do_tweet ) {
|
436 |
$connection->post( $api, $status );
|
437 |
$http_code = ( $connection ) ? (int) $connection->http_code : 'failed';
|
546 |
}
|
547 |
}
|
548 |
if ( ! $return ) {
|
549 |
+
/**
|
550 |
+
* Executes an action after posting a Tweet fails.
|
551 |
+
*
|
552 |
+
* @hook wpt_tweet_failed
|
553 |
+
*
|
554 |
+
* @since 3.6.0
|
555 |
+
*
|
556 |
+
* @param {object} $connection The current OAuth connection.
|
557 |
+
* @param {int} $id Post ID for Tweeted post.
|
558 |
+
* @param {string} $error Error message returned.
|
559 |
+
*/
|
560 |
+
do_action( 'wpt_tweet_failed', $connection, $id, $error );
|
561 |
wpt_set_log( 'wpt_status_message', $id, $error );
|
562 |
} else {
|
563 |
+
/**
|
564 |
+
* Executes an action after a Tweet is posted successfully.
|
565 |
+
*
|
566 |
+
* @hook wpt_tweet_posted
|
567 |
+
*
|
568 |
+
* @param {object} $connection The current OAuth connection.
|
569 |
+
* @param {int} $id Post ID for Tweeted post.
|
570 |
+
*/
|
571 |
do_action( 'wpt_tweet_posted', $connection, $id );
|
572 |
// Log the Tweet ID of the first Tweet for this post.
|
573 |
$has_tweet_id = get_post_meta( $id, '_wpt_tweet_id', true );
|
670 |
$cats[] = $cat->cat_name;
|
671 |
$cat_descs[] = $cat->description;
|
672 |
}
|
673 |
+
/**
|
674 |
+
* Filter the space separated list of category names in #cats#.
|
675 |
+
*
|
676 |
+
* @hook wpt_twitter_category_names
|
677 |
+
* @param {array} $cats Array of category names attached to this Tweet.
|
678 |
+
*
|
679 |
+
* @return {array}
|
680 |
+
*/
|
681 |
$cat_names = implode( ' ', apply_filters( 'wpt_twitter_category_names', $cats ) );
|
682 |
+
/**
|
683 |
+
* Filter the space separated list of category descriptions in #cat_descs#.
|
684 |
+
*
|
685 |
+
* @hook wpt_twitter_category_descs
|
686 |
+
* @param {array} $cats Array of category descriptions attached to this Tweet.
|
687 |
+
*
|
688 |
+
* @return {array}
|
689 |
+
*/
|
690 |
$cat_descs = implode( ' ', apply_filters( 'wpt_twitter_category_descs', $cat_descs ) );
|
691 |
} else {
|
692 |
$category = '';
|
703 |
$values['postExcerpt'] = html_entity_decode( $post_excerpt, ENT_COMPAT, $encoding );
|
704 |
$thisposttitle = $post->post_title;
|
705 |
if ( '' === $thisposttitle && isset( $_POST['title'] ) ) {
|
706 |
+
$thisposttitle = wp_kses_post( $_POST['title'] );
|
707 |
}
|
708 |
$thisposttitle = strip_tags( apply_filters( 'the_title', stripcslashes( $thisposttitle ), $post_ID ) );
|
709 |
// These are common sequences that may not be fixed by html_entity_decode due to double encoding.
|
752 |
*
|
753 |
* @param int $post_ID Post ID.
|
754 |
* @param array $post_info Array of post data.
|
755 |
+
*
|
756 |
* @return boolean
|
757 |
*/
|
758 |
function wpt_post_with_media( $post_ID, $post_info = array() ) {
|
772 |
$return = true;
|
773 |
}
|
774 |
}
|
775 |
+
/**
|
776 |
+
* Filter whether this post should upload media.
|
777 |
+
*
|
778 |
+
* @hook wpt_upload_media
|
779 |
+
* @param {bool} $upload True to allow this post to upload media.
|
780 |
+
* @param {int} $post_ID Post ID.
|
781 |
+
*
|
782 |
+
* @return {bool}
|
783 |
+
*/
|
784 |
return apply_filters( 'wpt_upload_media', $return, $post_ID );
|
785 |
}
|
786 |
|
862 |
return false;
|
863 |
}
|
864 |
}
|
865 |
+
/**
|
866 |
+
* Return true to ignore this post based on POST data. Default false.
|
867 |
+
*
|
868 |
+
* @hook wpt_filter_post_data
|
869 |
+
* @param {bool} $filter True if this post should not be Tweeted.
|
870 |
+
* @param {array} $post POST global.
|
871 |
+
*
|
872 |
+
* @return {bool}
|
873 |
+
*/
|
874 |
$filter = apply_filters( 'wpt_filter_post_data', false, $_POST );
|
875 |
if ( $filter ) {
|
876 |
return false;
|
961 |
$offset = ( $auth !== $acct ) ? apply_filters( 'wpt_random_delay', rand( 60, 480 ) ) : 0;
|
962 |
if ( wtt_oauth_test( $acct, 'verify' ) ) {
|
963 |
$time = apply_filters( 'wpt_schedule_delay', ( (int) $post_info['wpt_delay_tweet'] ) * 60, $acct );
|
964 |
+
|
965 |
+
/**
|
966 |
+
* Render the template of a scheduled Tweet only at the time it's sent.
|
967 |
+
*
|
968 |
+
* @hook wpt_postpone_rendering
|
969 |
+
* @param {bool} $postpone True to postpone rendering.
|
970 |
+
*
|
971 |
+
* @return {bool}
|
972 |
+
*/
|
973 |
+
$postpone_rendering = apply_filters( 'wpt_postpone_rendering', get_option( 'wpt_postpone_rendering', 'false' ) );
|
974 |
+
if ( 'false' !== $postpone_rendering ) {
|
975 |
+
$sentence = $template;
|
976 |
+
}
|
977 |
wp_schedule_single_event(
|
978 |
time() + $time + $offset,
|
979 |
'wpt_schedule_tweet_action',
|
1018 |
$continue = apply_filters( 'wpt_allow_reposts', true, $i, $post_ID, $acct );
|
1019 |
if ( $continue ) {
|
1020 |
$retweet = apply_filters( 'wpt_set_retweet_text', $template, $i, $post_ID );
|
1021 |
+
|
1022 |
+
/**
|
1023 |
+
* Render the template of a scheduled Tweet only at the time it's sent.
|
1024 |
+
*
|
1025 |
+
* @hook wpt_postpone_rendering
|
1026 |
+
* @param {bool} $postpone True to postpone rendering.
|
1027 |
+
*
|
1028 |
+
* @return {bool}
|
1029 |
+
*/
|
1030 |
+
$postpone_rendering = apply_filters( 'wpt_postpone_rendering', get_option( 'wpt_postpone_rendering', 'false' ) );
|
1031 |
+
if ( 'false' !== $postpone_rendering ) {
|
1032 |
+
$retweet = $retweet;
|
1033 |
+
} else {
|
1034 |
+
$retweet = jd_truncate_tweet( $retweet, $post_info, $post_ID, true, $acct );
|
1035 |
+
}
|
1036 |
if ( '' === $retweet ) {
|
1037 |
// If a filter sets this value to empty, exit without scheduling.
|
1038 |
return $post_ID;
|
1116 |
if ( mb_strlen( $sentence ) > 118 ) {
|
1117 |
$sentence = mb_substr( $sentence, 0, 114 ) . '...';
|
1118 |
}
|
1119 |
+
|
1120 |
$shrink = apply_filters( 'wptt_shorten_link', $thispostlink, $thislinkname, false, 'link' );
|
1121 |
if ( false === stripos( $sentence, '#url#' ) ) {
|
1122 |
$sentence = $sentence . ' ' . $shrink;
|
1159 |
}
|
1160 |
$use_cats = ( '1' === get_option( 'wpt_use_cats' ) ) ? true : false;
|
1161 |
$tags = ( true === $use_cats ) ? wp_get_post_categories( $post_ID, array( 'fields' => 'all' ) ) : get_the_tags( $post_ID );
|
1162 |
+
/**
|
1163 |
+
* Change the taxonomy used by default to generate post tags. Array of terms attached to post.
|
1164 |
+
*
|
1165 |
+
* @hook wpt_hash_source
|
1166 |
+
* @param {array} $tags Array of post terms.
|
1167 |
+
* @param {int} $post_ID Post ID.
|
1168 |
+
*
|
1169 |
+
* @return {array}
|
1170 |
+
*/
|
1171 |
+
$tags = apply_filters( 'wpt_hash_source', $tags, $post_ID );
|
1172 |
if ( $tags && count( $tags ) > 0 ) {
|
1173 |
$i = 1;
|
1174 |
foreach ( $tags as $value ) {
|
1219 |
$newtag = "@$tag";
|
1220 |
break;
|
1221 |
default:
|
1222 |
+
/**
|
1223 |
+
* Change the default tag character. Default '#'.
|
1224 |
+
*
|
1225 |
+
* @hook wpt_tag_default
|
1226 |
+
* @param {string} $char Character used to convert tags into hashtags.
|
1227 |
+
* @param {int} $t_id Term ID.
|
1228 |
+
*
|
1229 |
+
* @return {string}
|
1230 |
+
*/
|
1231 |
$newtag = apply_filters( 'wpt_tag_default', '#', $t_id ) . $tag;
|
1232 |
}
|
1233 |
if ( mb_strlen( $newtag ) > 2 && ( mb_strlen( $newtag ) <= $max_characters ) && ( $i <= $max_tags ) ) {
|
1285 |
* @param object $post Post object.
|
1286 |
*/
|
1287 |
function wpt_add_twitter_inner_box( $post ) {
|
1288 |
+
$nonce = wp_create_nonce( 'wp-to-twitter-nonce' );
|
1289 |
+
?>
|
1290 |
+
<div><input type="hidden" name="wp_to_twitter_nonce" value="<?php echo $nonce; ?>"></div>
|
1291 |
+
<?php
|
1292 |
if ( current_user_can( 'wpt_can_tweet' ) ) {
|
1293 |
+
$is_pro = ( function_exists( 'wpt_pro_exists' ) ) ? 'pro' : 'free';
|
1294 |
+
?>
|
1295 |
<div class='wp-to-twitter <?php echo $is_pro; ?>'>
|
1296 |
<?php
|
1297 |
$tweet_status = '';
|
1649 |
break;
|
1650 |
}
|
1651 |
// Translators: Full text of Tweet, time scheduled for.
|
1652 |
+
$return = ( 'tweet' === $action ) ? wpt_get_log( 'wpt_status_message', $post_ID ) : sprintf( __( 'Tweet scheduled: %1$s for %2$s', 'wp-to-twitter' ), '"' . $sentence . '"', $print_schedule );
|
1653 |
echo $return;
|
1654 |
if ( count( $authors ) > 1 ) {
|
1655 |
echo '<br />';
|
1713 |
if ( empty( $_POST ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $id ) || isset( $_POST['_inline_edit'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! wpt_in_post_type( $id ) ) {
|
1714 |
return $id;
|
1715 |
}
|
1716 |
+
$nonce = ( isset( $_POST['wp_to_twitter_nonce'] ) ) ? $_POST['wp_to_twitter_nonce'] : false;
|
1717 |
+
if ( ! ( $nonce && wp_verify_nonce( $nonce, 'wp-to-twitter-nonce' ) ) ) {
|
1718 |
+
die( 'Security check failed' );
|
1719 |
+
}
|
1720 |
if ( isset( $_POST['_yourls_keyword'] ) ) {
|
1721 |
$yourls = sanitize_text_field( $_POST['_yourls_keyword'] );
|
1722 |
$update = update_post_meta( $id, '_yourls_keyword', $yourls );
|
1887 |
}
|
1888 |
}
|
1889 |
|
1890 |
+
/**
|
1891 |
+
* Return array of post types that can be sent as Tweets.
|
1892 |
+
*
|
1893 |
+
* @hook wpt_allowed_post_types
|
1894 |
+
* @param {array} $types Array of post type names enabled for Tweets either when editing or publishing.
|
1895 |
+
* @param {array} $post_type_settings Multidimensional array of post types and post type settings.
|
1896 |
+
*
|
1897 |
+
* @return {array}
|
1898 |
+
*/
|
1899 |
return apply_filters( 'wpt_allowed_post_types', $allowed_types, $post_type_settings );
|
1900 |
}
|
1901 |
|
1925 |
$state = get_option( 'wpt_auto_tweet_allowed', '0' );
|
1926 |
$return = ( '0' !== $state ) ? true : false;
|
1927 |
|
1928 |
+
/**
|
1929 |
+
* Return true if auto tweeting of old posts is enabled.
|
1930 |
+
*
|
1931 |
+
* @hook wpt_auto_tweet_allowed
|
1932 |
+
* @param {bool} $return true if enabled.
|
1933 |
+
* @param {int} $post_id Post ID.
|
1934 |
+
*
|
1935 |
+
* @return {bool}
|
1936 |
+
*/
|
1937 |
return apply_filters( 'wpt_auto_tweet_allowed', $return, $post_id );
|
1938 |
}
|
1939 |
|
2070 |
* Enqueue front-end styles for Twitter Feed widget if enabled.
|
2071 |
*/
|
2072 |
function wpt_stylesheet() {
|
2073 |
+
/**
|
2074 |
+
* Disable WP to Twitter feeds stylesheet. Styles the Twitter Feed widgets.
|
2075 |
+
*
|
2076 |
+
* @hook wpt_enqueue_feed_styles
|
2077 |
+
* @param {bool} $apply False to disable.
|
2078 |
+
*
|
2079 |
+
* @return {bool}
|
2080 |
+
*/
|
2081 |
$apply = apply_filters( 'wpt_enqueue_feed_styles', true );
|
2082 |
if ( $apply ) {
|
2083 |
+
/**
|
2084 |
+
* Replace the WP to Twitter feeds stylesheet.
|
2085 |
+
*
|
2086 |
+
* @hook wpt_feed_stylesheet
|
2087 |
+
* @param {string} $file URL to stylesheet.
|
2088 |
+
*
|
2089 |
+
* @return {string}
|
2090 |
+
*/
|
2091 |
$file = apply_filters( 'wpt_feed_stylesheet', plugins_url( 'css/twitter-feed.css', __FILE__ ) );
|
2092 |
wp_register_style( 'wpt-twitter-feed', $file );
|
2093 |
wp_enqueue_style( 'wpt-twitter-feed' );
|
wpt-functions.php
CHANGED
@@ -676,7 +676,7 @@ $plugins_string
|
|
676 |
if ( ! wp_verify_nonce( $nonce, 'wp-to-twitter-nonce' ) ) {
|
677 |
die( 'Security check failed' );
|
678 |
}
|
679 |
-
$request = ( ! empty( $_POST['support_request'] ) ) ? stripslashes( $_POST['support_request'] ) : false;
|
680 |
$has_donated = ( isset( $_POST['has_donated'] ) ) ? 'Donor' : 'No donation';
|
681 |
$has_read_faq = ( isset( $_POST['has_read_faq'] ) ) ? 'Read FAQ' : false;
|
682 |
if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
|
@@ -691,7 +691,7 @@ $plugins_string
|
|
691 |
if ( 'www.' === substr( $sitename, 0, 4 ) ) {
|
692 |
$sitename = substr( $sitename, 4 );
|
693 |
}
|
694 |
-
$response_email = ( isset( $_POST['response_email'] ) ) ? $_POST['response_email'] : false;
|
695 |
$from_email = 'wordpress@' . $sitename;
|
696 |
$from = "From: $current_user->display_name <$response_email>\r\nReply-to: $current_user->display_name <$response_email>\r\n";
|
697 |
|
676 |
if ( ! wp_verify_nonce( $nonce, 'wp-to-twitter-nonce' ) ) {
|
677 |
die( 'Security check failed' );
|
678 |
}
|
679 |
+
$request = ( ! empty( $_POST['support_request'] ) ) ? stripslashes( sanitize_textarea_field( $_POST['support_request'] ) ) : false;
|
680 |
$has_donated = ( isset( $_POST['has_donated'] ) ) ? 'Donor' : 'No donation';
|
681 |
$has_read_faq = ( isset( $_POST['has_read_faq'] ) ) ? 'Read FAQ' : false;
|
682 |
if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) {
|
691 |
if ( 'www.' === substr( $sitename, 0, 4 ) ) {
|
692 |
$sitename = substr( $sitename, 4 );
|
693 |
}
|
694 |
+
$response_email = ( isset( $_POST['response_email'] ) ) ? sanitize_email( $_POST['response_email'] ) : false;
|
695 |
$from_email = 'wordpress@' . $sitename;
|
696 |
$from = "From: $current_user->display_name <$response_email>\r\nReply-to: $current_user->display_name <$response_email>\r\n";
|
697 |
|
wpt-rate-limiting.php
CHANGED
@@ -150,7 +150,7 @@ function wpt_term_rate_limits() {
|
|
150 |
*/
|
151 |
function wpt_save_term_rate_limit( $term_id, $tax_id ) {
|
152 |
$limits = get_option( 'wpt_rate_limit' );
|
153 |
-
$option_set = isset( $_POST['wpt_rate_limit'] ) ? $_POST['wpt_rate_limit'] : wpt_default_rate_limit( $term_id );
|
154 |
if ( isset( $_POST['taxonomy'] ) ) {
|
155 |
if ( isset( $_POST['wpt_rate_limit'] ) ) {
|
156 |
$limits[ $term_id ] = $option_set;
|
@@ -172,7 +172,7 @@ function wpt_edit_term_rate_limit( $term, $taxonomy ) {
|
|
172 |
?>
|
173 |
<tr class="form-field">
|
174 |
<th valign="top" scope="row">
|
175 |
-
<label for="wpt_rate_limit"><?php _e( 'Max Tweets per hour on this term', 'wp-
|
176 |
</th>
|
177 |
<td>
|
178 |
<input type='number' size='4' value='<?php echo esc_attr( $option_set ); ?>' name='wpt_rate_limit' id='wpt_rate_limit' />
|
@@ -190,7 +190,7 @@ function wpt_add_term_rate_limit( $term ) {
|
|
190 |
$default = wpt_default_rate_limit();
|
191 |
?>
|
192 |
<div class="form-field">
|
193 |
-
<label for="wpt_rate_limit"><?php _e( 'Max Tweets per hour on this term', 'wp-
|
194 |
</div>
|
195 |
<?php
|
196 |
}
|
150 |
*/
|
151 |
function wpt_save_term_rate_limit( $term_id, $tax_id ) {
|
152 |
$limits = get_option( 'wpt_rate_limit' );
|
153 |
+
$option_set = isset( $_POST['wpt_rate_limit'] ) ? sanitize_text_field( $_POST['wpt_rate_limit'] ) : wpt_default_rate_limit( $term_id );
|
154 |
if ( isset( $_POST['taxonomy'] ) ) {
|
155 |
if ( isset( $_POST['wpt_rate_limit'] ) ) {
|
156 |
$limits[ $term_id ] = $option_set;
|
172 |
?>
|
173 |
<tr class="form-field">
|
174 |
<th valign="top" scope="row">
|
175 |
+
<label for="wpt_rate_limit"><?php _e( 'Max Tweets per hour on this term', 'wp-to-twitter' ); ?></label>
|
176 |
</th>
|
177 |
<td>
|
178 |
<input type='number' size='4' value='<?php echo esc_attr( $option_set ); ?>' name='wpt_rate_limit' id='wpt_rate_limit' />
|
190 |
$default = wpt_default_rate_limit();
|
191 |
?>
|
192 |
<div class="form-field">
|
193 |
+
<label for="wpt_rate_limit"><?php _e( 'Max Tweets per hour on this term', 'wp-to-twitter' ); ?></label> <input type='number' value='<?php echo esc_attr( $default ); ?>' id='wpt_rate_limit' name='wpt_rate_limit' />
|
194 |
</div>
|
195 |
<?php
|
196 |
}
|
wpt-truncate.php
CHANGED
@@ -65,7 +65,7 @@ function wpt_filter_urls( $tweet, $post_ID ) {
|
|
65 |
* @param array $post Post data.
|
66 |
* @param int $post_ID Post ID.
|
67 |
* @param boolean $retweet Is this a retweet.
|
68 |
-
* @param boolean $ref Reference.
|
69 |
*
|
70 |
* @return string New text.
|
71 |
*/
|
@@ -73,11 +73,20 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
|
|
73 |
// media file no longer needs accounting in shortening. 9/22/2016.
|
74 |
$maxlength = wpt_max_length();
|
75 |
$length = $maxlength['base_length'];
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
// Add custom append/prepend fields to Tweet text.
|
83 |
if ( '' !== get_option( 'jd_twit_prepend', '' ) && '' !== $tweet ) {
|
@@ -90,6 +99,18 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
|
|
90 |
// there are no tags in this Tweet. Truncate and return.
|
91 |
if ( ! wpt_has_tags( $tweet ) ) {
|
92 |
$post_tweet = mb_substr( $tweet, 0, $length, $encoding );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
return apply_filters( 'wpt_custom_truncate', $post_tweet, $tweet, $post_ID, $retweet, 1 );
|
94 |
}
|
95 |
|
@@ -107,7 +128,18 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
|
|
107 |
if ( mb_strlen( wpt_normalize( $post_tweet ) ) > $length + 1 ) {
|
108 |
$post_tweet = mb_substr( $post_tweet, 0, $length, $encoding );
|
109 |
}
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
return apply_filters( 'wpt_custom_truncate', $post_tweet, $tweet, $post_ID, $retweet, 2 ); // return early if all is well.
|
112 |
} else {
|
113 |
$has_excerpt_tag = wpt_has( $tweet, '#post#' );
|
@@ -181,6 +213,17 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
|
|
181 |
$last_space = strrpos( $new_value, ' ' );
|
182 |
$new_value = mb_substr( $new_value, 0, $last_space, $encoding );
|
183 |
// If you want to add something like an ellipsis after truncation, use this filter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
$new_value = apply_filters( 'wpt_filter_truncated_value', $new_value, $key, $old_value );
|
185 |
}
|
186 |
$post_tweet = str_ireplace( $old_value, $new_value, $post_tweet );
|
@@ -225,7 +268,18 @@ function jd_truncate_tweet( $tweet, $post, $post_ID, $retweet = false, $ref = fa
|
|
225 |
}
|
226 |
}
|
227 |
}
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
return apply_filters( 'wpt_custom_truncate', $post_tweet, $tweet, $post_ID, $retweet, 3 );
|
230 |
}
|
231 |
|
@@ -295,6 +349,14 @@ function wpt_remove_tag( $key ) {
|
|
295 |
* @return array tags.
|
296 |
*/
|
297 |
function wpt_tags() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
return apply_filters( 'wpt_tags', array( 'url', 'title', 'blog', 'post', 'category', 'categories', 'date', 'author', 'displayname', 'tags', 'modified', 'reference', 'account', '@', 'cat_desc', 'longurl' ) );
|
299 |
}
|
300 |
|
65 |
* @param array $post Post data.
|
66 |
* @param int $post_ID Post ID.
|
67 |
* @param boolean $retweet Is this a retweet.
|
68 |
+
* @param boolean $ref Twitter author Reference.
|
69 |
*
|
70 |
* @return string New text.
|
71 |
*/
|
73 |
// media file no longer needs accounting in shortening. 9/22/2016.
|
74 |
$maxlength = wpt_max_length();
|
75 |
$length = $maxlength['base_length'];
|
76 |
+
/**
|
77 |
+
* Filter a Tweet template prior to parsing tags.
|
78 |
+
*
|
79 |
+
* @hook wpt_tweet_sentence
|
80 |
+
* @param {string} $tweet Template for this Tweet.
|
81 |
+
* @param {int} $post_ID Post ID.
|
82 |
+
*
|
83 |
+
* @return {string}
|
84 |
+
*/
|
85 |
+
$tweet = apply_filters( 'wpt_tweet_sentence', $tweet, $post_ID );
|
86 |
+
$tweet = trim( wpt_custom_shortcodes( $tweet, $post_ID ) );
|
87 |
+
$tweet = trim( wpt_user_meta_shortcodes( $tweet, $post['authId'] ) );
|
88 |
+
$encoding = ( 'UTF-8' !== get_option( 'blog_charset' ) && '' !== get_option( 'blog_charset', '' ) ) ? get_option( 'blog_charset' ) : 'UTF-8';
|
89 |
+
$diff = 0;
|
90 |
|
91 |
// Add custom append/prepend fields to Tweet text.
|
92 |
if ( '' !== get_option( 'jd_twit_prepend', '' ) && '' !== $tweet ) {
|
99 |
// there are no tags in this Tweet. Truncate and return.
|
100 |
if ( ! wpt_has_tags( $tweet ) ) {
|
101 |
$post_tweet = mb_substr( $tweet, 0, $length, $encoding );
|
102 |
+
/**
|
103 |
+
* Filter a Tweet template that does not contain any WP to Twitter template tags.
|
104 |
+
*
|
105 |
+
* @hook wpt_custom_truncate
|
106 |
+
* @param {string} $post_tweet Text to Tweet truncated to maximum allowed length.
|
107 |
+
* @param {string} $tweet Original passed text.
|
108 |
+
* @param {int} $post_ID Post ID.
|
109 |
+
* @param {bool} $retweet Boolean flag that indicates whether this is being reposted.
|
110 |
+
* @param {int} $reference Pass reference (1).
|
111 |
+
*
|
112 |
+
* @return {string}
|
113 |
+
*/
|
114 |
return apply_filters( 'wpt_custom_truncate', $post_tweet, $tweet, $post_ID, $retweet, 1 );
|
115 |
}
|
116 |
|
128 |
if ( mb_strlen( wpt_normalize( $post_tweet ) ) > $length + 1 ) {
|
129 |
$post_tweet = mb_substr( $post_tweet, 0, $length, $encoding );
|
130 |
}
|
131 |
+
/**
|
132 |
+
* Filter a Tweet template after tags have been parsed but prior to truncating for length.
|
133 |
+
*
|
134 |
+
* @hook wpt_custom_truncate
|
135 |
+
* @param {string} $post_tweet Text to Tweet truncated to maximum allowed length.
|
136 |
+
* @param {string} $tweet Original passed text.
|
137 |
+
* @param {int} $post_ID Post ID.
|
138 |
+
* @param {bool} $retweet Boolean flag that indicates whether this is being reposted.
|
139 |
+
* @param {int} $reference Pass reference (2).
|
140 |
+
*
|
141 |
+
* @return {string}
|
142 |
+
*/
|
143 |
return apply_filters( 'wpt_custom_truncate', $post_tweet, $tweet, $post_ID, $retweet, 2 ); // return early if all is well.
|
144 |
} else {
|
145 |
$has_excerpt_tag = wpt_has( $tweet, '#post#' );
|
213 |
$last_space = strrpos( $new_value, ' ' );
|
214 |
$new_value = mb_substr( $new_value, 0, $last_space, $encoding );
|
215 |
// If you want to add something like an ellipsis after truncation, use this filter.
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Filter a template tag value after truncation. If a value like an excerpt or post content has been truncated, you can modify the output using this filter.
|
219 |
+
*
|
220 |
+
* @hook wpt_filter_truncated_value
|
221 |
+
* @param {string} $new_value Text truncated to maximum allowed length.
|
222 |
+
* @param {string} $key Template tag.
|
223 |
+
* @param {string} $old_value Text prior to truncation.
|
224 |
+
*
|
225 |
+
* @return {string}
|
226 |
+
*/
|
227 |
$new_value = apply_filters( 'wpt_filter_truncated_value', $new_value, $key, $old_value );
|
228 |
}
|
229 |
$post_tweet = str_ireplace( $old_value, $new_value, $post_tweet );
|
268 |
}
|
269 |
}
|
270 |
}
|
271 |
+
/**
|
272 |
+
* Filter a Tweet template after all content checks are completed.
|
273 |
+
*
|
274 |
+
* @hook wpt_custom_truncate
|
275 |
+
* @param {string} $post_tweet Text to Tweet truncated to maximum allowed length.
|
276 |
+
* @param {string} $tweet Original passed text.
|
277 |
+
* @param {int} $post_ID Post ID.
|
278 |
+
* @param {bool} $retweet Boolean flag that indicates whether this is being reposted.
|
279 |
+
* @param {int} $reference Pass reference (3).
|
280 |
+
*
|
281 |
+
* @return {string}
|
282 |
+
*/
|
283 |
return apply_filters( 'wpt_custom_truncate', $post_tweet, $tweet, $post_ID, $retweet, 3 );
|
284 |
}
|
285 |
|
349 |
* @return array tags.
|
350 |
*/
|
351 |
function wpt_tags() {
|
352 |
+
/**
|
353 |
+
* Add a new template tag placeholder.
|
354 |
+
*
|
355 |
+
* @hook wpt_tags
|
356 |
+
* @param {array} $tags Array of strings for each tag, e.g. 'blog' for #blog#.
|
357 |
+
*
|
358 |
+
* @return {array}
|
359 |
+
*/
|
360 |
return apply_filters( 'wpt_tags', array( 'url', 'title', 'blog', 'post', 'category', 'categories', 'date', 'author', 'displayname', 'tags', 'modified', 'reference', 'account', '@', 'cat_desc', 'longurl' ) );
|
361 |
}
|
362 |
|