: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @package AdvancedAds\Framework\Form
* @author Advanced Ads <info@wpadvancedads.com>
namespace AdvancedAds\Framework\Form;
use Advanced_Ads_Admin_Upgrades;
use AdvancedAds\Framework\Utilities\Str;
defined( 'ABSPATH' ) || exit;
* @param array $field Field data.
public function __construct( $field ) {
'name' => $field['name'] ?? $field['id'],
$this->field = wp_parse_args( $field, $defaults );
* Get from field data by id.
* @param string $id Id of the data to get.
* @param mixed $default Default value if not set.
public function get( $id, $default = false ) {
return $this->field[ $id ] ?? $default;
public function render_field() {
* This filter allows to extend the class dynamically by add-ons
* this would allow add-ons to dynamically hide/show only attributes belonging to them, practically not used now
$class = apply_filters( 'advanced-ads-option-class', $this->get( 'id' ) );
$classnames = Str::classnames(
'advads-field-' . sanitize_html_class( $this->get( 'type' ) ),
'advads-option-' . sanitize_html_class( $class ),
sanitize_html_class( $this->get( 'wrapper_class' ) )
<div id="<?php echo esc_attr( $this->get( 'id' ) ); ?>" class="<?php echo $classnames; // phpcs:ignore ?>">
<span class="advads-field-label"><?php echo esc_html( $this->get( 'label' ) ); ?></span>
<div class="advads-field-input">
$this->render_callback( 'before' );
$this->render_callback( 'after' );
if ( $this->get( 'desc' ) ) {
echo '<p class="description">' . wp_kses_post( $this->get( 'desc' ) ) . '</p>';
// Place an upgrade link below the description if there is one.
if ( $this->get( 'is_pro_pitch' ) ) {
Advanced_Ads_Admin_Upgrades::upgrade_link( 'upgrade-pro-' . $this->get( 'id' ) );
public function wrap_before() {}
public function wrap_after() {}
abstract public function render();
* @param string $name Id of callback.
private function render_callback( $name ): void {
$callback = $this->get( $name );
if ( ! $callback || ! is_callable( $callback ) ) {
call_user_func( $callback, $this );