| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Ipsum functions and definitions. 4 * 5 * @link https://developer.wordpress.org/themes/basics/theme-functions/ 6 * 7 * @package Ipsum 8 * @since Ipsum 1.0 9 */ 10 11 // Loads style.css in the editors too, then the few overrides only the editors need. 12 if ( ! function_exists( 'ipsum_register_editor_styles' ) ) : 13 /** 14 * Adds style.css and editor-style.css as editor stylesheets. 15 * 16 * @since Ipsum 1.0 17 * 18 * @return void 19 */ 20 function ipsum_register_editor_styles() { 21 add_editor_style( array( 'style.css', 'assets/css/editor-style.css' ) ); 22 } 23 endif; 24 add_action( 'after_setup_theme', 'ipsum_register_editor_styles' ); 25 26 if ( ! function_exists( 'ipsum_add_theme_support' ) ) : 27 /** 28 * Adds HTML5 support for navigation widgets, so their lists render inside a 29 * nav element. Block themes already get core's other HTML5 features, and this 30 * call merges with them. 31 * 32 * @since Ipsum 1.0 33 * 34 * @return void 35 */ 36 function ipsum_add_theme_support() { 37 add_theme_support( 'html5', array( 'navigation-widgets' ) ); 38 } 39 endif; 40 add_action( 'after_setup_theme', 'ipsum_add_theme_support' ); 41 42 if ( ! function_exists( 'ipsum_enqueue_styles' ) ) : 43 /** 44 * Enqueues styles. 45 * 46 * @since Ipsum 1.0 47 * 48 * @return void 49 */ 50 function ipsum_enqueue_styles() { 51 $style_path = get_parent_theme_file_path( 'style.css' ); 52 $style_min_path = get_parent_theme_file_path( 'style.min.css' ); 53 54 /* 55 * Use the minified stylesheet, unless script debugging is on or style.css 56 * has changed since style.min.css was built. That keeps edits made in the 57 * Theme File Editor working: saving style.css makes it the newer file. 58 */ 59 if ( 60 SCRIPT_DEBUG 61 || ! file_exists( $style_min_path ) 62 || ( filemtime( $style_path ) > filemtime( $style_min_path ) ) 63 ) { 64 $src = 'style.css'; 65 } else { 66 $src = 'style.min.css'; 67 } 68 69 // Register theme stylesheet. 70 wp_register_style( 71 'ipsum-style', 72 get_parent_theme_file_uri( $src ), 73 array(), 74 wp_get_theme( get_template() )->get( 'Version' ) 75 ); 76 77 // Let WordPress inline the stylesheet, so it is not a render-blocking request. 78 wp_style_add_data( 'ipsum-style', 'path', get_parent_theme_file_path( $src ) ); 79 80 // Enqueue theme stylesheet. 81 wp_enqueue_style( 'ipsum-style' ); 82 } 83 endif; 84 add_action( 'wp_enqueue_scripts', 'ipsum_enqueue_styles' ); 85 86 if ( ! function_exists( 'ipsum_comments_cta_binding' ) ) : 87 /** 88 * Returns the comments call to action for the current post, or nothing when 89 * comments are closed, since readers can no longer comment. 90 * 91 * @since Ipsum 1.0 92 * 93 * @param array<string, mixed> $source_args Block binding source arguments. Unused. 94 * @param WP_Block $block_instance The block instance. 95 * @return string|null The call to action text, an empty string when comments 96 * are closed, or null to keep the block's original content 97 * when there is no post. 98 */ 99 function ipsum_comments_cta_binding( $source_args, $block_instance ) { 100 unset( $source_args ); // Unused, but must be accepted to get the block instance. 101 102 $post_id = $block_instance->context['postId'] ?? null; 103 $post = get_post( is_numeric( $post_id ) ? (int) $post_id : null ); 104 if ( ! $post ) { 105 return null; 106 } 107 108 if ( ! comments_open( $post ) ) { 109 return ''; 110 } 111 112 $post_title = wp_strip_all_tags( get_the_title( $post ) ); 113 $has_title = ! empty( $post_title ); 114 115 if ( get_comments_number( $post ) > 0 ) { 116 $text = $has_title 117 ? sprintf( 118 /* translators: %s: Post title. */ 119 __( 'Join the conversation<span class="screen-reader-text"> on %s</span>', 'ipsum' ), 120 esc_html( $post_title ) 121 ) 122 : __( 'Join the conversation', 'ipsum' ); 123 } else { 124 $text = $has_title 125 ? sprintf( 126 /* translators: %s: Post title. */ 127 __( 'Be the first to comment<span class="screen-reader-text"> on %s</span>', 'ipsum' ), 128 esc_html( $post_title ) 129 ) 130 : __( 'Be the first to comment', 'ipsum' ); 131 } 132 133 return '<a href="' . esc_url( get_comments_link( $post ) ) . '">' . wp_kses_post( $text ) . '</a>'; 134 } 135 endif; 136 137 if ( ! function_exists( 'ipsum_register_block_bindings' ) ) : 138 /** 139 * Registers the comments call-to-action block binding source. 140 * 141 * @since Ipsum 1.0 142 * 143 * @return void 144 */ 145 function ipsum_register_block_bindings() { 146 register_block_bindings_source( 147 'ipsum/comments-cta', 148 array( 149 'label' => __( 'Comments call to action', 'ipsum' ), 150 'get_value_callback' => 'ipsum_comments_cta_binding', 151 'uses_context' => array( 'postId' ), 152 ) 153 ); 154 } 155 endif; 156 add_action( 'init', 'ipsum_register_block_bindings' ); 157 158 if ( ! function_exists( 'ipsum_sidebar_template_types' ) ) : 159 /** 160 * Registers the sidebar template variants as template types, so they are 161 * listed with proper titles and descriptions in the Site Editor. 162 * 163 * @since Ipsum 1.0 164 * 165 * @param array<string, array<string, string>> $default_template_types The default template types, keyed by 166 * slug, each with a title and description. 167 * @return array<string, array<string, string>> The template types, with the sidebar variants added. 168 */ 169 function ipsum_sidebar_template_types( $default_template_types ) { 170 $default_template_types['index-sidebar'] = array( 171 'title' => _x( 'Index Sidebar', 'Template name', 'ipsum' ), 172 'description' => __( 'Displays the latest posts beside a sidebar with categories and recent posts.', 'ipsum' ), 173 ); 174 $default_template_types['archive-sidebar'] = array( 175 'title' => _x( 'All Archives Sidebar', 'Template name', 'ipsum' ), 176 'description' => __( 'Displays post archives beside a sidebar with categories and recent posts.', 'ipsum' ), 177 ); 178 return $default_template_types; 179 } 180 endif; 181 add_filter( 'default_template_types', 'ipsum_sidebar_template_types' ); 182 183 if ( ! function_exists( 'ipsum_register_pattern_categories' ) ) : 184 /** 185 * Registers the pattern categories the theme's patterns use beyond core's. 186 * 187 * @since Ipsum 1.0 188 * 189 * @return void 190 */ 191 function ipsum_register_pattern_categories() { 192 register_block_pattern_category( 193 'ipsum_page', 194 array( 195 'label' => _x( 'Pages', 'Block pattern category', 'ipsum' ), 196 'description' => __( 'Full page layouts, ready to be applied to a page.', 'ipsum' ), 197 ) 198 ); 199 200 register_block_pattern_category( 201 'ipsum_post-format', 202 array( 203 'label' => _x( 'Post formats', 'Block pattern category', 'ipsum' ), 204 'description' => __( 'Layouts for post formats, like audio and link posts.', 'ipsum' ), 205 ) 206 ); 207 } 208 endif; 209 add_action( 'init', 'ipsum_register_pattern_categories' ); 210 211 if ( ! function_exists( 'ipsum_search_aria_label_support' ) ) : 212 /** 213 * Lets the Search block take an ARIA label, so its search landmark can be named. 214 * 215 * Every Search block is a search landmark, and a page can hold more than one, 216 * such as the search bar next to the search call to action, or next to the 217 * search in the navigation overlay. Repeated landmarks need unique names, but 218 * the block has no ariaLabel support of its own, so this turns on core's and 219 * the patterns set the name. 220 * 221 * @since Ipsum 1.0 222 * 223 * @param array<string, mixed> $metadata Metadata for the block type being registered. 224 * @return array<string, mixed> The block metadata, with ARIA label support on the Search block. 225 */ 226 function ipsum_search_aria_label_support( $metadata ) { 227 if ( isset( $metadata['name'] ) && 'core/search' === $metadata['name'] ) { 228 $supports = isset( $metadata['supports'] ) && is_array( $metadata['supports'] ) ? $metadata['supports'] : array(); 229 $supports['ariaLabel'] = true; 230 $metadata['supports'] = $supports; 231 } 232 return $metadata; 233 } 234 endif; 235 add_filter( 'block_type_metadata', 'ipsum_search_aria_label_support' ); 236 237 if ( ! function_exists( 'ipsum_register_block_styles' ) ) : 238 /** 239 * Registers block style variations. 240 * 241 * The Evening code style keeps the Evening palette's literals on purpose, 242 * so the block reads as a dark slab under every style variation. 243 * 244 * Each style's CSS is an inline style, as in the default themes. Row Hover 245 * can't move to styles/blocks/, because a theme.json css string cannot hold 246 * its at-rules and selector lists. 247 * 248 * @since Ipsum 1.0 249 * 250 * @return void 251 */ 252 function ipsum_register_block_styles() { 253 register_block_style( 254 'core/code', 255 array( 256 'name' => 'evening', 257 'label' => _x( 'Evening', 'Block style label', 'ipsum' ), 258 'inline_style' => '.wp-block-code.is-style-evening{background-color:#000000;color:#fafafa;border-color:#fafafa40;}', 259 ) 260 ); 261 262 register_block_style( 263 'core/site-logo', 264 array( 265 'name' => 'sharp', 266 'label' => _x( 'Sharp', 'Block style label', 'ipsum' ), 267 'inline_style' => '.wp-block-site-logo.is-style-sharp{border-radius:0;}', 268 ) 269 ); 270 271 /* 272 * Pins the part to the bottom of the viewport, so it belongs at the root 273 * of the template. It keeps to its content's width at the inline end, so 274 * the rest of the band doesn't block clicks on the page. The editors also 275 * need the override in editor-style.css. 276 */ 277 register_block_style( 278 'core/template-part', 279 array( 280 'name' => 'sticky-bottom', 281 'label' => _x( 'Pinned to Bottom', 'Block style label', 'ipsum' ), 282 'inline_style' => ' 283 .wp-block-template-part.is-style-sticky-bottom { 284 position: sticky; 285 inset-block-end: 0; 286 z-index: 10; 287 width: fit-content; 288 margin-inline-start: auto; 289 }', 290 ) 291 ); 292 293 /* 294 * Outlines the Search button until it is hovered, focused or pressed, when 295 * the global button states take back over. A theme.json css string would 296 * wrap this in :where() and only tie with the global button styles. 297 */ 298 register_block_style( 299 'core/search', 300 array( 301 'name' => 'outline', 302 'label' => _x( 'Outline', 'Block style label', 'ipsum' ), 303 'inline_style' => ' 304 .wp-block-search.is-style-outline .wp-block-search__button.wp-element-button:not(:hover):not(:focus):not(:active) { 305 background-color: var(--wp--preset--color--base); 306 border: 1px dotted var(--wp--preset--color--contrast); 307 color: var(--wp--preset--color--contrast); 308 }', 309 ) 310 ); 311 312 /* 313 * Hovering any part of a post row colors the whole row and tilts its 314 * featured image. Targets the row's child blocks, since the Group spans 315 * the full band. Needs each post's blocks wrapped in one Group. 316 */ 317 register_block_style( 318 'core/post-template', 319 array( 320 'name' => 'hover-together', 321 'label' => _x( 'Row Hover', 'Block style label', 'ipsum' ), 322 'inline_style' => ' 323 .wp-block-post-template.is-style-hover-together .wp-block-post > .wp-block-group, 324 .wp-block-post-template.is-style-hover-together .wp-block-post > .wp-block-group a { 325 transition: color 0.15s ease-out; 326 } 327 328 .wp-block-post-template.is-style-hover-together .wp-block-post > .wp-block-group:has(> :hover), 329 .wp-block-post-template.is-style-hover-together .wp-block-post > .wp-block-group:has(> :hover) a { 330 color: var(--wp--preset--color--accent-3); 331 } 332 333 @media (prefers-reduced-motion: no-preference) { 334 @keyframes tilt-settle { 335 35% { 336 transform: rotate(-1deg); 337 } 338 339 100% { 340 transform: rotate(0deg); 341 } 342 } 343 344 .wp-block-post-template.is-style-hover-together .wp-block-post > .wp-block-group:has(> :hover) .wp-block-post-featured-image img { 345 animation: tilt-settle 0.5s ease-out; 346 } 347 }', 348 ) 349 ); 350 } 351 endif; 352 add_action( 'init', 'ipsum_register_block_styles' ); 353 354 // Registers the design guide ability for agents. 355 require get_parent_theme_file_path( 'inc/abilities.php' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Nov 11 08:20:02 2026 | Cross-referenced by PHPXref |