[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Twenty Nineteen functions and definitions 4 * 5 * @link https://developer.wordpress.org/themes/basics/theme-functions/ 6 * 7 * @package WordPress 8 * @subpackage Twenty_Nineteen 9 * @since Twenty Nineteen 1.0 10 */ 11 12 /** 13 * Twenty Nineteen only works in WordPress 4.7 or later. 14 */ 15 if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) { 16 require get_template_directory() . '/inc/back-compat.php'; 17 return; 18 } 19 20 if ( ! function_exists( 'twentynineteen_setup' ) ) : 21 /** 22 * Sets up theme defaults and registers support for various WordPress features. 23 * 24 * Note that this function is hooked into the after_setup_theme hook, which 25 * runs before the init hook. The init hook is too late for some features, such 26 * as indicating support for post thumbnails. 27 */ 28 function twentynineteen_setup() { 29 30 // Add default posts and comments RSS feed links to head. 31 add_theme_support( 'automatic-feed-links' ); 32 33 /* 34 * Let WordPress manage the document title. 35 * By adding theme support, we declare that this theme does not use a 36 * hard-coded <title> tag in the document head, and expect WordPress to 37 * provide it for us. 38 */ 39 add_theme_support( 'title-tag' ); 40 41 /* 42 * Enable support for Post Thumbnails on posts and pages. 43 * 44 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ 45 */ 46 add_theme_support( 'post-thumbnails' ); 47 set_post_thumbnail_size( 1568, 9999 ); 48 49 // This theme uses wp_nav_menu() in two locations. 50 register_nav_menus( 51 array( 52 'menu-1' => __( 'Primary', 'twentynineteen' ), 53 'footer' => __( 'Footer Menu', 'twentynineteen' ), 54 'social' => __( 'Social Links Menu', 'twentynineteen' ), 55 ) 56 ); 57 58 /* 59 * Switch default core markup for search form, comment form, and comments 60 * to output valid HTML5. 61 */ 62 add_theme_support( 63 'html5', 64 array( 65 'search-form', 66 'comment-form', 67 'comment-list', 68 'gallery', 69 'caption', 70 'script', 71 'style', 72 'navigation-widgets', 73 ) 74 ); 75 76 /** 77 * Add support for core custom logo. 78 * 79 * @link https://codex.wordpress.org/Theme_Logo 80 */ 81 add_theme_support( 82 'custom-logo', 83 array( 84 'height' => 190, 85 'width' => 190, 86 'flex-width' => false, 87 'flex-height' => false, 88 ) 89 ); 90 91 // Add theme support for selective refresh for widgets. 92 add_theme_support( 'customize-selective-refresh-widgets' ); 93 94 // Add support for Block Styles. 95 add_theme_support( 'wp-block-styles' ); 96 97 // Add support for full and wide align images. 98 add_theme_support( 'align-wide' ); 99 100 // Add support for editor styles. 101 add_theme_support( 'editor-styles' ); 102 103 // Enqueue editor styles. 104 add_editor_style( 'style-editor.css' ); 105 106 // Add custom editor font sizes. 107 add_theme_support( 108 'editor-font-sizes', 109 array( 110 array( 111 'name' => __( 'Small', 'twentynineteen' ), 112 'shortName' => __( 'S', 'twentynineteen' ), 113 'size' => 19.5, 114 'slug' => 'small', 115 ), 116 array( 117 'name' => __( 'Normal', 'twentynineteen' ), 118 'shortName' => __( 'M', 'twentynineteen' ), 119 'size' => 22, 120 'slug' => 'normal', 121 ), 122 array( 123 'name' => __( 'Large', 'twentynineteen' ), 124 'shortName' => __( 'L', 'twentynineteen' ), 125 'size' => 36.5, 126 'slug' => 'large', 127 ), 128 array( 129 'name' => __( 'Huge', 'twentynineteen' ), 130 'shortName' => __( 'XL', 'twentynineteen' ), 131 'size' => 49.5, 132 'slug' => 'huge', 133 ), 134 ) 135 ); 136 137 // Editor color palette. 138 add_theme_support( 139 'editor-color-palette', 140 array( 141 array( 142 'name' => 'default' === get_theme_mod( 'primary_color', 'default' ) ? __( 'Blue', 'twentynineteen' ) : null, 143 'slug' => 'primary', 144 'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ), 145 ), 146 array( 147 'name' => 'default' === get_theme_mod( 'primary_color', 'default' ) ? __( 'Dark Blue', 'twentynineteen' ) : null, 148 'slug' => 'secondary', 149 'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ), 150 ), 151 array( 152 'name' => __( 'Dark Gray', 'twentynineteen' ), 153 'slug' => 'dark-gray', 154 'color' => '#111', 155 ), 156 array( 157 'name' => __( 'Light Gray', 'twentynineteen' ), 158 'slug' => 'light-gray', 159 'color' => '#767676', 160 ), 161 array( 162 'name' => __( 'White', 'twentynineteen' ), 163 'slug' => 'white', 164 'color' => '#FFF', 165 ), 166 ) 167 ); 168 169 // Add support for responsive embedded content. 170 add_theme_support( 'responsive-embeds' ); 171 172 // Add support for custom line height. 173 add_theme_support( 'custom-line-height' ); 174 } 175 endif; 176 add_action( 'after_setup_theme', 'twentynineteen_setup' ); 177 178 if ( ! function_exists( 'wp_get_list_item_separator' ) ) : 179 /** 180 * Retrieves the list item separator based on the locale. 181 * 182 * Added for backward compatibility to support pre-6.0.0 WordPress versions. 183 * 184 * @since 6.0.0 185 */ 186 function wp_get_list_item_separator() { 187 /* translators: Used between list items, there is a space after the comma. */ 188 return __( ', ', 'twentynineteen' ); 189 } 190 endif; 191 192 /** 193 * Register widget area. 194 * 195 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar 196 */ 197 function twentynineteen_widgets_init() { 198 199 register_sidebar( 200 array( 201 'name' => __( 'Footer', 'twentynineteen' ), 202 'id' => 'sidebar-1', 203 'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ), 204 'before_widget' => '<section id="%1$s" class="widget %2$s">', 205 'after_widget' => '</section>', 206 'before_title' => '<h2 class="widget-title">', 207 'after_title' => '</h2>', 208 ) 209 ); 210 } 211 add_action( 'widgets_init', 'twentynineteen_widgets_init' ); 212 213 /** 214 * Replaces "[...]" (appended to automatically generated excerpts) with ... and 215 * a 'Continue reading' link. 216 * 217 * @since Twenty Nineteen 2.0 218 * 219 * @param string $link Link to single post/page. 220 * @return string 'Continue reading' link prepended with an ellipsis. 221 */ 222 function twentynineteen_excerpt_more( $link ) { 223 if ( is_admin() ) { 224 return $link; 225 } 226 227 $link = sprintf( 228 '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>', 229 esc_url( get_permalink( get_the_ID() ) ), 230 /* translators: %s: Post title. Only visible to screen readers. */ 231 sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentynineteen' ), get_the_title( get_the_ID() ) ) 232 ); 233 return ' … ' . $link; 234 } 235 add_filter( 'excerpt_more', 'twentynineteen_excerpt_more' ); 236 237 /** 238 * Set the content width in pixels, based on the theme's design and stylesheet. 239 * 240 * Priority 0 to make it available to lower priority callbacks. 241 * 242 * @global int $content_width Content width. 243 */ 244 function twentynineteen_content_width() { 245 // This variable is intended to be overruled from themes. 246 // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}. 247 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound 248 $GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 ); 249 } 250 add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 ); 251 252 /** 253 * Enqueue scripts and styles. 254 */ 255 function twentynineteen_scripts() { 256 wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) ); 257 258 wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' ); 259 260 if ( has_nav_menu( 'menu-1' ) ) { 261 wp_enqueue_script( 262 'twentynineteen-priority-menu', 263 get_theme_file_uri( '/js/priority-menu.js' ), 264 array(), 265 '20200129', 266 array( 267 'in_footer' => false, // Because involves header. 268 'strategy' => 'defer', 269 ) 270 ); 271 wp_enqueue_script( 272 'twentynineteen-touch-navigation', 273 get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), 274 array(), 275 '20230621', 276 array( 277 'in_footer' => true, 278 'strategy' => 'defer', 279 ) 280 ); 281 } 282 283 wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' ); 284 285 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 286 wp_enqueue_script( 'comment-reply' ); 287 } 288 } 289 add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' ); 290 291 /** 292 * Fix skip link focus in IE11. 293 * 294 * This does not enqueue the script because it is tiny and because it is only for IE11, 295 * thus it does not warrant having an entire dedicated blocking script being loaded. 296 * 297 * @since Twenty Nineteen 1.0 298 * @deprecated Twenty Nineteen 2.6 Removed from wp_print_footer_scripts action. 299 * 300 * @link https://git.io/vWdr2 301 */ 302 function twentynineteen_skip_link_focus_fix() { 303 // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`. 304 ?> 305 <script> 306 /(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); 307 </script> 308 <?php 309 } 310 311 /** 312 * Enqueue supplemental block editor styles. 313 */ 314 function twentynineteen_editor_customizer_styles() { 315 316 wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '2.1', 'all' ); 317 318 if ( 'custom' === get_theme_mod( 'primary_color' ) ) { 319 // Include color patterns. 320 require_once get_parent_theme_file_path( '/inc/color-patterns.php' ); 321 wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() ); 322 } 323 } 324 add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' ); 325 326 /** 327 * Display custom color CSS in customizer and on frontend. 328 */ 329 function twentynineteen_colors_css_wrap() { 330 331 // Only include custom colors in customizer or frontend. 332 if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) { 333 return; 334 } 335 336 require_once get_parent_theme_file_path( '/inc/color-patterns.php' ); 337 338 $primary_color = 199; 339 if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) { 340 $primary_color = get_theme_mod( 'primary_color_hue', 199 ); 341 } 342 ?> 343 344 <style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>> 345 <?php echo twentynineteen_custom_colors_css(); ?> 346 </style> 347 <?php 348 } 349 add_action( 'wp_head', 'twentynineteen_colors_css_wrap' ); 350 351 /** 352 * SVG Icons class. 353 */ 354 require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php'; 355 356 /** 357 * Custom Comment Walker template. 358 */ 359 require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php'; 360 361 /** 362 * Common theme functions. 363 */ 364 require get_template_directory() . '/inc/helper-functions.php'; 365 366 /** 367 * SVG Icons related functions. 368 */ 369 require get_template_directory() . '/inc/icon-functions.php'; 370 371 /** 372 * Enhance the theme by hooking into WordPress. 373 */ 374 require get_template_directory() . '/inc/template-functions.php'; 375 376 /** 377 * Custom template tags for the theme. 378 */ 379 require get_template_directory() . '/inc/template-tags.php'; 380 381 /** 382 * Customizer additions. 383 */ 384 require get_template_directory() . '/inc/customizer.php'; 385 386 /** 387 * Register block patterns and pattern categories. 388 * 389 * @since Twenty Nineteen 3.0 390 */ 391 function twentynineteen_register_block_patterns() { 392 require get_template_directory() . '/inc/block-patterns.php'; 393 } 394 395 add_action( 'init', 'twentynineteen_register_block_patterns' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |