of the toggle buttons. * @param string $warning Optional warning to be displayed above the toggles. * * @return void */ private function print_toggles( array $settings, Yoast_Form $yform, $title = '', $toggles = [], $warning = '' ) { if ( ! empty( $title ) ) { echo '

', \esc_html( $title ), '

'; } if ( ! empty( $warning ) ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in Alert_Presenter. echo new Alert_Presenter( $warning, 'warning' ); } if ( empty( $toggles ) ) { $toggles = [ 'off' => \__( 'Keep', 'wordpress-seo' ), 'on' => \__( 'Remove', 'wordpress-seo' ), ]; } $setting_prefix = WPSEO_Option::ALLOW_KEY_PREFIX; $toggles = [ // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch -- Reason: text is originally from Yoast SEO. 'on' => \__( 'Allow Control', 'wordpress-seo' ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch -- Reason: text is originally from Yoast SEO. 'off' => \__( 'Disable', 'wordpress-seo' ), ]; foreach ( $settings as $setting => $label ) { $attr = []; $variable = $setting_prefix . $setting; if ( $this->should_feature_be_disabled_permalink( $setting ) ) { $attr = [ 'disabled' => true, ]; $variable = $setting_prefix . $setting . '_disabled'; // Also add the original option as hidden, so as not to lose any values if it's disabled and the form is saved. $yform->hidden( $setting_prefix . $setting, $setting_prefix . $setting ); } elseif ( $this->should_feature_be_disabled_multisite( $setting ) ) { $attr = [ 'disabled' => true, 'preserve_disabled_value' => false, ]; } $yform->toggle_switch( $variable, $toggles, $label, '', $attr ); if ( $this->should_feature_be_disabled_permalink( $setting ) ) { echo '

'; if ( \current_user_can( 'manage_options' ) ) { \printf( /* translators: 1: Link start tag to the Permalinks settings page, 2: Link closing tag. */ \esc_html__( 'This feature is disabled when your site is not using %1$spretty permalinks%2$s.', 'wordpress-seo' ), '', '' ); } else { echo \esc_html__( 'This feature is disabled when your site is not using pretty permalinks.', 'wordpress-seo' ); } echo '

'; } } } /** * Checks if the feature should be disabled due to non-pretty permalinks. * * @param string $setting The setting to be displayed. * * @return bool */ protected function should_feature_be_disabled_permalink( $setting ) { return ( \in_array( $setting, [ 'clean_permalinks', 'clean_campaign_tracking_urls' ], true ) && empty( \get_option( 'permalink_structure' ) ) ); } /** * Checks if the feature should be disabled due to the site being a multisite. * * @param string $setting The setting to be displayed. * * @return bool */ protected function should_feature_be_disabled_multisite( $setting ) { return ( \in_array( $setting, [ 'deny_search_crawling', 'deny_wp_json_crawling', 'deny_adsbot_crawling' ], true ) && \is_multisite() ); } }