[ Index ]

PHP Cross Reference of WordPress

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   * @return string
 275   */
 276  function twentytwenty_get_custom_logo( $html ) {
 277  
 278      $logo_id = get_theme_mod( 'custom_logo' );
 279  
 280      if ( ! $logo_id ) {
 281          return $html;
 282      }
 283  
 284      $logo = wp_get_attachment_image_src( $logo_id, 'full' );
 285  
 286      if ( $logo ) {
 287          // For clarity.
 288          $logo_width  = esc_attr( $logo[1] );
 289          $logo_height = esc_attr( $logo[2] );
 290  
 291          // If the retina logo setting is active, reduce the width/height by half.
 292          if ( get_theme_mod( 'retina_logo', false ) ) {
 293              $logo_width  = floor( $logo_width / 2 );
 294              $logo_height = floor( $logo_height / 2 );
 295  
 296              $search = array(
 297                  '/width=\"\d+\"/iU',
 298                  '/height=\"\d+\"/iU',
 299              );
 300  
 301              $replace = array(
 302                  "width=\"{$logo_width}\"",
 303                  "height=\"{$logo_height}\"",
 304              );
 305  
 306              // Add a style attribute with the height, or append the height to the style attribute if the style attribute already exists.
 307              if ( strpos( $html, ' style=' ) === false ) {
 308                  $search[]  = '/(src=)/';
 309                  $replace[] = "style=\"height: {$logo_height}px;\" src=";
 310              } else {
 311                  $search[]  = '/(style="[^"]*)/';
 312                  $replace[] = "$1 height: {$logo_height}px;";
 313              }
 314  
 315              $html = preg_replace( $search, $replace, $html );
 316  
 317          }
 318      }
 319  
 320      return $html;
 321  
 322  }
 323  
 324  add_filter( 'get_custom_logo', 'twentytwenty_get_custom_logo' );
 325  
 326  if ( ! function_exists( 'wp_body_open' ) ) {
 327  
 328      /**
 329       * Shim for wp_body_open, ensuring backward compatibility with versions of WordPress older than 5.2.
 330       */
 331  	function wp_body_open() {
 332          do_action( 'wp_body_open' );
 333      }
 334  }
 335  
 336  /**
 337   * Include a skip to content link at the top of the page so that users can bypass the menu.
 338   */
 339  function twentytwenty_skip_link() {
 340      echo '<a class="skip-link screen-reader-text" href="#site-content">' . __( 'Skip to the content', 'twentytwenty' ) . '</a>';
 341  }
 342  
 343  add_action( 'wp_body_open', 'twentytwenty_skip_link', 5 );
 344  
 345  /**
 346   * Register widget areas.
 347   *
 348   * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 349   */
 350  function twentytwenty_sidebar_registration() {
 351  
 352      // Arguments used in all register_sidebar() calls.
 353      $shared_args = array(
 354          'before_title'  => '<h2 class="widget-title subheading heading-size-3">',
 355          'after_title'   => '</h2>',
 356          'before_widget' => '<div class="widget %2$s"><div class="widget-content">',
 357          'after_widget'  => '</div></div>',
 358      );
 359  
 360      // Footer #1.
 361      register_sidebar(
 362          array_merge(
 363              $shared_args,
 364              array(
 365                  'name'        => __( 'Footer #1', 'twentytwenty' ),
 366                  'id'          => 'sidebar-1',
 367                  'description' => __( 'Widgets in this area will be displayed in the first column in the footer.', 'twentytwenty' ),
 368              )
 369          )
 370      );
 371  
 372      // Footer #2.
 373      register_sidebar(
 374          array_merge(
 375              $shared_args,
 376              array(
 377                  'name'        => __( 'Footer #2', 'twentytwenty' ),
 378                  'id'          => 'sidebar-2',
 379                  'description' => __( 'Widgets in this area will be displayed in the second column in the footer.', 'twentytwenty' ),
 380              )
 381          )
 382      );
 383  
 384  }
 385  
 386  add_action( 'widgets_init', 'twentytwenty_sidebar_registration' );
 387  
 388  /**
 389   * Enqueue supplemental block editor styles.
 390   */
 391  function twentytwenty_block_editor_styles() {
 392  
 393      // Enqueue the editor styles.
 394      wp_enqueue_style( 'twentytwenty-block-editor-styles', get_theme_file_uri( '/assets/css/editor-style-block.css' ), array(), wp_get_theme()->get( 'Version' ), 'all' );
 395      wp_style_add_data( 'twentytwenty-block-editor-styles', 'rtl', 'replace' );
 396  
 397      // Add inline style from the Customizer.
 398      wp_add_inline_style( 'twentytwenty-block-editor-styles', twentytwenty_get_customizer_css( 'block-editor' ) );
 399  
 400      // Add inline style for non-latin fonts.
 401      wp_add_inline_style( 'twentytwenty-block-editor-styles', TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' ) );
 402  
 403      // Enqueue the editor script.
 404      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 );
 405  }
 406  
 407  add_action( 'enqueue_block_editor_assets', 'twentytwenty_block_editor_styles', 1, 1 );
 408  
 409  /**
 410   * Enqueue classic editor styles.
 411   */
 412  function twentytwenty_classic_editor_styles() {
 413  
 414      $classic_editor_styles = array(
 415          '/assets/css/editor-style-classic.css',
 416      );
 417  
 418      add_editor_style( $classic_editor_styles );
 419  
 420  }
 421  
 422  add_action( 'init', 'twentytwenty_classic_editor_styles' );
 423  
 424  /**
 425   * Output Customizer settings in the classic editor.
 426   * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
 427   *
 428   * @param array $mce_init TinyMCE styles.
 429   * @return array TinyMCE styles.
 430   */
 431  function twentytwenty_add_classic_editor_customizer_styles( $mce_init ) {
 432  
 433      $styles = twentytwenty_get_customizer_css( 'classic-editor' );
 434  
 435      if ( ! isset( $mce_init['content_style'] ) ) {
 436          $mce_init['content_style'] = $styles . ' ';
 437      } else {
 438          $mce_init['content_style'] .= ' ' . $styles . ' ';
 439      }
 440  
 441      return $mce_init;
 442  
 443  }
 444  
 445  add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_customizer_styles' );
 446  
 447  /**
 448   * Output non-latin font styles in the classic editor.
 449   * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
 450   *
 451   * @param array $mce_init TinyMCE styles.
 452   * @return array TinyMCE styles.
 453   */
 454  function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) {
 455  
 456      $styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' );
 457  
 458      // Return if there are no styles to add.
 459      if ( ! $styles ) {
 460          return $mce_init;
 461      }
 462  
 463      if ( ! isset( $mce_init['content_style'] ) ) {
 464          $mce_init['content_style'] = $styles . ' ';
 465      } else {
 466          $mce_init['content_style'] .= ' ' . $styles . ' ';
 467      }
 468  
 469      return $mce_init;
 470  
 471  }
 472  
 473  add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' );
 474  
 475  /**
 476   * Block Editor Settings.
 477   * Add custom colors and font sizes to the block editor.
 478   */
 479  function twentytwenty_block_editor_settings() {
 480  
 481      // Block Editor Palette.
 482      $editor_color_palette = array(
 483          array(
 484              'name'  => __( 'Accent Color', 'twentytwenty' ),
 485              'slug'  => 'accent',
 486              'color' => twentytwenty_get_color_for_area( 'content', 'accent' ),
 487          ),
 488          array(
 489              'name'  => _x( 'Primary', 'color', 'twentytwenty' ),
 490              'slug'  => 'primary',
 491              'color' => twentytwenty_get_color_for_area( 'content', 'text' ),
 492          ),
 493          array(
 494              'name'  => _x( 'Secondary', 'color', 'twentytwenty' ),
 495              'slug'  => 'secondary',
 496              'color' => twentytwenty_get_color_for_area( 'content', 'secondary' ),
 497          ),
 498          array(
 499              'name'  => __( 'Subtle Background', 'twentytwenty' ),
 500              'slug'  => 'subtle-background',
 501              'color' => twentytwenty_get_color_for_area( 'content', 'borders' ),
 502          ),
 503      );
 504  
 505      // Add the background option.
 506      $background_color = get_theme_mod( 'background_color' );
 507      if ( ! $background_color ) {
 508          $background_color_arr = get_theme_support( 'custom-background' );
 509          $background_color     = $background_color_arr[0]['default-color'];
 510      }
 511      $editor_color_palette[] = array(
 512          'name'  => __( 'Background Color', 'twentytwenty' ),
 513          'slug'  => 'background',
 514          'color' => '#' . $background_color,
 515      );
 516  
 517      // If we have accent colors, add them to the block editor palette.
 518      if ( $editor_color_palette ) {
 519          add_theme_support( 'editor-color-palette', $editor_color_palette );
 520      }
 521  
 522      // Block Editor Font Sizes.
 523      add_theme_support(
 524          'editor-font-sizes',
 525          array(
 526              array(
 527                  'name'      => _x( 'Small', 'Name of the small font size in the block editor', 'twentytwenty' ),
 528                  'shortName' => _x( 'S', 'Short name of the small font size in the block editor.', 'twentytwenty' ),
 529                  'size'      => 18,
 530                  'slug'      => 'small',
 531              ),
 532              array(
 533                  'name'      => _x( 'Regular', 'Name of the regular font size in the block editor', 'twentytwenty' ),
 534                  'shortName' => _x( 'M', 'Short name of the regular font size in the block editor.', 'twentytwenty' ),
 535                  'size'      => 21,
 536                  'slug'      => 'normal',
 537              ),
 538              array(
 539                  'name'      => _x( 'Large', 'Name of the large font size in the block editor', 'twentytwenty' ),
 540                  'shortName' => _x( 'L', 'Short name of the large font size in the block editor.', 'twentytwenty' ),
 541                  'size'      => 26.25,
 542                  'slug'      => 'large',
 543              ),
 544              array(
 545                  'name'      => _x( 'Larger', 'Name of the larger font size in the block editor', 'twentytwenty' ),
 546                  'shortName' => _x( 'XL', 'Short name of the larger font size in the block editor.', 'twentytwenty' ),
 547                  'size'      => 32,
 548                  'slug'      => 'larger',
 549              ),
 550          )
 551      );
 552  
 553      add_theme_support( 'editor-styles' );
 554  
 555      // If we have a dark background color then add support for dark editor style.
 556      // We can determine if the background color is dark by checking if the text-color is white.
 557      if ( '#ffffff' === strtolower( twentytwenty_get_color_for_area( 'content', 'text' ) ) ) {
 558          add_theme_support( 'dark-editor-style' );
 559      }
 560  
 561  }
 562  
 563  add_action( 'after_setup_theme', 'twentytwenty_block_editor_settings' );
 564  
 565  /**
 566   * Overwrite default more tag with styling and screen reader markup.
 567   *
 568   * @param string $html The default output HTML for the more tag.
 569   * @return string
 570   */
 571  function twentytwenty_read_more_tag( $html ) {
 572      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 );
 573  }
 574  
 575  add_filter( 'the_content_more_link', 'twentytwenty_read_more_tag' );
 576  
 577  /**
 578   * Enqueues scripts for customizer controls & settings.
 579   *
 580   * @since Twenty Twenty 1.0
 581   *
 582   * @return void
 583   */
 584  function twentytwenty_customize_controls_enqueue_scripts() {
 585      $theme_version = wp_get_theme()->get( 'Version' );
 586  
 587      // Add main customizer js file.
 588      wp_enqueue_script( 'twentytwenty-customize', get_template_directory_uri() . '/assets/js/customize.js', array( 'jquery' ), $theme_version, false );
 589  
 590      // Add script for color calculations.
 591      wp_enqueue_script( 'twentytwenty-color-calculations', get_template_directory_uri() . '/assets/js/color-calculations.js', array( 'wp-color-picker' ), $theme_version, false );
 592  
 593      // Add script for controls.
 594      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 );
 595      wp_localize_script( 'twentytwenty-customize-controls', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
 596  }
 597  
 598  add_action( 'customize_controls_enqueue_scripts', 'twentytwenty_customize_controls_enqueue_scripts' );
 599  
 600  /**
 601   * Enqueue scripts for the customizer preview.
 602   *
 603   * @since Twenty Twenty 1.0
 604   *
 605   * @return void
 606   */
 607  function twentytwenty_customize_preview_init() {
 608      $theme_version = wp_get_theme()->get( 'Version' );
 609  
 610      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 );
 611      wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
 612      wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyPreviewEls', twentytwenty_get_elements_array() );
 613  
 614      wp_add_inline_script(
 615          'twentytwenty-customize-preview',
 616          sprintf(
 617              'wp.customize.selectiveRefresh.partialConstructor[ %1$s ].prototype.attrs = %2$s;',
 618              wp_json_encode( 'cover_opacity' ),
 619              wp_json_encode( twentytwenty_customize_opacity_range() )
 620          )
 621      );
 622  }
 623  
 624  add_action( 'customize_preview_init', 'twentytwenty_customize_preview_init' );
 625  
 626  /**
 627   * Get accessible color for an area.
 628   *
 629   * @since Twenty Twenty 1.0
 630   *
 631   * @param string $area The area we want to get the colors for.
 632   * @param string $context Can be 'text' or 'accent'.
 633   * @return string Returns a HEX color.
 634   */
 635  function twentytwenty_get_color_for_area( $area = 'content', $context = 'text' ) {
 636  
 637      // Get the value from the theme-mod.
 638      $settings = get_theme_mod(
 639          'accent_accessible_colors',
 640          array(
 641              'content'       => array(
 642                  'text'      => '#000000',
 643                  'accent'    => '#cd2653',
 644                  'secondary' => '#6d6d6d',
 645                  'borders'   => '#dcd7ca',
 646              ),
 647              'header-footer' => array(
 648                  'text'      => '#000000',
 649                  'accent'    => '#cd2653',
 650                  'secondary' => '#6d6d6d',
 651                  'borders'   => '#dcd7ca',
 652              ),
 653          )
 654      );
 655  
 656      // If we have a value return it.
 657      if ( isset( $settings[ $area ] ) && isset( $settings[ $area ][ $context ] ) ) {
 658          return $settings[ $area ][ $context ];
 659      }
 660  
 661      // Return false if the option doesn't exist.
 662      return false;
 663  }
 664  
 665  /**
 666   * Returns an array of variables for the customizer preview.
 667   *
 668   * @since Twenty Twenty 1.0
 669   *
 670   * @return array
 671   */
 672  function twentytwenty_get_customizer_color_vars() {
 673      $colors = array(
 674          'content'       => array(
 675              'setting' => 'background_color',
 676          ),
 677          'header-footer' => array(
 678              'setting' => 'header_footer_background_color',
 679          ),
 680      );
 681      return $colors;
 682  }
 683  
 684  /**
 685   * Get an array of elements.
 686   *
 687   * @since Twenty Twenty 1.0
 688   *
 689   * @return array
 690   */
 691  function twentytwenty_get_elements_array() {
 692  
 693      // The array is formatted like this:
 694      // [key-in-saved-setting][sub-key-in-setting][css-property] = [elements].
 695      $elements = array(
 696          'content'       => array(
 697              'accent'     => array(
 698                  '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' ),
 699                  'border-color'     => array( 'blockquote', '.border-color-accent', '.border-color-accent-hover:hover', '.border-color-accent-hover:focus' ),
 700                  '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' ),
 701                  'fill'             => array( '.fill-children-accent', '.fill-children-accent *' ),
 702              ),
 703              'background' => array(
 704                  '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)' ),
 705                  'background-color' => array( ':root .has-background-background-color' ),
 706              ),
 707              'text'       => array(
 708                  'color'            => array( 'body', '.entry-title a', ':root .has-primary-color' ),
 709                  'background-color' => array( ':root .has-primary-background-color' ),
 710              ),
 711              'secondary'  => array(
 712                  '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' ),
 713                  'background-color' => array( ':root .has-secondary-background-color' ),
 714              ),
 715              'borders'    => array(
 716                  'border-color'        => array( 'pre', 'fieldset', 'input', 'textarea', 'table', 'table *', 'hr' ),
 717                  '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' ),
 718                  'border-bottom-color' => array( '.wp-block-table.is-style-stripes' ),
 719                  'border-top-color'    => array( '.wp-block-latest-posts.is-grid li' ),
 720                  'color'               => array( ':root .has-subtle-background-color' ),
 721              ),
 722          ),
 723          'header-footer' => array(
 724              'accent'     => array(
 725                  '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' ),
 726                  '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"]' ),
 727              ),
 728              'background' => array(
 729                  '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"]' ),
 730                  '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' ),
 731              ),
 732              'text'       => array(
 733                  'color'               => array( '.header-footer-group', 'body:not(.overlay-header) #site-header .toggle', '.menu-modal .toggle' ),
 734                  'background-color'    => array( 'body:not(.overlay-header) .primary-menu ul' ),
 735                  'border-bottom-color' => array( 'body:not(.overlay-header) .primary-menu > li > ul:after' ),
 736                  'border-left-color'   => array( 'body:not(.overlay-header) .primary-menu ul ul:after' ),
 737              ),
 738              'secondary'  => array(
 739                  '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' ),
 740              ),
 741              'borders'    => array(
 742                  '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' ),
 743                  'background-color' => array( '.header-footer-group table caption', 'body:not(.overlay-header) .header-inner .toggle-wrapper::before' ),
 744              ),
 745          ),
 746      );
 747  
 748      /**
 749      * Filters Twenty Twenty theme elements
 750      *
 751      * @since Twenty Twenty 1.0
 752      *
 753      * @param array Array of elements
 754      */
 755      return apply_filters( 'twentytwenty_get_elements_array', $elements );
 756  }


Generated: Mon Sep 21 01:00:03 2020 Cross-referenced by PHPXref 0.7.1