'text', 'id' => '', 'wrapper_class' => '', 'input_class' => '', 'label_class' => '', 'label' => '', 'name' => '', 'value' => '', 'placeholder' => '', 'description' => '', 'field_description' => '', 'options' => [], 'has_optgroups' => false, 'attributes' => [], 'risk' => '', 'breaks' => '', ]; $args = wp_parse_args( $args, $defaults ); $this->type = $args['type']; $this->id = $args['id']; $this->wrapper_class = $args['wrapper_class']; $this->input_class = $args['input_class']; $this->label = $args['label']; $this->label_class = $args['label_class']; $this->name = $args['name']; $this->description = $args['description']; $this->field_description = $args['field_description']; $this->value = $args['value']; $this->placeholder = $args['placeholder']; $this->options = $args['options']; $this->has_optgroups = $args['has_optgroups']; $this->attributes = $args['attributes']; $this->risk = $args['risk']; $this->breaks = $args['breaks']; $this->allowed_html = [ 'a' => [ 'id' => [], 'class' => [], 'href' => [ 'javascript:void(0);' => [], ], 'title' => [], 'target' => [], 'rel' => [], ], 'span' => [ 'class' => [], ], 'p' => [], 'br' => [], 'em' => [], 'strong' => [], 'small' => [], 'ul' => [], 'ol' => [], 'li' => [], ]; } /** * Renders an HTML form field based on the specified type and attributes. * This method dynamically generates the appropriate form field (e.g., switch, textarea, number, text) * including its label, input elements, and additional descriptive text if provided. * @return void Outputs the generated HTML form field directly. */ public function render(): void { $attr = $this->build_attributes(); ?>
type ) { case 'switch': { $is_on = is_scalar( $this->value ) ? (int) $this->value : 0; ?> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

render_risk(); break; } case 'textarea': { ?> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

/> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

/> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

/> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

/> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

/> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

/> field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

/>
/>
field_description ) ) { ?>

field_description, $this->allowed_html ); ?>

attributes ) && is_array( $this->attributes ) ) { foreach( $this->attributes as $key => $value ) { if( 'disabled' === $key && false === $value ) { continue; } $attributes .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( $value ) ); } } return $attributes; } /** * Builds the small risk label that sits right after a switch label. * @return string Escaped HTML, or an empty string for a switch with no risk set. */ protected function risk_badge(): string { if( 'safe' === $this->risk ) { return '' . esc_html__( 'Safe', 'adminease' ) . ''; } if( 'careful' === $this->risk ) { return '' . esc_html__( 'Check your site after turning on', 'adminease' ) . ''; } if( 'destructive' === $this->risk ) { return '' . esc_html__( 'Deletes data', 'adminease' ) . ''; } return ''; } /** * Prints the "Might affect" line under a switch when it has a risk label and a sentence for it. * @return void */ protected function render_risk(): void { if( '' === $this->risk_badge() ) { return; } if( !empty( $this->breaks ) ) { ?>

breaks ) ); ?>