[ 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      /*
 123       * Adds starter content to highlight the theme on fresh sites.
 124       * This is done conditionally to avoid loading the starter content on every
 125       * page load, as it is a one-off operation only needed once in the customizer.
 126       */
 127      if ( is_customize_preview() ) {
 128          require get_template_directory() . '/inc/starter-content.php';
 129          add_theme_support( 'starter-content', twentytwenty_get_starter_content() );
 130      }
 131  
 132      // Add theme support for selective refresh for widgets.
 133      add_theme_support( 'customize-selective-refresh-widgets' );
 134  
 135      /*
 136       * Adds `async` and `defer` support for scripts registered or enqueued
 137       * by the theme.
 138       */
 139      $loader = new TwentyTwenty_Script_Loader();
 140      add_filter( 'script_loader_tag', array( $loader, 'filter_script_loader_tag' ), 10, 2 );
 141  
 142  }
 143  
 144  add_action( 'after_setup_theme', 'twentytwenty_theme_support' );
 145  
 146  /**
 147   * REQUIRED FILES
 148   * Include required files.
 149   */
 150  require get_template_directory() . '/inc/template-tags.php';
 151  
 152  // Handle SVG icons.
 153  require get_template_directory() . '/classes/class-twentytwenty-svg-icons.php';
 154  require get_template_directory() . '/inc/svg-icons.php';
 155  
 156  // Handle Customizer settings.
 157  require get_template_directory() . '/classes/class-twentytwenty-customize.php';
 158  
 159  // Require Separator Control class.
 160  require get_template_directory() . '/classes/class-twentytwenty-separator-control.php';
 161  
 162  // Custom comment walker.
 163  require get_template_directory() . '/classes/class-twentytwenty-walker-comment.php';
 164  
 165  // Custom page walker.
 166  require get_template_directory() . '/classes/class-twentytwenty-walker-page.php';
 167  
 168  // Custom script loader class.
 169  require get_template_directory() . '/classes/class-twentytwenty-script-loader.php';
 170  
 171  // Non-latin language handling.
 172  require get_template_directory() . '/classes/class-twentytwenty-non-latin-languages.php';
 173  
 174  // Custom CSS.
 175  require get_template_directory() . '/inc/custom-css.php';
 176  
 177  /**
 178   * Register and Enqueue Styles.
 179   */
 180  function twentytwenty_register_styles() {
 181  
 182      $theme_version = wp_get_theme()->get( 'Version' );
 183  
 184      wp_enqueue_style( 'twentytwenty-style', get_stylesheet_uri(), array(), $theme_version );
 185      wp_style_add_data( 'twentytwenty-style', 'rtl', 'replace' );
 186  
 187      // Add output of Customizer settings as inline style.
 188      wp_add_inline_style( 'twentytwenty-style', twentytwenty_get_customizer_css( 'front-end' ) );
 189  
 190      // Add print CSS.
 191      wp_enqueue_style( 'twentytwenty-print-style', get_template_directory_uri() . '/print.css', null, $theme_version, 'print' );
 192  
 193  }
 194  
 195  add_action( 'wp_enqueue_scripts', 'twentytwenty_register_styles' );
 196  
 197  /**
 198   * Register and Enqueue Scripts.
 199   */
 200  function twentytwenty_register_scripts() {
 201  
 202      $theme_version = wp_get_theme()->get( 'Version' );
 203  
 204      if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 205          wp_enqueue_script( 'comment-reply' );
 206      }
 207  
 208      wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/assets/js/index.js', array(), $theme_version, false );
 209      wp_script_add_data( 'twentytwenty-js', 'async', true );
 210  
 211  }
 212  
 213  add_action( 'wp_enqueue_scripts', 'twentytwenty_register_scripts' );
 214  
 215  /**
 216   * Fix skip link focus in IE11.
 217   *
 218   * This does not enqueue the script because it is tiny and because it is only for IE11,
 219   * thus it does not warrant having an entire dedicated blocking script being loaded.
 220   *
 221   * @link https://git.io/vWdr2
 222   */
 223  function twentytwenty_skip_link_focus_fix() {
 224      // The following is minified via `terser --compress --mangle -- assets/js/skip-link-focus-fix.js`.
 225      ?>
 226      <script>
 227      /(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);
 228      </script>
 229      <?php
 230  }
 231  add_action( 'wp_print_footer_scripts', 'twentytwenty_skip_link_focus_fix' );
 232  
 233  /** Enqueue non-latin language styles
 234   *
 235   * @since Twenty Twenty 1.0
 236   *
 237   * @return void
 238   */
 239  function twentytwenty_non_latin_languages() {
 240      $custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'front-end' );
 241  
 242      if ( $custom_css ) {
 243          wp_add_inline_style( 'twentytwenty-style', $custom_css );
 244      }
 245  }
 246  
 247  add_action( 'wp_enqueue_scripts', 'twentytwenty_non_latin_languages' );
 248  
 249  /**
 250   * Register navigation menus uses wp_nav_menu in five places.
 251   */
 252  function twentytwenty_menus() {
 253  
 254      $locations = array(
 255          'primary'  => __( 'Desktop Horizontal Menu', 'twentytwenty' ),
 256          'expanded' => __( 'Desktop Expanded Menu', 'twentytwenty' ),
 257          'mobile'   => __( 'Mobile Menu', 'twentytwenty' ),
 258          'footer'   => __( 'Footer Menu', 'twentytwenty' ),
 259          'social'   => __( 'Social Menu', 'twentytwenty' ),
 260      );
 261  
 262      register_nav_menus( $locations );
 263  }
 264  
 265  add_action( 'init', 'twentytwenty_menus' );
 266  
 267  /**
 268   * Get the information about the logo.
 269   *
 270   * @param string $html The HTML output from get_custom_logo (core function).
 271   *
 272   * @return string $html
 273   */
 274  function twentytwenty_get_custom_logo( $html ) {
 275  
 276      $logo_id = get_theme_mod( 'custom_logo' );
 277  
 278      if ( ! $logo_id ) {
 279          return $html;
 280      }
 281  
 282      $logo = wp_get_attachment_image_src( $logo_id, 'full' );
 283  
 284      if ( $logo ) {
 285          // For clarity.
 286          $logo_width  = esc_attr( $logo[1] );
 287          $logo_height = esc_attr( $logo[2] );
 288  
 289          // If the retina logo setting is active, reduce the width/height by half.
 290          if ( get_theme_mod( 'retina_logo', false ) ) {
 291              $logo_width  = floor( $logo_width / 2 );
 292              $logo_height = floor( $logo_height / 2 );
 293  
 294              $search = array(
 295                  '/width=\"\d+\"/iU',
 296                  '/height=\"\d+\"/iU',
 297              );
 298  
 299              $replace = array(
 300                  "width=\"{$logo_width}\"",
 301                  "height=\"{$logo_height}\"",
 302              );
 303  
 304              // Add a style attribute with the height, or append the height to the style attribute if the style attribute already exists.
 305              if ( strpos( $html, ' style=' ) === false ) {
 306                  $search[]  = '/(src=)/';
 307                  $replace[] = "style=\"height: {$logo_height}px;\" src=";
 308              } else {
 309                  $search[]  = '/(style="[^"]*)/';
 310                  $replace[] = "$1 height: {$logo_height}px;";
 311              }
 312  
 313              $html = preg_replace( $search, $replace, $html );
 314  
 315          }
 316      }
 317  
 318      return $html;
 319  
 320  }
 321  
 322  add_filter( 'get_custom_logo', 'twentytwenty_get_custom_logo' );
 323  
 324  if ( ! function_exists( 'wp_body_open' ) ) {
 325  
 326      /**
 327       * Shim for wp_body_open, ensuring backwards compatibility with versions of WordPress older than 5.2.
 328       */
 329  	function wp_body_open() {
 330          do_action( 'wp_body_open' );
 331      }
 332  }
 333  
 334  /**
 335   * Include a skip to content link at the top of the page so that users can bypass the menu.
 336   */
 337  function twentytwenty_skip_link() {
 338      echo '<a class="skip-link screen-reader-text" href="#site-content">' . __( 'Skip to the content', 'twentytwenty' ) . '</a>';
 339  }
 340  
 341  add_action( 'wp_body_open', 'twentytwenty_skip_link', 5 );
 342  
 343  /**
 344   * Register widget areas.
 345   *
 346   * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 347   */
 348  function twentytwenty_sidebar_registration() {
 349  
 350      // Arguments used in all register_sidebar() calls.
 351      $shared_args = array(
 352          'before_title'  => '<h2 class="widget-title subheading heading-size-3">',
 353          'after_title'   => '</h2>',
 354          'before_widget' => '<div class="widget %2$s"><div class="widget-content">',
 355          'after_widget'  => '</div></div>',
 356      );
 357  
 358      // Footer #1.
 359      register_sidebar(
 360          array_merge(
 361              $shared_args,
 362              array(
 363                  'name'        => __( 'Footer #1', 'twentytwenty' ),
 364                  'id'          => 'sidebar-1',
 365                  'description' => __( 'Widgets in this area will be displayed in the first column in the footer.', 'twentytwenty' ),
 366              )
 367          )
 368      );
 369  
 370      // Footer #2.
 371      register_sidebar(
 372          array_merge(
 373              $shared_args,
 374              array(
 375                  'name'        => __( 'Footer #2', 'twentytwenty' ),
 376                  'id'          => 'sidebar-2',
 377                  'description' => __( 'Widgets in this area will be displayed in the second column in the footer.', 'twentytwenty' ),
 378              )
 379          )
 380      );
 381  
 382  }
 383  
 384  add_action( 'widgets_init', 'twentytwenty_sidebar_registration' );
 385  
 386  /**
 387   * Enqueue supplemental block editor styles.
 388   */
 389  function twentytwenty_block_editor_styles() {
 390  
 391      $css_dependencies = array();
 392  
 393      // Enqueue the editor styles.
 394      wp_enqueue_style( 'twentytwenty-block-editor-styles', get_theme_file_uri( '/assets/css/editor-style-block.css' ), $css_dependencies, 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   *
 430   * @return array $mce_init 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   *
 454   * @return array $mce_init TinyMCE styles.
 455   */
 456  function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) {
 457  
 458      $styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' );
 459  
 460      // Return if there are no styles to add.
 461      if ( ! $styles ) {
 462          return $mce_init;
 463      }
 464  
 465      if ( ! isset( $mce_init['content_style'] ) ) {
 466          $mce_init['content_style'] = $styles . ' ';
 467      } else {
 468          $mce_init['content_style'] .= ' ' . $styles . ' ';
 469      }
 470  
 471      return $mce_init;
 472  
 473  }
 474  
 475  add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' );
 476  
 477  /**
 478   * Block Editor Settings.
 479   * Add custom colors and font sizes to the block editor.
 480   */
 481  function twentytwenty_block_editor_settings() {
 482  
 483      // Block Editor Palette.
 484      $editor_color_palette = array(
 485          array(
 486              'name'  => __( 'Accent Color', 'twentytwenty' ),
 487              'slug'  => 'accent',
 488              'color' => twentytwenty_get_color_for_area( 'content', 'accent' ),
 489          ),
 490          array(
 491              'name'  => __( 'Primary', 'twentytwenty' ),
 492              'slug'  => 'primary',
 493              'color' => twentytwenty_get_color_for_area( 'content', 'text' ),
 494          ),
 495          array(
 496              'name'  => __( 'Secondary', 'twentytwenty' ),
 497              'slug'  => 'secondary',
 498              'color' => twentytwenty_get_color_for_area( 'content', 'secondary' ),
 499          ),
 500          array(
 501              'name'  => __( 'Subtle Background', 'twentytwenty' ),
 502              'slug'  => 'subtle-background',
 503              'color' => twentytwenty_get_color_for_area( 'content', 'borders' ),
 504          ),
 505      );
 506  
 507      // Add the background option.
 508      $background_color = get_theme_mod( 'background_color' );
 509      if ( ! $background_color ) {
 510          $background_color_arr = get_theme_support( 'custom-background' );
 511          $background_color     = $background_color_arr[0]['default-color'];
 512      }
 513      $editor_color_palette[] = array(
 514          'name'  => __( 'Background Color', 'twentytwenty' ),
 515          'slug'  => 'background',
 516          'color' => '#' . $background_color,
 517      );
 518  
 519      // If we have accent colors, add them to the block editor palette.
 520      if ( $editor_color_palette ) {
 521          add_theme_support( 'editor-color-palette', $editor_color_palette );
 522      }
 523  
 524      // Block Editor Font Sizes.
 525      add_theme_support(
 526          'editor-font-sizes',
 527          array(
 528              array(
 529                  'name'      => _x( 'Small', 'Name of the small font size in the block editor', 'twentytwenty' ),
 530                  'shortName' => _x( 'S', 'Short name of the small font size in the block editor.', 'twentytwenty' ),
 531                  'size'      => 18,
 532                  'slug'      => 'small',
 533              ),
 534              array(
 535                  'name'      => _x( 'Regular', 'Name of the regular font size in the block editor', 'twentytwenty' ),
 536                  'shortName' => _x( 'M', 'Short name of the regular font size in the block editor.', 'twentytwenty' ),
 537                  'size'      => 21,
 538                  'slug'      => 'normal',
 539              ),
 540              array(
 541                  'name'      => _x( 'Large', 'Name of the large font size in the block editor', 'twentytwenty' ),
 542                  'shortName' => _x( 'L', 'Short name of the large font size in the block editor.', 'twentytwenty' ),
 543                  'size'      => 26.25,
 544                  'slug'      => 'large',
 545              ),
 546              array(
 547                  'name'      => _x( 'Larger', 'Name of the larger font size in the block editor', 'twentytwenty' ),
 548                  'shortName' => _x( 'XL', 'Short name of the larger font size in the block editor.', 'twentytwenty' ),
 549                  'size'      => 32,
 550                  'slug'      => 'larger',
 551              ),
 552          )
 553      );
 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   *
 570   * @return string $html
 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: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' ),
 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: Tue Dec 10 01:00:04 2019 Cross-referenced by PHPXref 0.7.1