sectionId = $inpSectionId;
$this->sectionDisPage = $inpSectionDisPage;
$this->sectionTitle = $inpSectionTitle;
$this->typeId = $inpTypeId;
$this->typeProperties = $inpTypeProperties;
$this->typeLevel = $inpTypeLevel;
$this->isEmpty = $inpIsEmpty;
$this->createSection();
}
/**
* Function that creates the settings section, each schema type has its own section.
*
* @since 0.13
*/
function createSection(){
$activeTypesOptionName = 'active_schema_type';
//Registering options for active type
register_setting($this->sectionDisPage, $activeTypesOptionName);
//Callback function for the section
$sectionCallback = !isset($this->isEmpty) ? (get_option('active_schema_type') == $this->sectionId ? null : function(){
$html = '
';
echo $html;
}) : function() {
$html = '
'.__('The type is Empty of Properties.', 'all-in-one-metadata').'
';
echo $html;
};
//Adding the settings section
add_settings_section($this->sectionId,$this->sectionTitle
,$sectionCallback,$this->sectionDisPage);
//If the type has properties then we populate them
if(!isset($this->isEmpty) && get_option('active_schema_type') == $this->sectionId){
$this->createFields($this->typeProperties['native']);
array_shift($this->typeProperties);
foreach ($this->typeProperties as $key=>$properties){
$this->createFields($properties, $key);
}
}
}
/**
* Function that creates the fields for each section, each schema type property is a field.
*
* @since 0.10
*/
function createFields($data, $subsection = null){
//declaring names for accumulated options
$optionName = 'property_network_value';
$freezeOptionName = $optionName.'_freeze';
$shareOptionName = $optionName.'_share';
//getting option array, if not, initialize empty array
$values = get_option($optionName) ?: [];
$freeze_values = get_option($freezeOptionName) ?: [];
$share_values = get_option($shareOptionName) ?: [];
//Registering the setting holding the values of options
register_setting($this->sectionDisPage,$optionName);
//Registering the setting for freezing values
register_setting($this->sectionDisPage,$freezeOptionName);
//Registering option fpr option sharing
register_setting($this->sectionDisPage,$shareOptionName);
$this->flag = 0;
//Looping through the properties of the type
foreach($data as $propertyId => $details){
//Creating the name of the options
$propertyOptionName = $propertyId.'_'.$this->typeId.'_'.$this->typeLevel;
$propertyFreeze = $propertyOptionName.'_freeze';
$propertyShare = $propertyOptionName.'_share';
//retrieving property option from array, if not, initialize it
$values[$propertyOptionName] = isset($values[$propertyOptionName]) ? $values[$propertyOptionName] : '';
$freeze_values[$propertyFreeze] = isset($freeze_values[$propertyFreeze]) ? $freeze_values[$propertyFreeze] : '';
$share_values[$propertyShare] = isset($share_values[$propertyShare]) ? $share_values[$propertyShare] : '';
//Callback function for the input field
$fieldRenderFunction = function() use ($propertyOptionName, $optionName, $values, $share_values, $propertyShare, $shareOptionName, $subsection){
$html = '';
if (isset($share_values[$propertyOptionName.'_share']) ? ($share_values[$propertyOptionName.'_share'] == 1 ? 1 : 0) : 0) {
$html .= '';
$html .= ' ';
$html .= ' ';
$html .= '';
} else {
$html .= '';
$html .= ' ';
$html .= '';
}
echo $html;
};
//Callback function for the freeze checkbox
$checkboxRenderFunction = function() use ($propertyFreeze, $freezeOptionName, $freeze_values){
?>
flag && isset($subsection)){
add_settings_field($subsection.'_head', '