[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentytwenty/ -> functions.php (source)

   1  <?php
   2  /**
   3   * Twenty Twenty functions and definitions
   4   *
   5   * @link https://developer.wordpress.org/themes/basics/theme-functions/
   6   *
   7   * @package WordPress
   8   * @subpackage Twenty_Twenty
   9   * @since Twenty Twenty 1.0
  10   */
  11  
  12  /**
  13   * Table of Contents:
  14   * Theme Support
  15   * Required Files
  16   * Register Styles
  17   * Register Scripts
  18   * Register Menus
  19   * Custom Logo
  20   * WP Body Open
  21   * Register Sidebars
  22   * Enqueue Block Editor Assets
  23   * Enqueue Classic Editor Styles
  24   * Block Editor Settings
  25   */
  26  
  27  /**
  28   * Sets up theme defaults and registers support for various WordPress features.
  29   *
  30   * Note that this function is hooked into the after_setup_theme hook, which
  31   * runs before the init hook. The init hook is too late for some features, such
  32   * as indicating support for post thumbnails.
  33   */
  34  function twentytwenty_theme_support() {
  35  
  36      // Add default posts and comments RSS feed links to head.
  37      add_theme_support( 'automatic-feed-links' );
  38  
  39      // Custom background color.
  40      add_theme_support(
  41          'custom-background',
  42          array(
  43              'default-color' => 'f5efe0',
  44          )
  45      );
  46  
  47      // Set content-width.
  48      global $content_width;
  49      if ( ! isset( $content_width ) ) {
  50          $content_width = 580;
  51      }
  52  
  53      /*
  54       * Enable support for Post Thumbnails on posts and pages.
  55       *
  56       * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  57       */
  58      add_theme_support( 'post-thumbnails' );
  59  
  60      // Set post thumbnail size.
  61      set_post_thumbnail_size( 1200, 9999 );
  62  
  63      // Add custom image size used in Cover Template.
  64      add_image_size( 'twentytwenty-fullscreen', 1980, 9999 );
  65  
  66      // Custom logo.
  67      $logo_width  = 120;
  68      $logo_height = 90;
  69  
  70      // If the retina setting is active, double the recommended width and height.
  71      if ( get_theme_mod( 'retina_logo', false ) ) {
  72          $logo_width  = floor( $logo_width * 2 );
  73          $logo_height = floor( $logo_height * 2 );
  74      }
  75  
  76      add_theme_support(
  77          'custom-logo',
  78          array(
  79              'height'      => $logo_height,
  80              'width'       => $logo_width,
  81              'flex-height' => true,
  82              'flex-width'  => true,
  83          )
  84      );
  85  
  86      /*
  87       * Let WordPress manage the document title.
  88       * By adding theme support, we declare that this theme does not use a
  89       * hard-coded <title> tag in the document head, and expect WordPress to
  90       * provide it for us.
  91       */
  92      add_theme_support( 'title-tag' );
  93  
  94      /*
  95       * Switch default core markup for search form, comment form, and comments
  96       * to output valid HTML5.
  97       */
  98      add_theme_support(
  99          'html5',
 100          array(
 101              'search-form',
 102              'comment-form',
 103              'comment-list',
 104              'gallery',
 105              'caption',
 106              'script',
 107              'style',
 108          )
 109      );
 110  
 111      /*
 112       * Make theme available for translation.
 113       * Translations can be filed in the /languages/ directory.
 114       * If you're building a theme based on Twenty Twenty, use a find and replace
 115       * to change 'twentytwenty' to the name of your theme in all the template files.
 116       */
 117      load_theme_textdomain( 'twentytwenty' );
 118  
 119      // Add support for full and wide align images.
 120      add_theme_support( 'align-wide' );
 121  
 122      // Add support for responsive embeds.
 123      add_theme_support( 'responsive-embeds' );
 124  
 125      /*
 126       * Adds starter content to highlight the theme on fresh sites.
 127       * This is done conditionally to avoid loading the starter content on every
 128       * page load, as it is a one-off operation only needed once in the customizer.
 129       */
 130      if ( is_customize_preview() ) {
 131          require get_template_directory() . '/inc/starter-content.php';
 132          add_theme_support( 'starter-content', twentytwenty_get_starter_content() );
 133      }
 134  
 135      // Add theme support for selective refresh for widgets.
 136      add_theme_support( 'customize-selective-refresh-widgets' );
 137  
 138      /*
 139       * Adds `async` and `defer` support for scripts registered or enqueued
 140       * by the theme.
 141       */
 142      $loader = new TwentyTwenty_Script_Loader();
 143      add_filter( 'script_loader_tag', array( $loader, 'filter_script_loader_tag' ), 10, 2 );
 144  
 145  }
 146  
 147  add_action( 'after_setup_theme', 'twentytwenty_theme_support' );
 148  
 149  /**
 150   * REQUIRED FILES
 151   * Include required files.
 152   */
 153  require get_template_directory() . '/inc/template-tags.php';
 154  
 155  // Handle SVG icons.
 156  require get_template_directory() . '/classes/class-twentytwenty-svg-icons.php';
 157  require get_template_directory() . '/inc/svg-icons.php';
 158  
 159  // Handle Customizer settings.
 160  require get_template_directory() . '/classes/class-twentytwenty-customize.php';
 161  
 162  // Require Separator Control class.
 163  require get_template_directory() . '/classes/class-twentytwenty-separator-control.php';
 164  
 165  // Custom comment walker.
 166  require get_template_directory() . '/classes/class-twentytwenty-walker-comment.php';
 167  
 168  // Custom page walker.
 169  require get_template_directory() . '/classes/class-twentytwenty-walker-page.php';
 170  
 171  // Custom script loader class.
 172  require get_template_directory() . '/classes/class-twentytwenty-script-loader.php';
 173  
 174  // Non-latin language handling.
 175  require get_template_directory() . '/classes/class-twentytwenty-non-latin-languages.php';
 176  
 177  // Custom CSS.
 178  require get_template_directory() . '/inc/custom-css.php';
 179  
 180  /**
 181   * Register and Enqueue Styles.
 182   */
 183  function twentytwenty_register_styles() {
 184  
 185      $theme_version = wp_get_theme()->get( 'Version' );
 186  
 187      wp_enqueue_style( 'twentytwenty-style', get_stylesheet_uri(), array(), $theme_version );
 188      wp_style_add_data( 'twentytwenty-style', 'rtl', 'replace' );
 189  
 190      // Add output of Customizer settings as inline style.
 191      wp_add_inline_style( 'twentytwenty-style', twentytwenty_get_customizer_css( 'front-end' ) );
 192  
 193      // Add print CSS.
 194      wp_enqueue_style( 'twentytwenty-print-style', get_template_directory_uri() . '/print.css', null, $theme_version, 'print' );
 195  
 196  }
 197  
 198  add_action( 'wp_enqueue_scripts', 'twentytwenty_register_styles' );
 199  
 200  /**
 201   * Register and Enqueue Scripts.
 202   */
 203  function twentytwenty_register_scripts() {
 204  
 205      $theme_version = wp_get_theme()->get( 'Version' );
 206  
 207      if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 208          wp_enqueue_script( 'comment-reply' );
 209      }
 210  
 211      wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/assets/js/index.js', array(), $theme_version, false );
 212      wp_script_add_data( 'twentytwenty-js', 'async', true );
 213  
 214  }
 215  
 216  add_action( 'wp_enqueue_scripts', 'twentytwenty_register_scripts' );
 217  
 218  /**
 219   * Fix skip link focus in IE11.
 220   *
 221   * This does not enqueue the script because it is tiny and because it is only for IE11,
 222   * thus it does not warrant having an entire dedicated blocking script being loaded.
 223   *
 224   * @link https://git.io/vWdr2
 225   */
 226  function twentytwenty_skip_link_focus_fix() {
 227      // The following is minified via `terser --compress --mangle -- assets/js/skip-link-focus-fix.js`.
 228      ?>
 229      <script>
 230      /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
 231      </script>
 232      <?php
 233  }
 234  add_action( 'wp_print_footer_scripts', 'twentytwenty_skip_link_focus_fix' );
 235  
 236  /** Enqueue non-latin language styles
 237   *
 238   * @since Twenty Twenty 1.0
 239   *
 240   * @return void
 241   */
 242  function twentytwenty_non_latin_languages() {
 243      $custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'front-end' );
 244  
 245      if ( $custom_css ) {
 246          wp_add_inline_style( 'twentytwenty-style', $custom_css );
 247      }
 248  }
 249  
 250  add_action( 'wp_enqueue_scripts', 'twentytwenty_non_latin_languages' );
 251  
 252  /**
 253   * Register navigation menus uses wp_nav_menu in five places.
 254   */
 255  function twentytwenty_menus() {
 256  
 257      $locations = array(
 258          'primary'  => __( 'Desktop Horizontal Menu', 'twentytwenty' ),
 259          'expanded' => __( 'Desktop Expanded Menu', 'twentytwenty' ),
 260          'mobile'   => __( 'Mobile Menu', 'twentytwenty' ),
 261          'footer'   => __( 'Footer Menu', 'twentytwenty' ),
 262          'social'   => __( 'Social Menu', 'twentytwenty' ),
 263      );
 264  
 265      register_nav_menus( $locations );
 266  }
 267  
 268  add_action( 'init', 'twentytwenty_menus' );
 269  
 270  /**
 271   * Get the information about the logo.
 272   *
 273   * @param string $html The HTML output from get_custom_logo (core function).
 274   *
 275   * @return string $html
 276   */
 277  function twentytwenty_get_custom_logo( $html ) {
 278  
 279      $logo_id = get_theme_mod( 'custom_logo' );
 280  
 281      if ( ! $logo_id ) {
 282          return $html;
 283      }
 284  
 285      $logo = wp_get_attachment_image_src( $logo_id, 'full' );
 286  
 287      if ( $logo ) {
 288          // For clarity.
 289          $logo_width  = esc_attr( $logo[1] );
 290          $logo_height = esc_attr( $logo[2] );
 291  
 292          // If the retina logo setting is active, reduce the width/height by half.
 293          if ( get_theme_mod( 'retina_logo', false ) ) {
 294              $logo_width  = floor( $logo_width / 2 );
 295              $logo_height = floor( $logo_height / 2 );
 296  
 297              $search = array(
 298                  '/width=\"\d+\"/iU',
 299                  '/height=\"\d+\"/iU',
 300              );
 301  
 302              $replace = array(
 303                  "width=\"{$logo_width}\"",
 304                  "height=\"{$logo_height}\"",
 305              );
 306  
 307              // Add a style attribute with the height, or append the height to the style attribute if the style attribute already exists.
 308              if ( strpos( $html, ' style=' ) === false ) {
 309                  $search[]  = '/(src=)/';
 310                  $replace[] = "style=\"height: {$logo_height}px;\" src=";
 311              } else {
 312                  $search[]  = '/(style="[^"]*)/';
 313                  $replace[] = "$1 height: {$logo_height}px;";
 314              }
 315  
 316              $html = preg_replace( $search, $replace, $html );
 317  
 318          }
 319      }
 320  
 321      return $html;
 322  
 323  }
 324  
 325  add_filter( 'get_custom_logo', 'twentytwenty_get_custom_logo' );
 326  
 327  if ( ! function_exists( 'wp_body_open' ) ) {
 328  
 329      /**
 330       * Shim for wp_body_open, ensuring backward compatibility with versions of WordPress older than 5.2.
 331       */
 332  	function wp_body_open() {
 333          do_action( 'wp_body_open' );
 334      }
 335  }
 336  
 337  /**
 338   * Include a skip to content link at the top of the page so that users can bypass the menu.
 339   */
 340  function twentytwenty_skip_link() {
 341      echo '<a class="skip-link screen-reader-text" href="#site-content">' . __( 'Skip to the content', 'twentytwenty' ) . '</a>';
 342  }
 343  
 344  add_action( 'wp_body_open', 'twentytwenty_skip_link', 5 );
 345  
 346  /**
 347   * Register widget areas.
 348   *
 349   * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 350   */
 351  function twentytwenty_sidebar_registration() {
 352  
 353      // Arguments used in all register_sidebar() calls.
 354      $shared_args = array(
 355          'before_title'  => '<h2 class="widget-title subheading heading-size-3">',
 356          'after_title'   => '</h2>',
 357          'before_widget' => '<div class="widget %2$s"><div class="widget-content">',
 358          'after_widget'  => '</div></div>',
 359      );
 360  
 361      // Footer #1.
 362      register_sidebar(
 363          array_merge(
 364              $shared_args,
 365              array(
 366                  'name'        => __( 'Footer #1', 'twentytwenty' ),
 367                  'id'          => 'sidebar-1',
 368                  'description' => __( 'Widgets in this area will be displayed in the first column in the footer.', 'twentytwenty' ),
 369              )
 370          )
 371      );
 372  
 373      // Footer #2.
 374      register_sidebar(
 375          array_merge(
 376              $shared_args,
 377              array(
 378                  'name'        => __( 'Footer #2', 'twentytwenty' ),
 379                  'id'          => 'sidebar-2',
 380                  'description' => __( 'Widgets in this area will be displayed in the second column in the footer.', 'twentytwenty' ),
 381              )
 382          )
 383      );
 384  
 385  }
 386  
 387  add_action( 'widgets_init', 'twentytwenty_sidebar_registration' );
 388  
 389  /**
 390   * Enqueue supplemental block editor styles.
 391   */
 392  function twentytwenty_block_editor_styles() {
 393  
 394      // Enqueue the editor styles.
 395      wp_enqueue_style( 'twentytwenty-block-editor-styles', get_theme_file_uri( '/assets/css/editor-style-block.css' ), array(), wp_get_theme()->get( 'Version' ), 'all' );
 396      wp_style_add_data( 'twentytwenty-block-editor-styles', 'rtl', 'replace' );
 397  
 398      // Add inline style from the Customizer.
 399      wp_add_inline_style( 'twentytwenty-block-editor-styles', twentytwenty_get_customizer_css( 'block-editor' ) );
 400  
 401      // Add inline style for non-latin fonts.
 402      wp_add_inline_style( 'twentytwenty-block-editor-styles', TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' ) );
 403  
 404      // Enqueue the editor script.
 405      wp_enqueue_script( 'twentytwenty-block-editor-script', get_theme_file_uri( '/assets/js/editor-script-block.js' ), array( 'wp-blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true );
 406  }
 407  
 408  add_action( 'enqueue_block_editor_assets', 'twentytwenty_block_editor_styles', 1, 1 );
 409  
 410  /**
 411   * Enqueue classic editor styles.
 412   */
 413  function twentytwenty_classic_editor_styles() {
 414  
 415      $classic_editor_styles = array(
 416          '/assets/css/editor-style-classic.css',
 417      );
 418  
 419      add_editor_style( $classic_editor_styles );
 420  
 421  }
 422  
 423  add_action( 'init', 'twentytwenty_classic_editor_styles' );
 424  
 425  /**
 426   * Output Customizer settings in the classic editor.
 427   * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
 428   *
 429   * @param array $mce_init TinyMCE styles.
 430   *
 431   * @return array $mce_init TinyMCE styles.
 432   */
 433  function twentytwenty_add_classic_editor_customizer_styles( $mce_init ) {
 434  
 435      $styles = twentytwenty_get_customizer_css( 'classic-editor' );
 436  
 437      if ( ! isset( $mce_init['content_style'] ) ) {
 438          $mce_init['content_style'] = $styles . ' ';
 439      } else {
 440          $mce_init['content_style'] .= ' ' . $styles . ' ';
 441      }
 442  
 443      return $mce_init;
 444  
 445  }
 446  
 447  add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_customizer_styles' );
 448  
 449  /**
 450   * Output non-latin font styles in the classic editor.
 451   * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
 452   *
 453   * @param array $mce_init TinyMCE styles.
 454   *
 455   * @return array $mce_init TinyMCE styles.
 456   */
 457  function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) {
 458  
 459      $styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' );
 460  
 461      // Return if there are no styles to add.
 462      if ( ! $styles ) {
 463          return $mce_init;
 464      }
 465  
 466      if ( ! isset( $mce_init['content_style'] ) ) {
 467          $mce_init['content_style'] = $styles . ' ';
 468      } else {
 469          $mce_init['content_style'] .= ' ' . $styles . ' ';
 470      }
 471  
 472      return $mce_init;
 473  
 474  }
 475  
 476  add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' );
 477  
 478  /**
 479   * Block Editor Settings.
 480   * Add custom colors and font sizes to the block editor.
 481   */
 482  function twentytwenty_block_editor_settings() {
 483  
 484      // Block Editor Palette.
 485      $editor_color_palette = array(
 486          array(
 487              'name'  => __( 'Accent Color', 'twentytwenty' ),
 488              'slug'  => 'accent',
 489              'color' => twentytwenty_get_color_for_area( 'content', 'accent' ),
 490          ),
 491          array(
 492              'name'  => __( 'Primary', 'twentytwenty' ),
 493              'slug'  => 'primary',
 494              'color' => twentytwenty_get_color_for_area( 'content', 'text' ),
 495          ),
 496          array(
 497              'name'  => __( 'Secondary', 'twentytwenty' ),
 498              'slug'  => 'secondary',
 499              'color' => twentytwenty_get_color_for_area( 'content', 'secondary' ),
 500          ),
 501          array(
 502              'name'  => __( 'Subtle Background', 'twentytwenty' ),
 503              'slug'  => 'subtle-background',
 504              'color' => twentytwenty_get_color_for_area( 'content', 'borders' ),
 505          ),
 506      );
 507  
 508      // Add the background option.
 509      $background_color = get_theme_mod( 'background_color' );
 510      if ( ! $background_color ) {
 511          $background_color_arr = get_theme_support( 'custom-background' );
 512          $background_color     = $background_color_arr[0]['default-color'];
 513      }
 514      $editor_color_palette[] = array(
 515          'name'  => __( 'Background Color', 'twentytwenty' ),
 516          'slug'  => 'background',
 517          'color' => '#' . $background_color,
 518      );
 519  
 520      // If we have accent colors, add them to the block editor palette.
 521      if ( $editor_color_palette ) {
 522          add_theme_support( 'editor-color-palette', $editor_color_palette );
 523      }
 524  
 525      // Block Editor Font Sizes.
 526      add_theme_support(
 527          'editor-font-sizes',
 528          array(
 529              array(
 530                  'name'      => _x( 'Small', 'Name of the small font size in the block editor', 'twentytwenty' ),
 531                  'shortName' => _x( 'S', 'Short name of the small font size in the block editor.', 'twentytwenty' ),
 532                  'size'      => 18,
 533                  'slug'      => 'small',
 534              ),
 535              array(
 536                  'name'      => _x( 'Regular', 'Name of the regular font size in the block editor', 'twentytwenty' ),
 537                  'shortName' => _x( 'M', 'Short name of the regular font size in the block editor.', 'twentytwenty' ),
 538                  'size'      => 21,
 539                  'slug'      => 'normal',
 540              ),
 541              array(
 542                  'name'      => _x( 'Large', 'Name of the large font size in the block editor', 'twentytwenty' ),
 543                  'shortName' => _x( 'L', 'Short name of the large font size in the block editor.', 'twentytwenty' ),
 544                  'size'      => 26.25,
 545                  'slug'      => 'large',
 546              ),
 547              array(
 548                  'name'      => _x( 'Larger', 'Name of the larger font size in the block editor', 'twentytwenty' ),
 549                  'shortName' => _x( 'XL', 'Short name of the larger font size in the block editor.', 'twentytwenty' ),
 550                  'size'      => 32,
 551                  'slug'      => 'larger',
 552              ),
 553          )
 554      );
 555  
 556      add_theme_support( 'editor-styles' );
 557  
 558      // If we have a dark background color then add support for dark editor style.
 559      // We can determine if the background color is dark by checking if the text-color is white.
 560      if ( '#ffffff' === strtolower( twentytwenty_get_color_for_area( 'content', 'text' ) ) ) {
 561          add_theme_support( 'dark-editor-style' );
 562      }
 563  
 564  }
 565  
 566  add_action( 'after_setup_theme', 'twentytwenty_block_editor_settings' );
 567  
 568  /**
 569   * Overwrite default more tag with styling and screen reader markup.
 570   *
 571   * @param string $html The default output HTML for the more tag.
 572   *
 573   * @return string $html
 574   */
 575  function twentytwenty_read_more_tag( $html ) {
 576      return preg_replace( '/<a(.*)>(.*)<\/a>/iU', sprintf( '<div class="read-more-button-wrap"><a$1><span class="faux-button">$2</span> <span class="screen-reader-text">"%1$s"</span></a></div>', get_the_title( get_the_ID() ) ), $html );
 577  }
 578  
 579  add_filter( 'the_content_more_link', 'twentytwenty_read_more_tag' );
 580  
 581  /**
 582   * Enqueues scripts for customizer controls & settings.
 583   *
 584   * @since Twenty Twenty 1.0
 585   *
 586   * @return void
 587   */
 588  function twentytwenty_customize_controls_enqueue_scripts() {
 589      $theme_version = wp_get_theme()->get( 'Version' );
 590  
 591      // Add main customizer js file.
 592      wp_enqueue_script( 'twentytwenty-customize', get_template_directory_uri() . '/assets/js/customize.js', array( 'jquery' ), $theme_version, false );
 593  
 594      // Add script for color calculations.
 595      wp_enqueue_script( 'twentytwenty-color-calculations', get_template_directory_uri() . '/assets/js/color-calculations.js', array( 'wp-color-picker' ), $theme_version, false );
 596  
 597      // Add script for controls.
 598      wp_enqueue_script( 'twentytwenty-customize-controls', get_template_directory_uri() . '/assets/js/customize-controls.js', array( 'twentytwenty-color-calculations', 'customize-controls', 'underscore', 'jquery' ), $theme_version, false );
 599      wp_localize_script( 'twentytwenty-customize-controls', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
 600  }
 601  
 602  add_action( 'customize_controls_enqueue_scripts', 'twentytwenty_customize_controls_enqueue_scripts' );
 603  
 604  /**
 605   * Enqueue scripts for the customizer preview.
 606   *
 607   * @since Twenty Twenty 1.0
 608   *
 609   * @return void
 610   */
 611  function twentytwenty_customize_preview_init() {
 612      $theme_version = wp_get_theme()->get( 'Version' );
 613  
 614      wp_enqueue_script( 'twentytwenty-customize-preview', get_theme_file_uri( '/assets/js/customize-preview.js' ), array( 'customize-preview', 'customize-selective-refresh', 'jquery' ), $theme_version, true );
 615      wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
 616      wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyPreviewEls', twentytwenty_get_elements_array() );
 617  
 618      wp_add_inline_script(
 619          'twentytwenty-customize-preview',
 620          sprintf(
 621              'wp.customize.selectiveRefresh.partialConstructor[ %1$s ].prototype.attrs = %2$s;',
 622              wp_json_encode( 'cover_opacity' ),
 623              wp_json_encode( twentytwenty_customize_opacity_range() )
 624          )
 625      );
 626  }
 627  
 628  add_action( 'customize_preview_init', 'twentytwenty_customize_preview_init' );
 629  
 630  /**
 631   * Get accessible color for an area.
 632   *
 633   * @since Twenty Twenty 1.0
 634   *
 635   * @param string $area The area we want to get the colors for.
 636   * @param string $context Can be 'text' or 'accent'.
 637   * @return string Returns a HEX color.
 638   */
 639  function twentytwenty_get_color_for_area( $area = 'content', $context = 'text' ) {
 640  
 641      // Get the value from the theme-mod.
 642      $settings = get_theme_mod(
 643          'accent_accessible_colors',
 644          array(
 645              'content'       => array(
 646                  'text'      => '#000000',
 647                  'accent'    => '#cd2653',
 648                  'secondary' => '#6d6d6d',
 649                  'borders'   => '#dcd7ca',
 650              ),
 651              'header-footer' => array(
 652                  'text'      => '#000000',
 653                  'accent'    => '#cd2653',
 654                  'secondary' => '#6d6d6d',
 655                  'borders'   => '#dcd7ca',
 656              ),
 657          )
 658      );
 659  
 660      // If we have a value return it.
 661      if ( isset( $settings[ $area ] ) && isset( $settings[ $area ][ $context ] ) ) {
 662          return $settings[ $area ][ $context ];
 663      }
 664  
 665      // Return false if the option doesn't exist.
 666      return false;
 667  }
 668  
 669  /**
 670   * Returns an array of variables for the customizer preview.
 671   *
 672   * @since Twenty Twenty 1.0
 673   *
 674   * @return array
 675   */
 676  function twentytwenty_get_customizer_color_vars() {
 677      $colors = array(
 678          'content'       => array(
 679              'setting' => 'background_color',
 680          ),
 681          'header-footer' => array(
 682              'setting' => 'header_footer_background_color',
 683          ),
 684      );
 685      return $colors;
 686  }
 687  
 688  /**
 689   * Get an array of elements.
 690   *
 691   * @since Twenty Twenty 1.0
 692   *
 693   * @return array
 694   */
 695  function twentytwenty_get_elements_array() {
 696  
 697      // The array is formatted like this:
 698      // [key-in-saved-setting][sub-key-in-setting][css-property] = [elements].
 699      $elements = array(
 700          'content'       => array(
 701              'accent'     => array(
 702                  'color'            => array( '.color-accent', '.color-accent-hover:hover', '.color-accent-hover:focus', ':root .has-accent-color', '.has-drop-cap:not(:focus):first-letter', '.wp-block-button.is-style-outline', 'a' ),
 703                  'border-color'     => array( 'blockquote', '.border-color-accent', '.border-color-accent-hover:hover', '.border-color-accent-hover:focus' ),
 704                  'background-color' => array( 'button:not(.toggle)', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file .wp-block-file__button', 'input[type="button"]', 'input[type="reset"]', 'input[type="submit"]', '.bg-accent', '.bg-accent-hover:hover', '.bg-accent-hover:focus', ':root .has-accent-background-color', '.comment-reply-link' ),
 705                  'fill'             => array( '.fill-children-accent', '.fill-children-accent *' ),
 706              ),
 707              'background' => array(
 708                  'color'            => array( ':root .has-background-color', 'button', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file__button', 'input[type="button"]', 'input[type="reset"]', 'input[type="submit"]', '.wp-block-button', '.comment-reply-link', '.has-background.has-primary-background-color:not(.has-text-color)', '.has-background.has-primary-background-color *:not(.has-text-color)', '.has-background.has-accent-background-color:not(.has-text-color)', '.has-background.has-accent-background-color *:not(.has-text-color)' ),
 709                  'background-color' => array( ':root .has-background-background-color' ),
 710              ),
 711              'text'       => array(
 712                  'color'            => array( 'body', '.entry-title a', ':root .has-primary-color' ),
 713                  'background-color' => array( ':root .has-primary-background-color' ),
 714              ),
 715              'secondary'  => array(
 716                  'color'            => array( 'cite', 'figcaption', '.wp-caption-text', '.post-meta', '.entry-content .wp-block-archives li', '.entry-content .wp-block-categories li', '.entry-content .wp-block-latest-posts li', '.wp-block-latest-comments__comment-date', '.wp-block-latest-posts__post-date', '.wp-block-embed figcaption', '.wp-block-image figcaption', '.wp-block-pullquote cite', '.comment-metadata', '.comment-respond .comment-notes', '.comment-respond .logged-in-as', '.pagination .dots', '.entry-content hr:not(.has-background)', 'hr.styled-separator', ':root .has-secondary-color' ),
 717                  'background-color' => array( ':root .has-secondary-background-color' ),
 718              ),
 719              'borders'    => array(
 720                  'border-color'        => array( 'pre', 'fieldset', 'input', 'textarea', 'table', 'table *', 'hr' ),
 721                  'background-color'    => array( 'caption', 'code', 'code', 'kbd', 'samp', '.wp-block-table.is-style-stripes tbody tr:nth-child(odd)', ':root .has-subtle-background-background-color' ),
 722                  'border-bottom-color' => array( '.wp-block-table.is-style-stripes' ),
 723                  'border-top-color'    => array( '.wp-block-latest-posts.is-grid li' ),
 724                  'color'               => array( ':root .has-subtle-background-color' ),
 725              ),
 726          ),
 727          'header-footer' => array(
 728              'accent'     => array(
 729                  'color'            => array( 'body:not(.overlay-header) .primary-menu > li > a', 'body:not(.overlay-header) .primary-menu > li > .icon', '.modal-menu a', '.footer-menu a, .footer-widgets a', '#site-footer .wp-block-button.is-style-outline', '.wp-block-pullquote:before', '.singular:not(.overlay-header) .entry-header a', '.archive-header a', '.header-footer-group .color-accent', '.header-footer-group .color-accent-hover:hover' ),
 730                  'background-color' => array( '.social-icons a', '#site-footer button:not(.toggle)', '#site-footer .button', '#site-footer .faux-button', '#site-footer .wp-block-button__link', '#site-footer .wp-block-file__button', '#site-footer input[type="button"]', '#site-footer input[type="reset"]', '#site-footer input[type="submit"]' ),
 731              ),
 732              'background' => array(
 733                  'color'            => array( '.social-icons a', 'body:not(.overlay-header) .primary-menu ul', '.header-footer-group button', '.header-footer-group .button', '.header-footer-group .faux-button', '.header-footer-group .wp-block-button:not(.is-style-outline) .wp-block-button__link', '.header-footer-group .wp-block-file__button', '.header-footer-group input[type="button"]', '.header-footer-group input[type="reset"]', '.header-footer-group input[type="submit"]' ),
 734                  'background-color' => array( '#site-header', '.footer-nav-widgets-wrapper', '#site-footer', '.menu-modal', '.menu-modal-inner', '.search-modal-inner', '.archive-header', '.singular .entry-header', '.singular .featured-media:before', '.wp-block-pullquote:before' ),
 735              ),
 736              'text'       => array(
 737                  'color'               => array( '.header-footer-group', 'body:not(.overlay-header) #site-header .toggle', '.menu-modal .toggle' ),
 738                  'background-color'    => array( 'body:not(.overlay-header) .primary-menu ul' ),
 739                  'border-bottom-color' => array( 'body:not(.overlay-header) .primary-menu > li > ul:after' ),
 740                  'border-left-color'   => array( 'body:not(.overlay-header) .primary-menu ul ul:after' ),
 741              ),
 742              'secondary'  => array(
 743                  'color' => array( '.site-description', 'body:not(.overlay-header) .toggle-inner .toggle-text', '.widget .post-date', '.widget .rss-date', '.widget_archive li', '.widget_categories li', '.widget cite', '.widget_pages li', '.widget_meta li', '.widget_nav_menu li', '.powered-by-wordpress', '.to-the-top', '.singular .entry-header .post-meta', '.singular:not(.overlay-header) .entry-header .post-meta a' ),
 744              ),
 745              'borders'    => array(
 746                  'border-color'     => array( '.header-footer-group pre', '.header-footer-group fieldset', '.header-footer-group input', '.header-footer-group textarea', '.header-footer-group table', '.header-footer-group table *', '.footer-nav-widgets-wrapper', '#site-footer', '.menu-modal nav *', '.footer-widgets-outer-wrapper', '.footer-top' ),
 747                  'background-color' => array( '.header-footer-group table caption', 'body:not(.overlay-header) .header-inner .toggle-wrapper::before' ),
 748              ),
 749          ),
 750      );
 751  
 752      /**
 753      * Filters Twenty Twenty theme elements
 754      *
 755      * @since Twenty Twenty 1.0
 756      *
 757      * @param array Array of elements
 758      */
 759      return apply_filters( 'twentytwenty_get_elements_array', $elements );
 760  }


Generated : Wed Jun 3 08:20:02 2020 Cross-referenced by PHPXref