New Hook Issues
Posted: Mon Dec 26, 2022 11:57 am
Hi Guys, Happy Christmas
I am working on a new hook to display an on/of switch to enable a page to only be shown on a particular page i.e. a blog page.
I have added a new field to the 'pages' table and have cobbled together the code below.
As it stands at the minute there are few problems I am struggling with
1. The public function listen_formEdit() breaks the page but if commented out the page loads ok
2. The on/off switch only appears on pages that have a physical file such as 'Terms & Conditions' and not on new info pages that do not have a physical file
3. The database is not being updated with 1 or 0 when the page is saved.
I am working on a new hook to display an on/of switch to enable a page to only be shown on a particular page i.e. a blog page.
I have added a new field to the 'pages' table and have cobbled together the code below.
As it stands at the minute there are few problems I am struggling with
1. The public function listen_formEdit() breaks the page but if commented out the page loads ok
2. The on/off switch only appears on pages that have a physical file such as 'Terms & Conditions' and not on new info pages that do not have a physical file
3. The database is not being updated with 1 or 0 when the page is saved.
Code: Select all
class hook_admin_info_pages_blog_only {
public function listen_addNewAction() {
global $pages_id;
if ( isset($_GET['pID'], $_GET['flag']) && ($_GET['flag'] == '0') || ($_GET['flag'] == '1') ) {
$db->query("UPDATE pages SET blog_only = " . (int)$_GET['flag'] . " WHERE pages_id = " . (int)$_GET['pID']);
}
return $link->set_parameter('pID', (int)$_GET['pID']);
}
public function listen_updateAction() {
global $pages_id;
if ( isset($_GET['pID'], $_GET['flag']) && ($_GET['flag'] == '0') || ($_GET['flag'] == '1') ) {
$db->query("UPDATE pages SET blog_only = " . (int)$_GET['flag'] . " WHERE pages_id = " . (int)$_GET['pID']);
}
return $link->set_parameter('pID', (int)$_GET['pID']);
}
public function listen_formNew() {
$blog_only = BLOG_ONLY;
$blog_only_input = new Select('blog_only', $this->make_page_array(), ['class' => 'form-control w-50']);
$blog_only = <<<ff
<hr>
<div class="form-group row align-items-center" id="zStatus">
<label class="col-form-label col-sm-3 text-left text-sm-right"><?= BLOG_ONLY_STATUS ?></label>
<div class="col-sm-9">
<div class="custom-control custom-radio custom-control-inline">
<?= new Tickable('blog_only_status', ['value' => '1', 'id' => 'inStatus', 'class' => 'custom-control-input'], 'radio') ?>
<label class="custom-control-label" for="inStatus"><?= BLOG_ONLY_PUBLISHED ?></label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<?= (new Tickable('blog_only_status', ['value' => '0', 'id' => 'outStatus', 'class' => 'custom-control-input'], 'radio'))->tick() ?>
<label class="custom-control-label" for="outStatus"><?= BLOG_ONLY_NOT_PUBLISHED ?></label>
</div>
</div>
</div>
ff;
return $blog_only;
}
public function listen_formEdit() {
$blog_only = BLOG_ONLY;
$blog_only_input = new Select('blog_only', $this->make_page_array(), ['class' => 'form-control w-50']);
$blog_only = <<<ff
<hr>
<div class="form-group row align-items-center" id="zStatus">
<label class="col-form-label col-sm-3 text-left text-sm-right"><?= BLOG_ONLY_STATUS ?></label>
<div class="col-sm-9">
<div class="custom-control custom-radio custom-control-inline">
<?= new Tickable('blog_only_status', ['value' => '1', 'id' => 'inStatus', 'class' => 'custom-control-input'], 'radio') ?>
<label class="custom-control-label" for="inStatus"><?= BLOG_ONLY_PUBLISHED ?></label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<?= (new Tickable('blog_only_status', ['value' => '0', 'id' => 'outStatus', 'class' => 'custom-control-input'], 'radio'))->tick() ?>
<label class="custom-control-label" for="outStatus"><?= BLOG_ONLY_NOT_PUBLISHED ?></label>
</div>
</div>
</div>
ff;
return $blog_only;
}
}