[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/ipsum/ -> functions.php (source)

   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          // Register theme stylesheet.
  52          wp_register_style(
  53              'ipsum-style',
  54              get_parent_theme_file_uri( 'style.css' ),
  55              array(),
  56              wp_get_theme()->get( 'Version' )
  57          );
  58  
  59          // Enqueue theme stylesheet.
  60          wp_enqueue_style( 'ipsum-style' );
  61      }
  62  endif;
  63  add_action( 'wp_enqueue_scripts', 'ipsum_enqueue_styles' );
  64  
  65  if ( ! function_exists( 'ipsum_comments_cta_binding' ) ) :
  66      /**
  67       * Returns the comments call to action for the current post.
  68       *
  69       * @since Ipsum 1.0
  70       *
  71       * @param array    $source_args    Block binding source arguments.
  72       * @param WP_Block $block_instance The block instance.
  73       * @return string The call to action text.
  74       */
  75  	function ipsum_comments_cta_binding( $source_args, $block_instance ) {
  76          $post_id = $block_instance->context['postId'] ?? get_the_ID();
  77  
  78          if ( get_comments_number( $post_id ) > 0 ) {
  79              $text = __( 'Join the conversation', 'ipsum' );
  80          } else {
  81              $text = __( 'Be the first to comment', 'ipsum' );
  82          }
  83  
  84          return '<a href="' . esc_url( get_comments_link( $post_id ) ) . '">' . esc_html( $text ) . '</a>';
  85      }
  86  endif;
  87  
  88  if ( ! function_exists( 'ipsum_register_block_bindings' ) ) :
  89      /**
  90       * Registers the comments call-to-action block binding source.
  91       *
  92       * @since Ipsum 1.0
  93       *
  94       * @return void
  95       */
  96  	function ipsum_register_block_bindings() {
  97          register_block_bindings_source(
  98              'ipsum/comments-cta',
  99              array(
 100                  'label'              => __( 'Comments call to action', 'ipsum' ),
 101                  'get_value_callback' => 'ipsum_comments_cta_binding',
 102                  'uses_context'       => array( 'postId' ),
 103              )
 104          );
 105      }
 106  endif;
 107  add_action( 'init', 'ipsum_register_block_bindings' );
 108  
 109  if ( ! function_exists( 'ipsum_sidebar_template_types' ) ) :
 110      /**
 111       * Registers the sidebar template variants as template types, so they are
 112       * listed with proper titles and descriptions in the Site Editor.
 113       *
 114       * @since Ipsum 1.0
 115       *
 116       * @param array $default_template_types The default template types.
 117       * @return array The template types, with the sidebar variants added.
 118       */
 119  	function ipsum_sidebar_template_types( $default_template_types ) {
 120          $default_template_types['index-sidebar']   = array(
 121              'title'       => _x( 'Index Sidebar', 'Template name', 'ipsum' ),
 122              'description' => __( 'Displays the latest posts beside a sidebar with categories and recent posts.', 'ipsum' ),
 123          );
 124          $default_template_types['archive-sidebar'] = array(
 125              'title'       => _x( 'All Archives Sidebar', 'Template name', 'ipsum' ),
 126              'description' => __( 'Displays post archives beside a sidebar with categories and recent posts.', 'ipsum' ),
 127          );
 128          return $default_template_types;
 129      }
 130  endif;
 131  add_filter( 'default_template_types', 'ipsum_sidebar_template_types' );
 132  
 133  if ( ! function_exists( 'ipsum_register_pattern_categories' ) ) :
 134      /**
 135       * Registers the pattern categories the theme's patterns use beyond core's.
 136       *
 137       * @since Ipsum 1.0
 138       *
 139       * @return void
 140       */
 141  	function ipsum_register_pattern_categories() {
 142          register_block_pattern_category(
 143              'ipsum_page',
 144              array(
 145                  'label'       => _x( 'Pages', 'Block pattern category', 'ipsum' ),
 146                  'description' => __( 'Full page layouts, ready to be applied to a page.', 'ipsum' ),
 147              )
 148          );
 149      }
 150  endif;
 151  add_action( 'init', 'ipsum_register_pattern_categories' );
 152  
 153  if ( ! function_exists( 'ipsum_search_aria_label_support' ) ) :
 154      /**
 155       * Lets the Search block take an ARIA label, so its search landmark can be named.
 156       *
 157       * Every Search block is a search landmark, and a page can hold more than one,
 158       * such as the search bar next to the search call to action, or next to the
 159       * search in the navigation overlay. Repeated landmarks need unique names, but
 160       * the block has no ariaLabel support of its own, so this turns on core's and
 161       * the patterns set the name.
 162       *
 163       * @since Ipsum 1.0
 164       *
 165       * @param array $metadata Metadata for the block type being registered.
 166       * @return array The block metadata, with ARIA label support on the Search block.
 167       */
 168  	function ipsum_search_aria_label_support( $metadata ) {
 169          if ( isset( $metadata['name'] ) && 'core/search' === $metadata['name'] ) {
 170              $metadata['supports']['ariaLabel'] = true;
 171          }
 172          return $metadata;
 173      }
 174  endif;
 175  add_filter( 'block_type_metadata', 'ipsum_search_aria_label_support' );
 176  
 177  if ( ! function_exists( 'ipsum_register_block_styles' ) ) :
 178      /**
 179       * Registers block style variations.
 180       *
 181       * The Evening code style keeps the Evening palette's literals on purpose,
 182       * so the block reads as a dark slab under every style variation.
 183       *
 184       * @since Ipsum 1.0
 185       *
 186       * @return void
 187       */
 188  	function ipsum_register_block_styles() {
 189          register_block_style(
 190              'core/code',
 191              array(
 192                  'name'         => 'evening',
 193                  'label'        => _x( 'Evening', 'Block style label', 'ipsum' ),
 194                  'inline_style' => '.wp-block-code.is-style-evening{background-color:#000000;color:#fafafa;border-color:#fafafa40;}',
 195              )
 196          );
 197  
 198          register_block_style(
 199              'core/site-logo',
 200              array(
 201                  'name'         => 'sharp',
 202                  'label'        => _x( 'Sharp', 'Block style label', 'ipsum' ),
 203                  'inline_style' => '.wp-block-site-logo.is-style-sharp{border-radius:0;}',
 204              )
 205          );
 206      }
 207  endif;
 208  add_action( 'init', 'ipsum_register_block_styles' );


Generated : Thu Oct 22 08:20:34 2026 Cross-referenced by PHPXref