Store Just WordPress Transients Persistently

WordPress comes with an option of keeping cache in a persistent storage, if provided. It provides a great deal of performance since everything that WordPress was doing repeatedly on each page request now can be saved in the persistent cache storage (APC / Memcached / Redis) and retrieve easily & very fastly without doing much work.

The way to activate that is to drop an object-cache.php file in your wp-content directory which does the heavy lifting for you. Following plugins are available if you want to get started with it:

You don't have a reason to not use object caching unless you are stuck with a plugin which doesn't follow WordPress standards and causes the site to malfunction when a persistent cache storage is used. An example of such a plugin is Wishlist Member plugin.

It simply doesn't work well with persistent object cache because it updates the options table directly by making SQL queries instead of using functions like get_option(), update_option() etc.

I needed to solve the problem, where we could atleast store some of stuff in the persistent cache & hence improving performance. The site for which this was done, is a learning portal where all members are logged in, hence full pages were generated dynamically every single time. To take off some of the load, I developed a plugin in which transients are stored in memcached (persistent storage) so that they can be retrieved very quickly without making SQL queries to the database.

I suggest you use this plugin or use it as a starting point to build what you need. Plugins of this kind, require installation & verification by a developer since its a very barebones-prototype plugin, which does the job of saving transients and retrieving them quickly.

Plugin's repository - https://github.com/ashfame/Store-Just-Transients-Persistently

It also overrides wp transient delete-all WP-CLI command so that you can flush transients from both database and memcached (persistent cache storage in use).

Its always a good idea to contribute back your work to the plugin if you build on top of it or extend it, so that other community members can gain from it.

Let me know if you have a question that I can help answer.

Updated Facebook Like Thumbnail WordPress plugin (v0.3.1) released

I just pushed out the latest version of my plugin Facebook Like Thumbnail, v0.3.1 to be precise, on WordPress.org plugins repo. It should show up in your WordPress admin shortly if you are using it and if not, then here is yet another reason to try the plugin out if random or unwanted images show up for your WordPress site when links are liked or shared on Facebook.

The new version is a complete rewrite and is really good at figuring out the context specific image to use for different types of pages. It also deals with situations where earlier version would run into compatibility issues with other plugins. And last but not least, this version is developer friendly in case you want to short-circuit the logic, you are able to do so now. All power to you.

Hit me up if you have any questions. And one real good of piece of advice that I can't mention too much is - Facebook maintains a cache of images selected for every URL (usually 24hours), so your new images won't show up right away, but eventually they will. Facebook has a really nice tool to debug your URLs outside of their cache to test the image being selected for display - https://developers.facebook.com/tools/debug

If you are looking for premium support - get in touch with me via my contact form.

WordPress plugin Facebook Like Thumbnail Updates

I have updated my WordPress plugin to fix Facebook Like Thumbnails to version 0.2 which I am sure will make the existing users happy! ūüôā

Some of the users who quickly upgraded might be facing issues because of a silly mistake on my part. If the plugin has disappeared from the plugins listing, then you would have to delete the folder "facebook-like-thumbnail" folder in your plugins folder (/wp-content/plugins/) and then reinstall the plugin by typing "Facebook Like Thumbnail" in Add New Plugins screen. I apologise for the issue, please excuse me, I am not used to pushing updates to public repositories.

The plugin now features an options pages which can be found under Settings > Facebook Like Thumbnail. You can specify your default thumbnail image on that page, no more code edits are required. This was a necessary move as the users would have to edit the plugin to specify their default image after every upgrade.

The plugin now supports featured thumbnails and NextGEN galleries (other than the slideshow ones).

The plugin picks the thumbnail in the following order (whichever is found first)

  • If its a post or page
    • Featured Thumbnail
    • First Image in the post
    • Default
  • If its a Front Page or Search Page
    • Default
  • Anything else
    • First image in the first post of the loop
    • Default

Facebook Like Thumbnail

Author: Ashfame, version: 0.4, updated: December 7, 2016,
Requires WP version: 3.1 or higher, tested up to: 4.7.3.
Download (82 231 hits) (5 votes)

Adding the author avatar on author pages to be used as thumbnail and ignoring smilies as a possible match for thumbnail are on my To-do lists. If you have any suggestions, comments section is all yours.

Also the plugin can be totally uninstalled by using the delete option from WordPress dashboard, it won't leave anything behind in the database.

I have tried to keep the plugin as fast as it can be. If any developer can provide any suggestions/improvements, I would love that. If you have any questions or facing any issues because of the early upgrade or need any help, give me a shout in the comments.

WordPress Plugin to fix Facebook Like Thumbnail

Today, Facebook pushed live another change which made Like button work similar to what we had known the Share button to do. Just to brush up, Share button was used to show the Title, Description and a screenshot of the page which you shared and the Like button would only show up as a line that the user liked XYZ Story on ABC site. But now after the new change is live, like button functions the same as the Share button.

Here is a screenshot of how the new like would show up on your profile:

facebook-new-like

I don't like the move as people tend to like a lot more stuff than what they share. This is going to stuff the stream with lots of noise. After like is not, and can't be equivalent to share. I might like a post on Ubuntu tutorial but is that something I would want to share with everyone else. No! But that's totally a different story.

Coming back to the point, many sites would show up random image of their page instead of an appropriate image. I have seen this on several blogs including mine, that sometimes an advertisement image would show up (from the sidebar), or a totally unrelated image of my another project (from the footer). so, I took this opportunity today to fix it for everyone.

You can check what thumbnail would Facebook show for a particular page by using their Lint tool.

The problem can be solved for non-WordPress based or html sites or whatever, by adding this line to their head section.

<link rel="image_src" href="http://example.com/logo.png" />

This will show that image on every page. But in WordPress, we can do a lot more, that's because WordPress is a brilliant piece of software.

You can use the plugin to fix the issue. It will display the first image of the post or page you are on. In case someone likes your Category or Tag page, then the first image of the first post in the listing will be used.

Facebook Like Thumbnail

Author: Ashfame, version: 0.4, updated: December 7, 2016,
Requires WP version: 3.1 or higher, tested up to: 4.7.3.
Download (82 231 hits) (5 votes)

You will need to edit a line which is highlighted in the code below to change the default fallback image to your logo so that whenever, the post doesn't have any image in it, your logo will be displayed. If you don't edit that line, then my logo will be displayed and I might sue you for that.

I have added a couple of features in the plugin, so I don't recommend you to use the snippet anymore. Using the plugin will make it easier for you to receive updates without touching any code. WordPress Facebook Like Thumbnail Plugin v0.2

In case, you don't want to download yet another plugin, you can add the following code in your functions.php file I recommend everyone to use the plugin version instead so that you can receive updates automatically.

Facebook crawls your page every 24 hours (at max), so you may not see the change right away but you would see it instantaneously, if you use the Linter tool once for that page because it updates the thumbnail for that page, right away.

I might add an options page for it to add an image if users request start coming up. Also I will host it on WordPress repositories once I get the time to, as I will need to look into it first.

If you have any question, you can ask in the comments. Also, please like it (not share) to share it with other fellow bloggers.

Kontactr WordPress plugin

My friend, Shankar Ganesh, is involved with Kontactr which provides an easy way for people to let others contact them. After some talk with my friend about implementing it as a plugin on the WordPress side, today I am going to do a quick post on Kontactr implementation on WordPress. Its very basic at the moment but I just wanted to show that adapting it to be a WordPress plugin is certainly very easy.

<?php
/*
Plugin Name: Kontactr WordPress Plugin
Plugin URI: http://blog.ashfame.com/?p=880
Description: Provides a shortcode which you can use to embed Kontactr form in your page
Author: Ashfame
Author URI: http://blog.ashfame.com/
License: GPL
Usage: [kontactr id=78523] in a post or page and <?php echo do_shortcode('[kontactr id=78523]'); ?> in your theme anywhere
*/

add_shortcode ( 'kontactr', 'kontactr_handler' );

function kontactr_handler( $atts, $content = null )
{
    extract( shortcode_atts( array(
        "id" => 0
        ), $atts ));

    if ( $id == 0 )
        return;
    else
    {
        $output = '<script type="text/javascript"> id = '.$id.'; </script>
            <script type="text/javascript" src="http://kontactr.com/wp.js"></script>';
        return $output;
    }
}
?>

You would need to take your ID from your Kontactr account, and then use it as follows:

 [kontactr id=78523] 

78523 is my ID. So replace it with your own.

You can also use this shortcode anywhere in the theme as

 <?php echo do_shortcode('[kontactr id=78523]'); ?> 

Download Kontactr WordPress plugin

If you have any questions, ask them in the comments section.

Show recent comments of a particular user in WordPress

A friend asked for a help in his project where he required to list all the comments a registered user made on the site. So just for play, I created a small plugin which provides you with a shortcode which you can use on a page link example.com/my-comments/ or whatever.

I am zipping it up as a plugin but you can copy paste the code inside your functions.php file and you should be fine.

<?php
/*
Plugin Name: Show Recent Comments by a particular user
Plugin URI: http://blog.ashfame.com/?p=876
Description: Provides a shortcode which you can use to show recent comments by a particular user
Author: Ashfame
Author URI: http://blog.ashfame.com/
License: GPL
Usage: 
*/

add_shortcode ( 'show_recent_comments', 'show_recent_comments_handler' );

function show_recent_comments_handler( $atts, $content = null )
{
    extract( shortcode_atts( array( 
        "count" => 10,
        "pretty_permalink" => 0
        ), $atts ));

    $output = ''; // this holds the output
    
    if ( is_user_logged_in() )
    {
        global $current_user;
        get_currentuserinfo();

        $args = array(
            'user_id' => $current_user->ID,
            'number' => $count, // how many comments to retrieve
            'status' => 'approve'
            );

        $comments = get_comments( $args );
        if ( $comments )
        {
            $output.= "<ul>\n";
            foreach ( $comments as $c )
            {
            $output.= '<li>';
            if ( $pretty_permalink ) // uses a lot more queries (not recommended)
                $output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
            else
                $output.= '<a href="'.get_settings('siteurl').'/?p='.$c->comment_post_ID.'#comment-'.$c->comment_ID.'">';         
            $output.= $c->comment_content;
            $output.= '</a>';
            $output.= "</li>\n";
            }
            $output.= '</ul>';
        }
    }
    else
    {
        $output.= "<h2>You should be logged in to see your comments. Make sense?</h2>";
        $output.= '<h2><a href="'.get_settings('siteurl').'/wp-login.php?redirect_to='.get_permalink().'">Login Now &rarr;</a></h2>';
    }
    return $output;
}
?>

You can use in a post or page as follows:

[show_recent_comments]

This will show last 10 comments of the current user.

[show_recent_comments count=15]

You can change the number of comments you want by providing it with the value of count.

Now, if you notice, they do link to the respective comments but links are not pretty permalinks. I don't recommend you do this (because it increases the query count), but if you really want to have pretty permalinks, you can use the shortcode as follows:

[show_recent_comments count=15 pretty_permalink=1]

or just with the default count of 10 as follows:

[show_recent_comments pretty_permalink=1]

I should highlight the fact that the current user (registered member) will see the comments he or she has made. If you are not logged in, it asks you to login and after login brings you back on the post or page where you are using this shortcode.

You can use this code to make changes as per your need. You can use this shortcode anywhere in your theme by calling it as follows:

<?php echo do_shortcode( '[show_recent_comments count=15]' ); ?>

And I think if you use it like that outside the loop, it won't bring the user back to the previous page. You will need to change the get_permalink() call near the end of the plugin.

Good thing is that it works correctly with cache plugins such as WP Super Cache or W3 Total Cache because logged in users are served live pages instead of cached pages. Correct me if I am wrong.

Download Show Recent Comments plugin

Other than that, if you have any questions, comment section is all yours!

WordPress dashboard in different language

I am a freelancer and build sites powered by WordPress, bbPress & BuddyPress.

Recently I took work from a client who operates a WordPress installation in a language other than English and it was a productivity killer for me as I wasn't able to browse it quickly.

I searched something and found two plugins which are worth sharing - Admin in English & WP Native Dashboard

WordPress Dashboard in English language

For me Admin in English plugin does the job after installing and activating it, the WordPress dashboard was back to English language keeping the original language intact on the rest of the WordPress install i.e. the front end of the website / blog (what user sees).

WordPress Dashboard in different language

In case you want more control and also wish to provide user the preference to chose their preferred language, then you can try WP Native Dashboard plugin. This plugin enables you to give users the option to select a preferred language. Pretty cool!

Happy developing!