Instantly share code, notes, and snippets.

What would you like to do?
Place this file inside a new hide_comments folder in your backend livewhale/clients/modules folder.
/* Hide Comments
This application hides the Comments checkbox on all editors in
the LiveWhale backend management interface, except for admins. */
$_LW->REGISTERED_APPS['hide_comments']=array( // register this application
'title'=>'Hide Comments', // the module name
class LiveWhaleApplicationHideComments {
public function onOutput($buffer) { // make changes to backend page buffer before widget processing
global $_LW;
if (substr($_LW->page, -5) === '_edit' && ((method_exists($_LW->d_framework, 'userSetting') && !$_LW->userSetting('core_admin')) || $_SESSION['livewhale']['manage']['is_admin'] !== TRUE)) { // check that the user is on an editor page and not an admin
$pattern = '~<input([^>]+)name="has_comments"([^>]+)/?>\s*Allow users to post comments\s*~imsU';
if (preg_match($pattern, $buffer, $matches)) {
if (strpos($matches[1], 'checked="checked"') !== FALSE || strpos($matches[2], 'checked="checked"') !== FALSE) { // check to see if comments are enabled
$matches[0] = str_ireplace('type="checkbox"', 'type="hidden"', $matches[0]); // change the field to hidden
$matches[0] = str_ireplace(' checked="checked"', '', $matches[0]); // remove the checked attribute
$matches[0] = str_ireplace('Allow users to post comments', 'Comments are enabled.', $matches[0]); // change the message
$buffer = preg_replace($pattern, $matches[0], $buffer); // and update the page
} else {
$buffer = preg_replace('~<fieldset[^>]*class="[^"]*comments[^"]*"[^>]*>.*</fieldset>~imsU', '', $buffer); // find the entire comments block and remove it
return $buffer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment