:::: MENU ::::

WordPress Plugin Tutorial – Most shared/popular articles on facebook

To implement most shared url of any wordpress blog, first of all download facebook php sdk here Some basic setup already explained there.

wp_most_popular

Basic setup for write wordpress plugin

  • Create your plugin directoy and file with same name.
    i.e. Directory: MostPopular and File: MostPopular.php inside MostPopular direcotory.
  • Place base_facebook.php, fb_ca_chain_bundle.crt and facebook.php within the directory.

Start coding plugin in MostPopular.php with plugin info.

It’s possible many other wordpress plugins may already using facebook sdk and initialized by them. So there might be class collision issue. (i.e. class re-declare error) To avoid this situation you could use php namespaces that we already discussed here. Otherwise, You could also check, if class already initialize by other plugins or not?

Now initialize your widget class by extending wordpress WP_Widget class

Register your widget with wordpress framework.

Wordpress will call our class ‘MostPopular‘ and initialize its constructor and then look for widget() function to draw widget (HTML/CSS) in frontend. (Why?)

Adding widget() function within our class.

Admin Area:-

Widget Customization. Add form() & update() function in your widget. (why?)

Fetching and storing most liked posts using Facebook API

Call this function() hourly using wordpress scheduler.

Making plugin more graceful.

Use plugin activation and deactivation hook to start and stop wordpress cron jobs using register_activation_hook() and register_deactivation_hook() whenever user activate or deactivate the plugin.


So, what do you think ?

  •