: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @param bool $inverse_keys Whether or not the option keys need to be inverted to support older functions.
* @param string $help Inline Help that will be printed out before the visible toggles text.
* @param array $attr Extra attributes to add to the show-hide switch.
public function show_hide_switch( $variable, $label, $inverse_keys = false, $help = '', $attr = [] ) {
$attr = wp_parse_args( $attr, $defaults );
$on_key = ( $inverse_keys ) ? 'off' : 'on';
$off_key = ( $inverse_keys ) ? 'on' : 'off';
$on_key => __( 'On', 'wordpress-seo' ),
$off_key => __( 'Off', 'wordpress-seo' ),
$is_disabled = ( isset( $attr['disabled'] ) && $attr['disabled'] );
[ 'disabled' => $is_disabled ]
* Retrieves the value for the form field.
* @param string $field_name The field name to retrieve the value for.
* @param string|null $default_value The default value, when field has no value.
* @return mixed|null The retrieved value.
protected function get_field_value( $field_name, $default_value = null ) {
// On multisite subsites, the Usage tracking feature should always be set to Off.
if ( $this->is_tracking_on_subsite( $field_name ) ) {
return WPSEO_Options::get( $field_name, $default_value );
* Checks whether a given control should be disabled.
* @param string $variable The variable within the option to check whether its control should be disabled.
* @return bool True if control should be disabled, false otherwise.
protected function is_control_disabled( $variable ) {
if ( $this->option_instance === null ) {
// Disable the Usage tracking feature for multisite subsites.
if ( $this->is_tracking_on_subsite( $variable ) ) {
return $this->option_instance->is_disabled( $variable );
* Gets the explanation note to print if a given control is disabled.
* @param string $variable The variable within the option to print a disabled note for.
* @param string $custom_note An optional custom note to print instead.
* @return string Explanation note HTML string, or empty string if no note necessary.
protected function get_disabled_note( $variable, $custom_note = '' ) {
if ( $custom_note === '' && ! $this->is_control_disabled( $variable ) ) {
$disabled_message = esc_html__( 'This feature has been disabled by the network admin.', 'wordpress-seo' );
// The explanation to show when disabling the Usage tracking feature for multisite subsites.
if ( $this->is_tracking_on_subsite( $variable ) ) {
$disabled_message = esc_html__( 'This feature has been disabled since subsites never send tracking data.', 'wordpress-seo' );
$disabled_message = esc_html( $custom_note );
return '<p class="disabled-note">' . $disabled_message . '</p>';
* Determines whether we are dealing with the Usage tracking feature on a multisite subsite.
* This feature requires specific behavior for the toggle switch.
* @param string $feature_setting The feature setting.
* @return bool True if we are dealing with the Usage tracking feature on a multisite subsite.
protected function is_tracking_on_subsite( $feature_setting ) {
return ( $feature_setting === 'tracking' && ! is_network_admin() && ! is_main_site() );
* Returns the disabled attribute HTML.
* @param string $variable The variable within the option of the related form element.
* @param array $attr Extra attributes added to the form element.
* @return string The disabled attribute HTML.
protected function get_disabled_attribute( $variable, $attr ) {
if ( $this->is_control_disabled( $variable ) || ( isset( $attr['disabled'] ) && $attr['disabled'] ) ) {