: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use Yoast\WP\SEO\Presenters\Admin\Light_Switch_Presenter;
use Yoast\WP\SEO\Presenters\Admin\Sidebar_Presenter;
* The short name of the option to use for the current page.
protected $option_instance = null;
* Get the singleton instance of this class.
public static function get_instance() {
if ( ! ( self::$instance instanceof self ) ) {
self::$instance = new self();
* Generates the header for admin pages.
* @param bool $form Whether or not the form start tag should be included.
* @param string $option The short name of the option to use for the current page.
* @param bool $contains_files Whether the form should allow for file uploads.
* @param bool $option_long_name Group name of the option.
public function admin_header( $form = true, $option = 'wpseo', $contains_files = false, $option_long_name = false ) {
if ( ! $option_long_name ) {
$option_long_name = WPSEO_Options::get_group_name( $option );
<div class="wrap yoast wpseo-admin-page <?php echo esc_attr( 'page-' . $option ); ?>">
* Display the updated/error messages.
* Only needed as our settings page is not under options, otherwise it will automatically be included.
require_once ABSPATH . 'wp-admin/options-head.php';
<h1 id="wpseo-title"><?php echo esc_html( get_admin_page_title() ); ?></h1>
<div id="yst-settings-header-root"></div>
<div class="wpseo_content_wrapper">
<div class="wpseo_content_cell" id="wpseo_content_top">
$enctype = ( $contains_files ) ? ' enctype="multipart/form-data"' : '';
$network_admin = new Yoast_Network_Admin();
if ( $network_admin->meets_requirements() ) {
$action_url = network_admin_url( 'settings.php' );
$hidden_fields_cb = [ $network_admin, 'settings_fields' ];
$action_url = admin_url( 'options.php' );
$hidden_fields_cb = 'settings_fields';
. '" method="post" id="wpseo-conf"'
. $enctype . ' accept-charset="' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- nothing to escape.
. esc_attr( get_bloginfo( 'charset' ) )
. '" novalidate="novalidate">';
call_user_func( $hidden_fields_cb, $option_long_name );
$this->set_option( $option );
* Set the option used in output for form elements.
* @param string $option_name Option key.
public function set_option( $option_name ) {
$this->option_name = $option_name;
$this->option_instance = WPSEO_Options::get_option_instance( $option_name );
if ( ! $this->option_instance ) {
$this->option_instance = null;
* Generates the footer for admin pages.
* @param bool $submit Whether or not a submit button and form end tag should be shown.
* @param bool $show_sidebar Whether or not to show the banner sidebar - used by premium plugins to disable it.
public function admin_footer( $submit = true, $show_sidebar = true ) {
$settings_changed_listener = new WPSEO_Admin_Settings_Changed_Listener();
echo '<div id="wpseo-submit-container">';
echo '<div id="wpseo-submit-container-float" class="wpseo-admin-submit">';
submit_button( __( 'Save changes', 'wordpress-seo' ) );
$settings_changed_listener->show_success_message();
echo '<div id="wpseo-submit-container-fixed" class="wpseo-admin-submit wpseo-admin-submit-fixed" style="display: none;">';
submit_button( __( 'Save changes', 'wordpress-seo' ) );
$settings_changed_listener->show_success_message();
* Apply general admin_footer hooks.
do_action( 'wpseo_admin_footer', $this );
* Run possibly set actions to add for example an i18n box.
do_action( 'wpseo_admin_promo_footer' );
</div><!-- end of div wpseo_content_top -->';
echo '</div><!-- end of div wpseo_content_wrapper -->';
do_action( 'wpseo_admin_below_content', $this );
</div><!-- end of wrap -->';
* Generates the sidebar for admin pages.
public function admin_sidebar() {
// No banners in Premium.
$addon_manager = new WPSEO_Addon_Manager();
if ( YoastSEO()->helpers->product->is_premium() && $addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG ) ) {
$sidebar_presenter = new Sidebar_Presenter();
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in presenter.
echo $sidebar_presenter->present();
* Output a label element.
* @param string $text Label text string, which can contain escaped html.
* @param array $attr HTML attributes set.
public function label( $text, $attr ) {
$attr = wp_parse_args( $attr, $defaults );
if ( $attr['aria_label'] !== '' ) {
$aria_label = ' aria-label="' . esc_attr( $attr['aria_label'] ) . '"';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before. Specifically, the $text variable can contain escaped html.
echo "<label class='" . esc_attr( $attr['class'] ) . "' for='" . esc_attr( $attr['for'] ) . "'$aria_label>$text";
* Output a legend element.
* @param string $text Legend text string.
* @param array $attr HTML attributes set.
public function legend( $text, $attr ) {
$attr = wp_parse_args( $attr, $defaults );
$id = ( $attr['id'] === '' ) ? '' : ' id="' . esc_attr( $attr['id'] ) . '"';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped before.
echo '<legend class="' . esc_attr( 'yoast-form-legend ' . $attr['class'] ) . '"' . $id . '>' . $text . '</legend>';
* Create a Checkbox input field.
* @param string $variable The variable within the option to create the checkbox for.
* @param string $label The label to show for the variable.
* @param bool $label_left Whether the label should be left (true) or right (false).
* @param array $attr Extra attributes to add to the checkbox.
public function checkbox( $variable, $label, $label_left = false, $attr = [] ) {
$val = $this->get_field_value( $variable, false );
$attr = wp_parse_args( $attr, $defaults );
if ( $label_left !== false ) {
$this->label( $label_left, [ 'for' => $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 class="', esc_attr( 'checkbox ' . $class ), '" type="checkbox" id="', esc_attr( $variable ), '" name="', esc_attr( $this->option_name . '[' . $variable . ']' ), '" value="on"', checked( $val, 'on', false ), $disabled_attribute, '/>';
if ( ! empty( $label ) ) {
$this->label( $label, [ 'for' => $variable ] );
echo '<br class="clear" />';
* Creates a Checkbox input field list.
* @param string $variable The variables within the option to create the checkbox list for.
* @param string $labels The labels to show for the variable.
* @param array $attr Extra attributes to add to the checkbox list.
public function checkbox_list( $variable, $labels, $attr = [] ) {
$attr = wp_parse_args( $attr, $defaults );
$values = $this->get_field_value( $variable, [] );
foreach ( $labels as $name => $label ) {
'<input class="checkbox double" id="%1$s" type="checkbox" name="%2$s" %3$s %5$s value="%4$s"/>',
esc_attr( $variable . '-' . $name ),
esc_attr( $this->option_name . '[' . $variable . '][' . $name . ']' ),
checked( ! empty( $values[ $name ] ), true, false ),
disabled( ( isset( $attr['disabled'] ) && $attr['disabled'] ), true, false )
'<label class="checkbox" for="%1$s">%2$s</label>',
esc_attr( $variable . '-' . $name ), // #1
echo '<br class="clear">';
* Create a light switch input field using a single checkbox.
* @param string $variable The variable within the option to create the checkbox for.
* @param string $label The visual label text for the toggle.
* @param array $buttons Array of two visual labels for the buttons (defaults Disabled/Enabled).
* @param bool $reverse Reverse order of buttons (default true).
* @param string $help Inline Help that will be printed out before the toggle.
* @param bool $strong Whether the visual label is displayed in strong text. Default is false.
* Starting from Yoast SEO 16.5, the visual label is forced to bold via CSS.
* @param array $attr Extra attributes to add to the light switch.
public function light_switch( $variable, $label, $buttons = [], $reverse = true, $help = '', $strong = false, $attr = [] ) {
$val = $this->get_field_value( $variable, false );
$attr = wp_parse_args( $attr, $defaults );
$disabled_attribute = $this->get_disabled_attribute( $variable, $attr );
$output = new Light_Switch_Presenter(
$this->option_name . '[' . $variable . ']',
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: All output is properly escaped or hardcoded in the presenter.
* Create a Text input field.
* @since 2.1 Introduced the `$attr` parameter.
* @param string $variable The variable within the option to create the text input field for.
* @param string $label The label to show for the variable.
* @param array|string $attr Extra attributes to add to the input field. Can be class, disabled, autocomplete.
public function textinput( $variable, $label, $attr = [] ) {
if ( ! is_array( $attr ) ) {
$attr = wp_parse_args( $attr, $defaults );
$val = $this->get_field_value( $variable, '' );
if ( isset( $attr['type'] ) && $attr['type'] === 'url' ) {
$val = urldecode( $val );
$attributes = isset( $attr['autocomplete'] ) ? ' autocomplete="' . esc_attr( $attr['autocomplete'] ) . '"' : '';
$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 );
$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', $attributes, $aria_attributes, ' class="', esc_attr( 'textinput ' . $attr['class'] ), '" placeholder="', esc_attr( $attr['placeholder'] ), '" type="', $type, '" id="', esc_attr( $variable ), '" name="', esc_attr( $this->option_name . '[' . $variable . ']' ), '" value="', esc_attr( $val ), '"', $disabled_attribute, '/>', '<br class="clear" />';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in getter.
echo Yoast_Input_Validation::get_the_error_description( $variable );
* Create a Number input field.
* @param string $variable The variable within the option to create the text input field for.
* @param string $label The label to show for the variable.
* @param array|string $attr Extra attributes to add to the input field. Can be class, disabled, autocomplete.
public function number( $variable, $label, $attr = [] ) {
$attr = wp_parse_args( $attr, $defaults );
$val = $this->get_field_value( $variable, 0 );
'class' => 'textinput ' . $attr['class'],
$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 );
$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' . $aria_attributes . ' class="' . esc_attr( $attr['class'] ) . '" type="' . $type . '" id="', esc_attr( $variable ), '" min="', esc_attr( $attr['min'] ), '" max="', esc_attr( $attr['max'] ), '" name="', esc_attr( $this->option_name . '[' . $variable . ']' ), '" value="', esc_attr( $val ), '"', $disabled_attribute, '/>', '<br class="clear" />';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in getter.
echo Yoast_Input_Validation::get_the_error_description( $variable );
* Creates a text input field with with the ability to add content after the label.
* @param string $variable The variable within the option to create the text input field for.
* @param string $label The label to show for the variable.
* @param array $attr Extra attributes to add to the input field.
public function textinput_extra_content( $variable, $label, $attr = [] ) {
'class' => 'yoast-field-group__inputfield',
$attr = wp_parse_args( $attr, $defaults );