[ 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              'navigation-widgets',
 109          )
 110      );
 111  
 112      /*
 113       * Make theme available for translation.
 114       * Translations can be filed in the /languages/ directory.
 115       * If you're building a theme based on Twenty Twenty, use a find and replace
 116       * to change 'twentytwenty' to the name of your theme in all the template files.
 117       */
 118      load_theme_textdomain( 'twentytwenty' );
 119  
 120      // Add support for full and wide align images.
 121      add_theme_support( 'align-wide' );
 122  
 123      // Add support for responsive embeds.
 124      add_theme_support( 'responsive-embeds' );
 125  
 126      /*
 127       * Adds starter content to highlight the theme on fresh sites.
 128       * This is done conditionally to avoid loading the starter content on every
 129       * page load, as it is a one-off operation only needed once in the customizer.
 130       */
 131      if ( is_customize_preview() ) {
 132          require get_template_directory() . '/inc/starter-content.php';
 133          add_theme_support( 'starter-content', twentytwenty_get_starter_content() );
 134      }
 135  
 136      // Add theme support for selective refresh for widgets.
 137      add_theme_support( 'customize-selective-refresh-widgets' );
 138  
 139      /*
 140       * Adds `async` and `defer` support for scripts registered or enqueued
 141       * by the theme.
 142       */
 143      $loader = new TwentyTwenty_Script_Loader();
 144      add_filter( 'script_loader_tag', array( $loader, 'filter_script_loader_tag' ), 10, 2 );
 145  
 146  }
 147  
 148  add_action( 'after_setup_theme', 'twentytwenty_theme_support' );
 149  
 150  /**
 151   * REQUIRED FILES
 152   * Include required files.
 153   */
 154  require get_template_directory() . '/inc/template-tags.php';
 155  
 156  // Handle SVG icons.
 157  require get_template_directory() . '/classes/class-twentytwenty-svg-icons.php';
 158  require get_template_directory() . '/inc/svg-icons.php';
 159  
 160  // Handle Customizer settings.
 161  require get_template_directory() . '/classes/class-twentytwenty-customize.php';
 162  
 163  // Require Separator Control class.
 164  require get_template_directory() . '/classes/class-twentytwenty-separator-control.php';
 165  
 166  // Custom comment walker.
 167  require get_template_directory() . '/classes/class-twentytwenty-walker-comment.php';
 168  
 169  // Custom page walker.
 170  require get_template_directory() . '/classes/class-twentytwenty-walker-page.php';
 171  
 172  // Custom script loader class.
 173  require get_template_directory() . '/classes/class-twentytwenty-script-loader.php';
 174  
 175  // Non-latin language handling.
 176  require get_template_directory() . '/classes/class-twentytwenty-non-latin-languages.php';
 177  
 178  // Custom CSS.
 179  require get_template_directory() . '/inc/custom-css.php';
 180  
 181  /**
 182   * Register and Enqueue Styles.
 183   */
 184  function twentytwenty_register_styles() {
 185  
 186      $theme_version = wp_get_theme()->get( 'Version' );
 187  
 188      wp_enqueue_style( 'twentytwenty-style', get_stylesheet_uri(), array(), $theme_version );
 189      wp_style_add_data( 'twentytwenty-style', 'rtl', 'replace' );
 190  
 191      // Add output of Customizer settings as inline style.
 192      wp_add_inline_style( 'twentytwenty-style', twentytwenty_get_customizer_css( 'front-end' ) );
 193  
 194      // Add print CSS.
 195      wp_enqueue_style( 'twentytwenty-print-style', get_template_directory_uri() . '/print.css', null, $theme_version, 'print' );
 196  
 197  }
 198  
 199  add_action( 'wp_enqueue_scripts', 'twentytwenty_register_styles' );
 200  
 201  /**
 202   * Register and Enqueue Scripts.
 203   */
 204  function twentytwenty_register_scripts() {
 205  
 206      $theme_version = wp_get_theme()->get( 'Version' );
 207  
 208      if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 209          wp_enqueue_script( 'comment-reply' );
 210      }
 211  
 212      wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/assets/js/index.js', array(), $theme_version, false );
 213      wp_script_add_data( 'twentytwenty-js', 'async', true );
 214  
 215  }
 216  
 217  add_action( 'wp_enqueue_scripts', 'twentytwenty_register_scripts' );
 218  
 219  /**
 220   * Fix skip link focus in IE11.
 221   *
 222   * This does not enqueue the script because it is tiny and because it is only for IE11,
 223   * thus it does not warrant having an entire dedicated blocking script being loaded.
 224   *
 225   * @link https://git.io/vWdr2
 226   */
 227  function twentytwenty_skip_link_focus_fix() {
 228      // The following is minified via `terser --compress --mangle -- assets/js/skip-link-focus-fix.js`.
 229      ?>
 230      <script>
 231      /(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);
 232      </script>
 233      <?php
 234  }
 235  add_action( 'wp_print_footer_scripts', 'twentytwenty_skip_link_focus_fix' );
 236  
 237  /** Enqueue non-latin language styles
 238   *
 239   * @since Twenty Twenty 1.0
 240   *
 241   * @return void
 242   */
 243  function twentytwenty_non_latin_languages() {
 244      $custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'front-end' );
 245  
 246      if ( $custom_css ) {
 247          wp_add_inline_style( 'twentytwenty-style', $custom_css );
 248      }
 249  }
 250  
 251  add_action( 'wp_enqueue_scripts', 'twentytwenty_non_latin_languages' );
 252  
 253  /**
 254   * Register navigation menus uses wp_nav_menu in five places.
 255   */
 256  function twentytwenty_menus() {
 257  
 258      $locations = array(
 259          'primary'  => __( 'Desktop Horizontal Menu', 'twentytwenty' ),
 260          'expanded' => __( 'Desktop Expanded Menu', 'twentytwenty' ),
 261          'mobile'   => __( 'Mobile Menu', 'twentytwenty' ),
 262          'footer'   => __( 'Footer Menu', 'twentytwenty' ),
 263          'social'   => __( 'Social Menu', 'twentytwenty' ),
 264      );
 265  
 266      register_nav_menus( $locations );
 267  }
 268  
 269  add_action( 'init', 'twentytwenty_menus' );
 270  
 271  /**
 272   * Get the information about the logo.
 273   *
 274   * @param string $html The HTML output from get_custom_logo (core function).
 275   * @return string
 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   * @return array TinyMCE styles.
 431   */
 432  function twentytwenty_add_classic_editor_customizer_styles( $mce_init ) {
 433  
 434      $styles = twentytwenty_get_customizer_css( 'classic-editor' );
 435  
 436      if ( ! isset( $mce_init['content_style'] ) ) {
 437          $mce_init['content_style'] = $styles . ' ';
 438      } else {
 439          $mce_init['content_style'] .= ' ' . $styles . ' ';
 440      }
 441  
 442      return $mce_init;
 443  
 444  }
 445  
 446  add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_customizer_styles' );
 447  
 448  /**
 449   * Output non-latin font styles in the classic editor.
 450   * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
 451   *
 452   * @param array $mce_init TinyMCE styles.
 453   * @return array TinyMCE styles.
 454   */
 455  function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) {
 456  
 457      $styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' );
 458  
 459      // Return if there are no styles to add.
 460      if ( ! $styles ) {
 461          return $mce_init;
 462      }
 463  
 464      if ( ! isset( $mce_init['content_style'] ) ) {
 465          $mce_init['content_style'] = $styles . ' ';
 466      } else {
 467          $mce_init['content_style'] .= ' ' . $styles . ' ';
 468      }
 469  
 470      return $mce_init;
 471  
 472  }
 473  
 474  add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' );
 475  
 476  /**
 477   * Block Editor Settings.
 478   * Add custom colors and font sizes to the block editor.
 479   */
 480  function twentytwenty_block_editor_settings() {
 481  
 482      // Block Editor Palette.
 483      $editor_color_palette = array(
 484          array(
 485              'name'  => __( 'Accent Color', 'twentytwenty' ),
 486              'slug'  => 'accent',
 487              'color' => twentytwenty_get_color_for_area( 'content', 'accent' ),
 488          ),
 489          array(
 490              'name'  => _x( 'Primary', 'color', 'twentytwenty' ),
 491              'slug'  => 'primary',
 492              'color' => twentytwenty_get_color_for_area( 'content', 'text' ),
 493          ),
 494          array(
 495              'name'  => _x( 'Secondary', 'color', 'twentytwenty' ),
 496              'slug'  => 'secondary',
 497              'color' => twentytwenty_get_color_for_area( 'content', 'secondary' ),
 498          ),
 499          array(
 500              'name'  => __( 'Subtle Background', 'twentytwenty' ),
 501              'slug'  => 'subtle-background',
 502              'color' => twentytwenty_get_color_for_area( 'content', 'borders' ),
 503          ),
 504      );
 505  
 506      // Add the background option.
 507      $background_color = get_theme_mod( 'background_color' );
 508      if ( ! $background_color ) {
 509          $background_color_arr = get_theme_support( 'custom-background' );
 510          $background_color     = $background_color_arr[0]['default-color'];
 511      }
 512      $editor_color_palette[] = array(
 513          'name'  => __( 'Background Color', 'twentytwenty' ),
 514          'slug'  => 'background',
 515          'color' => '#' . $background_color,
 516      );
 517  
 518      // If we have accent colors, add them to the block editor palette.
 519      if ( $editor_color_palette ) {
 520          add_theme_support( 'editor-color-palette', $editor_color_palette );
 521      }
 522  
 523      // Block Editor Font Sizes.
 524      add_theme_support(
 525          'editor-font-sizes',
 526          array(
 527              array(
 528                  'name'      => _x( 'Small', 'Name of the small font size in the block editor', 'twentytwenty' ),
 529                  'shortName' => _x( 'S', 'Short name of the small font size in the block editor.', 'twentytwenty' ),
 530                  'size'      => 18,
 531                  'slug'      => 'small',
 532              ),
 533              array(
 534                  'name'      => _x( 'Regular', 'Name of the regular font size in the block editor', 'twentytwenty' ),
 535                  'shortName' => _x( 'M', 'Short name of the regular font size in the block editor.', 'twentytwenty' ),
 536                  'size'      => 21,
 537                  'slug'      => 'normal',
 538              ),
 539              array(
 540                  'name'      => _x( 'Large', 'Name of the large font size in the block editor', 'twentytwenty' ),
 541                  'shortName' => _x( 'L', 'Short name of the large font size in the block editor.', 'twentytwenty' ),
 542                  'size'      => 26.25,
 543                  'slug'      => 'large',
 544              ),
 545              array(
 546                  'name'      => _x( 'Larger', 'Name of the larger font size in the block editor', 'twentytwenty' ),
 547                  'shortName' => _x( 'XL', 'Short name of the larger font size in the block editor.', 'twentytwenty' ),
 548                  'size'      => 32,
 549                  'slug'      => 'larger',
 550              ),
 551          )
 552      );
 553  
 554      add_theme_support( 'editor-styles' );
 555  
 556      // If we have a dark background color then add support for dark editor style.
 557      // We can determine if the background color is dark by checking if the text-color is white.
 558      if ( '#ffffff' === strtolower( twentytwenty_get_color_for_area( 'content', 'text' ) ) ) {
 559          add_theme_support( 'dark-editor-style' );
 560      }
 561  
 562  }
 563  
 564  add_action( 'after_setup_theme', 'twentytwenty_block_editor_settings' );
 565  
 566  /**
 567   * Overwrite default more tag with styling and screen reader markup.
 568   *
 569   * @param string $html The default output HTML for the more tag.
 570   * @return string
 571   */
 572  function twentytwenty_read_more_tag( $html ) {
 573      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 );
 574  }
 575  
 576  add_filter( 'the_content_more_link', 'twentytwenty_read_more_tag' );
 577  
 578  /**
 579   * Enqueues scripts for customizer controls & settings.
 580   *
 581   * @since Twenty Twenty 1.0
 582   *
 583   * @return void
 584   */
 585  function twentytwenty_customize_controls_enqueue_scripts() {
 586      $theme_version = wp_get_theme()->get( 'Version' );
 587  
 588      // Add main customizer js file.
 589      wp_enqueue_script( 'twentytwenty-customize', get_template_directory_uri() . '/assets/js/customize.js', array( 'jquery' ), $theme_version, false );
 590  
 591      // Add script for color calculations.
 592      wp_enqueue_script( 'twentytwenty-color-calculations', get_template_directory_uri() . '/assets/js/color-calculations.js', array( 'wp-color-picker' ), $theme_version, false );
 593  
 594      // Add script for controls.
 595      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 );
 596      wp_localize_script( 'twentytwenty-customize-controls', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
 597  }
 598  
 599  add_action( 'customize_controls_enqueue_scripts', 'twentytwenty_customize_controls_enqueue_scripts' );
 600  
 601  /**
 602   * Enqueue scripts for the customizer preview.
 603   *
 604   * @since Twenty Twenty 1.0
 605   *
 606   * @return void
 607   */
 608  function twentytwenty_customize_preview_init() {
 609      $theme_version = wp_get_theme()->get( 'Version' );
 610  
 611      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 );
 612      wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
 613      wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyPreviewEls', twentytwenty_get_elements_array() );
 614  
 615      wp_add_inline_script(
 616          'twentytwenty-customize-preview',
 617          sprintf(
 618              'wp.customize.selectiveRefresh.partialConstructor[ %1$s ].prototype.attrs = %2$s;',
 619              wp_json_encode( 'cover_opacity' ),
 620              wp_json_encode( twentytwenty_customize_opacity_range() )
 621          )
 622      );
 623  }
 624  
 625  add_action( 'customize_preview_init', 'twentytwenty_customize_preview_init' );
 626  
 627  /**
 628   * Get accessible color for an area.
 629   *
 630   * @since Twenty Twenty 1.0
 631   *
 632   * @param string $area The area we want to get the colors for.
 633   * @param string $context Can be 'text' or 'accent'.
 634   * @return string Returns a HEX color.
 635   */
 636  function twentytwenty_get_color_for_area( $area = 'content', $context = 'text' ) {
 637  
 638      // Get the value from the theme-mod.
 639      $settings = get_theme_mod(
 640          'accent_accessible_colors',
 641          array(
 642              'content'       => array(
 643                  'text'      => '#000000',
 644                  'accent'    => '#cd2653',
 645                  'secondary' => '#6d6d6d',
 646                  'borders'   => '#dcd7ca',
 647              ),
 648              'header-footer' => array(
 649                  'text'      => '#000000',
 650                  'accent'    => '#cd2653',
 651                  'secondary' => '#6d6d6d',
 652                  'borders'   => '#dcd7ca',
 653              ),
 654          )
 655      );
 656  
 657      // If we have a value return it.
 658      if ( isset( $settings[ $area ] ) && isset( $settings[ $area ][ $context ] ) ) {
 659          return $settings[ $area ][ $context ];
 660      }
 661  
 662      // Return false if the option doesn't exist.
 663      return false;
 664  }
 665  
 666  /**
 667   * Returns an array of variables for the customizer preview.
 668   *
 669   * @since Twenty Twenty 1.0
 670   *
 671   * @return array
 672   */
 673  function twentytwenty_get_customizer_color_vars() {
 674      $colors = array(
 675          'content'       => array(
 676              'setting' => 'background_color',
 677          ),
 678          'header-footer' => array(
 679              'setting' => 'header_footer_background_color',
 680          ),
 681      );
 682      return $colors;
 683  }
 684  
 685  /**
 686   * Get an array of elements.
 687   *
 688   * @since Twenty Twenty 1.0
 689   *
 690   * @return array
 691   */
 692  function twentytwenty_get_elements_array() {
 693  
 694      // The array is formatted like this:
 695      // [key-in-saved-setting][sub-key-in-setting][css-property] = [elements].
 696      $elements = array(
 697          'content'       => array(
 698              'accent'     => array(
 699                  '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' ),
 700                  'border-color'     => array( 'blockquote', '.border-color-accent', '.border-color-accent-hover:hover', '.border-color-accent-hover:focus' ),
 701                  'background-color' => array( 'button', '.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' ),
 702                  'fill'             => array( '.fill-children-accent', '.fill-children-accent *' ),
 703              ),
 704              'background' => array(
 705                  '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)' ),
 706                  'background-color' => array( ':root .has-background-background-color' ),
 707              ),
 708              'text'       => array(
 709                  'color'            => array( 'body', '.entry-title a', ':root .has-primary-color' ),
 710                  'background-color' => array( ':root .has-primary-background-color' ),
 711              ),
 712              'secondary'  => array(
 713                  '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' ),
 714                  'background-color' => array( ':root .has-secondary-background-color' ),
 715              ),
 716              'borders'    => array(
 717                  'border-color'        => array( 'pre', 'fieldset', 'input', 'textarea', 'table', 'table *', 'hr' ),
 718                  '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' ),
 719                  'border-bottom-color' => array( '.wp-block-table.is-style-stripes' ),
 720                  'border-top-color'    => array( '.wp-block-latest-posts.is-grid li' ),
 721                  'color'               => array( ':root .has-subtle-background-color' ),
 722              ),
 723          ),
 724          'header-footer' => array(
 725              'accent'     => array(
 726                  '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' ),
 727                  '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"]' ),
 728              ),
 729              'background' => array(
 730                  '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"]' ),
 731                  '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' ),
 732              ),
 733              'text'       => array(
 734                  'color'               => array( '.header-footer-group', 'body:not(.overlay-header) #site-header .toggle', '.menu-modal .toggle' ),
 735                  'background-color'    => array( 'body:not(.overlay-header) .primary-menu ul' ),
 736                  'border-bottom-color' => array( 'body:not(.overlay-header) .primary-menu > li > ul:after' ),
 737                  'border-left-color'   => array( 'body:not(.overlay-header) .primary-menu ul ul:after' ),
 738              ),
 739              'secondary'  => array(
 740                  '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' ),
 741              ),
 742              'borders'    => array(
 743                  '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' ),
 744                  'background-color' => array( '.header-footer-group table caption', 'body:not(.overlay-header) .header-inner .toggle-wrapper::before' ),
 745              ),
 746          ),
 747      );
 748  
 749      /**
 750      * Filters Twenty Twenty theme elements
 751      *
 752      * @since Twenty Twenty 1.0
 753      *
 754      * @param array Array of elements
 755      */
 756      return apply_filters( 'twentytwenty_get_elements_array', $elements );
 757  }


Generated : Thu Oct 22 08:20:02 2020 Cross-referenced by PHPXref