How to Make Your Own Plugins/Themes Updating Service

INTRO

Several times ago, my Smells Like Facebook theme was suspended from being updated in WordPress Theme Directory. It’s still being available to download, but I can’t submit a new version, therefore the theme users can’t get a notification and auto update from their dashboard.

So I try how to override WordPress auto update check routine and make it check the latest version of Smells Like Facebook to my own server. Here’s how:

THE CODE

1. Exclude your theme from the auto update check

I took this from Mark Jaquith blog. This piece of code will exclude your theme when WordPress does a check to WordPress API server. In Smells Like Facebook 2.7, it looks like this:

function slf_prevent_wp_update($r, $url) {
if ( 0 !== strpos( $url, 'http://api.wordpress.org/themes/update-check' ) )
return $r;
$themes = unserialize( $r['body']['themes'] );
unset( $themes[ 'smells-like-facebook' ] );
$r['body']['themes'] = serialize( $themes );
return $r;
}
add_filter( 'http_request_args', 'slf_prevent_wp_update', 5, 2 );

Change the ‘smells-like-facebook’ to your own theme name. Usually it’s a slug name of the theme name.

2. Create the ‘API’ server

Before creating the updating service, first you need to create a URL on your site that will provide the information of current version of your theme / plugin. Note that this page have to provide the link to download the new version.

As the example, for Smells Like Facebook, I create a URL in http://api.nazieb.com/smells-like-facebook/check_update which will show these:

2.7|https://nazieb.com/download/smells-like-facebook-2.7.zip

That line show 2 things; the current stable version of Smells Like Facebook and the link to download it. It’s separated by a pipeline (‘|’) because it will be exploded by the update function.

3. Make your own update check routine

After your theme is excluded from WordPress check routine, you have to make your own one. To do this, you have to know about WordPress pseudo-cron scheduling.

This piece of code will make your own schedule routine:

$next = wp_next_scheduled('slf_check_routine');
if ($next === false) wp_schedule_event(time(), 'hourly', 'slf_check_routine');

Explanation:
– the first line will check whether your routine has been scheduled. ‘slf_check_routine’ is the name of your routine action. The updating function will be hooked to this action.
– and then the second line will register your routine hourly if your routine isn’t scheduled yet

And then the main update function is:

function slf_check_update() {
global $wp_version;
if ( defined( 'WP_INSTALLING' ) )
return false;

if(!function_exists('get_theme_data'))
require_once( ABSPATH . 'wp-includes/theme.php' );

$theme = get_theme_data(WP_CONTENT_DIR . '/themes/smells-like-facebook/style.css');
$options = array(
'timeout'    => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
);

$response = wp_remote_get( "http://api.nazieb.com/smells-like-facebook/check_update/", $options );
list($version, $url) = explode('|', $response['body']);
if($theme['Version'] == $version) return false;
$theme_transient = get_site_transient('update_themes');
$theme_transient->response['smells-like-facebook'] = array(
'new_version' => $version,
'url' => 'http://smells-like-facebook.nazieb.com',
'package' => $url
);
set_site_transient('update_themes', $theme_transient);
}
add_action('slf_check_routine', 'slf_check_update');

Note:
– The ‘url’ in theme transient is not the URL to download the new version. It’s the URL of information page of your theme / plugin. The URL to download is set to ‘package’
– To read more about WordPress Transient, read here
– Don’t forget to hook the function to your routine action

That’s all. Confusing huh? Sorry for my bad explanation, if you have any question leave it in comments.

46 thoughts on “How to Make Your Own Plugins/Themes Updating Service

      1. @nazieb Emangnya menyalahi license-nya Facebook kerna judul tema ini punya trademark Facebook seperti yang dinyatakan pada terms yg ke-5.6 seperti berikut:

        “6. You will not use our copyrights or trademarks (including Facebook, the Facebook and F Logos, FB, Face, Poke, Wall and 32665), or any confusingly similar marks, without our written permission.”
        source: https://www.facebook.com/terms.php

        Like

  1. cantik banget blog ni mas. Easy to load and user friendly.
    salam kenal sob. ^_^

    I also have created a new wordpress plugin. Please leave me some feedback or suggestion about my new wordpress plugin. makasih ya mas🙂

    Like

  2. I love to read and visit this kind of blog. When I read this kind of article, it seems that I was there and I feel the place. Someday, when I have time to visit the places they have mentioned then I will already know what to do. Also, there are sites who post directions and advises when going in a the features place.

    Like

  3. I am starting building a site and I always browse to the internet to search on how to build a site. Thanks for this information and I realize that I need to build my own plugins and themes to have a unique and interesting site.

    Like

  4. untuk pengaturan tema yang kita inginkan misalnya seperti design webnya itu juga seperti itu??? supaya bisa menarik pengunjung tetap stay di situs kita. untuk pengaturan tema yang kita inginkan itu seperti gimana ya.,. tolong di buatkan artikel yang caranya buat design thema gmna?? sebelumnya thanks buat pelajaran yang sangat power full ini.,🙂 saya tunggu updatannya . salam senyum🙂

    Like

  5. Hey all, only started to be responsive to your current blog site as a result of Yahoo and google, and discovered that it is genuinely educational. My business is going to watch out for the city. I’ll be grateful if you continue on that later on. Appear as healthy is going to be benefited from the composing. Many thanks!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s