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