Mobile Admin - Advanced

Extending the WP MobileAdmin Plugin : Section 4

Extending the base plugin class

As mentioned in the “Basics” section, all MobileAdmin plugin files extend the base functionality of the default plugin.

That section gave an example of creating a plugin by extending the base MobileAdmin class, and the CSS & Javascript section showed how to override a couple of the methods from the base MobileAdmin class to include your own CSS and script files.

If you check the iPhone_MobileAdmin class in the incldued iPhone plugin, you will notice a couple additional extensions that weren’t covered in the previous sections.

The $UseQuickTags and $UseRichEdit are used to determine whether quicktags and/or TinyMCE support (respectively) should be enabled on the “Write” pages. They are set to false by default, since they won’t work in most mobile devices, but if your target device supports them, you can set one (or both) of these to true to enable them.

The iPhone plugin also overrides a function called RenderHeaderTop, which adds some stuff to the top of every page in the mobile UI. You can use this as a reference if you’d like to do the same thing.

The base class that these plugins are extending (MobileAdmin) is found in the default plugin (Default.php). There you will find a few other available methods to extend.

Extending individual pages / forms

The main plugin files defined and extended above make use of other classes to handle the individual customizations of the various pages supported by the MobileAdmin plugin.

Default implementations of all of these classes are defined in the Default.php file, and these will be used, unless your plugin overrides them, in which case the ones in your plugin will be used instead. The six form classes (which all inherit from / extend MobileAdminForm_Default) are:

  • MobileAdminDashboardForm_Default
  • MobileAdminPostForm_Default
  • MobileAdminPostNewForm_Default
  • MobileAdminManageForm_Default
  • MobileAdminCommentModerationForm_Default
  • MobileAdminProfileForm_Default

You can extend any of these classes in your plugin by adding a class to your plugin file that extends one of the six _Default classes listed above, and uses the name of your plugin (as defined in its ‘Name’ variable) rather than _Default in the class name. For example, the iPhone plugin has a class MobileAdminDashboardForm_iPhone that extends MobileAdminDashboardForm_Default and adds some things to the default dashboard page by overriding the RenderExtraHeaderInfo function.

There are all sorts of functions in each of the classes that you can experiment with overriding, and you can use the plugins provided as samples. In many cases the extensions go a couple levels deep, so the MobileAdminDashboardForm_iPhone for example extends MobileAdminDashboardForm_Default, which itself extends MobileAdminForm_Default.

The MobileAdminForm_Default base class is where you can find many of the shared functions that all classes make use of, and you can override and alter any of them in your own plugins by simply including them in one of your classes that overrides one of the defaults.

Conclusion

The MobileAdmin plugin is built from the ground up with extensibility in mind, and is designed to allow you to build plugins as easily as possible, by only needing to override the default behavior where you’d like it to be different. I’d recommend reading up a bit on basic OO programming in PHP before diving in too deeply on these sorts of modifications. There is a lot you can do that isn’t covered in this guide, but once you’re familiar enough with PHP it will hopefully be obvious to you how to proceed, using the code from the included plugins as a guide.