Loklak enters WordPress Universe

In my last post, I briefly commented on how one could now use Loklak API in WordPress plugins. Lets discuss that here in detail.

The post is mostly focused on novice WP plugin/widget developers. If you ain’t novice (or don’t consider yourself to be) just a quick skim would be enough.

Suppose, you want to make a plugin with functionalities as given below:

  1. View tweets by a twitter account
  2. Between a time frame
  3. Containing specific “mentions” and “hashtags”

After deciding the design, you want best tools at your disposal. You search for the twitter API and find that you need to make a twitter app to use the API in your plugin.

Now you ask yourself “Is there a better way?”.

Yes there is! Its called Loklak!

You can use Loklak’s PHP API (refer to my previous blog post) and the included WordPress library to render tweets anonymously (No annoying ‘Create an app’ procedures!).

“Oh yes! that’s what I was looking for. How do I use it?”

So lets dive in!

When you are done with your plugin’s frontend, add loklak_php_api as a submodule (if using Github) or just download the zipped file and extract it in your plugin repo.

To add loklak PHP API as a submodule to your project, just execute the below-mentioned command.

cd path/to/your/project;
git submodule add https://github.com/loklak/loklak_php_api.git; 

Include loklak.php in your plugin file where you want to render your Loklak API results.


Create an object of Loklak class.

$loklak = new Loklak($base_url);

Since we want our tweets filtered based on points we listed above, we could use the search API.

See the definition below.


You just need to create a form to input the arguments and you will be good to go!

For example: If the plugin user wants to see tweets by @lklknt which mention #loklak and were tweeted between 31st January, 2015 and 31st December, 2015.

$query = '#loklak';
$since = '2015-01-31';
$until = '2015-12-31';
$from_user = `lklknt';

Considering that we got these values from the frontend form where user could enter his choices. This is how the search function would look like.

$tweet_results = $loklak->search($query, $since, $until, $from_user);


You can use these results directly in your plugin.

For plugin developers who are currently using twitter API and want to provide Loklak as an option to their users.

Just include Lib/loklak-api-admin.php in your settings page to display loklak as an option.

Loklak enters WordPress Universe