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