: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Form rendering utility functions
* @package AdvancedAds\Framework\Form
* @author Advanced Ads <info@wpadvancedads.com>
namespace AdvancedAds\Framework\Form;
defined( 'ABSPATH' ) || exit;
private $field_types = [];
public function __construct() {
'checkbox' => Field_Checkbox::class,
'color' => Field_Color::class,
'number' => Field_Text::class,
'position' => Field_Position::class,
'password' => Field_Text::class,
'radio' => Field_Radio::class,
'selector' => Field_Selector::class,
'size' => Field_Size::class,
'switch' => Field_Switch::class,
'text' => Field_Text::class,
'textarea' => Field_Textarea::class,
* @throws Exception If no id is define.
* @throws Exception If no type is define.
* @param array $args Field args.
public function add_field( $args ) {
if ( ! isset( $args['id'] ) || empty( $args['id'] ) ) {
throw new Exception( 'A field must have an id.' );
if ( ! isset( $args['type'] ) || empty( $args['type'] ) ) {
throw new Exception( 'A field must have a type.' );
$this->fields[ $args['id'] ] = $args;
* @param string $id Field id to remove.
public function remove_field( $id ) {
if ( isset( $this->fields[ $id ] ) ) {
unset( $this->fields[ $id ] );
public function render() {
foreach ( $this->fields as $field ) {
if ( isset( $this->field_types[ $type ] ) ) {
$class = $this->field_types[ $type ];
( new $class( $field ) )->render_field();