Better Click To Tweet - Version 0.4

Version Description

  • rescued 9 characters that were being stolen by some incorrect math in my tweet-generating function. (now tweets won't be truncated until they actually need to be).
Download this release

Release Info

Developer ben.meredith@gmail.com
Plugin Icon 128x128 Better Click To Tweet
Version 0.4
Comparing to
See all releases

Code changes from version 0.3 to 0.4

Files changed (3) hide show
  1. bctt_options.php +5 -5
  2. better-click-to-tweet.php +15 -15
  3. readme.txt +18 -4
bctt_options.php CHANGED
@@ -14,13 +14,13 @@ add_action('admin_menu', 'bctt_admin_menu');
14
  add_action('init', 'bctt_tinymce_button');
15
 
16
  function bctt_tinymce_button() {
17
- if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
18
  return;
19
  }
20
 
21
- if (get_user_option('rich_editing') == 'true') {
22
- add_filter('mce_external_plugins', 'bctt_tinymce_register_plugin');
23
- add_filter('mce_buttons', 'bctt_tinymce_register_button');
24
  }
25
  }
26
  function bctt_tinymce_register_button($buttons) {
@@ -64,7 +64,7 @@ function bctt_settings_page() {
64
  To add styled click-to-tweet quote boxes include the Better Click To Tweet shortcode in your post.</p>
65
  <p>Here's how you format the shortcode: <pre>[bctt tweet="Meaningful, tweetable quote."]</pre></p>
66
  <p>If you are using the visual editor, click the BCTT birdie in the toolbar to add a pre-formatted shortcode to your post.</p>
67
- <p>Tweet length will be automatically shortened to 118 characters minus the length of your twitter name, to leave room for it and a link back to the post.
68
  </p>
69
 
70
  <h2>Settings</h2>
14
  add_action('init', 'bctt_tinymce_button');
15
 
16
  function bctt_tinymce_button() {
17
+ if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
18
  return;
19
  }
20
 
21
+ if ( get_user_option( 'rich_editing' ) == 'true' ) {
22
+ add_filter( 'mce_external_plugins', 'bctt_tinymce_register_plugin' );
23
+ add_filter( 'mce_buttons', 'bctt_tinymce_register_button' );
24
  }
25
  }
26
  function bctt_tinymce_register_button($buttons) {
64
  To add styled click-to-tweet quote boxes include the Better Click To Tweet shortcode in your post.</p>
65
  <p>Here's how you format the shortcode: <pre>[bctt tweet="Meaningful, tweetable quote."]</pre></p>
66
  <p>If you are using the visual editor, click the BCTT birdie in the toolbar to add a pre-formatted shortcode to your post.</p>
67
+ <p>Tweet length will be automatically shortened to 117 characters minus the length of your twitter name, to leave room for it and a link back to the post.
68
  </p>
69
 
70
  <h2>Settings</h2>
better-click-to-tweet.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Better Click To Tweet
4
  Description: Add click to tweet boxes to your WordPress posts, easily. This is a new, fully renovated version of the late "Click to Tweet" plugin by Todaymade. I overhauled the plugin using the shortcode API, and (perhaps most importantly) removed the "powered by" link.
5
- Version: 0.3
6
  Author: Ben Meredith
7
  Author URI: http://benandjacq.com
8
  Plugin URI: https://wordpress.org/plugins/better-click-to-tweet/
@@ -10,36 +10,36 @@ License: GPL2
10
  */
11
  include 'bctt_options.php';
12
 
13
- defined('ABSPATH') or die("No script kiddies please!");
14
 
15
- function bctt_shorten($input, $length, $ellipsis = true, $strip_html = true) {
16
- if ($strip_html) {
17
- $input = strip_tags($input);
18
  }
19
- if (strlen($input) <= $length) {
20
  return $input;
21
  }
22
- $last_space = strrpos(substr($input, 0, $length), ' ');
23
- $trimmed_text = substr($input, 0, $last_space);
24
- if ($ellipsis) {
25
  $trimmed_text .= '…';
26
  }
27
  return $trimmed_text;
28
  };
29
 
30
- function bctt_shortcode($atts, $content) {
31
- $handle = get_option('bctt-twitter-handle');
32
- if (!empty($handle)) {
33
  $handle_code = "&via=".$handle."&related=".$handle;
34
  } else {
35
  $handle_code = $handle;
36
  }
37
- extract(shortcode_atts(array(
38
  'tweet' => '$content',
39
  'handle' => '$handle_code'
40
- ), $atts));
41
  $text = $tweet;
42
- $short = bctt_shorten($text, (118 - strlen($handle_code)));
43
  return "<div class='bctt-click-to-tweet'><span class='bctt-ctt-text'><a href='https://twitter.com/intent/tweet?text=".urlencode($short).$handle_code."&url=".get_permalink()."' target='_blank'>".$short."</a></span><a href='https://twitter.com/intent/tweet?text=".urlencode($short).$handle_code."&url=".get_permalink()."' target='_blank' class='bctt-ctt-btn'>Click To Tweet</a></div>";
44
  }
45
 
2
  /*
3
  Plugin Name: Better Click To Tweet
4
  Description: Add click to tweet boxes to your WordPress posts, easily. This is a new, fully renovated version of the late "Click to Tweet" plugin by Todaymade. I overhauled the plugin using the shortcode API, and (perhaps most importantly) removed the "powered by" link.
5
+ Version: 0.4
6
  Author: Ben Meredith
7
  Author URI: http://benandjacq.com
8
  Plugin URI: https://wordpress.org/plugins/better-click-to-tweet/
10
  */
11
  include 'bctt_options.php';
12
 
13
+ defined( 'ABSPATH' ) or die( "No script kiddies please!" );
14
 
15
+ function bctt_shorten( $input, $length, $ellipsis = true, $strip_html = true ) {
16
+ if ( $strip_html ) {
17
+ $input = strip_tags( $input );
18
  }
19
+ if ( strlen( $input ) <= $length ) {
20
  return $input;
21
  }
22
+ $last_space = strrpos( substr( $input, 0, $length) , ' ');
23
+ $trimmed_text = substr( $input, 0, $last_space );
24
+ if ( $ellipsis ) {
25
  $trimmed_text .= '…';
26
  }
27
  return $trimmed_text;
28
  };
29
 
30
+ function bctt_shortcode( $atts, $content ) {
31
+ $handle = get_option( 'bctt-twitter-handle' );
32
+ if ( !empty( $handle ) ) {
33
  $handle_code = "&via=".$handle."&related=".$handle;
34
  } else {
35
  $handle_code = $handle;
36
  }
37
+ extract( shortcode_atts( array(
38
  'tweet' => '$content',
39
  'handle' => '$handle_code'
40
+ ), $atts ) );
41
  $text = $tweet;
42
+ $short = bctt_shorten( $text, ( 117 - strlen( $handle ) ) );
43
  return "<div class='bctt-click-to-tweet'><span class='bctt-ctt-text'><a href='https://twitter.com/intent/tweet?text=".urlencode($short).$handle_code."&url=".get_permalink()."' target='_blank'>".$short."</a></span><a href='https://twitter.com/intent/tweet?text=".urlencode($short).$handle_code."&url=".get_permalink()."' target='_blank' class='bctt-ctt-btn'>Click To Tweet</a></div>";
44
  }
45
 
readme.txt CHANGED
@@ -4,17 +4,19 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: click to tweet, twitter, tweet, twitter plugin, Twitter boxes, share, social media, post, posts, plugin, auto post
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
- Stable tag: 0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- This plugin allows you to create beautiful Click To Tweet boxes anywhere in your blog post.
12
 
13
  == Description ==
14
 
15
- This plugin allows you to easily create tweetable content for your readers. Using a simple shortcode, your selected text is highlighted and made tweetable.
16
 
17
- This is a complete retool of the late "Click To Tweet" plugin by Todaymade. It now uses the WordPress shortcode API, making it more secure, and I've cleaned up the CSS from the old plugin. Perhaps most significantly, I removed the "powered by Coschedule" link.
 
 
18
 
19
  Don't be scared to donate, if this plugin makes your blogging life any better.
20
 
@@ -47,6 +49,15 @@ In the visual editor, you can click the blue birdy icon in the toolbar and a cor
47
  = What do I do if it's not working right? =
48
  I am active in [the support forums](https://wordpress.org/support/plugin/better-click-to-tweet "Better CTT Support"), and in patching the plugin. Start a thread there, and I will gladly help you out. Most of the time you can expect a few hours before a response. I'm in the eastern US, and I like playing with my kids at night, so you might not hear back immediately. Don't panic.
49
 
 
 
 
 
 
 
 
 
 
50
  == Screenshots ==
51
 
52
  1. This in the editor...
@@ -54,6 +65,9 @@ I am active in [the support forums](https://wordpress.org/support/plugin/better-
54
 
55
  == Changelog ==
56
 
 
 
 
57
  = 0.3 =
58
  * added margin on the bottom of the bcct-clicktotweet div
59
 
4
  Tags: click to tweet, twitter, tweet, twitter plugin, Twitter boxes, share, social media, post, posts, plugin, auto post
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
+ Stable tag: 0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Add click to tweet boxes securely, using the official WordPress API. An overhaul of the Click To Tweet plugin by Todaymade.
12
 
13
  == Description ==
14
 
15
+ This plugin allows you to easily create tweetable content for your readers. Using a simple shortcode, your selected text is highlighted and made tweetable.
16
 
17
+ This is a complete retool of the "Click To Tweet" plugin by Todaymade. It now uses the WordPress shortcode API, making it more secure, and I've cleaned up the CSS from the old plugin. Perhaps most significantly, I removed the "powered by Coschedule" link. For more on the differences between this plugin and the Click To Tweet plugin by Todaymade, read the FAQ section.
18
+
19
+ I am working on a tutorial to swtich to my plugin from the previous version in a way that doesn't mean you have to switch every shortcode by hand. Stay tuned!
20
 
21
  Don't be scared to donate, if this plugin makes your blogging life any better.
22
 
49
  = What do I do if it's not working right? =
50
  I am active in [the support forums](https://wordpress.org/support/plugin/better-click-to-tweet "Better CTT Support"), and in patching the plugin. Start a thread there, and I will gladly help you out. Most of the time you can expect a few hours before a response. I'm in the eastern US, and I like playing with my kids at night, so you might not hear back immediately. Don't panic.
51
 
52
+ = What are the differences between this plugin and Click To Tweet by Todaymade? =
53
+ I originally was planning on contacting Justin at Todaymade to suggest some improvements to the code on his plugin, and in the midst of that, his plugin was unexpectedly pulled from the official repository, for having a (frowned upon) "Powered By" link. So, I set about fully overhauling the plugin.
54
+
55
+ Since that time Justin and the team over at Todaymade have rereleased a version of their plugin without the "Powered By" link. His plugin (which was originally released before the advent of the shortcode API) still doesn't use it, and for that reason is less secure than mine. For him to change to support the shortcode API is a more comlicated issue, as he'll need to still provide support for how his plugin currently handles the pseudo-shortcode system, or risk breaking every current user's website.
56
+
57
+ The bottom line for an end user is that both plugins are great, with the main difference being mine using the official WordPress shortcode API, and some other minor tweaks to the code. For example, my plugin adds some calculation based on the length of your Twitter handle to prevent truncated tweets from still being over 140 characters.
58
+
59
+ Also from an end user perspective, I am more active in the support forums than Justin (who has a paid product to support, which justifiably takes more of his time and energy), and you can count on my response and resolution to your issues!
60
+
61
  == Screenshots ==
62
 
63
  1. This in the editor...
65
 
66
  == Changelog ==
67
 
68
+ = 0.4 =
69
+ * rescued 9 characters that were being stolen by some incorrect math in my tweet-generating function. (now tweets won't be truncated until they actually need to be).
70
+
71
  = 0.3 =
72
  * added margin on the bottom of the bcct-clicktotweet div
73