Tag Archives: plugins

Stop SOPA Ribbon for your WordPress site or network. A plugin I made in a few minutes to show my support. It works with Multisite if you need a ribbon throughout the whole network. Learn more about SOPA on the Stop American Censorship website or read the Help Stop SOPA/PIPA in the WordPress news section.



About the "Lock in Effect" in WordPress Themes and Plugins

The WordPress themes and plugins market is huge these days. With all that wide range of products available, we sometimes stumble into situations where we’d like to change our mind, i.e. use a different plugin or theme instead of the one we’re currently using.

Eventually we figure out that it’s incredibly tough to replace some of the themes and plugins, because as soon as they’re deactivated, all (or part) of our data is lost, and the new theme or plugin that was supposed to replace the old ones, doesn’t see the data we previously had. So we say that we’re locked in.

This post describes the lock in effect, shows you some methods to identify such themes and plugins. Plus, if you really do have to use one such theme or plugin, we’ll cover some tips on escaping or locking yourself out.

Continue reading



Posted this yesterday on Twitter, thanks for all the retweet and fave love! I started seeing quite a lot of tweets and posts on how to do things “without a plugin” in WordPress and 99% of them involve writing snippets in your theme’s functions.php file. Now, how does that differ from writing a plugin?

  1. It’s more difficult to manage and maintain.
  2. If something stops working you can’t “deactivate” your functions.php snippets one by one to figure out which is causing the problem, you can do this with plugins.
  3. When you switch to a new theme you’ll have to port and then merge and cleanup the functions file too.
  4. It’s easier to share plugin files than it is to share functions.php snippets.

I’m pretty sure there are a lot more reasons. So dear all, write plugins, even if they’re dead simple and do one thing only. The “all in one” plugins carry the real overhead which is never used. Then, when you’re ready, submit your plugins to the WordPress.org Plugins Directory to give back to the community. That’s why the open source WordPress is so strong.



Announcing the Twitter Embed Plugin for WordPress

Hey there! I just released a brand new WordPress plugin called Twitter Embed. It supports several ways of embedding tweets into your WordPress posts and pages. The new (new-new) Twitter interface has introduced a new link on tweets called “Embed this Tweet” which allows embedding through HTML code, shortcode or link.

Twitter Embed

This plugin implements all of those ways. It will even reverse an embed HTML into a shortcode if the user doesn’t have privileges to post unfiltered HTML. It caches the API responses from Twitter.com for better performance and well, it’s as simple as it looks and sounds, doesn’t require any configuration and works out of the box, right after activation.

Download it from the WordPress.org Plugins Directory, give it a spin and let me know if it works for you. Cheers and Happy New Year!



Varnish and WordPress Comment Cookies

I wrote before that I’ve been running some experiments with Varnish lately. Not that I have huge traffic here but I’ve always used my own website to test things out. As I wrote earlier, the problem with WordPress and Varnish is that WordPress relies on cookies which create cache misses on Varnish and in that previous post I shared a snippet on how to strip all incoming and outgoing cookies, which hopefully solves one problem.

The second problem now is that cookies are disabled throughout the whole website (except the admin section of course) so if you’ve got commenters on your website, their browsers will no longer save their names and e-mails, so they’ll have to type them in every time they want to leave a comment. I agree it’s a pain, which is why I was searching for a solution, which turned out to be quite simple — handle it all on the client side using javascript.

So I wrote a little plugin which you can download and use. It simply enqueues a javascript file if the request is a singular page and comments are open. It passes in some cookie constants used by WordPress. The javascript itself hooks onto the submission of the comment form to create cookies and restores the form fields upon page load.

Note that the plugin can fail if you’re rendering your comment form differently (with different DOM IDs) from WordPress, and don’t forget to purge.url your Varnish cache after activating!



New Plugin: Posts Screen Excerpt – makes an excerpt column available in the All Posts screen in WordPress. Useful for when working with posts without titles, where (no title) doesn’t say much about which post you’re about to edit.



Got tired of dealing with “support” comments and bug reports on my blog, so now I’m opening Github repositories for some of my WordPress plugins. The first two are Twitter Friendly Links and Technical Support. Eagerly waiting for the first pull request now ;)



Unreplied Comments in WordPress

Dealing with comments. What a mess! I’ve been quite busy lately so I hadn’t had too much time to reply to each and every comment on my blog, but I’d really love too, seriously! The problem however is that there were times when I replied to somebody, and times when I hadn’t and now with this mess in my comments admin it’s impossible to find out ones I haven’t replied to.

Comments: Such a mess!

I was looking for a plugin but haven’t found anything good enough. Even hosted commenting services like Disqus and Livefyre seem to lack that. Ideally I’d like to work with comments like with e-mail — read them, mark as unread, flag, assign to somebody, etc. So I quickly drafted an SQL query that gave me a list of IDs of comments that have not been replied to excluding my own:

SELECT t1.comment_ID FROM wp_comments AS t1
    LEFT JOIN wp_comments AS t2 ON t2.comment_parent = t1.comment_ID
    WHERE t2.comment_ID IS NULL
    AND t1.user_id = 0
    AND (t1.comment_approved = '0' OR t1.comment_approved = '1')
    ORDER BY t1.comment_date_gmt;

I was shocked by the amount of rows it returned so I switched the “disable commenting on posts older than 14 days” checkbox to make sure that doesn’t happen again. You can always reach me on Twitter or e-mail, right? ;)

I’d love to see this as a beginning for a new WordPress plugin that would implement some goodies for handling comments, or maybe as a tip to the hosted commenting services to create new features. In any case, I’m now stuck with over a thousand comments I have to go through.



Using Google's URL Shortener (goo.gl) in WordPress

The Google URL Shortener API has been released this week so I came up with a short snippet that generates short goo.gl URLs. The script is quite simple, you can paste it in your theme’s functions.php file or create a plugin out of it, so without further ado:

function googl_shortlink($url, $post_id) {
	global $post;
	if (!$post_id && $post) $post_id = $post->ID;

	if ($post->post_status != 'publish')
		return "";

	$shortlink = get_post_meta($post_id, '_googl_shortlink', true);
	if ($shortlink)
		return $shortlink;

	$permalink = get_permalink($post_id);

	$http = new WP_Http();
	$headers = array('Content-Type' => 'application/json');
	$result = $http->request('https://www.googleapis.com/urlshortener/v1/url', array( 'method' => 'POST', 'body' => '{"longUrl": "' . $permalink . '"}', 'headers' => $headers));
	$result = json_decode($result['body']);
	$shortlink = $result->id;

	if ($shortlink) {
		add_post_meta($post_id, '_googl_shortlink', $shortlink, true);
		return $shortlink;
	}
	else {
		return $url;
	}
}

add_filter('get_shortlink', 'googl_shortlink', 9, 2);

For the tech people I’ll explain what I’m trying to do here. So first of all we don’t want to shorten links on draft posts as that could be a waste of resources, so we return an empty string. The magic with get_post_meta and add_post meta in the middle and at the end of the function are done for caching purposes — we don’t want to send too many requests to the Google API so let’s keep the already shortened links in the post’s custom fields. This may be annoying in the UI so you might want to add an underscore in the meta key (“_googl_shortlink”) which will make it invisible to the UI.

Next up, I retrieve the permalink of the published post, since we don’t want to shorten an already shortened URL which is that ugly one by WordPress. I use that permalink in an HTTP request to Google’s API using WordPress’ WP_Http object. Note that I’ve added the Content-Type header, which is required by Google, otherwise it’ll return an error. I decode the result body using json_decode (you need PHP 5.2 or later to do this) and if there’s a valid id, which is the shortened URL, I save it to the post’s meta and return the shortlink. If something went wrong, I return the original WordPress’ short URL.

So, clicking on the “Get Shortlink” button in your admin UI will now produce a Goo.gl shortened link to your post. Neat eh? You can also use short links in your theme, somewhere in The Loop:

echo "Shortlink: " . wp_get_shortlink();

Goo.gl Analytics

Right, you might want to see your short links’ analytics at some point. Well, Goo.gl shortened links are all public and their analytics are public too, so all you have to do is browse to goo.gl/info/code where code is the 5-6 alphanumeric digits attached to your shortened URL at the end.

For convenience I wrote a little snippet that would output the short URL and a link to it’s analytics page in your posts list screen inside the admin panel. Below is the code that should go to your functions.php file or plugin file:

function googl_post_columns($columns) {
	$columns['shortlink'] = 'Shortlink';
	return $columns;
}

function googl_custom_columns($column) {
	global $post;
	if ('shortlink' == $column)
	{
		$shorturl = wp_get_shortlink();
		$shorturl_caption = str_replace('http://', '', $shorturl);
		$shorturl_info = str_replace('goo.gl/', 'goo.gl/info/', $shorturl);
		echo "<a href='{$shorturl}'>{$shorturl_caption}</a> (<a href='{$shorturl_info}'>info</a>)";
	}
}

add_action('manage_posts_custom_column', 'googl_custom_columns');
add_filter('manage_edit-post_columns', 'googl_post_columns');

I wrote about custom columns in a post called Custom Post Types in WordPress 3.0, which should give you a general idea of what’s going on here. For more details visit the WordPress Codex.

That’s about it! Yeah, I know there’s some stuff that can be improved here, like smooth error handling, but it’s up to you to implement it. For more info check out the Google URL Shortener Getting Started page. A good place for experiments with Google’s APIs is Google APIs Console.

The plugin-version of this code is available at the WordPress plugin directory: Goo.gl for WordPress. Thank you for reading and retweeting ;)



Introducing Retweet Anywhere for WordPress

Hey, guess what! I’ve just released a new WordPress plugin called Retweet Anywhere. It’s something I’ve been working on a few days, inspired by the previoulsy used Sociable and Tweetmeme plugins, allowing visitors to tweet my posts. What I didn’t like about those two is that Sociable simply redirects to twitter.com with a preset status, and Tweetmeme is not customizable enough in terms of application name, etc. Retweet Anywhere solves both issues.

Retweet Anywhere enables you to place retweet buttons, links, images, literally anywhere in your blog. The standard mode fades the background and shows a lightbox with the text input with a preset status, where all one has to do is click the tweet button. Everything happens via OAuth, so you’re never asking your visitors for their Twitter names or passwords, and your branded tweets are fired through their accounts tagged with your application name.

Retweet Anywhere allows visitors to modify the text they’re about to tweet. This enables them to address somebody in particular, or simply add a few hashtags. As the administrator you’re allowed to customize the format of the default text, using simple codes like %s and %l which end up in professional looking tweets, such as “Reading: Post Title http://example.org #hashtag (via @kovshenin)”. Now isn’t that awesome? You’re also allowed to shorten your links using your bit.ly account, then track your click through rate. Bang!

Retweet Anywhere

Moreover, you can place such retweet buttons, links or your own custom HTML anywhere in your posts, for instance: Thank you for retweeting this awesome post. It uses the WordPress shortcodes system, which enable you to place such links into your posts, pages and widgets. Speaking about widgets, here’s a surprise for you.. Retweet Anywhere comes with an awesome, fully customizable retweet widget which you can push into your sidebars in seconds, allowing your visitors to retweet your posts, pages, archives, with a single click of a mouse! Fantastic!

And of course, the plugin is totally free of charge, yup yup, all yours, GPL licensed! Download available at the WordPress plugin directory, right over here: Retweet Anywhere.

Now, for the more techy guys, let’s go over some details. The plugin comes bundled with the jQuery Facebox plugin, and uses the Twitter @Anywhere pack to display their tweetBox() inside Facebox, which makes it look very slick. The URL trimming is all happeneing on the server-side and fired via AJAX on your pages, this means that your page will not slow down. Furthermore, the already trimmed links are saved into custom fields to your posts and pages, which saves you time and bandwidth, next time somebody tries to shorten – simple, yet effective caching!

As usual, all your comments and thoughts are highly appreciated. Bugs will be fixed, functionality will be improved. All thanks to WordPress and @Anywhere. If you’re wondering about upcoming features then the only one I could mention at this stage is of course localization – Russian and a few other languages ;) More info, discussions, changelog, etc on the dev page.

Cheers, good luck and don’t forget to retweet this post!