groupId = $inpGroupId;
$this->metaboxName = $inpMetaboxName;
$this->metaboxlevel = $inpMetaboxlevel;
$this->fieldProp = $inpFieldProp;
//Running functions
$this->create_metabox();
}
/**
* The function for creating the metabox.
*
* @since 0.10
*/
function create_metabox(){
//Creating the metabox
x_add_metadata_group( $this->groupId,$this->metaboxlevel, array(
'label' => $this->metaboxName,
'priority' => 'high'
) );
$this->create_metabox_fields();
}
/**
* The function for rendering frozen fields.
*
* @since 0.18
*/
function frozen_field( $field_slug, $field, $value ) {
$value = get_post_meta(get_the_ID(),$field_slug);
if(array_key_exists(0, $value)){
$value = $value[0];
}else{
$value = "";
}
$broken_slug = explode('_',$field_slug);
$property = ucfirst($broken_slug[1]);
?>
=$property?> is Frozen by super admin. The value is "=$value?>".
$postType]) ?: [];
$siteMeta = empty($siteMeta) ? [] : $siteMeta[0];
//creating name for metakey of site-meta/meatdata type
$broken_slug = explode('_',$field_slug);
$property = ucfirst($broken_slug[1]);
$field_slug_site = $broken_slug[0].'_'.$broken_slug[1].'_'.$broken_slug[2].'_'.$broken_slug[3].'_'.$postType;
//getting value of post meta
$value = $siteMeta == [] ? '' : get_post_meta($siteMeta->ID,$field_slug_site, true);
?>
=$property?> =__('is Overwritten by', 'all-in-one-metadata').' '.$dataFrom?>.
fieldProp as $property => $details ) {
//Creating the field id
$fieldId = 'pb_' . $property . '_' .$this->groupId. '_' .$this->metaboxlevel;
//Render function name, by default is empty
$renderFunction = '';
//get general option for freezes
if(is_multisite()) {
$option = get_blog_option( 1, 'property_network_value_freeze' );
}
//Checking if the property is frozen from super admin
if(is_multisite() && ($this->metaboxlevel == 'site-meta' || $this->metaboxlevel == 'metadata')){
$frozzenFieldId = isset($option[$property . '_' .$this->groupId. '_' .$this->metaboxlevel.'_freeze']) ?: '';
if($frozzenFieldId && get_option($this->metaboxlevel.'_saoverwr')){
$renderFunction = 'frozen_field';
}
}
//getting accumulated options for overwritten properties
$propertiesOptionNativeOverwrite = get_option('schema_properties_'.$this->groupId. '_overwrite') ?: [];
$propertiesOptionsParentOverwrite = [];
foreach(structure::$allSchemaTypes as $type) {
if(genFunc::get_type_id($type) == $this->groupId) {
foreach ( $type::$type_parents as $parent ) {
$propertiesOptionParentOverwrite = get_option( $this->groupId . '_overwrite_' .$parent::type_name[1].'_dis' ) ?: [];
$propertiesOptionsParentOverwrite = array_merge( $propertiesOptionsParentOverwrite, $propertiesOptionParentOverwrite );
}
}
}
$propertiesOptionOverwrite = array_merge($propertiesOptionNativeOverwrite, $propertiesOptionsParentOverwrite);
//Checking if the property is being overwritten
//Giving message
if($this->metaboxlevel == 'post' || $this->metaboxlevel == 'chapter'){
if( isset($propertiesOptionOverwrite[$property]) ? ($propertiesOptionOverwrite[$property] == 1 ? 1 : 0) : 0){
$renderFunction = 'overwritten_field';
}
}
//getting accumulated options for properties
$propertiesOptionNative = get_option('schema_properties_'.$this->groupId. '_' . $this->metaboxlevel . '_level') ?: [];
$propertiesOptionsParent = [];
foreach(structure::$allSchemaTypes as $type) {
if(genFunc::get_type_id($type) == $this->groupId) {
foreach ( $type::$type_parents as $parent ) {
$propertiesOptionParent = get_option( $this->groupId . '_' . $this->metaboxlevel . '_level_' .$parent::type_name[1].'_dis' ) ?: [];
$propertiesOptionsParent = array_merge( $propertiesOptionsParent, $propertiesOptionParent );
}
}
}
$propertiesOption = array_merge($propertiesOptionsParent, $propertiesOptionNative);
//Checking if we need a dropdown field
if(!isset($details[3])){
//Checking if the property is required
if ($details[0] == true) {
x_add_metadata_field( $fieldId, $this->metaboxlevel, array(
'group' => $this->groupId,
'label' => $details[1],
'description' => $details[2],
'display_callback' => array($this,$renderFunction)
) );
}else if(isset($propertiesOption[$property]) ? ($propertiesOption[$property] == 1 ? 1 : 0) : 0){
x_add_metadata_field( $fieldId, $this->metaboxlevel, array(
'group' => $this->groupId,
'label' => $details[1],
'description' => $details[2],
'display_callback' => array($this,$renderFunction)
) );
}
}else{
if($details[3]=='number'){
//This creates a field of type number
//To use this functionality add the string 'number' in the fourth parameter when creating a field -> [3] position in the array
//'dublin_time_required' => array( true, 'Required Time', '', 'number' ),
if ($details[0] == true) {
x_add_metadata_field( $fieldId, $this->metaboxlevel, array(
'group' => $this->groupId,
'field_type' => 'number',
'label' => $details[1],
'description' => $details[2],
'display_callback' => array($this,$renderFunction)
) );
}else if(isset($propertiesOption[$property]) ? ($propertiesOption[$property] == 1 ? 1 : 0) : 0){
x_add_metadata_field( $fieldId, $this->metaboxlevel, array(
'group' => $this->groupId,
'field_type' => 'number',
'label' => $details[1],
'description' => $details[2],
'display_callback' => array($this,$renderFunction)
) );
}
}else{
if ($details[0] == true) {
x_add_metadata_field( $fieldId, $this->metaboxlevel, array(
'group' => $this->groupId,
'field_type' => 'select',
'values' => $details[3],
'label' => $details[1],
'description' => $details[2],
'display_callback' => array($this,$renderFunction)
) );
}else if(isset($propertiesOption[$property]) ? ($propertiesOption[$property] == 1 ? 1 : 0) : 0){
x_add_metadata_field( $fieldId, $this->metaboxlevel, array(
'group' => $this->groupId,
'field_type' => 'select',
'values' => $details[3],
'label' => $details[1],
'description' => $details[2],
'display_callback' => array($this,$renderFunction)
) );
}
}
}
}
}
}