I created a checkbox in the settingsTemp.php file and i want to create an if condition (if the checkbox is ckecked or not) in a Metabox.php file.
public function checkerCallback() {
isset($this->options[self::FI_CHECKBOX_FIELD]) ? $isChecked="checked" : $isChecked="";
printf(
'<input id="%s" type="checkbox" name="%s[%s]" %s />',
self::FI_CHECKBOX_FIELD,
self::OPTION_NAME,
self::FI_CHECKBOX_FIELD,
$isChecked
);
}
i tried the following two solutions but it made my metabox almost to disappear (without the if condition the metabox works fine). So, there must be a mistake on how i try to connect the two files and how i name the if condition. Could you give me some suggestions? Thank u!
solution 1:
if (SettingsTemp::checkerCallback()->$isChecked=="checked")
{
echo '<label for="align_name_field">Name</label><br>';
echo '<input type="text" name="align_name_field" value="Education" readonly /><br>';
echo '<label for="align_url_field">Url</label><br>';
echo '<input type="text" name="align_url_field" value="Education" readonly /><br>';
echo '<label for="align_desc_field">Description</label><br>';
echo '<input type="text" name="align_desc_field" value="Education" readonly />';
}
solution 2:
if (isset(SettingsTemp->options[SettingsTemp::FI_CHECKBOX_FIELD]))
{
echo '<label for="align_name_field">Name</label><br>';
echo '<input type="text" name="align_name_field" value="Education" readonly /><br>';
echo '<label for="align_url_field">Url</label><br>';
echo '<input type="text" name="align_url_field" value="Education" readonly /><br>';
echo '<label for="align_desc_field">Description</label><br>';
echo '<input type="text" name="align_desc_field" value="Education" readonly />';
}
Aucun commentaire:
Enregistrer un commentaire