HIDING PHP ERROR LOGS FROM THE ADMIN SECTION (V2.64+) - Dec 1st, 2015


While best practices dictate that a (perfect) site should throw no errors, reality dictates that almost every site will
throw errors, and that some of those will not affect the site's operation.

With the inclusion of Global error logging in version 2.64, PHP errors, no matter how small, show bright red in the
Admin section and may become an issue for some developer / client relationships.

Dave Edis, the senior programmer at Interactive Tools, offers this workaround (which, for now, will have to be manually
added to any CMSB upgrades).

Note that it does not stop the logging of errors, it just hides them from the admin section until you're ready to deal
with them.

he said

If you want to remove the menu link with some custom code you can do that as follows:

- Open /lib/menus/header_functions.php
- Scroll to the bottom
- Add the code:


array_pop($adminMenus); // remove "Error Log" from menu


after


'recordCount' => $errorCount,
);


Like This:


//
$errorCount = mysql_count('_error_log');
$adminMenus[] = array(
'menuType' => 'custom',
'menuName' => t('Error Log') . " ($errorCount)", //
'menuOrder' => ++$menuOrder,
'link' => '?menu=_error_log',
'isSelected' => ($menu == '_error_log'),

'tableName' => '_error_log',
'recordCount' => $errorCount,
);

array_pop($adminMenus); // remove "Error Log" from menu

//
return $adminMenus;


The PHP array_pop() removes the last item off an array, so that line of code just removes the "Error Log" menu that was
just added. Note that you'll still be able to directly access the log with admin.php?menu=_error_log All this code
does is remove the menu link.

Don't' forget to safely copy your code before updating CMSB or it will be overwritten
_________________________________________

Taking this one step further, I added a check box field called ("No Error Log") in a single record section (called
"Organization Information"), that will show or remove the error log from the Admin menu

Building on the code above, my final now looks like this:


//
$errorCount = mysql_count('_error_log');
$adminMenus[] = array(
'menuType' => 'custom',
'menuName' => t('Error Log') . " ($errorCount)", //
'menuOrder' => ++$menuOrder,
'link' => '?menu=_error_log',
'isSelected' => ($menu == '_error_log'),

'tableName' => '_error_log',
'recordCount' => $errorCount,
);
?>
<?php
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/path_to_your_server/','','../','../../','../../../');
foreach (
$dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!
function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

list(
$organization_informationRecords, $organization_informationMetaData) = getRecords(array(
'tableName' => 'organization_information',
'where' => '', // load first record
'limit' => '1',
));
$organization_informationRecord = @$organization_informationRecords[0]; // get first record
?>

<?php $no_error_log = 1 ?>
<?php $no_error_log = $organization_informationRecord['no_error_log'] ?>
<?php if ($no_error_log == 1 ):?>

<?php array_pop($adminMenus); // remove "Error Log" from menu
?>
<?php endif?>
<?php

return $adminMenus;
}

?>





The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service