Top posts

Posts in WordPress


Creating your first WordPress plugin

Posted by Jongerius under Development, WordPress
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (No Ratings Yet)
Loading ... Loading ...

Since I’ve been experimenting a little with WordPress plugin development, I thought it might be useful to write a simple introduction into developing a basic WordPress plugin.

Basic setup of the PHP file for your plugin (which would be called ‘my_plugin/plugin.php’):

// register the plugin activation and de-activation hooks
// you could also register a plugin class, but that's out of scope.
register_activation_hook('my_plugin/plugin.php', 'my_plugin_activate');
register_deactivation_hook('my_plugin/plugin.php', 'my_plugin_deactivate'); 

function my_plugin_activate()
{
    // you might wanna register some data into the settings of WordPress here
   $_plugin_settings = array('my_var1' => true, 'my_var2' => 'dingy');
   for ( $_plugin_settings as $name => $value )
  {
      if (!get_option($name))
         set_option($name, $value);
  }
}

function my_plugin_deactivate()
{
  // this is the place to clean-up WordPress, do not erase the settings,
  // as you might want to reinitialize the plugin without loosing the users settings.
}

With this done your plugin is able to register the settings that are needed for it to work and clean up after the user is done playing around with it. Keep in mind that you will need to set all settings you need in the activate method, otherwise you might get unexpected exceptions later on.

// register the admin menu for the plugin, you don't need to do this if there are no changable settings
add_action('admin_menu', 'wp_myplugin_admin');

function wp_myplugin_admin()
{
   add_options_page('MyPlugin', 'My plugin name',
                                            3, basename(__FILE__), 'wordpress_my_plugin_admin');
}

function wordpress_my_plugin_admin()
{
   // simple check to see if the admin settings where posted
    if ($_POST['myvar']) {
       // deal with the post request (change settings)
    }
    require_once('admin_menu.php');
}

As you can see the code block above registers an administration section for the plugin. This will enable the plugin to be configured by the end user. The PHP file ‘admin_menu.php’ basically contains the HTML code for the administration page.

You now have the basics setup, the plugin will be called every time a page is requested from WordPress. So all that is left to do is develop the code that will do your magic and you’re done.


Published the WordPress Mobile plugin

Posted by Jongerius under Development, Webdevelopment, WordPress
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (No Ratings Yet)
Loading ... Loading ...

A long time ago I posted that I was working on a plugin for WordPress that enabled you to display a optimized version of any WordPress blog for phone or mobile visitors. Though I actually developed the plugin about a year ago I never got around to publishing it. Today is the launch day!!!! :-D

Since I developed the plugin for this site you can see it in action by visiting it with your mobile phone or by visiting the mobile version. Please note that the lay-out is not completely bug free yet, but I’m still working on that.

You can access the WordPress Mobile plugin page under the Plugin section in the header of the blog.


Working On WordPress Mobile plugin

Posted by Jongerius under Webdevelopment, WordPress
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars (No Ratings Yet)
Loading ... Loading ...

A while back I got some questions if it was possible to create a more mobile friendly version of this blog. Appearantly I have several visitors that are browsing using mobile devices. And I must say my design is not user friendly for them.

Off course they are right, any user should be able to access this blog. Be it from a mobile phone or a computer. So I had to find a way to offer my mobile visitors a better experience. First thing to do that is looking into the wordpress.org plugin library. There are a lot of plugins available for a lot of different things. There had to be some for switching the display to mobile when a mobile device is detected.

And there are. I first tried WordPress Mobile Edition which is pretty good. Big issues I had with it are that it’s not as light weight as I want it to be. And the coding is crappy! But beyond that it does what it’s supposed to.

But me being a developer I decided to write my own little plugin to offer a mobile version of this blog. Fully customizable using templates and settings in the admin menu. I haven’t yet completed the entire design, nor is the admin part working ;) . But it’s currently running on this blog :D . If you want to check it out just add ‘?mobile=true’ to any page or visit using your phone.

When I’m done developing the plugin I’ll share with you all how you can write a simple WordPress plugin. I will also publish the plugin for anyone to download, for free!!!

So stay tuned for an update…….

« Previous Page