[ 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 /** This action is documented in wp-includes/general-template.php */ 365 do_action( 'wp_body_open' ); 366 } 367 } 368 369 /** 370 * Include a skip to content link at the top of the page so that users can bypass the menu. 371 * 372 * @since Twenty Twenty 1.0 373 */ 374 function twentytwenty_skip_link() { 375 echo '<a class="skip-link screen-reader-text" href="#site-content">' . 376 /* translators: Hidden accessibility text. */ 377 __( 'Skip to the content', 'twentytwenty' ) . 378 '</a>'; 379 } 380 381 add_action( 'wp_body_open', 'twentytwenty_skip_link', 5 ); 382 383 /** 384 * Register widget areas. 385 * 386 * @since Twenty Twenty 1.0 387 * 388 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar 389 */ 390 function twentytwenty_sidebar_registration() { 391 392 // Arguments used in all register_sidebar() calls. 393 $shared_args = array( 394 'before_title' => '<h2 class="widget-title subheading heading-size-3">', 395 'after_title' => '</h2>', 396 'before_widget' => '<div class="widget %2$s"><div class="widget-content">', 397 'after_widget' => '</div></div>', 398 ); 399 400 // Footer #1. 401 register_sidebar( 402 array_merge( 403 $shared_args, 404 array( 405 'name' => __( 'Footer #1', 'twentytwenty' ), 406 'id' => 'sidebar-1', 407 'description' => __( 'Widgets in this area will be displayed in the first column in the footer.', 'twentytwenty' ), 408 ) 409 ) 410 ); 411 412 // Footer #2. 413 register_sidebar( 414 array_merge( 415 $shared_args, 416 array( 417 'name' => __( 'Footer #2', 'twentytwenty' ), 418 'id' => 'sidebar-2', 419 'description' => __( 'Widgets in this area will be displayed in the second column in the footer.', 'twentytwenty' ), 420 ) 421 ) 422 ); 423 } 424 425 add_action( 'widgets_init', 'twentytwenty_sidebar_registration' ); 426 427 /** 428 * Enqueue supplemental block editor styles. 429 * 430 * @since Twenty Twenty 1.0 431 * @since Twenty Twenty 2.4 Removed a script related to the obsolete Squared style of Button blocks. 432 * @since Twenty Twenty 2.6 Enqueue the CSS file for the variable font. 433 */ 434 function twentytwenty_block_editor_styles() { 435 436 $theme_version = wp_get_theme()->get( 'Version' ); 437 438 // Enqueue the editor styles. 439 wp_enqueue_style( 'twentytwenty-block-editor-styles', get_theme_file_uri( '/assets/css/editor-style-block.css' ), array(), $theme_version, 'all' ); 440 wp_style_add_data( 'twentytwenty-block-editor-styles', 'rtl', 'replace' ); 441 442 // Add inline style from the Customizer. 443 $customizer_css = twentytwenty_get_customizer_css( 'block-editor' ); 444 if ( $customizer_css ) { 445 wp_add_inline_style( 'twentytwenty-block-editor-styles', $customizer_css ); 446 } 447 448 // Enqueue the CSS file for the variable font, Inter. 449 wp_enqueue_style( 'twentytwenty-fonts', get_theme_file_uri( '/assets/css/font-inter.css' ), array(), $theme_version, 'all' ); 450 451 // Add inline style for non-latin fonts. 452 $custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' ); 453 if ( $custom_css ) { 454 wp_add_inline_style( 'twentytwenty-block-editor-styles', $custom_css ); 455 } 456 } 457 458 if ( is_admin() && version_compare( $GLOBALS['wp_version'], '6.3', '>=' ) ) { 459 add_action( 'enqueue_block_assets', 'twentytwenty_block_editor_styles', 1, 1 ); 460 } else { 461 add_action( 'enqueue_block_editor_assets', 'twentytwenty_block_editor_styles', 1, 1 ); 462 } 463 464 /** 465 * Enqueue classic editor styles. 466 * 467 * @since Twenty Twenty 1.0 468 * @since Twenty Twenty 2.6 Enqueue the CSS file for the variable font. 469 */ 470 function twentytwenty_classic_editor_styles() { 471 472 $classic_editor_styles = array( 473 '/assets/css/editor-style-classic.css', 474 '/assets/css/font-inter.css', 475 ); 476 477 add_editor_style( $classic_editor_styles ); 478 } 479 480 add_action( 'init', 'twentytwenty_classic_editor_styles' ); 481 482 /** 483 * Output Customizer settings in the classic editor. 484 * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution. 485 * 486 * @since Twenty Twenty 1.0 487 * 488 * @param array $mce_init TinyMCE styles. 489 * @return array TinyMCE styles. 490 */ 491 function twentytwenty_add_classic_editor_customizer_styles( $mce_init ) { 492 493 $styles = twentytwenty_get_customizer_css( 'classic-editor' ); 494 495 if ( ! $styles ) { 496 return $mce_init; 497 } 498 499 if ( ! isset( $mce_init['content_style'] ) ) { 500 $mce_init['content_style'] = $styles . ' '; 501 } else { 502 $mce_init['content_style'] .= ' ' . $styles . ' '; 503 } 504 505 return $mce_init; 506 } 507 508 add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_customizer_styles' ); 509 510 /** 511 * Output non-latin font styles in the classic editor. 512 * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution. 513 * 514 * @param array $mce_init TinyMCE styles. 515 * @return array TinyMCE styles. 516 */ 517 function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) { 518 519 $styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' ); 520 521 // Return if there are no styles to add. 522 if ( ! $styles ) { 523 return $mce_init; 524 } 525 526 if ( ! isset( $mce_init['content_style'] ) ) { 527 $mce_init['content_style'] = $styles . ' '; 528 } else { 529 $mce_init['content_style'] .= ' ' . $styles . ' '; 530 } 531 532 return $mce_init; 533 } 534 535 add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' ); 536 537 /** 538 * Block Editor Settings. 539 * Add custom colors and font sizes to the block editor. 540 * 541 * @since Twenty Twenty 1.0 542 */ 543 function twentytwenty_block_editor_settings() { 544 545 // Block Editor Palette. 546 $editor_color_palette = array( 547 array( 548 'name' => __( 'Accent Color', 'twentytwenty' ), 549 'slug' => 'accent', 550 'color' => twentytwenty_get_color_for_area( 'content', 'accent' ), 551 ), 552 array( 553 'name' => _x( 'Primary', 'color', 'twentytwenty' ), 554 'slug' => 'primary', 555 'color' => twentytwenty_get_color_for_area( 'content', 'text' ), 556 ), 557 array( 558 'name' => _x( 'Secondary', 'color', 'twentytwenty' ), 559 'slug' => 'secondary', 560 'color' => twentytwenty_get_color_for_area( 'content', 'secondary' ), 561 ), 562 array( 563 'name' => __( 'Subtle Background', 'twentytwenty' ), 564 'slug' => 'subtle-background', 565 'color' => twentytwenty_get_color_for_area( 'content', 'borders' ), 566 ), 567 ); 568 569 // Add the background option. 570 $background_color = get_theme_mod( 'background_color' ); 571 if ( ! $background_color ) { 572 $background_color_arr = get_theme_support( 'custom-background' ); 573 $background_color = $background_color_arr[0]['default-color']; 574 } 575 $editor_color_palette[] = array( 576 'name' => __( 'Background Color', 'twentytwenty' ), 577 'slug' => 'background', 578 'color' => '#' . $background_color, 579 ); 580 581 // If we have accent colors, add them to the block editor palette. 582 if ( $editor_color_palette ) { 583 add_theme_support( 'editor-color-palette', $editor_color_palette ); 584 } 585 586 // Block Editor Font Sizes. 587 add_theme_support( 588 'editor-font-sizes', 589 array( 590 array( 591 'name' => _x( 'Small', 'Name of the small font size in the block editor', 'twentytwenty' ), 592 'shortName' => _x( 'S', 'Short name of the small font size in the block editor.', 'twentytwenty' ), 593 'size' => 18, 594 'slug' => 'small', 595 ), 596 array( 597 'name' => _x( 'Regular', 'Name of the regular font size in the block editor', 'twentytwenty' ), 598 'shortName' => _x( 'M', 'Short name of the regular font size in the block editor.', 'twentytwenty' ), 599 'size' => 21, 600 'slug' => 'normal', 601 ), 602 array( 603 'name' => _x( 'Large', 'Name of the large font size in the block editor', 'twentytwenty' ), 604 'shortName' => _x( 'L', 'Short name of the large font size in the block editor.', 'twentytwenty' ), 605 'size' => 26.25, 606 'slug' => 'large', 607 ), 608 array( 609 'name' => _x( 'Larger', 'Name of the larger font size in the block editor', 'twentytwenty' ), 610 'shortName' => _x( 'XL', 'Short name of the larger font size in the block editor.', 'twentytwenty' ), 611 'size' => 32, 612 'slug' => 'larger', 613 ), 614 ) 615 ); 616 617 add_theme_support( 'editor-styles' ); 618 619 // If we have a dark background color then add support for dark editor style. 620 // We can determine if the background color is dark by checking if the text-color is white. 621 if ( '#ffffff' === strtolower( twentytwenty_get_color_for_area( 'content', 'text' ) ) ) { 622 add_theme_support( 'dark-editor-style' ); 623 } 624 } 625 626 add_action( 'after_setup_theme', 'twentytwenty_block_editor_settings' ); 627 628 /** 629 * Overwrite default more tag with styling and screen reader markup. 630 * 631 * @param string $html The default output HTML for the more tag. 632 * @return string 633 */ 634 function twentytwenty_read_more_tag( $html ) { 635 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 ); 636 } 637 638 add_filter( 'the_content_more_link', 'twentytwenty_read_more_tag' ); 639 640 /** 641 * Enqueues scripts for customizer controls & settings. 642 * 643 * @since Twenty Twenty 1.0 644 * 645 * @return void 646 */ 647 function twentytwenty_customize_controls_enqueue_scripts() { 648 $theme_version = wp_get_theme()->get( 'Version' ); 649 650 // Add main customizer js file. 651 wp_enqueue_script( 'twentytwenty-customize', get_template_directory_uri() . '/assets/js/customize.js', array( 'jquery' ), $theme_version ); 652 653 // Add script for color calculations. 654 wp_enqueue_script( 'twentytwenty-color-calculations', get_template_directory_uri() . '/assets/js/color-calculations.js', array( 'wp-color-picker' ), $theme_version ); 655 656 // Add script for controls. 657 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 ); 658 wp_localize_script( 'twentytwenty-customize-controls', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() ); 659 } 660 661 add_action( 'customize_controls_enqueue_scripts', 'twentytwenty_customize_controls_enqueue_scripts' ); 662 663 /** 664 * Enqueue scripts for the customizer preview. 665 * 666 * @since Twenty Twenty 1.0 667 * 668 * @return void 669 */ 670 function twentytwenty_customize_preview_init() { 671 $theme_version = wp_get_theme()->get( 'Version' ); 672 673 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 ) ); 674 wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() ); 675 wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyPreviewEls', twentytwenty_get_elements_array() ); 676 677 wp_add_inline_script( 678 'twentytwenty-customize-preview', 679 sprintf( 680 'wp.customize.selectiveRefresh.partialConstructor[ %1$s ].prototype.attrs = %2$s;', 681 wp_json_encode( 'cover_opacity' ), 682 wp_json_encode( twentytwenty_customize_opacity_range() ) 683 ) 684 ); 685 } 686 687 add_action( 'customize_preview_init', 'twentytwenty_customize_preview_init' ); 688 689 /** 690 * Get accessible color for an area. 691 * 692 * @since Twenty Twenty 1.0 693 * 694 * @param string $area The area we want to get the colors for. 695 * @param string $context Can be 'text' or 'accent'. 696 * @return string Returns a HEX color. 697 */ 698 function twentytwenty_get_color_for_area( $area = 'content', $context = 'text' ) { 699 700 // Get the value from the theme-mod. 701 $settings = get_theme_mod( 702 'accent_accessible_colors', 703 array( 704 'content' => array( 705 'text' => '#000000', 706 'accent' => '#cd2653', 707 'secondary' => '#6d6d6d', 708 'borders' => '#dcd7ca', 709 ), 710 'header-footer' => array( 711 'text' => '#000000', 712 'accent' => '#cd2653', 713 'secondary' => '#6d6d6d', 714 'borders' => '#dcd7ca', 715 ), 716 ) 717 ); 718 719 // If we have a value return it. 720 if ( isset( $settings[ $area ] ) && isset( $settings[ $area ][ $context ] ) ) { 721 return $settings[ $area ][ $context ]; 722 } 723 724 // Return false if the option doesn't exist. 725 return false; 726 } 727 728 /** 729 * Returns an array of variables for the customizer preview. 730 * 731 * @since Twenty Twenty 1.0 732 * 733 * @return array 734 */ 735 function twentytwenty_get_customizer_color_vars() { 736 $colors = array( 737 'content' => array( 738 'setting' => 'background_color', 739 ), 740 'header-footer' => array( 741 'setting' => 'header_footer_background_color', 742 ), 743 ); 744 return $colors; 745 } 746 747 /** 748 * Get an array of elements. 749 * 750 * @since Twenty Twenty 1.0 751 * 752 * @return array 753 */ 754 function twentytwenty_get_elements_array() { 755 756 // The array is formatted like this: 757 // [key-in-saved-setting][sub-key-in-setting][css-property] = [elements]. 758 $elements = array( 759 'content' => array( 760 'accent' => array( 761 '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' ), 762 'border-color' => array( 'blockquote', '.border-color-accent', '.border-color-accent-hover:hover', '.border-color-accent-hover:focus' ), 763 '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' ), 764 'fill' => array( '.fill-children-accent', '.fill-children-accent *' ), 765 ), 766 'background' => array( 767 '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)' ), 768 'background-color' => array( ':root .has-background-background-color' ), 769 ), 770 'text' => array( 771 'color' => array( 'body', '.entry-title a', ':root .has-primary-color' ), 772 'background-color' => array( ':root .has-primary-background-color' ), 773 ), 774 'secondary' => array( 775 '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' ), 776 'background-color' => array( ':root .has-secondary-background-color' ), 777 ), 778 'borders' => array( 779 'border-color' => array( 'pre', 'fieldset', 'input', 'textarea', 'table', 'table *', 'hr' ), 780 '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' ), 781 'border-bottom-color' => array( '.wp-block-table.is-style-stripes' ), 782 'border-top-color' => array( '.wp-block-latest-posts.is-grid li' ), 783 'color' => array( ':root .has-subtle-background-color' ), 784 ), 785 ), 786 'header-footer' => array( 787 'accent' => array( 788 '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' ), 789 '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"]' ), 790 ), 791 'background' => array( 792 '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"]' ), 793 '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' ), 794 ), 795 'text' => array( 796 'color' => array( '.header-footer-group', 'body:not(.overlay-header) #site-header .toggle', '.menu-modal .toggle' ), 797 'background-color' => array( 'body:not(.overlay-header) .primary-menu ul' ), 798 'border-bottom-color' => array( 'body:not(.overlay-header) .primary-menu > li > ul:after' ), 799 'border-left-color' => array( 'body:not(.overlay-header) .primary-menu ul ul:after' ), 800 ), 801 'secondary' => array( 802 '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' ), 803 ), 804 'borders' => array( 805 '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' ), 806 'background-color' => array( '.header-footer-group table caption', 'body:not(.overlay-header) .header-inner .toggle-wrapper::before' ), 807 ), 808 ), 809 ); 810 811 /** 812 * Filters Twenty Twenty theme elements. 813 * 814 * @since Twenty Twenty 1.0 815 * 816 * @param array Array of elements. 817 */ 818 return apply_filters( 'twentytwenty_get_elements_array', $elements ); 819 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |