property = $propertyInput; $this->details = $detailsInput; $this->sectionId = $sectionIdInput; $this->sectionName = $sectionNameInput; $this->displayPage = $displayPageInput; $this->generalOptionNative = get_option( 'schema_properties_' . $this->sectionId) ?: []; //checking to see if property is native or inherited if (!strpos($this->displayPage, '_dis')) { $this->pmdt_create_field(); } else { $this->generalOptionParent = get_option($this->displayPage) ?:[]; $this->pmdt_create_inherit_field(); } } /** * The main function used to create a field. * * @since 0.11 */ function pmdt_create_field(){ $postLevel = site_cpt::pressbooks_identify() ? 'metadata' : 'site-meta'; //Overwrite to, message $overwriteTo = site_cpt::pressbooks_identify() ? ' to Chapter' : ' to Post'; //Checking to see if we are on metadata post level or site-meta post level if((strpos($this->sectionId, $postLevel) !== false)){ //Create the id for the overwrite field $overwriteField = str_replace($postLevel.'_level','overwrite','schema_properties_'.$this->sectionId.'['.$this->property.']'); //get accumulated option for overwrites of given schema type $optionOverwrite = get_option(str_replace('['.$this->property.']', '', $overwriteField)); //Create the callback function for the overwrite field $overwriteCallback = function() use ($overwriteField,$overwriteTo, $optionOverwrite){ $disabled = $this->details[0]==true ? 'disabled' : ''; $overwriteHide = isset($optionOverwrite[$this->property]) ? 'style="display: none;"' : ''; $disableButton = $this->details[0] == false ? '
'.__('Disable property output on post level. Values stored will not be erased.', 'all-in-one-metadata').'
' : ''; $html = '
generalOptionNative[$this->property]) ? ( $this->generalOptionNative[$this->property] == 1 ? 1 : 0) : 0, false) . '' . $disabled . '/>' . $this->details[2] . '
'; $html .= $overwriteTo . ' property]) ? ($optionOverwrite[$this->property] == 1 ? 1 : 0) : 0, false) . '/>
'; $html .= '
'.__('Delete values from database for all posts.', 'all-in-one-metadata').'
'; $html .= $disableButton; echo $html; }; //Register overwrite setting register_setting( $this->displayPage, str_replace('['.$this->property.']', '', $overwriteField)); }else{ //If level is not metadata or site-meta we just create the property field without the overwrite $overwriteCallback = function(){ $disabled = $this->details[0]==true? 'disabled' : ''; $html = '
generalOptionNative[$this->property]) ? ( $this->generalOptionNative[$this->property] == 1 ? 1 : 0) : 0, false) . '' . $disabled . '/>' . $this->details[2] . '
'; echo $html; }; } //Adding the property field add_settings_field( 'schema_properties_'.$this->sectionId.'['.$this->property.']', // ID used to identify the field throughout the theme $this->details[1], // The label to the left of the option interface element $overwriteCallback, // The name of the function responsible for rendering the option interface $this->displayPage, // The page on which this option will be displayed $this->sectionId // The name of the section to which this field belongs ); //Registering the property field $this->generalOptionNative[$this->property] = isset($this->generalOptionNative[$this->property]) ? ( $this->generalOptionNative[$this->property] == 1 ? 1 : 0) : 0; update_option('schema_properties_'.$this->sectionId,$this->generalOptionNative); //Setting the required properties to be always enabled if($this->details[0] == true){ $this->generalOptionNative[$this->property] = 1; update_option('schema_properties_'.$this->sectionId,$this->generalOptionNative); } } /** * The main function used to create an inherited field. * * @since 0.17 */ function pmdt_create_inherit_field(){ $postLevel = site_cpt::pressbooks_identify() ? 'metadata' : 'site-meta'; //Overwrite to, message $overwriteTo = site_cpt::pressbooks_identify() ? __(' to Chapter', 'all-in-one-metadata') : __(' to Post', 'all-in-one-metadata'); //Checking to see if we are on metadata post level or site-meta post level if((strpos($this->sectionId, $postLevel) !== false)){ //Create the id for the overwrite field $overwriteField = str_replace($postLevel.'_level','overwrite',$this->displayPage.'['.$this->property.']'); //get accumulated option for overwrites of given schema type $optionOverwrite = get_option(str_replace('['.$this->property.']', '', $overwriteField)); //Create the callback function for the overwrite field $overwriteCallback = function() use ($overwriteField,$overwriteTo, $optionOverwrite){ $disabled = $this->details[0]==true ? 'disabled' : ''; $overwriteHide = isset($optionOverwrite[$this->property]) ? 'style="display: none;"' : ''; $disableButton = $this->details[0] == false ? '
'.__('Disable property output on post level. Values stored will not be erased.', 'all-in-one-metadata').'
' : ''; $html = '
generalOptionParent[$this->property]) ? ( $this->generalOptionParent[$this->property] == 1 ? 1 : 0) : 0, false) . '' . $disabled . '/>' . $this->details[2] . '
'; $html .= $overwriteTo . ' property]) ? ($optionOverwrite[$this->property] == 1 ? 1 : 0) : 0, false) . '/>
'; $html .= '
'.__('Delete values from database for all posts.', 'all-in-one-metadata').'
'; $html .= $disableButton; echo $html; }; //Register overwrite setting register_setting( $this->displayPage, str_replace('['.$this->property.']', '', $overwriteField)); }else{ //If level is not metadata or site-meta we just create the property field without the overwrite $overwriteCallback = function(){ $disabled = $this->details[0]==true? 'disabled' : ''; $html = '
generalOptionParent[$this->property]) ? ( $this->generalOptionParent[$this->property] == 1 ? 1 : 0) : 0, false) . '' . $disabled . '/>' . $this->details[2] . '
'; echo $html; }; } //Adding the property field add_settings_field( $this->displayPage.'['.$this->property.']', // ID used to identify the field throughout the theme $this->details[1], // The label to the left of the option interface element $overwriteCallback, // The name of the function responsible for rendering the option interface $this->displayPage, // The page on which this option will be displayed $this->sectionId // The name of the section to which this field belongs ); //Registering the property field $this->generalOptionParent[$this->property] = isset($this->generalOptionParent[$this->property]) ? ( $this->generalOptionParent[$this->property] == 1 ? 1 : 0) : 0; update_option($this->displayPage,$this->generalOptionParent); //Setting the required properties to be always enabled if($this->details[0] == true){ $this->generalOptionParent[$this->property] = 1; update_option($this->displayPage,$this->generalOptionParent); } } }