: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$val = $this->get_field_value( $variable, '' );
if ( isset( $attr['type'] ) && $attr['type'] === 'url' ) {
$val = urldecode( $val );
echo '<div class="yoast-field-group__title">';
'class' => $attr['class'] . '--label',
if ( isset( $attr['extra_content'] ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: may contain HTML that should not be escaped.
echo $attr['extra_content'];
$has_input_error = Yoast_Input_Validation::yoast_form_control_has_error( $variable );
$aria_attributes = Yoast_Input_Validation::get_the_aria_invalid_attribute( $variable );
Yoast_Input_Validation::set_error_descriptions();
$aria_attributes .= Yoast_Input_Validation::get_the_aria_describedby_attribute( $variable );
// phpcs:disable WordPress.Security.EscapeOutput -- Reason: output is properly escaped or hardcoded.
'<input type="%1$s" name="%2$s" id="%3$s" class="%4$s"%5$s%6$s%7$s value="%8$s"%9$s>',
esc_attr( $this->option_name . '[' . $variable . ']' ),
esc_attr( $attr['class'] ),
isset( $attr['placeholder'] ) ? ' placeholder="' . esc_attr( $attr['placeholder'] ) . '"' : '',
isset( $attr['autocomplete'] ) ? ' autocomplete="' . esc_attr( $attr['autocomplete'] ) . '"' : '',
$this->get_disabled_attribute( $variable, $attr )
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: output is properly escaped.
echo Yoast_Input_Validation::get_the_error_description( $variable );
* @param string $variable The variable within the option to create the textarea for.
* @param string $label The label to show for the variable.
* @param string|array $attr The CSS class or an array of attributes to assign to the textarea.
public function textarea( $variable, $label, $attr = [] ) {
if ( ! is_array( $attr ) ) {
$attr = wp_parse_args( $attr, $defaults );
$val = $this->get_field_value( $variable, '' );
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded and all other output is properly escaped.
echo '<textarea cols="' . esc_attr( $attr['cols'] ) . '" rows="' . esc_attr( $attr['rows'] ) . '" class="' . esc_attr( 'textinput ' . $attr['class'] ) . '" id="' . esc_attr( $variable ) . '" name="' . esc_attr( $this->option_name . '[' . $variable . ']' ), '"', $disabled_attribute, '>' . esc_textarea( $val ) . '</textarea><br class="clear" />';
* Create a hidden input field.
* @param string $variable The variable within the option to create the hidden input for.
* @param string $id The ID of the element.
* @param mixed $val Optional. The value to set in the input field. Otherwise the value from the options will be used.
public function hidden( $variable, $id = '', $val = null ) {
$val = $this->get_field_value( $variable, '' );
$val = ( $val === true ) ? 'true' : 'false';
$id = 'hidden_' . $variable;
echo '<input type="hidden" id="' . esc_attr( $id ) . '" name="' . esc_attr( $this->option_name . '[' . $variable . ']' ), '" value="' . esc_attr( $val ) . '"/>';
* @param string $variable The variable within the option to create the select for.
* @param string $label The label to show for the variable.
* @param array $select_options The select options to choose from.
* @param string $styled The select style. Use 'styled' to get a styled select. Default 'unstyled'.
* @param bool $show_label Whether or not to show the label, if not, it will be applied as an aria-label.
* @param array $attr Extra attributes to add to the select.
* @param string $help Optional. Inline Help HTML that will be printed after the label. Default is empty.
public function select( $variable, $label, array $select_options, $styled = 'unstyled', $show_label = true, $attr = [], $help = '' ) {
if ( empty( $select_options ) ) {
$attr = wp_parse_args( $attr, $defaults );
echo $help; // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: The help contains HTML.
$select_name = esc_attr( $this->option_name ) . '[' . esc_attr( $variable ) . ']';
$active_option = $this->get_field_value( $variable, '' );
$select = new Yoast_Input_Select( $variable, $select_name, $select_options, $active_option );
$select->add_attribute( 'class', 'select' );
if ( $this->is_control_disabled( $variable )
|| ( isset( $attr['disabled'] ) && $attr['disabled'] ) ) {
$select->add_attribute( 'disabled', 'disabled' );
$select->add_attribute( 'aria-label', $label );
if ( $styled === 'styled' ) {
$wrapper_start_tag = '<span class="yoast-styled-select">';
$wrapper_end_tag = '</span>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
echo '<br class="clear"/>';
* Create a File upload field.
* @param string $variable The variable within the option to create the file upload field for.
* @param string $label The label to show for the variable.
* @param array $attr Extra attributes to add to the file upload input.
public function file_upload( $variable, $label, $attr = [] ) {
$val = $this->get_field_value( $variable, '' );
if ( is_array( $val ) ) {
$attr = wp_parse_args( $attr, $defaults );
$var_esc = esc_attr( $variable );
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded and all other output is properly escaped.
echo '<input type="file" value="' . esc_attr( $val ) . '" class="textinput" name="' . esc_attr( $this->option_name ) . '[' . $var_esc . ']" id="' . $var_esc . '"', $disabled_attribute, '/>';
// Need to save separate array items in hidden inputs, because empty file inputs type will be deleted by settings API.
$this->hidden( 'file', $this->option_name . '_file' );
$this->hidden( 'url', $this->option_name . '_url' );
$this->hidden( 'type', $this->option_name . '_type' );
echo '<br class="clear"/>';
* @param string $variable Option name.
* @param string $label Label message.
* @param array $attr Extra attributes to add to the media input and buttons.
public function media_input( $variable, $label, $attr = [] ) {
$val = $this->get_field_value( $variable, '' );
$id_value = $this->get_field_value( $variable . '_id', '' );
$var_esc = esc_attr( $variable );
$attr = wp_parse_args( $attr, $defaults );
'for' => 'wpseo_' . $variable,
$id_field_id = 'wpseo_' . $var_esc . '_id';
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
' id="wpseo_', $var_esc, '"', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
' type="text" size="36"',
' name="', esc_attr( $this->option_name ), '[', $var_esc, ']"', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
' value="', esc_attr( $val ), '"',
' id="wpseo_', $var_esc, '_button"', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
' class="wpseo_image_upload_button button"',
' value="', esc_attr__( 'Upload Image', 'wordpress-seo' ), '"',
' data-target-id="', esc_attr( $id_field_id ), '"',
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded.
' class="wpseo_image_remove_button button"',
' value="', esc_attr__( 'Clear Image', 'wordpress-seo' ), '"',
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded.
' id="', esc_attr( $id_field_id ), '"',
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
' name="', esc_attr( $this->option_name ), '[', $var_esc, '_id]"',
' value="', esc_attr( $id_value ), '"',
echo '<br class="clear"/>';
* Create a Radio input field.
* @param string $variable The variable within the option to create the radio button for.
* @param array $values The radio options to choose from.
* @param string $legend Optional. The legend to show for the field set, if any.
* @param array $legend_attr Optional. The attributes for the legend, if any.
* @param array $attr Extra attributes to add to the radio button.
public function radio( $variable, $values, $legend = '', $legend_attr = [], $attr = [] ) {
if ( ! is_array( $values ) || $values === [] ) {
$val = $this->get_field_value( $variable, false );
$var_esc = esc_attr( $variable );
$attr = wp_parse_args( $attr, $defaults );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
echo '<fieldset class="yoast-form-fieldset wpseo_radio_block" id="' . $var_esc . '">';
if ( is_string( $legend ) && $legend !== '' ) {
$legend_attr = wp_parse_args( $legend_attr, $legend_defaults );
$this->legend( $legend, $legend_attr );
foreach ( $values as $key => $value ) {
if ( is_array( $value ) ) {
$label = ( $value['label'] ?? '' );
$aria_label = ( $value['aria_label'] ?? '' );
$key_esc = esc_attr( $key );
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded and all other output is properly escaped.
echo '<input type="radio" class="radio" id="' . $var_esc . '-' . $key_esc . '" name="' . esc_attr( $this->option_name ) . '[' . $var_esc . ']" value="' . $key_esc . '" ' . checked( $val, $key_esc, false ) . $disabled_attribute . ' />';
'for' => $var_esc . '-' . $key_esc,
'aria_label' => $aria_label,
* Create a toggle switch input field using two radio buttons.
* @param string $variable The variable within the option to create the radio buttons for.
* @param array $values Associative array of on/off keys and their values to be used as
* the label elements text for the radio buttons. Optionally, each
* value can be an array of visible label text and screen reader text.
* @param string $label The visual label for the radio buttons group, used as the fieldset legend.
* @param string $help Inline Help that will be printed out before the visible toggles text.
* @param array $attr Extra attributes to add to the toggle switch.
public function toggle_switch( $variable, $values, $label, $help = '', $attr = [] ) {
if ( ! is_array( $values ) || $values === [] ) {
$attr = wp_parse_args( $attr, $defaults );
if ( isset( $attr['preserve_disabled_value'] ) && $attr['preserve_disabled_value'] ) {
$this->hidden( $variable );
$variable .= '_disabled';
$val = $this->get_field_value( $variable, false );
$help_class = ! empty( $help ) ? ' switch-container__has-help' : '';
$has_premium_upsell = ( isset( $attr['show_premium_upsell'] ) && $attr['show_premium_upsell'] && isset( $attr['premium_upsell_url'] ) && ! empty( $attr['premium_upsell_url'] ) );
$upsell_class = ( $has_premium_upsell ) ? ' premium-upsell' : '';
$var_esc = esc_attr( $variable );
printf( '<div class="%s">', esc_attr( 'switch-container' . $help_class . $upsell_class ) );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
echo '<fieldset id="', $var_esc, '" class="fieldset-switch-toggle"><legend>', $label, '</legend>', $help;
// Show disabled note if attribute does not exists or does exist and is set to true.
if ( ! isset( $attr['show_disabled_note'] ) || ( $attr['show_disabled_note'] === true ) ) {
if ( isset( $attr['note_when_disabled'] ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
echo $this->get_disabled_note( $variable, $attr['note_when_disabled'] );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
echo $this->get_disabled_note( $variable );
echo '<div class="switch-toggle switch-candy switch-yoast-seo">';
foreach ( $values as $key => $value ) {
$screen_reader_text_html = '';
if ( is_array( $value ) ) {
$screen_reader_text = $value['screen_reader_text'];
$screen_reader_text_html = '<span class="screen-reader-text"> ' . esc_html( $screen_reader_text ) . '</span>';
$key_esc = esc_attr( $key );
$for = $var_esc . '-' . $key_esc;
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded and all other output is properly escaped.
echo '<input type="radio" id="' . $for . '" name="' . esc_attr( $this->option_name ) . '[' . $var_esc . ']" value="' . $key_esc . '" ' . checked( $val, $key_esc, false ) . $disabled_attribute . ' />',
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
'<label for="', $for, '">', esc_html( $value ), $screen_reader_text_html, '</label>';
if ( $has_premium_upsell ) {
$upsell_button = '<a class="yoast-button yoast-button--buy yoast-button--small" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2" href='
. esc_url( $attr['premium_upsell_url'] ) . ' target="_blank">'
. esc_html__( 'Unlock with Premium!', 'wordpress-seo' )
/* translators: Hidden accessibility text. */
. '<span class="screen-reader-text">' . esc_html__( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>'
. '<span aria-hidden="true" class="yoast-button--buy__caret"></span></a>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All variable output is escaped above.
echo '<a></a></div></fieldset><div class="clear"></div>' . $upsell_button . '</div>' . PHP_EOL . PHP_EOL;
* Creates a toggle switch to define whether an indexable should be indexed or not.
* @param string $variable The variable within the option to create the radio buttons for.
* @param string $label The visual label for the radio buttons group, used as the fieldset legend.
* @param string $help Inline Help that will be printed out before the visible toggles text.
* @param array $attr Extra attributes to add to the index switch.
public function index_switch( $variable, $label, $help = '', $attr = [] ) {
$attr = wp_parse_args( $attr, $defaults );
'off' => __( 'On', 'wordpress-seo' ),
'on' => __( 'Off', 'wordpress-seo' ),
$is_disabled = ( isset( $attr['disabled'] ) && $attr['disabled'] );
/* translators: %s expands to an indexable object's name, like a post type or taxonomy */
esc_html__( 'Show %s in search results?', 'wordpress-seo' ),
[ 'disabled' => $is_disabled ]
* Creates a toggle switch to show hide certain options.
* @param string $variable The variable within the option to create the radio buttons for.
* @param string $label The visual label for the radio buttons group, used as the fieldset legend.