by ShibaShake
WordPress Example Plugin

WordPress Example Plugin

The Shiba Example Plugin is an empty plugin to help you get started on writing a WordPress plugin.

The Shiba Example Plugin contains -

  • A plugin activation hook that runs when a plugin is first activated.
  • Plugin initialization functions.
  • An example plugin sub-menu page.
  • An uninstall.php file that runs when your plugin is uninstalled. Use this to clear out options (delete_option) or databases created by your plugin.
  • Example localization or language translation hooks. This enables others to easily add language translation capabilities to your plugin.
  • A plugin class wrapper which wraps around your plugin functions so that there will not be any function name conflicts with other plugins or themes in the user’s environment.

Adding a Plugin Menu Page

There is a section in the Shiba Example Plugin that adds a menu page to your WordPress Dashboard Settings menu.

function shiba_example_add_pages() {
 
	// Add a new submenu
	$addpage = add_options_page(	__('Shiba Example', 'shiba_example'), __('Shiba Example', 'shiba_example'), 
									'administrator', 'shiba_example', 
									array(&$this,'add_shiba_example_page') );
	add_action("admin_head-$addpage", array(&$this,'add_shiba_example_admin_head'));
	}

The function call add_options_page, adds the sub-menu called ‘Shiba Example’ to the Settings tab. Visiting the sub-menu will run the function add_shiba_example_page. If you want to add your plugin menu to a different WordPress tab, below are the other available options -

  • add_management_page – Adds a menu to the Tools tab. [tools.php]
  • add_options_page – Adds a menu to the Settings tab. [options-general.php]
  • add_theme_page – Adds a menu to the Appearance tab. [themes.php]
  • add_plugins_page – Adds a menu to the Plugins tab. [plugins.php]
  • add_users_page – Adds a menu to the Users tab. [users.php or profile.php]
  • add_dashboard_page – Adds a menu to the Dashboard tab (topmost). [index.php]
  • add_posts_page – Adds a menu to the Posts tab. [edit.php]
  • add_media_page – Adds a menu to the Media tab. [upload.php]
  • add_links_page – Adds a menu to the Links tab. [link-manager.php]
  • add_pages_page – Adds a menu to the Pages tab. [edit.php?post_type=page]
  • add_comments_page – Adds a menu to the Comments tab. [edit-comments.php]

Note – All of these functions call the add_submenu_page function.

You can also create your own top-level menu by following these steps from the WordPress Codex.

Adding Localization or Language Translation Capabilities

One of the best tutorials I have come across on localizing your plugin can be found on Urban Giraffe.

Here is the official tutorial from the WordPress Codex.

Future Additions

Please let me know if there are common plugin functions that I have missed, or if there are better ways to achieve some of the plugin functions described above.

Related Articles

<< Previous Next >>

<a href="http://shibashake.com/wordpress-theme/write-a-plugin-for-wordpress-multi-site" target="_top">Write a Plugin for WordPress Multi-Site</a>

Write a Plugin for WordPress Multi-Site

WordPress multisite functionality is now integrated into WordPress 3.0. Currently, we must go through a non-trivial process to turn on multisite capability. However, there are already plugins that try to automate this process in one-click. As this process becomes easier and more streamlined, the multisite capability will likely see wider adoption. ...

<< Previous Next >>

<a href="http://shibashake.com/wordpress-theme/wordpress-plugin-credits" target="_top">WordPress Plugin Credits</a>

WordPress Plugin Credits

The issue of how to credit plugin developers can often be an emotionally charged topic, with strong opinions on both sides. Everybody agrees that plugin developers are awesome for the WordPress community, but many disagreements arise as to what are the proper methods for getting credit for their hard work. On the one hand, many plugin developers...

<< Previous Next >>

<a href="http://shibashake.com/wordpress-theme/how-to-render-your-own-wordpress-photo-gallery" target="_top">How to Render Your Own WordPress Photo Gallery</a>

How to Render Your Own WordPress Photo Gallery

When you insert a WordPress gallery into your blog post, it gets rendered in native WordPress gallery mode. In particular, each of the photos in your gallery gets rendered as a thumbnail, and clicking on the thumbnail will connect you to the photo source file, or the photo attachment page. Here is an example WordPress native gallery- Sometimes,...

<Playback Stop Play >

RSS feed for comments on this post. TrackBack URL

Leave a Reply

search button search button
rss