Table of Contents

Plugin sample

Plugin file (include/plugins/display_errors/display_errors.php):

<?php
 
/**
 * PHP Displays Errors Plugin
 *
 * @plugin_name PHP Displays Errors
 * @plugin_link http://isp-control.net
 * @description Easy way to setup the PHP display_errors parameter.
 * @version 1.0.0
 * @author Laurent Declercq (nuxwin) <laurent.declercq@ispcp.net>
 * @author_link http://isp-control.net
 * @license MPL 1.1
 *
 */
 
// If we are in admin settings context, we register our action hooks for him
if(IspCP_Registry::get('Plugin')->get_context() == 'admin_settings'):
 
/**
 * Set display error field under admin/settings.tpl
 *
 * This function use the ERRORS_SETTINGS_HOOK template variable hook to add new
 * html elements to allow to setup the PHP display_errors parameters
 *
 * @param ptemplate $tpl pTemplate instance provided by before_update action hook
 * @return void
 */
function show_display_error($tpl) {
 
	IspCP_Registry::get('Config');
	$plugins_path = IspCP_Registry::get('Plugin')->base_path;
 
	$tpl->define_dynamic(
		'display_errors',
		$plugins_path . '/display_errors/display_errors.tpl'
	);
 
	$tpl->assign(
		array(
			'TR_DISPLAY_ERRORS' => tr('Display errors'),
			'TR_DISPLAY_ERRORS_ON' => tr('Enabled'),
			'TR_DISPLAY_ERRORS_OFF' => tr('Disabled')
		)
	);
 
	if (isset($cfg->DISPLAY_ERRORS) && $cfg->DISPLAY_ERRORS) {
		$tpl->assign('DISPLAY_ERRORS_ON', $cfg['HTML_SELECTED'];);
		$tpl->assign('DISPLAY_ERRORS_OFF', '');
	} else {
		$tpl->assign('DISPLAY_ERRORS_ON', '');
		$tpl->assign('DISPLAY_ERRORS_OFF',  $cfg['HTML_SELECTED'];);
	}
 
	$tpl->parse('ERRORS_SETTINGS_HOOK','.display_errors');
}
 
/**
 * Update the display_error configuration parameter in the database
 *
 * @return void
 */
function update_display_errors() {
 
	$db_cfg = IspCP_Registry::get('Config');
 
	$db_cfg->display_errors = (int) $_POST['display_errors'];
}
 
// Action that will be launch before the setting show page
IspCP_Plugin::add_action('before_output', 'show_display_error');
 
// Action that will be launch before settings update
IspCP_Plugin::add_action('before_update', 'update_display_errors');
 
endif;
 
// Action that will be always launch (Action hook from main context)
 
/**
 * Setup the PHP display_errors parameter
 *
 * @param IspCP_ConfigHandler_File $cfg provided by before_config action hook
 * @return void
 */
function set_display_errors($cfg) {
	if(isset($cfg->DISPLAY_ERRORS)) {
		ini_set('display_errors', $cfg->DISPLAY_ERRORS);
	}
}
 
// Will be launch at configuration process
IspCP_Plugin::add_action('before_config', 'set_display_errors');

Template file (include/plugins/display_errors/display_errors.tpl):

<tr>
 <td>&nbsp;</td>
 <td class="content2">{TR_DISPLAY_ERRORS}</td>
 <td class="content">
  <select name="display_errors" id="display_errors">
   <option value="1" {DISPLAY_ERRORS_ON}>{TR_DISPLAY_ERRORS_ON}</option>
   <option value="0" {DISPLAY_ERRORS_OFF}>{TR_DISPLAY_ERRORS_OFF}</option>
  </select>
 </td>
</tr>