WP to Twitter - Version 3.4.0

Version Description

  • New function: wpt_allowed_post_types(). Returns array of post types that can be Tweeted.
  • New template tag: #categories# Return string of all categories on post. Filterable with 'wpt_twitter_category_names'
  • Change: default tag length allowed raised to 20
  • Change: default number of tags allowed raised to 4
  • Breaking change: Remove major function deprecated in January 2017 and minor functions deprecated March 2018.
Download this release

Release Info

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

Code changes from version 3.3.12 to 3.4.0

classes/class-wpt-twitteroauth.php CHANGED
@@ -322,7 +322,7 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
322
  }
323
  $upload = wp_get_attachment_image_src( $attachment, apply_filters( 'wpt_upload_image_size', $size ) );
324
  $parent = get_post_ancestors( $attachment );
325
- $parent = ( is_array( $parent ) ) ? $parent[0] : false;
326
  $image_url = $upload[0];
327
  $remote = wp_remote_get( $image_url );
328
  if ( is_wp_error( $remote ) ) {
@@ -362,6 +362,33 @@ if ( ! class_exists( 'Wpt_TwitterOAuth' ) ) {
362
  $response = json_decode( $response );
363
  $media_id = $response->media_id_string;
364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  return $media_id;
366
  }
367
 
322
  }
323
  $upload = wp_get_attachment_image_src( $attachment, apply_filters( 'wpt_upload_image_size', $size ) );
324
  $parent = get_post_ancestors( $attachment );
325
+ $parent = ( is_array( $parent ) && isset( $parent[0] ) ) ? $parent[0] : false;
326
  $image_url = $upload[0];
327
  $remote = wp_remote_get( $image_url );
328
  if ( is_wp_error( $remote ) ) {
362
  $response = json_decode( $response );
363
  $media_id = $response->media_id_string;
364
 
365
+ /**
366
+ * Eventually, use this to add alt text. Not supported at this time.
367
+
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
+ if ( '' != $alt_text ) {
371
+ $image_alt = json_encode(
372
+ array(
373
+ 'media_id' => $media_id,
374
+ 'alt_text' => array(
375
+ 'text' => $alt_text,
376
+ ),
377
+ )
378
+ );
379
+ $post_alt = $tmh_oauth->request(
380
+ 'POST',
381
+ $metadata_api,
382
+ $image_alt,
383
+ true,
384
+ true,
385
+ array(
386
+ 'content-type' => 'application/json',
387
+ )
388
+ );
389
+ }
390
+ */
391
+
392
  return $media_id;
393
  }
394
 
readme.txt CHANGED
@@ -7,7 +7,7 @@ Tested up to: 5.2
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
- Stable tag: 3.3.12
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,14 @@ Check out my <a href="https://github.com/joedolson/plugin-extensions/tree/master
63
 
64
  == Changelog ==
65
 
 
 
 
 
 
 
 
 
66
  = 3.3.12 =
67
 
68
  * Missed ssl_verify=false removed
@@ -444,4 +452,4 @@ Writing and maintaining a plug-in is a lot of work. You can help me by providing
444
 
445
  == Upgrade Notice ==
446
 
447
- * 3.3.1: 280 character Tweets
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  Text Domain: wp-to-twitter
10
+ Stable tag: 3.4.0
11
 
12
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
13
 
63
 
64
  == Changelog ==
65
 
66
+ = 3.4.0 =
67
+
68
+ * New function: wpt_allowed_post_types(). Returns array of post types that can be Tweeted.
69
+ * New template tag: #categories# Return string of all categories on post. Filterable with 'wpt_twitter_category_names'
70
+ * Change: default tag length allowed raised to 20
71
+ * Change: default number of tags allowed raised to 4
72
+ * Breaking change: Remove major function deprecated in January 2017 and minor functions deprecated March 2018.
73
+
74
  = 3.3.12 =
75
 
76
  * Missed ssl_verify=false removed
452
 
453
  == Upgrade Notice ==
454
 
455
+ * 3.4.0: Removal of functions deprecated in January 2017 & March 2018. May break older Pro installations.
wp-to-twitter-manager.php CHANGED
@@ -510,7 +510,7 @@ function wpt_update_settings() {
510
  ?>
511
  <p>
512
  <label for="jd_max_tags"><?php _e( 'Maximum number of tags to include:', 'wp-to-twitter' ); ?></label>
513
- <input aria-describedby="jd_max_characters_label" type="text" name="jd_max_tags" id="jd_max_tags" value="<?php echo esc_attr( get_option( 'jd_max_tags' ) ); ?>" size="3"/>
514
  </p>
515
  <p>
516
  <label for="jd_max_characters"><?php _e( 'Maximum length in characters for included tags:', 'wp-to-twitter' ); ?></label>
510
  ?>
511
  <p>
512
  <label for="jd_max_tags"><?php _e( 'Maximum number of tags to include:', 'wp-to-twitter' ); ?></label>
513
+ <input aria-describedby="jd_max_characters_label" type="text" name="jd_max_tags" id="jd_max_tags" value="<?php echo esc_attr( get_option( 'jd_max_tags' ) ); ?>" size="3" />
514
  </p>
515
  <p>
516
  <label for="jd_max_characters"><?php _e( 'Maximum length in characters for included tags:', 'wp-to-twitter' ); ?></label>
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.3.12
21
  */
22
 
23
  /*
@@ -57,7 +57,7 @@ require_once( plugin_dir_path( __FILE__ ) . 'wpt-widget.php' );
57
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
58
 
59
  global $wpt_version;
60
- $wpt_version = '3.3.12';
61
 
62
  add_action( 'init', 'wpt_load_textdomain' );
63
  /**
@@ -130,8 +130,8 @@ function wptotwitter_activate() {
130
  update_option( 'newlink-published-text', 'New link: #title# #url#' );
131
  update_option( 'jd_shortener', '1' );
132
  update_option( 'jd_strip_nonan', '0' );
133
- update_option( 'jd_max_tags', 3 );
134
- update_option( 'jd_max_characters', 15 );
135
  $administrator = get_role( 'administrator' );
136
  if ( is_object( $administrator ) ) {
137
  // wpt_twitter_oauth is the general permission for editing user accounts.
@@ -357,20 +357,6 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false
357
  wpt_mail( 'Media Uploaded', "$auth, $media_id, $attachment", $id );
358
  if ( $media_id ) {
359
  $status['media_ids'] = $media_id;
360
- /**
361
- * Eventually, use this to add alt text. Not supported at this time.
362
- $metadata_api = 'https://upload.twitter.com/1.1/media/metadata/create.json';
363
- $alt_text = get_post_meta( $args['media'], '_wp_attachment_image_alt', true );
364
- if ( '' != $alt_text ) {
365
- $image_alt = json_encode( array(
366
- 'media_id' => $media_id,
367
- 'alt_text' => array(
368
- 'text' => $alt_text,
369
- ),
370
- ) );
371
- $post_alt = $connection->post( $metadata_api, array( 'auth' => $auth, 'json' => $image_alt ), true );
372
- }
373
- */
374
  }
375
  }
376
  }
@@ -1317,7 +1303,7 @@ function wpt_add_twitter_inner_box( $post ) {
1317
  <div class='wptab' id='notes' aria-labelledby='tab_notes' role='tabpanel'>
1318
  <p>
1319
  <?php
1320
- _e( 'Template Tags: <code>#url#</code>, <code>#title#</code>, <code>#post#</code>, <code>#category#</code>, <code>#date#</code>, <code>#modified#</code>, <code>#author#</code>, <code>#account#</code>, <code>#tags#</code>, <code>#blog#</code>, <code>#longurl#</code>.', 'wp-to-twitter' );
1321
  do_action( 'wpt_notes_tab', $post_id );
1322
  ?>
1323
  </p>
@@ -1723,18 +1709,32 @@ add_action( 'save_post', 'wpt_save_post', 10 );
1723
  * @return boolean True if post is allowed, false otherwise.
1724
  */
1725
  function wpt_in_post_type( $id ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1726
  $post_type_settings = get_option( 'wpt_post_types' );
 
1727
  if ( is_array( $post_type_settings ) && ! empty( $post_type_settings ) ) {
1728
- $post_types = array_keys( $post_type_settings );
1729
- $type = get_post_type( $id );
1730
- if ( in_array( $type, $post_types ) ) {
1731
- if ( '1' == $post_type_settings[ $type ]['post-edited-update'] || '1' == $post_type_settings[ $type ]['post-published-update'] ) {
1732
- return true;
1733
  }
1734
  }
1735
  }
1736
 
1737
- return false;
1738
  }
1739
 
1740
  add_action( 'future_to_publish', 'wpt_future_to_publish', 16 );
17
  * License: GPL-2.0+
18
  * License URI: http://www.gnu.org/license/gpl-2.0.txt
19
  * Domain Path: lang
20
+ * Version: 3.4.0
21
  */
22
 
23
  /*
57
  require_once( plugin_dir_path( __FILE__ ) . 'wpt-rate-limiting.php' );
58
 
59
  global $wpt_version;
60
+ $wpt_version = '3.4.0';
61
 
62
  add_action( 'init', 'wpt_load_textdomain' );
63
  /**
130
  update_option( 'newlink-published-text', 'New link: #title# #url#' );
131
  update_option( 'jd_shortener', '1' );
132
  update_option( 'jd_strip_nonan', '0' );
133
+ update_option( 'jd_max_tags', 4 );
134
+ update_option( 'jd_max_characters', 20 );
135
  $administrator = get_role( 'administrator' );
136
  if ( is_object( $administrator ) ) {
137
  // wpt_twitter_oauth is the general permission for editing user accounts.
357
  wpt_mail( 'Media Uploaded', "$auth, $media_id, $attachment", $id );
358
  if ( $media_id ) {
359
  $status['media_ids'] = $media_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  }
361
  }
362
  }
1303
  <div class='wptab' id='notes' aria-labelledby='tab_notes' role='tabpanel'>
1304
  <p>
1305
  <?php
1306
+ _e( 'Template Tags: <code>#url#</code>, <code>#title#</code>, <code>#post#</code>, <code>#category#</code>, <code>#categories#</code>, <code>#date#</code>, <code>#modified#</code>, <code>#author#</code>, <code>#account#</code>, <code>#tags#</code>, <code>#blog#</code>, <code>#longurl#</code>.', 'wp-to-twitter' );
1307
  do_action( 'wpt_notes_tab', $post_id );
1308
  ?>
1309
  </p>
1709
  * @return boolean True if post is allowed, false otherwise.
1710
  */
1711
  function wpt_in_post_type( $id ) {
1712
+ $post_types = wpt_allowed_post_types();
1713
+ $type = get_post_type( $id );
1714
+ if ( in_array( $type, $post_types ) ) {
1715
+ return true;
1716
+ }
1717
+
1718
+ return false;
1719
+ }
1720
+
1721
+ /**
1722
+ * Get array of post types that can be Tweeted.
1723
+ *
1724
+ * @return array
1725
+ */
1726
+ function wpt_allowed_post_types() {
1727
  $post_type_settings = get_option( 'wpt_post_types' );
1728
+ $allowed_types = array();
1729
  if ( is_array( $post_type_settings ) && ! empty( $post_type_settings ) ) {
1730
+ foreach ( $post_type_settings as $type => $settings ) {
1731
+ if ( '1' == $settings['post-edited-update'] || '1' == $settings['post-published-update'] ) {
1732
+ $allowed_types[] = $type;
 
 
1733
  }
1734
  }
1735
  }
1736
 
1737
+ return apply_filters( 'wpt_allowed_post_types', $allowed_types, $post_type_settings );
1738
  }
1739
 
1740
  add_action( 'future_to_publish', 'wpt_future_to_publish', 16 );
wpt-functions.php CHANGED
@@ -42,21 +42,6 @@ function wpt_checkbox( $field, $sub1 = false, $sub2 = '' ) {
42
  return '';
43
  }
44
 
45
- /**
46
- * See if checkboxes should be checked - fallback to old function.
47
- *
48
- * @param string $field Option name to check.
49
- * @param string $sub1 Array key if applicable.
50
- * @param string $sub2 Array key if applicable.
51
- *
52
- * @deprecated 3/26/2018
53
- *
54
- * @return Checked or unchecked.
55
- */
56
- function jd_checkCheckbox( $field, $sub1 = false, $sub2 = '' ) {
57
- return wpt_checkbox( $field, $sub1, $sub2 );
58
- }
59
-
60
  /**
61
  * See if options should be selected
62
  *
@@ -73,21 +58,6 @@ function wpt_selected( $field, $value, $type = 'select' ) {
73
  return '';
74
  }
75
 
76
- /**
77
- * See if options should be selected - fallback function
78
- *
79
- * @param string $field Option name to check.
80
- * @param string $value Value to verify against.
81
- * @param string $type Select or checkbox.
82
- *
83
- * @deprecated 3/26/2018
84
- *
85
- * @return Selected or unselected/ checked or unchecked..
86
- */
87
- function jd_checkSelect( $field, $value, $type = 'select' ) {
88
- return wpt_selected( $field, $value, $type );
89
- }
90
-
91
  /**
92
  * Insert a Tweet record into logs.
93
  *
@@ -113,9 +83,9 @@ function wpt_set_log( $data, $id, $message ) {
113
  * @return stored message.
114
  */
115
  function wpt_log( $data, $id ) {
116
- if ( 'test' == $id ) {
117
  $log = get_option( $data );
118
- } elseif ( 'last' == $id ) {
119
  $log = get_option( $data . '_last' );
120
  } else {
121
  $log = get_post_meta( $id, '_' . $data, true );
@@ -982,29 +952,6 @@ function jd_twit( $post_ID, $type = 'instant' ) {
982
  return wpt_tweet( $post_ID, $type );
983
  }
984
 
985
- /**
986
- * Set up admin styles.
987
- */
988
- function jd_addTwitterAdminStyles() {
989
- return wpt_admin_style();
990
- }
991
-
992
- /**
993
- * Send to Twitter API. Fallback; deprecated.
994
- *
995
- * @param string $twit Tweet.
996
- * @param mixed boolean/int $auth Author ID.
997
- * @param int $id Post ID.
998
- * @param boolean $media Include media.
999
- *
1000
- * @deprecated 1/19/2017
1001
- *
1002
- * @return boolean.
1003
- */
1004
- function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false ) {
1005
- return wpt_post_to_twitter( $twit, $auth, $id, $media );
1006
- }
1007
-
1008
  /**
1009
  * Update oauth settings.
1010
  *
42
  return '';
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  /**
46
  * See if options should be selected
47
  *
58
  return '';
59
  }
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  /**
62
  * Insert a Tweet record into logs.
63
  *
83
  * @return stored message.
84
  */
85
  function wpt_log( $data, $id ) {
86
+ if ( 'test' === $id ) {
87
  $log = get_option( $data );
88
+ } elseif ( 'last' === $id ) {
89
  $log = get_option( $data . '_last' );
90
  } else {
91
  $log = get_post_meta( $id, '_' . $data, true );
952
  return wpt_tweet( $post_ID, $type );
953
  }
954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
955
  /**
956
  * Update oauth settings.
957
  *
wpt-truncate.php CHANGED
@@ -307,6 +307,7 @@ function wpt_remove_tag( $key ) {
307
  case 'account':
308
  case 'author':
309
  case 'category':
 
310
  case 'date':
311
  case 'modified':
312
  case 'reference':
@@ -326,7 +327,7 @@ function wpt_remove_tag( $key ) {
326
  * @return array tags.
327
  */
328
  function wpt_tags() {
329
- return apply_filters( 'wpt_tags', array( 'url', 'title', 'blog', 'post', 'category', 'date', 'author', 'displayname', 'tags', 'modified', 'reference', 'account', '@', 'cat_desc', 'longurl' ) );
330
  }
331
 
332
  /**
@@ -358,6 +359,7 @@ function wpt_create_values( $post, $post_ID, $ref ) {
358
  $excerpt = trim( apply_filters( 'wpt_status', $post['postExcerpt'], $post_ID, 'post' ) );
359
  $thisposturl = trim( $shrink );
360
  $category = trim( $post['category'] );
 
361
  $cat_desc = trim( $post['cat_desc'] );
362
  $user_account = get_user_meta( $auth, 'wtt_twitter_username', true );
363
  $tags = wpt_generate_hash_tags( $post_ID );
@@ -402,6 +404,7 @@ function wpt_create_values( $post, $post_ID, $ref ) {
402
  'blog' => $blogname,
403
  'post' => $excerpt,
404
  'category' => $category,
 
405
  'date' => $date,
406
  'author' => $author,
407
  'displayname' => $display_name,
307
  case 'account':
308
  case 'author':
309
  case 'category':
310
+ case 'categories':
311
  case 'date':
312
  case 'modified':
313
  case 'reference':
327
  * @return array tags.
328
  */
329
  function wpt_tags() {
330
+ return apply_filters( 'wpt_tags', array( 'url', 'title', 'blog', 'post', 'category', 'categories', 'date', 'author', 'displayname', 'tags', 'modified', 'reference', 'account', '@', 'cat_desc', 'longurl' ) );
331
  }
332
 
333
  /**
359
  $excerpt = trim( apply_filters( 'wpt_status', $post['postExcerpt'], $post_ID, 'post' ) );
360
  $thisposturl = trim( $shrink );
361
  $category = trim( $post['category'] );
362
+ $categories = trim( $post['cats'] );
363
  $cat_desc = trim( $post['cat_desc'] );
364
  $user_account = get_user_meta( $auth, 'wtt_twitter_username', true );
365
  $tags = wpt_generate_hash_tags( $post_ID );
404
  'blog' => $blogname,
405
  'post' => $excerpt,
406
  'category' => $category,
407
+ 'categories' => $categories,
408
  'date' => $date,
409
  'author' => $author,
410
  'displayname' => $display_name,