• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Twenty_Twenty_One_Dark_Mode::customizer_controls() – Register customizer options.

You appear to be a bot. Output may be restricted

Description

Register customizer options.

Usage

$void = Twenty_Twenty_One_Dark_Mode::customizer_controls( $wp_customize );

Parameters

$wp_customize
( WP_Customize_Manager ) required – Theme Customizer object.

Returns

void

Source

File name: twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php
Lines:

1 to 80 of 80
  public function customizer_controls( $wp_customize ) {

    $colors_section = $wp_customize->get_section( 'colors' );
    if ( is_object( $colors_section ) ) {
      $colors_section->title = __( 'Colors & Dark Mode', 'twentytwentyone' );
    }

    // Custom notice control.
    include_once get_theme_file_path( 'classes/class-twenty-twenty-one-customize-notice-control.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound

    $wp_customize->add_setting(
      'respect_user_color_preference_notice',
      array(
        'capability'        => 'edit_theme_options',
        'default'           => '',
        'sanitize_callback' => '__return_empty_string',
      )
    );

    $wp_customize->add_control(
      new Twenty_Twenty_One_Customize_Notice_Control(
        $wp_customize,
        'respect_user_color_preference_notice',
        array(
          'section'         => 'colors',
          'priority'        => 100,
          'active_callback' => static function() {
            return 127 >= Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) );
          },
        )
      )
    );

    $wp_customize->add_setting(
      'respect_user_color_preference',
      array(
        'capability'        => 'edit_theme_options',
        'default'           => false,
        'sanitize_callback' => static function( $value ) {
          return (bool) $value;
        },
      )
    );

    $description  = '<p>';
    $description .= sprintf(
      /* translators: %s: Twenty Twenty-One support article URL. */
      __( 'Dark Mode is a device setting. If a visitor to your site requests it, your site will be shown with a dark background and light text. <a href="%s">Learn more about Dark Mode.</a>', 'twentytwentyone' ),
      esc_url( __( 'https://wordpress.org/support/article/twenty-twenty-one/#dark-mode-support', 'twentytwentyone' ) )
    );
    $description .= '</p>';
    $description .= '<p>' . __( 'Dark Mode can also be turned on and off with a button that you can find in the bottom corner of the page.', 'twentytwentyone' ) . '</p>';

    $wp_customize->add_control(
      'respect_user_color_preference',
      array(
        'type'            => 'checkbox',
        'section'         => 'colors',
        'label'           => esc_html__( 'Dark Mode support', 'twentytwentyone' ),
        'priority'        => 110,
        'description'     => $description,
        'active_callback' => static function( $value ) {
          return 127 < Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) );
        },
      )
    );

    // Add partial for background_color.
    $wp_customize->selective_refresh->add_partial(
      'background_color',
      array(
        'selector'            => '#dark-mode-toggler',
        'container_inclusive' => true,
        'render_callback'     => function() {
          $attrs = ( $this->switch_should_render() ) ? array() : array( 'style' => 'display:none;' );
          $this->the_html( $attrs );
        },
      )
    );
  }
 

 View on GitHub View on Trac

Published: 9th December 2020 | Last updated: 26th January 2022

Primary Sidebar

Information

Function name: Twenty_Twenty_One_Dark_Mode::customizer_controls
Class ref: Twenty_Twenty_One_Dark_Mode
Plugin ref: Twenty Twenty-One
Version: 1.7
Sourcefile: classes/class-twenty-twenty-one-dark-mode.php
File ref: classes/class-twenty-twenty-one-dark-mode.php
Deprecated?: No
API Letters: D,M,O,T

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites