Plugin Admin Area

As of Nucleus v2.5, plugins can create admin area pages that integrate with the Nucleus admin area. These pages can be accessed either from the plugin admin page, or the quickmenu on the left.

Basics

To provide an admin area, you'll need take these steps:

  1. Create a subdirectory of the plugins directory, and name it pluginname if your plugin is NP_PluginName. Note that the name should be lowercase!
  2. In that directory, create a file called index.php, which looks like this:
    <?php
    
    	// if your 'plugin' directory is not in the default location,
    	// edit this variable to point to your site directory
    	// (where config.php is)
    	$strRel = '../../../';
    
    	include($strRel . 'config.php');
    	if (!$member->isLoggedIn())
    		doError('You\'re not logged in.');
    
    	include($DIR_LIBS . 'PLUGINADMIN.php');
    
    	// create the admin area page
    	$oPluginAdmin = new PluginAdmin('PluginName');
    	$oPluginAdmin->start();
    
    	echo '<h2>Plugin Name</h2>';
    
    	echo '<p>Page contents here<p>';
    
    	$oPluginAdmin->end();
    
    ?>
  3. Subscribe to the QuickMenu event and add this code in your plugin:
    function event_QuickMenu(&$data) {
    		array_push(
    			$data['options'],
    			array(
    				'title' => 'Plugin Name',
    				'url' => $this->getAdminURL(),
    				'tooltip' => 'Tooltip text'
    			)
    		);
    	}
  4. Implement this method in your plugin:
    function hasAdminArea()
    {
    	return 1;
    }

Considerations

  • Don't just add an entry to the quick menu because it is possible. Imagine having 100 plugins installed, which all add an entry in the menu. This would result in a real mess. So, even if you add an entry in the menu, please consider adding an option (global or member-level) to enable/disable the quick menu entry.
  • The $strRel variable in the index.php needs to be adapted manually if the plugins directory is not located in nucleus/plugins/
  • Make sure your admin area outputs valid XHTML. If not, the page will be broken in Gecko-based (Mozilla etc) browsers.

The PluginAdmin class

The purpose of the PluginAdmin is to help you. Once created, you can use $oPluginAdmin->plugin to access the instance of your plugin.

Plugin API