WordPress plugin: Automagic Twitter Profile URI for WordPress
As of now, the plugin currently cannot work anymore.
Please see Twitter Issue 353 and second my request to bring back the required functionality by either “starring” the topic or contributing to it. Thank you very much for your help.
Automagically adds a Twitter profile link to your commenters: If they have a Twitter profile, a link to it is “magically” added to their name in the comments. Whoo! (Idea by Otto.)
This plugin requires at least WordPress 2.7.
Overview
- Download
- Installation
- Frequently asked questions
- Customization
- Version history
- To-do list
- Comments, feedback & support
Download
You can find the plugin over at WordPress.org (as its hosted by WordPress.org). It is licensed under the GPL (which means it’s also open source software). Three step installation instructions are included.
Installation
- Upload the
automagic-twitter-profile-uridirectory to the/wp-content/plugins/directory. - Activate the plugin through the ‘Plugins’ menu in WordPress.
- That’s it! You may want to check the plugin settings for fine tuning, though.
Frequently asked questions
-
How does it work?
On most blogs, the commenter has to leave an email address. This plugin uses this email address to “ask” Twitter if there is a username with that email address. -
What about my existing commenters? What happens?
Your existing commenters won’t be automatically “enchanted” (no automatic opt-in). If your returning commenters want to take advantage of the magic, they just need to agree on it when commenting next time. All of their old comments will be updated then. However, if your commenters may not decide about the magic, all of this will be overridden, and even existing commenters will have their Twitter account being associated, if they have one. -
I now have a gazillion of comments and commenters that want the magic, but Twitter’s API has a limit of 100 queries an hour. What happens?
This plugin will subsequently retrieve all Twitter usernames, but it may not happen at once but over a period of some hours (depending on the number of different commenters you have). If you’re over the limit, the plugin “will know” and update the record as soon as possible. -
Won’t that generate lots of traffic to Twitter?
Nope, this plugin caches any results from Twitter. That means: once a Twitter username is known (or there is none), that record will be saved to the database immediately and won’t be refreshed before a defined period (default configuration: seven days). -
What are my options to customize the output of the plugin?
For a full description please have a look at “Customization“. -
No Twitter profile links show up. Curse you!
That could mean several things: Either your commenters just don’t use Twitter at all, or the email addresses they use to comment aren’t the ones they’re using for their Twitter accounts, or the automagic integration just doesn’t work. To find out if latter, have a look at the plugin’s dashboard widget, and if it shows there are some commenters with Twitter profiles, please have a look at “Using a template tag“. Arr! -
I use Disqus/IntenseDebate/something, and it won’t work!
Those services sort of replace WordPress’ commenting function. You’ll either need to switch back to “classic commenting”, or ask your commenting service provider if they can integrate the functionality of this plugin.
Customization
You can completely customize the output of the plugin through its options page. Updates of the settings take place immediately in your blog, also a preview on the options page will be shown. Here’s an overview of the possible settings (italic text in the title means default setting):
Basic settings
These settings are the most commonly used.
-
Enable automagic integration (yes/no)
When set to ‘yes’, the plugin will attempt to automagically integrate the Twitter profile link to your comments. This is the preferred option and should work most of the time. If it doesn’t, you’ll have to manually add a template tag (see “Using a template tag”). -
Show Twitter icon (yes/no)
When set to ‘yes’, the Twitter logo will be shown in front of the link. -
Show “Twitter” or “@username” (Twitter/@username/both)
This will define the actual link text. If set to ‘both’, only the @username will be linked.
Advanced settings
Allows fine tuning.
-
Wrap in brackets (yes/no)
When set to ‘yes’, the link will be wrapped in brackets (if not changed). -
Append a line break (no line break/before/after/before and after)
This setting allows to add a line break to the link: before, after and both. -
Wrap with a CSS class (yes/no)
When set to ‘yes’, the link will be wrapped in a CSS class called atpu (if not changed), so you can visually tune it as well. -
Show a notice about the magic under the comment form (to all/to visitors/no)
When enabled, a notice will be shown right under your comment form to inform your commenters about the “magic” that’ll happen. -
Let the commenter decide to publicize his/her username (all commenters/just visitors/no)
When enabled, your commenters may decide if they want their email address being associated with their Twitter account and thus it being shown or not (an option field will be added to your comment form).
Note: You should set this to “no” if you are manually integrating this function in your template (viaatpu_option()). -
If the commenter is allowed to decide, the default setting is (magic enabled/magic disabled)
When enabled, the checkbox (see point above) will be selected by default. If disabled, well, then it’s disabled by default. -
Apply a CSS “clear: both” to the notice/option about the magic (yes/no)
When set to yes, some CSS will be added to both the notice and option text for your commenters. This makes especially sense if those fields look weird under your comment form (they don’t seem to respect the position of the submit button). -
Use Twitter’s SSL capabilities (for both querying from and linking to Twitter/only for links to Twitter/only for querying from Twitter/no)
This setting enables you to use Twitter’s secure communication features. “Linking to” means pointing all Twitter profiles tohttps://twitter.com/username(notice the ’s’ for SSL encrypted communication) rather than to the standard host. “Querying from” means using the SSL encrypted communication when searching for Twitter accounts – this is highly recommended but may not work with your server. Also, it may slow down querying time to Twitter.
Customize strings
These settings allow modification of output strings. These strings will be used for both standard and custom output.
-
CSS class name (atpu)
Allows you to change the plugin’s CSS class name. -
Twitter icon URI (“blog uri/plugin folder/images/twitter.gif“)
Allows you to change the URI to the Twitter icon, so you can use your own. -
Text to prepend (like a bracket) (()
Allows you to change the prepending text to the link. Usually, this is an opening bracket, but you could use even HTML tags, for example<small>. -
Text to append (like a bracket) ())
Allows you to change the prepending text to the link. Usually, this is a closing bracket, but you could use even HTML tags, for example</small>. -
Line break HTML code (<br />)
Allows you to change the HTML tag of the line break. Usually, this is<br />, but you can use any non-nesting tag, such as<hr />. -
Text for separator (: )
Allows you to change the text used for separation, e.g. when displaying both “Twitter” and “@username”. -
The commenter notice text
Allows you to change the text that can be displayed about what’s happening due to this plugin. -
The commenter publicize option text
Allows you to change the text that will be shown to your commenters if they may decide their fate.
Custom link string
Using a custom output string allows you to override the basic and advanced settings. This requires some understanding of HTML, as you basically write a piece of code you’d like to see for the Twitter link and add special tags to where you’d like to get specific plugin output. The tags respect all settings from the options page.
The tags you can use:
-
%COMMENTER%
Returns the commenter name, like: ‘Benjamin Wittorf’ -
%USERNAME%
Returns the Twitter username, like: ‘bwittorf’ -
%BREAK%
Returns the line break, default: ‘<br />’ -
%SEPARATOR%
Returns the separator, default: ‘: ‘ -
%APP%
Returns the appending text, default: ‘(‘ -
%PRE%
Returns the prepending text:, default ‘(‘ -
%URI%
Returns Twitter’s base URI, default ‘http://twitter.com’ -
%IMG%
Returns the Twitter icon, default: ‘<img src=”host/plugin path/images/twitter.gif” title=”Twitter” />’ -
%TITLE%
Returns the title of Twitter, default: ‘Twitter’ -
%CSS%
Returns the CSS class name, default: ‘atpu’
Example
If you’d use the following custom link string:
%IMG% %TITLE%%SEPARATOR% <a href="%URI%/%USERNAME%" title="Follow %COMMENTER% at %TITLE%">@%USERNAME%</a>
You’d get an output like this:
<img src="/wp-content/plugins/automagic-twitter-profile-uri/images/twitter.gif" title="Twitter" /> Twitter: <a href="http://twitter.com/bwittorf" title="Follow Benjamin Wittorf at Twitter">@bwittorf</a>.
Core settings
These are the plugin core settings. You probably don’t want to change anything.
-
Days to cache Twitter queries (1, 7, 14, 28)
Allows you to change the amount of time Twitter queries should be cached. One day doesn’t make sense and should only be activated if a fast refresh of the cache is required, whereas 28 days is probably only useful on a blog with gazillion of new commenters every day. -
Name of service (Twitter)
Allows you to change the name of the service used for the output. Twitter itself probably won’t change that. Could be used when using a Twitter API compatible service, though. -
Twitter API URI
Allows you to change the URI of Twitter’s API. Unless Twitter doesn’t change it, you wouldn’t want to, too. Could be used for a Twitter API compatible service, though (yup). -
Twitter base URI
Allows you to change the base URI of Twitter. Seriously, unless Twitter doesn’t change it, you really wouldn’t want to, too! Could be also used for a Twitter API compatible service, though (just for the record). -
Plugin cache name (atpu_cache)
Allows you to change the name used for the internal WordPress cache. I don’t know why you would want to, but you can!
In case something went wrong
Just hit “Reset Options” on the options page to reset all values to their default values. This does not flush the Twitter query cache. “Flush Cache” does. Duh! “Drop Database Table” will drop and recreate the plugin database table (while preserving settings), this will effectively delete everything the plugin has ever known about your commenters.
Using a template tag
Sometimes the automagic integration just won’t work, or it won’t suite your template design. In that case, you’ll have to modify your comments template if you want to use the output of this plugin. Just put <?php if (function_exists('atpu')) { atpu(); } ?> wherever you’d like the link to appear (remember: it must be in the comments loop). This function respects all the settings you make on the options page – even the custom link string.
Example
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class="commentmetadata">
<a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit',' ',''); ?>
</small>
// “Automagic Twitter Profile URI”
<?php
if (function_exists('atpu')) { atpu(); }
?>
<?php comment_text() ?>
</li>
<?php
/* Changes every other comment to a different class */
$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
Comment form template tags
You can also add the comment form notice text and option field manually by using <?php if (function_exists('atpu')) { atpu_notice(); } ?> (will show the notice about the “magic”) and <?php if (function_exists('atpu')) { atpu_option(); } ?> (will show the option to disable the “magic”). Be sure to have them deactivated in Advanced Settings → Comment form options
to avoid duplicates.
Both of these functions must go to your comments form section in your template, and both functions respect their customized strings.
Direct function calling
Do you want even more control over the output? You know what you are doing, at least when coding PHP? You then can deactivate the automagic integration and find out how deep the rabbit hole really is by using the plugin’s PHP function get_atpu() in your template to get specific output.
The commands are (they are not ‘echoed’, so you have to):
-
get_atpu('commenter')
Returns the Name of the commenter (likeBenjamin Wittorf). -
get_atpu('nick')
Returns the Twitter username (likebwittorf) orfalseif empty. -
get_atpu('link_name')
Returns the link name (default:Twitter). -
get_atpu('text_pre')
Returns the prepending text (default:(). -
get_atpu('text_app')
Returns the appending text (default:)). -
get_atpu('css')
Returns the name of the CSS class (default:atpu). -
get_atpu('uri')
Returns the Twitter URI (duh) (default:http://twitter.com). -
get_atpu('icon')
Returns the Twitter icon URI (default:“host/plugin path/images/twitter.gif”). -
get_atpu('title')
Returns the title of Twitter (default:Twitter). -
get_atpu('line_break')
Returns the line break (default:<br />). -
get_atpu('separator')
Returns the separator (default::). -
get_atpu('custom_string')
Returns the custom link string.
Remember the code must go to the comments template in the comments loop. Otherwise, it just won’t work.
Version history
The current version is 1.2.2 (2009.04.13).
1.2.2 (2009.04.13)
- Attention: The plugin auto deactivates itself on updating. Please see Twitter Issue 353 and second my request to bring back the required functionality.
1.2.1 (2009.02.24)
- Changed: Fixed a typo that prevented this plugin from working. Sorry for any inconvenience.
1.2.0 (2009.02.24)
- New: You can now define the commenter display option checkbox default status (checked/unchecked; thanks to Jean-Paul Horn for the idea).
- Changed: Some internal routines to respect “function users” more.
1.1.2 (2009.02.22)
- Changed: Some minor code optimizations.
1.1.1 (2009.02.10)
- Changed: The plugin has a much nicer options page now.
1.1.0 (2009.02.09)
- New: Added another panic option, “Drop Database Table”, which will drop and recreate the plugin database table (while preserving settings). This is especially useful if you do not only want to flush the cache but old commenters not being associated with their Twitter username (no automatic opt-in, the next time they comment they can have the magic again).
1.0.2 (2009.02.09)
- Fixed: That manual opt in for existing commenters caused some trouble (making the plugin behave unexpected). Everything is fine and works as advertised now.
1.0.1 (2009.02.09)
- Changed: On new installations of this plugin, existing commenters won’t be automatically “enchanted” anymore. Returning commenters need to specifically agree to the magic if they want their old comments to be updated with the profile link. This will be overridden when the commenter isn’t shown the option to decide (thanks to Nicole for the idea).
1.0.0 (2009.02.08)
- There’s nothing new or changed in this version (it is exactly the same as 0.5.2), only with the “gold status”/”stable release” tag.
0.5.2 (2009.02.06)
- New: You can now enable SSL connections to Twitter.
- Changed: Updated localization strings.
- Changed: Default settings: Comment form option instead of notice will be shown.
0.5.1 (2009.02.05)
- New: Template tag support for comment form notice text and option (see documentation).
- Changed: Some code optimizations.
- Changed: Comment form notice will be shown using default settings.
0.5.0 (2009.02.05)
- New: You can now let your commenters decide if they want to let the “magic” happen.
- New: You can now enable CSS “clear: both” on comment form notice/option.
0.4.3 (2009.02.03)
- New: You can now have a notice about the “magic” automatically displayed under your comment form (and edit the text as well; thanks to Guy Vestal for the idea).
0.4.2 (2009.02.03)
- Fixed: Plays nice now with KeywordLuv (thanks to Guy Vestal for the hint).
0.4.1 (2009.02.02)
- New: Option to flush the cache on/from the options page.
- Fixed: Options page now also works with SSL hosts.
- Changed: Options page base name changed to plugin base name.
- Changed: Dashboard details (removed most of the line breaks).
- Changed: Even more error handlers when trying to get data from Twitter.
0.4.0 (2009.02.02)
- New: Automatic integration, no more template editing.
- New: An options page.
- New: Better / easier customization.
- Changed: Improved localization features.
0.3.0 (2009.02.01)
- New: Dashboard information widget.
- Changed: Deactivating the plugin no longer flushes the cache (what a mess on upgrading).
0.2.5 (2009.01.26)
- New: Support for WordPress’ own plugin deletion (removes the then unused database table and options).
0.2.4 (2009.01.26)
- New: Now supports caching plugins (thanks to Otto for the tip).
- Changed: Updated database table structure for the things to come.
- Changed: Even more internal calls are now optimized (yup, again).
0.2.3 (2009.01.25)
- Fixed: Commenting was not possible (whoops).
0.2.2 (2009.01.25)
- Changed: Improved code documentation.
- Removed: Removed an unnecessary “if” loop.
0.2.1 (2009.01.25)
- New: Added more Twitter exception handlers.
0.2.0 (2009.01.24)
- New: Now “prefetches” all Twitter usernames on displaying an entry, avoids redundancy and lots of database calls (thanks to Otto for the tip).
- New: Handler for Twitter “over capacity” or ”maximum requests”.
- Changed: Even more code optimizations.
0.1.1 (2009.01.23)
- Fixed: Entries without a Twitter username wouldn’t be updated.
- Fixed: Localization now fully works.
- Changed: The plugin doesn’t require PHP 5.2 anymore.
-
Changed: Switched from
json_decode()to good oldpreg_match()to extract Twitter usernames (thanks to Otto for the tip). Better compatibility to older PHP versions! -
Changed: Switched from
get_file_contents()towp_remote_get()to retrieve data from Twitter (thanks to Otto for the tip). Faster and more reliable! - Changed: General code optimization.
0.1.0 (2009.01.23)
- Initial release
To-do list
- A button to temporarily disable pulling from Twitter (to manually handle long “failwhale” times).