Now, based on your full code, there’s 3 problems:
Line 60 of your code is missing a semi colon and throwing a fatal error. So:
$instance['description_check_box'] = $new_instance['description_check_box']
Should be:
$instance['description_check_box'] = $new_instance['description_check_box'];
On line 66, you’re using strings instead of proper boolean true
or false
values. Both if these are ‘truthy’ (see this answer to another question for what that means), so will both resolve as true
if used in an if statement. if ('false')
is true
. So:
$description_check_box = $instance[ 'description_check_box' ] ? 'true' : 'false';
Should be:
$description_check_box = $instance[ 'description_check_box' ] ? true : false;
On line 121 you haven’t got on
in quotes, so you’re comparing $description_check_box
to the constant on
. This should be in quotes if you want to check if the value of $description_check_box
is on
. So:
<?php if($description_check_box==on){ ?>
Should be:
<?php if($description_check_box=='on'){ ?>
BUT. This still won’t work. Because you’d be setting $description_check_box
to true
or false
based on whether it’s checked on line 66, but later you’re checking if the value is 'on'
.
You either need to set the value of $description_check_box
to 'on'
, or change your comparison to checking if $description_check_box
is true
.
You should also use isset()
before using $instance['description_check_box']
, because otherwise you’ll get an undefined index notice in the customiser when WP_Debug is enabled.
Refer to my other answer for my approach, which avoids all these problems.