Category Archives: PHP

WordPress: Import Blogroll from Sage

Earlier today i exported the list with blogs i read from Sage and tried to import them into WordPress. Although all the entries had been processed but none of them appeared. Apparently you have to rename the xmlUrl attribute to … Continue reading

Posted in WordPress | Leave a comment

An example of why i don’t like the ext/filter API

Earlier this week i decided to experiment with the Filter functions. Here’s an example that illustrates why i think the API needs to be improved: <?php $isgoodapi = filter_input(INPUT_GET, ‘isgoodapi’, FILTER_VALIDATE_BOOLEAN); if (is_null($isgoodapi)) { echo "the ‘isgoodapi’ argument is missing."; … Continue reading

Posted in PHP | Leave a comment

Generate a menu with month names

I still see people building their calendar control or month (or day) picker with a hardcoded array of month (or day) names. With the use of strftime you can easily build a locale aware version. Here is an example: <?php … Continue reading

Posted in PHP | Leave a comment

Dynamic CSS with PHP

Both html and css are simply text. Thus you should be able to generate css as easily as html with php. Now if you add a reference to the css.php file in your html (eg: <link rel=”stylesheet” href=”http://example.com/css.php” type=”text/css” media=”screen” … Continue reading

Posted in PHP | Leave a comment

Allow a form to be posted only once

People can fill in a form and submit it. Then they can hit their back button, and choose to submit it again. Usually the second time this form is being posted, the values in that form aren’t valid anymore and … Continue reading

Posted in PHP | Comments Off

Using cmd.exe

Earlier someone asked me how he could use windows cmd.exe with PHP. People run into trouble as soon as there are quotes needed because there are special characters (>/&()[]{}^=;!’+,`~ and <space>) in the command. I do it like this: <?php … Continue reading

Posted in PHP | Leave a comment

Internationalizing strings with variables

Yesterday i wrote that you can use __($string, $domain) and _e($string, $domain) to internationalize a string with WordPress. I forgot to mention that if you use sprintf you can handle strings with variables too. An example: echo sprintf(__(‘There are %d … Continue reading

Posted in WordPress | Leave a comment

Adding support for localization to a WordPress plugin

WordPress uses GNU gettext, as explained in Translating WordPress and Writing a Plugin, for localization. I decided that my plugins should support l10n too. Here is how i realised it: I started with defining the WPLANG constant in my wp-config.php: … Continue reading

Posted in WordPress | Comments Off

Plugin template for WordPress

Today i’ve been cleaning up my code. All my plugins live in a directory %plugin_name% under the wp-content/plugins directory. Here is the code for %plugin_name%/%plugin_name%.php: <?php /* Plugin Name: %plugin_name% Version: %plugin_version% Plugin URI: %plugin_uri% Description: %plugin_description% Author: %plugin_author_name% <%plugin_author_mail%> … Continue reading

Posted in WordPress | Leave a comment

Adding an action when your plugin is activated

The WordPress documentation says that you have to call add_action(‘activate_pluginurl’, ‘somefunction’) to trigger somefunction when your plugin is activated. Unfortunately i couldn’t find with what pluginurl should be replaced. After a bit of experimenting i’ve found that in wp-admin/plugins.php the … Continue reading

Posted in WordPress | Comments Off