setName( $args['name'] ); } if ( isset( $args['label'] ) ) { $this->setLabel( $args['label'] ); } if ( isset( $args['description'] ) ) { $this->setDescription( $args['description'] ); } if ( isset( $args['value'] ) ) { $this->setValue( $args['value'] ); } if ( isset( $args['range'] ) ) { $this->setRange( $args['range'] ); } if ( isset( $args['type'] ) ) { $this->setType( $args['type'] ); } } /** * @return string */ public function getName() { return $this->_name; } /** * @param string $name */ public function setName( $name ) { $this->_name = $name; } /** * @return string */ public function getLabel() { $label = $this->_label; if ( ! $label ) { $label = ucwords( str_replace( '_', ' ', $this->getName() ) ); } return $label; } /** * @param string $label */ public function setLabel( $label ) { $this->_label = $label; } /** * @return string */ public function getDescription() { return $this->_description; } /** * @param string $description */ public function setDescription( $description ) { $this->_description = $description; } /** * @return string */ public function getValue() { $value = $this->_value; switch ( $this->getType() ) { } return $value; } /** * @param string $value */ public function setValue( $value ) { // Validate the value a little switch ( $this->getType() ) { case 'url' : $value = esc_url( $value ); break; default : if(is_string($value)) $value = esc_attr( $value ); } $this->_value = $value; } /** * @return string */ public function getRange() { return $this->_range; } /** * @param string $range */ public function setRange( $range ) { $this->_range = $range; } /** * @return string */ public function getType() { // Tidy up the type $type = trim( strtolower( $this->_type ) ); // Valid field types $valid = Array( 'input', 'url', 'checkbox' ); // Default invalid types to text fields if ( ! in_array( $type, $valid ) ) { $type = 'text'; } return $type; } /** * @param string $type */ public function setType( $type ) { $this->_type = $type; } /** * Output field settings in admin area * * @author Nigel Wells * @version 0.3.8.17.04.10 * @return string; */ public function outputField() { $input = ''; $descriptionAbove = false; switch ( $this->getType() ) { case 'checkbox' : $descriptionAbove = true; foreach($this->getRange() as $index => $range) { $input .= '
'; } break; case 'url' : case 'text' : $input = ''; } $html = $input; if ( $this->getDescription() ) { if($descriptionAbove) { $html = '

' . $this->getDescription() . '

' . $html; } else { $html .= '

' . $this->getDescription() . '

'; } } return $html; } /** * @return string */ public function getPrefix() { return $this->_prefix; } } }