metaType = $metaTypeInput; $this->metaInfo = $metaInfoInput; $this->sectionId = $sectionIdInput; $this->sectionName = $sectionNameInput; $this->displayPage = $displayPageInput; $this->parentType = genFunc::get_active_parent(); $this->post_type = explode('_', $this->displayPage)[0]; $this->optionGeneral = get_option($this->post_type.'_'.$this->parentType) ?: []; $this->pmdt_create_field(); } /** * The main function used to create a field. * * @since 0.8.1 */ function pmdt_create_field(){ add_settings_field( $this->parentType.'['.$this->metaType.']', // ID used to identify the field throughout the theme $this->metaInfo[0], // The label to the left of the option interface element array( $this, 'pmdt_field_draw' ), // 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 ); //We are using a combination of the metaType and the sectionId for the field id so // we can rapidly create fields of the same type in more that one sections, // without having to specify different ids for each section's field's $this->optionGeneral[$this->metaType] = isset($this->optionGeneral[$this->metaType]) ? $this->optionGeneral[$this->metaType] : ''; //Adding field to accumulated option update_option($this->post_type.'_'.$this->parentType, $this->optionGeneral); } /** * The function used to get the current type for finding its parents. * The function returns parent ID or parent Name * @since 0.10 */ private function get_type_parents($getName = false){ $foundParents = array(); foreach(structure::$allSchemaTypes as $type){ $typeSettings = $type::$type_setting; foreach($typeSettings as $name => $setting){ if($name == $this->metaType){ foreach($type::$type_parents as $parent){ $getName == false ? $foundParents []= $parent::type_name[1] : $foundParents []= $parent::type_name[0]; } } } } return $foundParents; } /** * The main function used to render the description of the field. * * @since 0.8.1 */ function pmdt_field_draw(){ //check if schema type is active for this post type $optionValue = isset($this->optionGeneral[$this->metaType]) ? ($this->optionGeneral[$this->metaType] == 1 ? '1' : '0') : '0'; //draw activation/deactivation buttons if (isset($this->optionGeneral[$this->metaType]) ? ($this->optionGeneral[$this->metaType] != 1 ? 1 : 0) : 1) { $html = ''; $html .= ''; } else { $ID = $this->metaType . '-' . $this->sectionId; $html = ''; $html .=''.__('Edit', 'all-in-one-metadata').''; $html .= ''; } //if schema type has properties, display them as hint if(!isset($this->metaInfo[2])) { $html .= '

'; foreach ( structure::$allSchemaTypes as $schema_type ) { if ( key_exists( $this->metaType, $schema_type::$type_setting ) ) { $flag = 0; foreach ( $schema_type::$type_properties as $property ) { $html .= $flag == 1 ? ', ' : ''; $html .= $property[1]; $flag = 1; } } } $html .= '.

'; } else { //If the type has no properties than we show the user that the parent type will be used instead $html .= '

'.__('Type is Empty of properties. ', 'all-in-one-metadata').$this->metaInfo[2].__(' properties will be used.', 'all-in-one-metadata').'

'; } //create a pop-up window for active schema types if(isset($this->optionGeneral[$this->metaType]) && $this->optionGeneral[$this->metaType] == 1) { //add pop-up box styles and scripts add_thickbox(); $properties_page = $this->metaType.'_'.$this->post_type.'_level'; /* START BUFFERING*/ ob_start(); //Creating the select element for selecting parents ?>
metaInfo[2])) { echo '
'; settings_fields( $properties_page . '_properties' ); do_settings_sections( $properties_page . '_properties' ); echo '

'; } else { echo '

'.__('Type is Empty of properties. Use parent properties from below selection.', 'all-in-one-metadata').'

'; } //Creating DIVS with the parents properties inside foreach($parentIds as $parent){ ?>

'.__('Choose ', 'all-in-one-metadata') . $this->metaInfo[0] . __(' Properties:', 'all-in-one-metadata').'



'.$contents.' '; } echo $html; } }