id = $id; // Id
$this->name = $name; // Name
$this->label = isset( $atts['label'] ) && !empty( $atts['label'] ) ? $atts['label'] : ''; // Label
$this->placeholder = isset( $atts['placeholder'] ) && !empty( $atts['placeholder'] ) ? $atts['placeholder'] : ''; // Placeholder
$this->default = isset( $atts['default'] ) && !empty( $atts['default'] ) ? $atts['default'] : ''; // Default
$this->value = $value; // Value
}
/**
* Output admin form field
*
* @since 1.0.0
* @return string Field output
*/
public function field() {
$html = '';
if ( empty( $this->name ) ) {
return $html;
}
if ( $this->label ) {
$html .= '';
}
// If value NULL (only first time before save) set default value if passed
$value = NULL === $this->value && '' !== $this->default ? $this->default : $this->value;
$html .= '';
return $html;
}
}
/**
* Add custom field via filter
*
* @param array $php_classes List of field_type => array( 'class' => 'PHP_Class_Name', 'path' => 'class_filepath' ), to use to render field html
* @return array List of field_type_id => array( 'class' => 'PHP_Class_Name', 'path' => 'class_filepath' )
*/
function add_custom_form_field( $fields_classes ) {
/**
* custom_textarea is your type when adding fields in configuration array
*/
$fields_classes['custom_textarea'] = array(
'class' => 'Custom_Textarea_Form_Field',
'path' => dirname( __FILE__ ) . '/custom-admin-form-field.php'
);
/**
* This is example of how you would add your custom field to
* form_fields configuration array
*
'form_fields' => array(
'custom_field_name' => array(
'type' => 'custom_textarea',
'label' => esc_html__( 'Label name:', 'textdomain' ),
'placeholder' => esc_html__( 'Placeholder text', 'textdomain' ),
'default' => esc_html__( 'Default text', 'textdomain' )
)
)
*/
return $fields_classes;
}
add_filter( 'predic_widget_fields_php_classes', 'add_custom_form_field' );