Month: June 2008

WordPress : Using jQuery library with your plugin or theme

When you develop a WordPress plugin or theme, you might want to make use of the jQuery library included and distributed with the WordPress package. The jQuery library is located inside the “wp-includes/js/jquery/” folder. Even though you know what the location of the jQuery library is, I do not recommend that you reference this script using a <script> tag. Rather make use of the wp_enqueue_script function included in the WordPress core which allows you to safely reference your Javascript scripts. I recently wrote an article entitled Using Javascript libraries with your WordPress plugin or theme which explains the wp_enqueue_script function. So, first off, fire the wp_enqueue_script function in order to safely reference your jQuery library to ensure that the jQuery core is available for usage with your plugin or theme. Other plugins might fire this function with the same handle in order to use jQuery, but you don’t know this and you aren’t sure what other plugins your users will be using, so you have to be sure that it is included. <?php wp_enqueue_script('jquery'); ?> Ultimately, WordPress will insert a <script> tag into the <head> section of the page referencing the jQuery library by including the “jquery.js” source file. Next thing to do is prevent conflicts between libraries. By default, jQuery is used with a global variable which is a dollar sign. See the example below which shows (makes...

Read More

WordPress : Translate a Plugin

First off, you have to know that not all WordPress plugins can be translated. The plugin developer(s) had to take the necessary steps such as using the WordPress __() and _e() functions and load_plugin_textdomain() in order to parse the strings/text of the plugin through the localization system. If you have a plugin with the ability of being translated, this tutorial will guide you through the steps of translating the plugin using an application called poEdit with screenshots taken on the Macintosh operating system. poEdit is available for Windows and Linux users as well though. Before we get started, you’ll need to obtain poEdit from the poEdit website. It is a free and has been released under an MIT license, which allows you to download, edit and redistribute the source code as long as the original license information is kept intact. I am going to translate the WordPress Mailing List plugin. I have my plugin folder ready for use, placed on my desktop where it is easily accessible. I will now open poEdit and go to “File” > “New Catalog…” to create a new catalog file for this plugin. The moment I click “New Catalog…”, the application displays a dialog window with three (3) tabs at the top. The first tab is called “Project Info”. The only mandatory field is the “Project Name”, though you can fill all of them...

Read More

WordPress : Using Javascript libraries with your plugin or theme

When you develop a WordPress plugin or theme, you might want to make use of some of the Javascript libraries distributed with the WordPress package such as Prototype, Scriptaculous and jQuery. Simple enough, they are in the “wp-includes/js/” folder, so what more is there to it? Can’t I just add a SCRIPT tag in the HEAD section (or any other part of the WordPress page for that matter)? Of course you can do that, but you’ll most likely be causing a headache for other plugin and theme developers out there since you’re not following WordPress conventions as you should when you simply dump a SCRIPT tag into the content of the page. This is the mistake that most plugin developers make. They usually make use of the “wp_head” action hook and inject SCRIPT tags referencing these declared Javascript libraries into the HEAD section of the WordPress pages. Problem is that when you do this, and another plugin has already referenced any of these libraries, you are redeclaring them which results in a Javascript error on the page, terminating execution of any other Javascript on the page (both internally and externally). So what is the correct way to do this? WordPress provides us (developers) with a function called wp_enqueue_script which allows you to safely reference the provided Javascript libraries and frameworks. The first parameter of this function is the handle/name...

Read More

PHP: Date difference in days

You might need to calculate the date difference in days using PHP. You can easily calculate the days difference by using something like the code below. function datediff($date1, $date2) { return round(abs(strtotime($d1) - strtotime($d2)) / (60 * 60 * 24)); } The code shown above takes the UNIX timestamp of two dates and subtracts the one date from the other to get the number of seconds. Then we simply divide the seconds by 60 (since there are 60 seconds in a minute) to get the minutes, again by 60 (since there are 60 minutes in an hour) to get the hours and lastly by 24 (since there are 24 hours in a day) to get the number of days. You don’t have to subtract the newer date from the older date though since we’re making use of the php abs() function which will automatically return an absolute value and eliminate a minus sign to make a negative value positive. I hope that...

Read More

Hash sign/symbol on the Macbook

I had to get a new notebook yesterday after spilling a cup of green tea on my Macbook pro. I’ve spilled some liquids on it before, but this time the keyboard and trackpad stopped working completely. After using the Macbook for a few minutes, I realized that it doesn’t have a hash symbol, also known as the pound sign where my Macbook pro did indeed have it as Shift + 3. I managed to figure out that in order to get a pound sign/hash symbol, you have to press Alt +...

Read More

Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!