WP to Twitter - Version 3.5.2

Version Description

  • Bug fix: missing CSS for headings.
  • Bug fix: Add option to allow autoposting to work. Option will break manual posting, however.
Download this release

Release Info

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

Code changes from version 3.5.0 to 3.5.2

classes/class-wpt-twitterfeed.php CHANGED
@@ -257,8 +257,8 @@ class WPT_TwitterFeed {
257
  $options = array_merge(
258
  $options,
259
  array(
260
- 'screen_name' => $screenname,
261
- 'count' => 20,
262
  )
263
  );
264
 
257
  $options = array_merge(
258
  $options,
259
  array(
260
+ 'screen_name' => $screenname,
261
+ 'count' => 20,
262
  )
263
  );
264
 
classes/class-wpt-twitteroauth.php CHANGED
@@ -368,7 +368,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
368
  $metadata_api = 'https://upload.twitter.com/1.1/media/metadata/create.json';
369
  $alt_text = get_post_meta( $attachment, '_wp_attachment_image_alt', true );
370
  $alt_text = apply_filters( 'wpt_uploaded_image_alt', $alt_text, $attachment );
371
- if ( '' != $alt_text ) {
372
  $image_alt = json_encode(
373
  array(
374
  'media_id' => $media_id,
@@ -377,7 +377,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
377
  ),
378
  )
379
  );
380
- $post_alt = $tmh_oauth->request(
381
  'POST',
382
  $metadata_api,
383
  $image_alt,
368
  $metadata_api = 'https://upload.twitter.com/1.1/media/metadata/create.json';
369
  $alt_text = get_post_meta( $attachment, '_wp_attachment_image_alt', true );
370
  $alt_text = apply_filters( 'wpt_uploaded_image_alt', $alt_text, $attachment );
371
+ if ( '' !== $alt_text ) {
372
  $image_alt = json_encode(
373
  array(
374
  'media_id' => $media_id,
377
  ),
378
  )
379
  );
380
+ $post_alt = $tmh_oauth->request(
381
  'POST',
382
  $metadata_api,
383
  $image_alt,
css/styles.css CHANGED
@@ -167,6 +167,14 @@ label[for="wpt_license_key"] {
167
  margin-left: 2em;
168
  }
169
 
 
 
 
 
 
 
 
 
170
  #wp-to-twitter .wpt-pro-tab {
171
  background: #213e7f;
172
  color: #fff;
167
  margin-left: 2em;
168
  }
169
 
170
+ #wp-to-twitter .postbox > h2,
171
+ #wpt_settings_page .postbox > h2 {
172
+ font-size: 14px;
173
+ padding: 8px 12px;
174
+ margin: 0;
175
+ line-height: 1.4;
176
+ }
177
+
178
  #wp-to-twitter .wpt-pro-tab {
179
  background: #213e7f;
180
  color: #fff;
js/tabs.js CHANGED
@@ -1,8 +1,8 @@
1
  jQuery(document).ready(function ($) {
2
  var tabs = $('.wpt-settings .wptab').length;
3
- $('.wpt-settings .tabs a[href="#' + firstItem + '"]').addClass('active').attr( 'aria-selected', 'true' );
4
  if (tabs > 1) {
5
- $('.wpt-settings .wptab').not('#' + firstItem).hide();
6
  $('.wpt-settings .tabs a').on('click', function (e) {
7
  e.preventDefault();
8
  $('.wpt-settings .tabs a').removeClass('active').attr( 'aria-selected', 'false' );
@@ -14,9 +14,9 @@ jQuery(document).ready(function ($) {
14
  };
15
 
16
  var permissions = $('.wpt-permissions .wptab').length;
17
- $('.wpt-permissions .tabs a[href="#' + firstPerm + '"]').addClass('active').attr( 'aria-selected', 'true' );
18
  if (permissions > 1) {
19
- $('.wpt-permissions .wptab').not('#' + firstPerm).hide();
20
  $('.wpt-permissions .tabs a').on('click', function (e) {
21
  e.preventDefault();
22
  $('.wpt-permissions .tabs a').removeClass('active').attr( 'aria-selected', 'false' );
1
  jQuery(document).ready(function ($) {
2
  var tabs = $('.wpt-settings .wptab').length;
3
+ $('.wpt-settings .tabs a[href="#' + wpt.firstItem + '"]').addClass('active').attr( 'aria-selected', 'true' );
4
  if (tabs > 1) {
5
+ $('.wpt-settings .wptab').not('#' + wpt.firstItem).hide();
6
  $('.wpt-settings .tabs a').on('click', function (e) {
7
  e.preventDefault();
8
  $('.wpt-settings .tabs a').removeClass('active').attr( 'aria-selected', 'false' );
14
  };
15
 
16
  var permissions = $('.wpt-permissions .wptab').length;
17
+ $('.wpt-permissions .tabs a[href="#' + wpt.firstPerm + '"]').addClass('active').attr( 'aria-selected', 'true' );
18
  if (permissions > 1) {
19
+ $('.wpt-permissions .wptab').not('#' + wpt.firstPerm).hide();
20
  $('.wpt-permissions .tabs a').on('click', function (e) {
21
  e.preventDefault();
22
  $('.wpt-permissions .tabs a').removeClass('active').attr( 'aria-selected', 'false' );
readme.txt CHANGED
@@ -2,12 +2,12 @@
2
  Contributors: joedolson
3
  Donate link: http://www.joedolson.com/donate/
4
  Tags: twitter, microblogging, bitly, yourls, redirect, shortener, post, links, social, sharing, media, tweet
5
- Requires at least: 4.4
6
- Tested up to: 5.6
7
  Requires PHP: 5.6
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
- Stable tag: 3.5.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,6 +64,22 @@ Check out my <a href="https://github.com/joedolson/plugin-extensions/tree/master
64
 
65
  == Changelog ==
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  = 3.5.0 =
68
 
69
  * Update connection instructions to match Project & App structure at Twitter.
@@ -514,17 +530,15 @@ WP to Twitter has always followed the principle that you are the owner of your o
514
 
515
  = How can I help you make WP to Twitter a better plug-in? =
516
 
517
- Writing and maintaining a plug-in is a lot of work. You can help me by providing detailed support requests (which saves me time), or by providing financial support, either via my [plug-in donations page](https://www.joedolson.com/donate/) or by [upgrading to WP Tweets Pro](http://www.wptweetspro.com/wp-tweets-pro). Believe me, your donation really makes a difference!
518
 
519
  == Screenshots ==
520
 
521
- 1. WP to Twitter OAuth settings.
522
- 2. WP to Twitter post meta box settings.
523
- 3. WP to Twitter post meta box with WP Tweets PRO.
524
  4. WP Tweets PRO settings.
525
- 5. Twitter Feed
526
- 6. Settings
527
 
528
  == Upgrade Notice ==
529
-
530
- * 3.4.0: Removal of functions deprecated in January 2017 & March 2018. May break older Pro installations.
2
  Contributors: joedolson
3
  Donate link: http://www.joedolson.com/donate/
4
  Tags: twitter, microblogging, bitly, yourls, redirect, shortener, post, links, social, sharing, media, tweet
5
+ Requires at least: 4.9.8
6
+ Tested up to: 5.7
7
  Requires PHP: 5.6
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
+ Stable tag: 3.5.2
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
64
 
65
  == Changelog ==
66
 
67
+ = 3.5.2 =
68
+
69
+ * Bug fix: missing CSS for headings.
70
+ * Bug fix: Add option to allow autoposting to work. Option will break manual posting, however.
71
+
72
+ = 3.5.1 =
73
+
74
+ * Bug fix: Run metadate save on wp_after_insert_post, as well, when it exists.
75
+ * Bug fix: Incorrect value passed to wp_localize_script.
76
+ * Move PHP tests from Travis-CI to GitHub Actions.
77
+ * Fix results of PHP testing.
78
+ * Minor clean-up in debugging.
79
+ * Update screenshots for repository.
80
+ * Changed WP requirement to >= 4.9.8
81
+ * Bug fix: Post meta saving after post published in block editor
82
+
83
  = 3.5.0 =
84
 
85
  * Update connection instructions to match Project & App structure at Twitter.
530
 
531
  = How can I help you make WP to Twitter a better plug-in? =
532
 
533
+ Writing and maintaining a plug-in is a lot of work. You can help me by providing detailed support requests (which saves me time), or by providing financial support, either via my [plug-in donations page](https://www.joedolson.com/donate/) or by [upgrading to WP Tweets Pro](http://www.wptweetspro.com/wp-tweets-pro). Believe me, your support really makes a difference!
534
 
535
  == Screenshots ==
536
 
537
+ 1. WP to Twitter Set up.
538
+ 2. WP to Twitter Post Meta box.
539
+ 3. WP to Twitter post meta box with WP Tweets PRO active.
540
  4. WP Tweets PRO settings.
541
+ 5. Example Twitter Feed (Twenty Nineteen)
542
+ 6. Basic WP to Twitter Settings
543
 
544
  == Upgrade Notice ==
 
 
uninstall.php CHANGED
@@ -70,6 +70,8 @@ if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
70
  delete_option( 'jd_twit_custom_url' );
71
  delete_option( 'jd_shortener' );
72
  delete_option( 'jd_strip_nonan' );
 
 
73
 
74
  delete_option( 'jd_individual_twitter_users' );
75
  delete_option( 'use_tags_as_hashtags' );
70
  delete_option( 'jd_twit_custom_url' );
71
  delete_option( 'jd_shortener' );
72
  delete_option( 'jd_strip_nonan' );
73
+ delete_option( 'wpt_auto_tweet_allowed' );
74
+ delete_option( 'wpt_tweet_length' );
75
 
76
  delete_option( 'jd_individual_twitter_users' );
77
  delete_option( 'use_tags_as_hashtags' );
wp-to-twitter-manager.php CHANGED
@@ -293,7 +293,10 @@ function wpt_update_settings() {
293
  <?php _e( 'The core WP to Twitter plug-in is free, and has been since 2008. WP Tweets Pro sales help keep this going, but they don\'t cover everything.', 'wp-to-twitter' ); ?>
294
  </p>
295
  <p>
296
- <?php _e( 'I know that not everybody has a use for the features supported by WP Tweets Pro. If you\'re happy with what you\'ve found in WP to Twitter, you can still support me - either by <a href="%1$s">making a donation</a> or by <a href="%2$s">writing a review</a>. If you have the time or money, I\'ll sincerely appreciate anything you can do!', 'wp-to-twitter' ); ?>
 
 
 
297
  </p>
298
  </div>
299
  </div>
@@ -317,6 +320,7 @@ function wpt_update_settings() {
317
  <div>
318
  <?php
319
  echo apply_filters( 'wpt_tweet_length', '' );
 
320
  echo apply_filters( 'wpt_pick_shortener', '' );
321
  $post_types = get_post_types( array(), 'objects' );
322
  $wpt_settings = get_option( 'wpt_post_types' );
@@ -1008,3 +1012,32 @@ function wpt_set_tweet_length() {
1008
  update_option( 'wpt_tweet_length', intval( $_POST['wpt_tweet_length'] ) );
1009
  }
1010
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  <?php _e( 'The core WP to Twitter plug-in is free, and has been since 2008. WP Tweets Pro sales help keep this going, but they don\'t cover everything.', 'wp-to-twitter' ); ?>
294
  </p>
295
  <p>
296
+ <?php
297
+ // Translators: Donation link, review link.
298
+ sprintf( __( 'I know that not everybody has a use for the features supported by WP Tweets Pro. If you\'re happy with what you\'ve found in WP to Twitter, you can still support me - either by <a href="%1$s">making a donation</a> or by <a href="%2$s">writing a review</a>. If you have the time or money, I\'ll sincerely appreciate anything you can do!', 'wp-to-twitter' ), 'https://www.joedolson.com/donate/', 'https://wordpress.org/support/plugin/wp-to-twitter/reviews/#new-post' );
299
+ ?>
300
  </p>
301
  </div>
302
  </div>
320
  <div>
321
  <?php
322
  echo apply_filters( 'wpt_tweet_length', '' );
323
+ echo apply_filters( 'wpt_auto_tweet', '' );
324
  echo apply_filters( 'wpt_pick_shortener', '' );
325
  $post_types = get_post_types( array(), 'objects' );
326
  $wpt_settings = get_option( 'wpt_post_types' );
1012
  update_option( 'wpt_tweet_length', intval( $_POST['wpt_tweet_length'] ) );
1013
  }
1014
  }
1015
+
1016
+
1017
+ add_filter( 'wpt_auto_tweet', 'wpt_auto_tweet' );
1018
+ /**
1019
+ * Add control to set maximum length for a Tweet.
1020
+ *
1021
+ * @return string HTML control.
1022
+ */
1023
+ function wpt_auto_tweet() {
1024
+ $allow = ( '0' === get_option( 'wpt_auto_tweet_allowed', '0' ) ) ? false : true;
1025
+ $note = ( $allow ) ? '<strong id="auto_tweet_note">(' . __( 'When publishing manually, you will need to save drafts prior to publishing to support WP to Twitter metabox options.', 'wp-to-twitter' ) . ')</strong>' : '';
1026
+ $control = "<p class='wpt_auto_tweet_allowed'>
1027
+ <input type='checkbox' value='1' " . checked( $allow, true, false ) . "id='wpt_auto_tweet_allowed' name='wpt_auto_tweet_allowed' aria-describedby='auto_tweet_note' /> <label for='wpt_auto_tweet_allowed'>" . __( 'Allow Tweets from Post Importers', 'wp-to-twitter' ) . "</label> $note
1028
+ </p>";
1029
+
1030
+ return $control;
1031
+ }
1032
+
1033
+ add_filter( 'wpt_settings', 'wpt_set_auto_tweet_allowed' );
1034
+ /**
1035
+ * Set the automatic Tweet allowed parameter..
1036
+ */
1037
+ function wpt_set_auto_tweet_allowed() {
1038
+ if ( isset( $_POST['wpt_auto_tweet_allowed'] ) ) {
1039
+ update_option( 'wpt_auto_tweet_allowed', '1' );
1040
+ } else {
1041
+ delete_option( 'wpt_auto_tweet_allowed' );
1042
+ }
1043
+ }
wp-to-twitter-oauth.php CHANGED
@@ -259,7 +259,7 @@ function wtt_connect_oauth( $auth = false ) {
259
  if ( ! wtt_oauth_test( $auth, 'verify' ) ) {
260
 
261
  // show notification to authenticate with OAuth. No longer global; settings only.
262
- if ( ! wpt_check_oauth() && ! isset( $_GET['tab'] ) && 'connection' === $_GET['tab'] ) {
263
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
264
  // Translators: Settings page to authenticate via OAuth.
265
  $message = sprintf( __( "Twitter requires authentication by OAuth. You will need to <a href='%s'>update your settings</a> to complete installation of WP to Twitter.", 'wp-to-twitter' ), $admin_url );
259
  if ( ! wtt_oauth_test( $auth, 'verify' ) ) {
260
 
261
  // show notification to authenticate with OAuth. No longer global; settings only.
262
+ if ( ! wpt_check_oauth() && ! ( isset( $_GET['tab'] ) && 'connection' === $_GET['tab'] ) ) {
263
  $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
264
  // Translators: Settings page to authenticate via OAuth.
265
  $message = sprintf( __( "Twitter requires authentication by OAuth. You will need to <a href='%s'>update your settings</a> to complete installation of WP to Twitter.", 'wp-to-twitter' ), $admin_url );
wp-to-twitter.php CHANGED
@@ -4,24 +4,24 @@
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
11
  * Plugin Name: WP to Twitter
12
  * Plugin URI: http://www.joedolson.com/wp-to-twitter/
13
- * Description: Posts a Tweet when you update your WordPress blog or post a link, using your URL shortener. Rich options to customize and promote your Tweets.
14
  * Author: Joseph C Dolson
15
  * Author URI: http://www.joedolson.com
16
  * Text Domain: wp-to-twitter
17
  * License: GPL-2.0+
18
  * License URI: http://www.gnu.org/license/gpl-2.0.txt
19
  * Domain Path: lang
20
- * Version: 3.5.0
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
@@ -64,7 +64,7 @@ require_once( plugin_dir_path( __FILE__ ) . 'wpt-widget.php' );
64
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
65
 
66
  global $wpt_version;
67
- $wpt_version = '3.5.0';
68
 
69
  add_action( 'init', 'wpt_load_textdomain' );
70
  /**
@@ -385,7 +385,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
385
  wpt_mail( 'Media Uploaded', "$auth, $media_id, $attachment", $id );
386
  if ( $media_id ) {
387
  $status['media_ids'] = $media_id;
388
-
389
  }
390
  }
391
  }
@@ -732,7 +732,6 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null,
732
  if ( wp_is_post_autosave( $post_ID ) || wp_is_post_revision( $post_ID ) ) {
733
  return $post_ID;
734
  }
735
-
736
  wpt_check_version();
737
  $tweet_this = get_post_meta( $post_ID, '_jd_tweet_this', true );
738
  $newpost = false;
@@ -879,7 +878,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null,
879
  'post_id' => $post_ID,
880
  )
881
  );
882
- if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
883
  $author_id = ( $acct ) ? "#$acct" : 'Main';
884
  wpt_mail(
885
  "7a: Tweet Scheduled for author: $author_id",
@@ -889,11 +888,9 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null,
889
  'sentence' => $sentence,
890
  'rt' => 0,
891
  'post_id' => $post_ID,
892
- 'timestamp' => time() + $time + $offset,
893
- 'current_time' => time(),
894
  'timezone' => get_option( 'gmt_offset' ),
895
- 'timestring' => gmdate( 'Y-m-d H:i:s', time() + $time + $offset ),
896
- 'current_ts' => gmdate( 'Y-m-d H:i:s', time() ),
897
  'users' => $wpt_selected_users,
898
  ),
899
  1
@@ -935,7 +932,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null,
935
  'post_id' => $post_ID,
936
  )
937
  );
938
- if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
939
  if ( $acct ) {
940
  $author_id = "#$acct";
941
  } else {
@@ -1135,13 +1132,9 @@ function wpt_add_twitter_debug_box() {
1135
  if ( WPT_DEBUG && current_user_can( 'manage_options' ) ) {
1136
  wpt_check_version();
1137
  // add Twitter panel to post types where it's enabled.
1138
- $wpt_post_types = get_option( 'wpt_post_types' );
1139
- if ( is_array( $wpt_post_types ) ) {
1140
- foreach ( $wpt_post_types as $key => $value ) {
1141
- if ( '1' === (string) $value['post-published-update'] || '1' === (string) $value['post-edited-update'] ) {
1142
- add_meta_box( 'wp2t-debug', 'WP to Twitter Debugging', 'wpt_show_debug', $key, 'advanced' );
1143
- }
1144
- }
1145
  }
1146
  }
1147
  }
@@ -1179,16 +1172,16 @@ function wpt_add_twitter_inner_box( $post ) {
1179
  }
1180
  }
1181
  }
1182
- $tweet = esc_attr( stripcslashes( get_post_meta( $post_id, '_jd_twitter', true ) ) );
1183
- $tweet = apply_filters( 'wpt_user_text', $tweet, $status );
1184
  // Formulate Template display.
1185
  $template = ( 'publish' === $status ) ? $options[ $type ]['post-edited-text'] : $options[ $type ]['post-published-text'];
1186
  $expanded = $template;
1187
  if ( '' !== get_option( 'jd_twit_prepend', '' ) ) {
1188
- $expanded = "<em>" . stripslashes( get_option( 'jd_twit_prepend' ) ) . '</em> ' . $expanded;
1189
  }
1190
  if ( '' !== get_option( 'jd_twit_append', '' ) ) {
1191
- $expanded = $expanded . " <em>" . stripslashes( get_option( 'jd_twit_append' ) ) . '</em>';
1192
  }
1193
  if ( 'publish' === $status && '1' !== $options[ $type ]['post-edited-update'] ) {
1194
  // Translators: post type.
@@ -1435,8 +1428,14 @@ function wpt_admin_scripts() {
1435
  }
1436
  if ( 'settings_page_wp-to-twitter/wp-to-twitter' === $current_screen->id || 'toplevel_page_wp-tweets-pro' === $current_screen->id ) {
1437
  wp_enqueue_script( 'wpt.tabs', plugins_url( 'js/tabs.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1438
- wp_localize_script( 'wpt.tabs', 'firstItem', 'wpt_post' );
1439
- wp_localize_script( 'wpt.tabs', 'firstPerm', 'wpt_editor' );
 
 
 
 
 
 
1440
  wp_enqueue_script( 'dashboard' );
1441
  }
1442
  }
@@ -1562,10 +1561,13 @@ function wpt_admin_script() {
1562
  * Post the Custom Tweet & custom Tweet data into the post meta table
1563
  *
1564
  * @param integer $id Post ID.
 
 
 
1565
  */
1566
- function wpt_save_post( $id ) {
1567
  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 ) ) {
1568
- return;
1569
  }
1570
  if ( isset( $_POST['_yourls_keyword'] ) ) {
1571
  $yourls = $_POST['_yourls_keyword'];
@@ -1600,15 +1602,16 @@ function wpt_save_post( $id ) {
1600
  $update = apply_filters( 'wpt_insert_post', $_POST, $id );
1601
  // WPT PRO.
1602
  // only send debug data if post meta is updated.
1603
- if ( true === $update || is_int( $update ) ) {
1604
- wpt_mail( 'Post Meta Inserted', 'WP to Twitter post meta was updated', $id ); // DEBUG.
1605
- }
1606
  if ( isset( $_POST['wpt-delete-debug'] ) && 'true' === $_POST['wpt-delete-debug'] ) {
1607
  delete_post_meta( $id, '_wpt_debug_log' );
1608
  }
1609
  if ( isset( $_POST['wpt-delete-all-debug'] ) && 'true' === $_POST['wpt-delete-all-debug'] ) {
1610
  delete_post_meta_by_key( '_wpt_debug_log' );
1611
  }
 
 
1612
  }
1613
 
1614
  add_action( 'init', 'wpt_old_admin_redirect' );
@@ -1689,13 +1692,16 @@ if ( '1' === get_option( 'jd_twit_blogroll' ) ) {
1689
 
1690
  if ( function_exists( 'wp_after_insert_post' ) ) {
1691
  /**
 
 
1692
  * @since WordPress 5.6
1693
  */
1694
- add_action( 'wp_after_insert_post', 'wpt_twit', 10, 4 );
 
1695
  } else {
 
1696
  add_action( 'save_post', 'wpt_twit', 15 );
1697
  }
1698
- add_action( 'save_post', 'wpt_save_post', 10 );
1699
  /**
1700
  * Check whether a given post is in an allowed post type and has an update template configured.
1701
  *
@@ -1709,7 +1715,7 @@ function wpt_in_post_type( $id ) {
1709
  if ( in_array( $type, $post_types, true ) ) {
1710
  return true;
1711
  }
1712
- if ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) {
1713
  wpt_mail( '0: Not a Tweeted post type', 'This post type is not enabled for Tweeting: ' . $type, $id );
1714
  }
1715
 
@@ -1750,28 +1756,40 @@ function wpt_future_to_publish( $post ) {
1750
  wpt_twit_future( $id );
1751
  }
1752
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1753
  /**
1754
  * Handle Tweeting posts published directly. As of 12/10/2020, supports new wp_after_insert_post to improve support when used with block editor.
1755
  *
1756
- * @param int $id Post ID.
1757
- * @param object $post Post object.
1758
  * @param boolean $updated True if updated, false if inserted.
1759
- * @param object $post_before The post prior to this update, or null for new posts.
1760
  */
1761
  function wpt_twit( $id, $post = null, $updated = null, $post_before = null ) {
1762
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! wpt_in_post_type( $id ) ) {
1763
- return;
1764
  }
 
1765
  $post = ( null === $post ) ? get_post( $id ) : $post;
1766
  if ( 'publish' !== $post->post_status ) {
1767
- return;
1768
  }
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, $post, $updated, $post_before );
1774
- add_action( 'save_post', 'wpt_twit', 15 );
1775
  }
1776
 
1777
  add_action( 'xmlrpc_publish_post', 'wpt_twit_xmlrpc' );
@@ -1784,7 +1802,7 @@ add_action( 'publish_phone', 'wpt_twit_xmlrpc' );
1784
  */
1785
  function wpt_twit_future( $id ) {
1786
  set_transient( '_wpt_twit_future', $id, 10 );
1787
- // instant action has already run for this post.
1788
  // prevent running actions twice (need both for older WP).
1789
  if ( get_transient( '_wpt_twit_instant' ) && (int) get_transient( '_wpt_twit_instant' ) === $id ) {
1790
  delete_transient( '_wpt_twit_instant' );
4
  *
5
  * @package WP to Twitter
6
  * @author Joe Dolson
7
+ * @copyright 2008-2021 Joe Dolson
8
  * @license GPL-2.0+
9
  *
10
  * @wordpress-plugin
11
  * Plugin Name: WP to Twitter
12
  * Plugin URI: http://www.joedolson.com/wp-to-twitter/
13
+ * Description: Posts a Tweet when you update your WordPress blog or post a link, using your URL shortener. Many options to customize and promote your Tweets.
14
  * Author: Joseph C Dolson
15
  * Author URI: http://www.joedolson.com
16
  * Text Domain: wp-to-twitter
17
  * License: GPL-2.0+
18
  * License URI: http://www.gnu.org/license/gpl-2.0.txt
19
  * Domain Path: lang
20
+ * Version: 3.5.2
21
  */
22
 
23
  /*
24
+ Copyright 2008-2021 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
64
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
65
 
66
  global $wpt_version;
67
+ $wpt_version = '3.5.2';
68
 
69
  add_action( 'init', 'wpt_load_textdomain' );
70
  /**
385
  wpt_mail( 'Media Uploaded', "$auth, $media_id, $attachment", $id );
386
  if ( $media_id ) {
387
  $status['media_ids'] = $media_id;
388
+
389
  }
390
  }
391
  }
732
  if ( wp_is_post_autosave( $post_ID ) || wp_is_post_revision( $post_ID ) ) {
733
  return $post_ID;
734
  }
 
735
  wpt_check_version();
736
  $tweet_this = get_post_meta( $post_ID, '_jd_tweet_this', true );
737
  $newpost = false;
878
  'post_id' => $post_ID,
879
  )
880
  );
881
+ if ( WPT_DEBUG ) {
882
  $author_id = ( $acct ) ? "#$acct" : 'Main';
883
  wpt_mail(
884
  "7a: Tweet Scheduled for author: $author_id",
888
  'sentence' => $sentence,
889
  'rt' => 0,
890
  'post_id' => $post_ID,
891
+ 'timestamp' => time() + $time + $offset . ', ' . gmdate( 'Y-m-d H:i:s', time() + $time + $offset ),
892
+ 'current_time' => time() . ', ' . gmdate( 'Y-m-d H:i:s', time() ),
893
  'timezone' => get_option( 'gmt_offset' ),
 
 
894
  'users' => $wpt_selected_users,
895
  ),
896
  1
932
  'post_id' => $post_ID,
933
  )
934
  );
935
+ if ( WPT_DEBUG ) {
936
  if ( $acct ) {
937
  $author_id = "#$acct";
938
  } else {
1132
  if ( WPT_DEBUG && current_user_can( 'manage_options' ) ) {
1133
  wpt_check_version();
1134
  // add Twitter panel to post types where it's enabled.
1135
+ $wpt_post_types = wpt_allowed_post_types();
1136
+ foreach ( $wpt_post_types as $type ) {
1137
+ add_meta_box( 'wp2t-debug', 'WP to Twitter Debugging', 'wpt_show_debug', $type, 'advanced' );
 
 
 
 
1138
  }
1139
  }
1140
  }
1172
  }
1173
  }
1174
  }
1175
+ $tweet = esc_attr( stripcslashes( get_post_meta( $post_id, '_jd_twitter', true ) ) );
1176
+ $tweet = apply_filters( 'wpt_user_text', $tweet, $status );
1177
  // Formulate Template display.
1178
  $template = ( 'publish' === $status ) ? $options[ $type ]['post-edited-text'] : $options[ $type ]['post-published-text'];
1179
  $expanded = $template;
1180
  if ( '' !== get_option( 'jd_twit_prepend', '' ) ) {
1181
+ $expanded = '<em>' . stripslashes( get_option( 'jd_twit_prepend' ) ) . '</em> ' . $expanded;
1182
  }
1183
  if ( '' !== get_option( 'jd_twit_append', '' ) ) {
1184
+ $expanded = $expanded . ' <em>' . stripslashes( get_option( 'jd_twit_append' ) ) . '</em>';
1185
  }
1186
  if ( 'publish' === $status && '1' !== $options[ $type ]['post-edited-update'] ) {
1187
  // Translators: post type.
1428
  }
1429
  if ( 'settings_page_wp-to-twitter/wp-to-twitter' === $current_screen->id || 'toplevel_page_wp-tweets-pro' === $current_screen->id ) {
1430
  wp_enqueue_script( 'wpt.tabs', plugins_url( 'js/tabs.js', __FILE__ ), array( 'jquery' ), $wpt_version );
1431
+ wp_localize_script(
1432
+ 'wpt.tabs',
1433
+ 'wpt',
1434
+ array(
1435
+ 'firstItem' => 'wpt_post',
1436
+ 'firstPerm' => 'wpt_editor',
1437
+ )
1438
+ );
1439
  wp_enqueue_script( 'dashboard' );
1440
  }
1441
  }
1561
  * Post the Custom Tweet & custom Tweet data into the post meta table
1562
  *
1563
  * @param integer $id Post ID.
1564
+ * @param object $post Post object.
1565
+ *
1566
+ * @return bool
1567
  */
1568
+ function wpt_save_post( $id, $post ) {
1569
  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 ) ) {
1570
+ return $id;
1571
  }
1572
  if ( isset( $_POST['_yourls_keyword'] ) ) {
1573
  $yourls = $_POST['_yourls_keyword'];
1602
  $update = apply_filters( 'wpt_insert_post', $_POST, $id );
1603
  // WPT PRO.
1604
  // only send debug data if post meta is updated.
1605
+ wpt_mail( 'Post Meta Processed', 'WP to Twitter post meta was updated' . print_r( $_POST, 1 ), $id ); // DEBUG.
1606
+
 
1607
  if ( isset( $_POST['wpt-delete-debug'] ) && 'true' === $_POST['wpt-delete-debug'] ) {
1608
  delete_post_meta( $id, '_wpt_debug_log' );
1609
  }
1610
  if ( isset( $_POST['wpt-delete-all-debug'] ) && 'true' === $_POST['wpt-delete-all-debug'] ) {
1611
  delete_post_meta_by_key( '_wpt_debug_log' );
1612
  }
1613
+
1614
+ return $id;
1615
  }
1616
 
1617
  add_action( 'init', 'wpt_old_admin_redirect' );
1692
 
1693
  if ( function_exists( 'wp_after_insert_post' ) ) {
1694
  /**
1695
+ * Use the `wp_after_insert_post` action to run Tweets.
1696
+ *
1697
  * @since WordPress 5.6
1698
  */
1699
+ add_action( 'wp_after_insert_post', 'wpt_save_post', 10, 2 );
1700
+ add_action( 'wp_after_insert_post', 'wpt_twit', 15, 4 );
1701
  } else {
1702
+ add_action( 'save_post', 'wpt_save_post', 10, 2 );
1703
  add_action( 'save_post', 'wpt_twit', 15 );
1704
  }
 
1705
  /**
1706
  * Check whether a given post is in an allowed post type and has an update template configured.
1707
  *
1715
  if ( in_array( $type, $post_types, true ) ) {
1716
  return true;
1717
  }
1718
+ if ( WPT_DEBUG ) {
1719
  wpt_mail( '0: Not a Tweeted post type', 'This post type is not enabled for Tweeting: ' . $type, $id );
1720
  }
1721
 
1756
  wpt_twit_future( $id );
1757
  }
1758
 
1759
+ /**
1760
+ * Check whether autotweeting has been allowed.
1761
+ *
1762
+ * @param int $post_id Post ID.
1763
+ *
1764
+ * @return bool
1765
+ */
1766
+ function wpt_auto_tweet_allowed( $post_id ) {
1767
+ $state = get_option( 'wpt_auto_tweet_allowed', '0' );
1768
+ $return = ( '0' !== $state ) ? true : false;
1769
+
1770
+ return apply_filters( 'wpt_auto_tweet_allowed', $return, $post_id );
1771
+ }
1772
+
1773
  /**
1774
  * Handle Tweeting posts published directly. As of 12/10/2020, supports new wp_after_insert_post to improve support when used with block editor.
1775
  *
1776
+ * @param int $id Post ID.
1777
+ * @param object $post Post object.
1778
  * @param boolean $updated True if updated, false if inserted.
1779
+ * @param object $post_before The post prior to this update, or null for new posts.
1780
  */
1781
  function wpt_twit( $id, $post = null, $updated = null, $post_before = null ) {
1782
+ if ( ( empty( $_POST ) && ! wpt_auto_tweet_allowed( $id ) ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $id ) || isset( $_POST['_inline_edit'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX && ! wpt_auto_tweet_allowed( $id ) ) || ! wpt_in_post_type( $id ) ) {
1783
+ return $id;
1784
  }
1785
+
1786
  $post = ( null === $post ) ? get_post( $id ) : $post;
1787
  if ( 'publish' !== $post->post_status ) {
1788
+ return $id;
1789
  }
1790
  // is there any reason to accept any other status?
 
 
1791
  wpt_mail( 'Tweeting published post', $id );
1792
  wpt_twit_instant( $id, $post, $updated, $post_before );
 
1793
  }
1794
 
1795
  add_action( 'xmlrpc_publish_post', 'wpt_twit_xmlrpc' );
1802
  */
1803
  function wpt_twit_future( $id ) {
1804
  set_transient( '_wpt_twit_future', $id, 10 );
1805
+ // instant action has already run for this post.
1806
  // prevent running actions twice (need both for older WP).
1807
  if ( get_transient( '_wpt_twit_instant' ) && (int) get_transient( '_wpt_twit_instant' ) === $id ) {
1808
  delete_transient( '_wpt_twit_instant' );
wpt-functions.php CHANGED
@@ -262,7 +262,8 @@ function wpt_cap_checkbox( $role, $cap, $name ) {
262
  * @param boolean $override Send message if debug disabled.
263
  */
264
  function wpt_mail( $subject, $body, $post_ID = false, $override = false ) {
265
- if ( ( WPT_DEBUG && function_exists( 'wpt_pro_exists' ) ) || true === $override ) {
 
266
  if ( WPT_DEBUG_BY_EMAIL ) {
267
  wp_mail( WPT_DEBUG_ADDRESS, $subject, $body, WPT_FROM );
268
  } else {
@@ -283,7 +284,7 @@ function wpt_debug_log( $subject, $body, $post_ID ) {
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
  }
@@ -298,7 +299,7 @@ function wpt_show_debug() {
298
  $debug_log = get_post_meta( $post_ID, '_wpt_debug_log' );
299
  if ( is_array( $debug_log ) ) {
300
  foreach ( $debug_log as $entry ) {
301
- $date = date_i18n( 'Y-m-d H:i', $entry[0] );
302
  $subject = $entry[1];
303
  $body = $entry[2];
304
  $records .= "<li><button type='button' class='toggle-debug button-secondary' aria-expanded='false'><strong>$date</strong>:<br />$subject</button><pre class='wpt-debug-details'>" . esc_html( $body ) . '</pre></li>';
262
  * @param boolean $override Send message if debug disabled.
263
  */
264
  function wpt_mail( $subject, $body, $post_ID = false, $override = false ) {
265
+ $body .= ' Active Filter:' . current_filter();
266
+ if ( ( WPT_DEBUG ) ) {
267
  if ( WPT_DEBUG_BY_EMAIL ) {
268
  wp_mail( WPT_DEBUG_ADDRESS, $subject, $body, WPT_FROM );
269
  } else {
284
  global $post_ID;
285
  }
286
  if ( $post_ID ) {
287
+ $time = microtime();
288
  add_post_meta( $post_ID, '_wpt_debug_log', array( $time, $subject, $body ) );
289
  }
290
  }
299
  $debug_log = get_post_meta( $post_ID, '_wpt_debug_log' );
300
  if ( is_array( $debug_log ) ) {
301
  foreach ( $debug_log as $entry ) {
302
+ $date = date_i18n( 'Y-m-d H:i:s', $entry[0] );
303
  $subject = $entry[1];
304
  $body = $entry[2];
305
  $records .= "<li><button type='button' class='toggle-debug button-secondary' aria-expanded='false'><strong>$date</strong>:<br />$subject</button><pre class='wpt-debug-details'>" . esc_html( $body ) . '</pre></li>';
wpt-truncate.php CHANGED
@@ -367,10 +367,10 @@ function wpt_create_values( $post, $post_ID, $ref ) {
367
  $account = get_option( 'wtt_twitter_username', '' );
368
  $user_meta = get_user_meta( $auth, 'wp-to-twitter-user-username', true );
369
  $user_account = get_user_meta( $auth, 'wtt_twitter_username', true );
370
- $user_account = ( $user_account ) ? $user_account: $user_meta;
371
  if ( '1' === get_option( 'jd_individual_twitter_users' ) ) {
372
  if ( 'mainAtTwitter' === get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
373
- $account = $user_account;
374
  } elseif ( 'mainAtTwitterPlus' === get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
375
  $account = stripcslashes( $user_account . ' @' . get_option( 'wtt_twitter_username' ) );
376
  } else {
367
  $account = get_option( 'wtt_twitter_username', '' );
368
  $user_meta = get_user_meta( $auth, 'wp-to-twitter-user-username', true );
369
  $user_account = get_user_meta( $auth, 'wtt_twitter_username', true );
370
+ $user_account = ( $user_account ) ? $user_account : $user_meta;
371
  if ( '1' === get_option( 'jd_individual_twitter_users' ) ) {
372
  if ( 'mainAtTwitter' === get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
373
+ $account = $user_account;
374
  } elseif ( 'mainAtTwitterPlus' === get_user_meta( $auth, 'wp-to-twitter-enable-user', true ) ) {
375
  $account = stripcslashes( $user_account . ' @' . get_option( 'wtt_twitter_username' ) );
376
  } else {
wpt-widget.php CHANGED
@@ -278,8 +278,13 @@ function wpt_twitter_feed( $instance ) {
278
 
279
  if ( $instance['source'] ) {
280
  $source = $tweet['source'];
281
- // Translators: 1 - time string, 2 - name of Tweet app, 3 - Link to Tweet.
282
- $timetweet = sprintf( __( '<a href="%3$s">about %1$s ago</a> via %2$s', 'wp-to-twitter' ), human_time_diff( strtotime( $tweet['created_at'] ) ), $source, 'http://twitter.com/' . $posted_by . "/status/$tweet[id_str]" );
 
 
 
 
 
283
  } else {
284
  // Translators: 1 - time string; 2 - link to Tweet.
285
  $timetweet = sprintf( __( '<a href="%2$s">about %1$s ago</a>', 'wp-to-twitter' ), human_time_diff( strtotime( $tweet['created_at'] ) ), "http://twitter.com/$posted_by/status/$tweet[id_str]" );
278
 
279
  if ( $instance['source'] ) {
280
  $source = $tweet['source'];
281
+ if ( '' !== $source ) {
282
+ // Translators: 1 - time string, 2 - name of Tweet app, 3 - Link to Tweet.
283
+ $timetweet = sprintf( __( '<a href="%3$s">about %1$s ago</a> via %2$s', 'wp-to-twitter' ), human_time_diff( strtotime( $tweet['created_at'] ) ), $source, 'http://twitter.com/' . $posted_by . "/status/$tweet[id_str]" );
284
+ } else {
285
+ // Translators: 1 - time string, 2 - Link to Tweet.
286
+ $timetweet = sprintf( __( '<a href="%2$s">about %1$s ago</a>', 'wp-to-twitter' ), human_time_diff( strtotime( $tweet['created_at'] ) ), $source, 'http://twitter.com/' . $posted_by . "/status/$tweet[id_str]" );
287
+ }
288
  } else {
289
  // Translators: 1 - time string; 2 - link to Tweet.
290
  $timetweet = sprintf( __( '<a href="%2$s">about %1$s ago</a>', 'wp-to-twitter' ), human_time_diff( strtotime( $tweet['created_at'] ) ), "http://twitter.com/$posted_by/status/$tweet[id_str]" );