[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-content/themes/twentytwenty/inc/ -> template-tags.php (source)

   1  <?php
   2  /**
   3   * Custom template tags for this theme.
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Twenty
   7   * @since 1.0.0
   8   */
   9  
  10  /**
  11   * Table of Contents:
  12   * Logo & Description
  13   * Comments
  14   * Post Meta
  15   * Menus
  16   * Classes
  17   * Archives
  18   * Miscellaneous
  19   */
  20  
  21  /**
  22   * Logo & Description
  23   */
  24  /**
  25   * Displays the site logo, either text or image.
  26   *
  27   * @param array   $args Arguments for displaying the site logo either as an image or text.
  28   * @param boolean $echo Echo or return the HTML.
  29   *
  30   * @return string $html Compiled HTML based on our arguments.
  31   */
  32  function twentytwenty_site_logo( $args = array(), $echo = true ) {
  33      $logo       = get_custom_logo();
  34      $site_title = get_bloginfo( 'name' );
  35      $contents   = '';
  36      $classname  = '';
  37  
  38      $defaults = array(
  39          'logo'        => '%1$s<span class="screen-reader-text">%2$s</span>',
  40          'logo_class'  => 'site-logo',
  41          'title'       => '<a href="%1$s">%2$s</a>',
  42          'title_class' => 'site-title',
  43          'home_wrap'   => '<h1 class="%1$s">%2$s</h1>',
  44          'single_wrap' => '<div class="%1$s faux-heading">%2$s</div>',
  45          'condition'   => ( is_front_page() || is_home() ) && ! is_page(),
  46      );
  47  
  48      $args = wp_parse_args( $args, $defaults );
  49  
  50      /**
  51       * Filters the arguments for `twentytwenty_site_logo()`.
  52       *
  53       * @param array  $args     Parsed arguments.
  54       * @param array  $defaults Function's default arguments.
  55       */
  56      $args = apply_filters( 'twentytwenty_site_logo_args', $args, $defaults );
  57  
  58      if ( has_custom_logo() ) {
  59          $contents  = sprintf( $args['logo'], $logo, esc_html( $site_title ) );
  60          $classname = $args['logo_class'];
  61      } else {
  62          $contents  = sprintf( $args['title'], esc_url( get_home_url( null, '/' ) ), esc_html( $site_title ) );
  63          $classname = $args['title_class'];
  64      }
  65  
  66      $wrap = $args['condition'] ? 'home_wrap' : 'single_wrap';
  67  
  68      $html = sprintf( $args[ $wrap ], $classname, $contents );
  69  
  70      /**
  71       * Filters the arguments for `twentytwenty_site_logo()`.
  72       *
  73       * @param string $html      Compiled html based on our arguments.
  74       * @param array  $args      Parsed arguments.
  75       * @param string $classname Class name based on current view, home or single.
  76       * @param string $contents  HTML for site title or logo.
  77       */
  78      $html = apply_filters( 'twentytwenty_site_logo', $html, $args, $classname, $contents );
  79  
  80      if ( ! $echo ) {
  81          return $html;
  82      }
  83  
  84      echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  85  
  86  }
  87  
  88  /**
  89   * Displays the site description.
  90   *
  91   * @param boolean $echo Echo or return the html.
  92   *
  93   * @return string $html The HTML to display.
  94   */
  95  function twentytwenty_site_description( $echo = true ) {
  96      $description = get_bloginfo( 'description' );
  97  
  98      if ( ! $description ) {
  99          return;
 100      }
 101  
 102      $wrapper = '<div class="site-description">%s</div><!-- .site-description -->';
 103  
 104      $html = sprintf( $wrapper, esc_html( $description ) );
 105  
 106      /**
 107       * Filters the html for the site description.
 108       *
 109       * @since 1.0.0
 110       *
 111       * @param string $html         The HTML to display.
 112       * @param string $description  Site description via `bloginfo()`.
 113       * @param string $wrapper      The format used in case you want to reuse it in a `sprintf()`.
 114       */
 115      $html = apply_filters( 'twentytwenty_site_description', $html, $description, $wrapper );
 116  
 117      if ( ! $echo ) {
 118          return $html;
 119      }
 120  
 121      echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
 122  }
 123  
 124  /**
 125   * Comments
 126   */
 127  /**
 128   * Check if the specified comment is written by the author of the post commented on.
 129   *
 130   * @param object $comment Comment data.
 131   *
 132   * @return bool
 133   */
 134  function twentytwenty_is_comment_by_post_author( $comment = null ) {
 135  
 136      if ( is_object( $comment ) && $comment->user_id > 0 ) {
 137  
 138          $user = get_userdata( $comment->user_id );
 139          $post = get_post( $comment->comment_post_ID );
 140  
 141          if ( ! empty( $user ) && ! empty( $post ) ) {
 142  
 143              return $comment->user_id === $post->post_author;
 144  
 145          }
 146      }
 147      return false;
 148  
 149  }
 150  
 151  /**
 152   * Filter comment reply link to not JS scroll.
 153   * Filter the comment reply link to add a class indicating it should not use JS slow-scroll, as it
 154   * makes it scroll to the wrong position on the page.
 155   *
 156   * @param string $link Link to the top of the page.
 157   *
 158   * @return string $link Link to the top of the page.
 159   */
 160  function twentytwenty_filter_comment_reply_link( $link ) {
 161  
 162      $link = str_replace( 'class=\'', 'class=\'do-not-scroll ', $link );
 163      return $link;
 164  
 165  }
 166  
 167  add_filter( 'comment_reply_link', 'twentytwenty_filter_comment_reply_link' );
 168  
 169  /**
 170   * Post Meta
 171   */
 172  /**
 173   * Get and Output Post Meta.
 174   * If it's a single post, output the post meta values specified in the Customizer settings.
 175   *
 176   * @param int    $post_id The ID of the post for which the post meta should be output.
 177   * @param string $location Which post meta location to output – single or preview.
 178   */
 179  function twentytwenty_the_post_meta( $post_id = null, $location = 'single-top' ) {
 180  
 181      echo twentytwenty_get_post_meta( $post_id, $location ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in twentytwenty_get_post_meta().
 182  
 183  }
 184  
 185  /**
 186   * Filters the edit post link to add an icon and use the post meta structure.
 187   *
 188   * @param string $link    Anchor tag for the edit link.
 189   * @param int    $post_id Post ID.
 190   * @param string $text    Anchor text.
 191   */
 192  function twentytwenty_edit_post_link( $link, $post_id, $text ) {
 193      if ( is_admin() ) {
 194          return $link;
 195      }
 196  
 197      $edit_url = get_edit_post_link( $post_id );
 198  
 199      if ( ! $edit_url ) {
 200          return;
 201      }
 202  
 203      $text = sprintf(
 204          wp_kses(
 205              /* translators: %s: Post title. Only visible to screen readers. */
 206              __( 'Edit <span class="screen-reader-text">%s</span>', 'twentytwenty' ),
 207              array(
 208                  'span' => array(
 209                      'class' => array(),
 210                  ),
 211              )
 212          ),
 213          get_the_title( $post_id )
 214      );
 215  
 216      return '<div class="post-meta-wrapper post-meta-edit-link-wrapper"><ul class="post-meta"><li class="post-edit meta-wrapper"><span class="meta-icon">' . twentytwenty_get_theme_svg( 'edit' ) . '</span><span class="meta-text"><a href="' . esc_url( $edit_url ) . '">' . $text . '</a></span></li></ul><!-- .post-meta --></div><!-- .post-meta-wrapper -->';
 217  
 218  }
 219  
 220  add_filter( 'edit_post_link', 'twentytwenty_edit_post_link', 10, 3 );
 221  
 222  /**
 223   * Get the post meta.
 224   *
 225   * @param int    $post_id The ID of the post.
 226   * @param string $location The location where the meta is shown.
 227   */
 228  function twentytwenty_get_post_meta( $post_id = null, $location = 'single-top' ) {
 229  
 230      // Require post ID.
 231      if ( ! $post_id ) {
 232          return;
 233      }
 234  
 235      /**
 236       * Filters post types array
 237       *
 238       * This filter can be used to hide post meta information of post, page or custom post type registerd by child themes or plugins
 239       *
 240       * @since 1.0.0
 241       *
 242       * @param array Array of post types
 243       */
 244      $disallowed_post_types = apply_filters( 'twentytwenty_disallowed_post_types_for_meta_output', array( 'page' ) );
 245      // Check whether the post type is allowed to output post meta.
 246      if ( in_array( get_post_type( $post_id ), $disallowed_post_types, true ) ) {
 247          return;
 248      }
 249  
 250      $post_meta_wrapper_classes = '';
 251      $post_meta_classes         = '';
 252  
 253      // Get the post meta settings for the location specified.
 254      if ( 'single-top' === $location ) {
 255          /**
 256          * Filters post meta info visibility
 257          *
 258          * Use this filter to hide post meta information like Author, Post date, Comments, Is sticky status
 259          *
 260          * @since 1.0.0
 261          *
 262          * @param array $args {
 263          *  @type string 'author'
 264          *  @type string 'post-date'
 265          *  @type string 'comments'
 266          *  @type string  'sticky'
 267          * }
 268          */
 269          $post_meta                 = apply_filters(
 270              'twentytwenty_post_meta_location_single_top',
 271              array(
 272                  'author',
 273                  'post-date',
 274                  'comments',
 275                  'sticky',
 276              )
 277          );
 278          $post_meta_wrapper_classes = ' post-meta-single post-meta-single-top';
 279  
 280      } elseif ( 'single-bottom' === $location ) {
 281  
 282          /**
 283          * Filters post tags visibility
 284          *
 285          * Use this filter to hide post tags
 286          *
 287          * @since 1.0.0
 288          *
 289          * @param array $args {
 290          *   @type string 'tags'
 291          * }
 292          */
 293          $post_meta                 = apply_filters(
 294              'twentytwenty_post_meta_location_single_bottom',
 295              array(
 296                  'tags',
 297              )
 298          );
 299          $post_meta_wrapper_classes = ' post-meta-single post-meta-single-bottom';
 300  
 301      }
 302  
 303      // If the post meta setting has the value 'empty', it's explicitly empty and the default post meta shouldn't be output.
 304      if ( $post_meta && ! in_array( 'empty', $post_meta, true ) ) {
 305  
 306          // Make sure we don't output an empty container.
 307          $has_meta = false;
 308  
 309          global $post;
 310          $the_post = get_post( $post_id );
 311          setup_postdata( $the_post );
 312  
 313          ob_start();
 314  
 315          ?>
 316  
 317          <div class="post-meta-wrapper<?php echo esc_attr( $post_meta_wrapper_classes ); ?>">
 318  
 319              <ul class="post-meta<?php echo esc_attr( $post_meta_classes ); ?>">
 320  
 321                  <?php
 322  
 323                  /**
 324                   * Fires before post meta html display.
 325                   *
 326                   * Allow output of additional post meta info to be added by child themes and plugins.
 327                   *
 328                   * @since 1.0.0
 329                   *
 330                   * @param int   $post_ID Post ID.
 331                   */
 332                  do_action( 'twentytwenty_start_of_post_meta_list', $post_id );
 333  
 334                  // Author.
 335                  if ( in_array( 'author', $post_meta, true ) ) {
 336  
 337                      $has_meta = true;
 338                      ?>
 339                      <li class="post-author meta-wrapper">
 340                          <span class="meta-icon">
 341                              <span class="screen-reader-text"><?php _e( 'Post author', 'twentytwenty' ); ?></span>
 342                              <?php twentytwenty_the_theme_svg( 'user' ); ?>
 343                          </span>
 344                          <span class="meta-text">
 345                              <?php
 346                              printf(
 347                                  /* translators: %s: Author name */
 348                                  __( 'By %s', 'twentytwenty' ),
 349                                  '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author_meta( 'display_name' ) ) . '</a>'
 350                              );
 351                              ?>
 352                          </span>
 353                      </li>
 354                      <?php
 355  
 356                  }
 357  
 358                  // Post date.
 359                  if ( in_array( 'post-date', $post_meta, true ) ) {
 360  
 361                      $has_meta = true;
 362                      ?>
 363                      <li class="post-date meta-wrapper">
 364                          <span class="meta-icon">
 365                              <span class="screen-reader-text"><?php _e( 'Post date', 'twentytwenty' ); ?></span>
 366                              <?php twentytwenty_the_theme_svg( 'calendar' ); ?>
 367                          </span>
 368                          <span class="meta-text">
 369                              <a href="<?php the_permalink(); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a>
 370                          </span>
 371                      </li>
 372                      <?php
 373  
 374                  }
 375  
 376                  // Categories.
 377                  if ( in_array( 'categories', $post_meta, true ) && has_category() ) {
 378  
 379                      $has_meta = true;
 380                      ?>
 381                      <li class="post-categories meta-wrapper">
 382                          <span class="meta-icon">
 383                              <span class="screen-reader-text"><?php _e( 'Categories', 'twentytwenty' ); ?></span>
 384                              <?php twentytwenty_the_theme_svg( 'folder' ); ?>
 385                          </span>
 386                          <span class="meta-text">
 387                              <?php _ex( 'In', 'A string that is output before one or more categories', 'twentytwenty' ); ?> <?php the_category( ', ' ); ?>
 388                          </span>
 389                      </li>
 390                      <?php
 391  
 392                  }
 393  
 394                  // Tags.
 395                  if ( in_array( 'tags', $post_meta, true ) && has_tag() ) {
 396  
 397                      $has_meta = true;
 398                      ?>
 399                      <li class="post-tags meta-wrapper">
 400                          <span class="meta-icon">
 401                              <span class="screen-reader-text"><?php _e( 'Tags', 'twentytwenty' ); ?></span>
 402                              <?php twentytwenty_the_theme_svg( 'tag' ); ?>
 403                          </span>
 404                          <span class="meta-text">
 405                              <?php the_tags( '', ', ', '' ); ?>
 406                          </span>
 407                      </li>
 408                      <?php
 409  
 410                  }
 411  
 412                  // Comments link.
 413                  if ( in_array( 'comments', $post_meta, true ) && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
 414  
 415                      $has_meta = true;
 416                      ?>
 417                      <li class="post-comment-link meta-wrapper">
 418                          <span class="meta-icon">
 419                              <?php twentytwenty_the_theme_svg( 'comment' ); ?>
 420                          </span>
 421                          <span class="meta-text">
 422                              <?php comments_popup_link(); ?>
 423                          </span>
 424                      </li>
 425                      <?php
 426  
 427                  }
 428  
 429                  // Sticky.
 430                  if ( in_array( 'sticky', $post_meta, true ) && is_sticky() ) {
 431  
 432                      $has_meta = true;
 433                      ?>
 434                      <li class="post-sticky meta-wrapper">
 435                          <span class="meta-icon">
 436                              <?php twentytwenty_the_theme_svg( 'bookmark' ); ?>
 437                          </span>
 438                          <span class="meta-text">
 439                              <?php _e( 'Sticky post', 'twentytwenty' ); ?>
 440                          </span>
 441                      </li>
 442                      <?php
 443  
 444                  }
 445  
 446                  /**
 447                   * Fires after post meta html display.
 448                   *
 449                   * Allow output of additional post meta info to be added by child themes and plugins.
 450                   *
 451                   * @since 1.0.0
 452                   *
 453                   * @param int   $post_ID Post ID.
 454                   */
 455                  do_action( 'twentytwenty_end_of_post_meta_list', $post_id );
 456  
 457                  ?>
 458  
 459              </ul><!-- .post-meta -->
 460  
 461          </div><!-- .post-meta-wrapper -->
 462  
 463          <?php
 464  
 465          wp_reset_postdata();
 466  
 467          $meta_output = ob_get_clean();
 468  
 469          // If there is meta to output, return it.
 470          if ( $has_meta && $meta_output ) {
 471  
 472              return $meta_output;
 473  
 474          }
 475      }
 476  
 477  }
 478  
 479  /**
 480   * Menus
 481   */
 482  /**
 483   * Filter Classes of wp_list_pages items to match menu items.
 484   * Filter the class applied to wp_list_pages() items with children to match the menu class, to simplify.
 485   * styling of sub levels in the fallback. Only applied if the match_menu_classes argument is set.
 486   *
 487   * @param array  $css_class CSS Class names.
 488   * @param string $item Comment.
 489   * @param int    $depth Depth of the current comment.
 490   * @param array  $args An array of arguments.
 491   * @param string $current_page Whether or not the item is the current item.
 492   *
 493   * @return array $css_class CSS Class names.
 494   */
 495  function twentytwenty_filter_wp_list_pages_item_classes( $css_class, $item, $depth, $args, $current_page ) {
 496  
 497      // Only apply to wp_list_pages() calls with match_menu_classes set to true.
 498      $match_menu_classes = isset( $args['match_menu_classes'] );
 499  
 500      if ( ! $match_menu_classes ) {
 501          return $css_class;
 502      }
 503  
 504      // Add current menu item class.
 505      if ( in_array( 'current_page_item', $css_class, true ) ) {
 506          $css_class[] = 'current-menu-item';
 507      }
 508  
 509      // Add menu item has children class.
 510      if ( in_array( 'page_item_has_children', $css_class, true ) ) {
 511          $css_class[] = 'menu-item-has-children';
 512      }
 513  
 514      return $css_class;
 515  
 516  }
 517  
 518  add_filter( 'page_css_class', 'twentytwenty_filter_wp_list_pages_item_classes', 10, 5 );
 519  
 520  /**
 521   * Add a Sub Nav Toggle to the Expanded Menu and Mobile Menu.
 522   *
 523   * @param stdClass $args An array of arguments.
 524   * @param string   $item Menu item.
 525   * @param int      $depth Depth of the current menu item.
 526   *
 527   * @return stdClass $args An object of wp_nav_menu() arguments.
 528   */
 529  function twentytwenty_add_sub_toggles_to_main_menu( $args, $item, $depth ) {
 530  
 531      // Add sub menu toggles to the Expanded Menu with toggles.
 532      if ( isset( $args->show_toggles ) && $args->show_toggles ) {
 533  
 534          // Wrap the menu item link contents in a div, used for positioning.
 535          $args->before = '<div class="ancestor-wrapper">';
 536          $args->after  = '';
 537  
 538          // Add a toggle to items with children.
 539          if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
 540  
 541              $toggle_target_string = '.menu-modal .menu-item-' . $item->ID . ' > .sub-menu';
 542              $toggle_duration      = twentytwenty_toggle_duration();
 543  
 544              // Add the sub menu toggle.
 545              $args->after .= '<button class="toggle sub-menu-toggle fill-children-current-color" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="' . absint( $toggle_duration ) . '" aria-expanded="false"><span class="screen-reader-text">' . __( 'Show sub menu', 'twentytwenty' ) . '</span>' . twentytwenty_get_theme_svg( 'chevron-down' ) . '</button>';
 546  
 547          }
 548  
 549          // Close the wrapper.
 550          $args->after .= '</div><!-- .ancestor-wrapper -->';
 551  
 552          // Add sub menu icons to the primary menu without toggles.
 553      } elseif ( 'primary' === $args->theme_location ) {
 554          if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
 555              $args->after = '<span class="icon"></span>';
 556          } else {
 557              $args->after = '';
 558          }
 559      }
 560  
 561      return $args;
 562  
 563  }
 564  
 565  add_filter( 'nav_menu_item_args', 'twentytwenty_add_sub_toggles_to_main_menu', 10, 3 );
 566  
 567  /**
 568   * Display SVG icons in social links menu.
 569   *
 570   * @param  string  $item_output The menu item output.
 571   * @param  WP_Post $item        Menu item object.
 572   * @param  int     $depth       Depth of the menu.
 573   * @param  array   $args        wp_nav_menu() arguments.
 574   * @return string  $item_output The menu item output with social icon.
 575   */
 576  function twentytwenty_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
 577      // Change SVG icon inside social links menu if there is supported URL.
 578      if ( 'social' === $args->theme_location ) {
 579          $svg = TwentyTwenty_SVG_Icons::get_social_link_svg( $item->url );
 580          if ( empty( $svg ) ) {
 581              $svg = twentytwenty_get_theme_svg( 'link' );
 582          }
 583          $item_output = str_replace( $args->link_after, '</span>' . $svg, $item_output );
 584      }
 585  
 586      return $item_output;
 587  }
 588  
 589  add_filter( 'walker_nav_menu_start_el', 'twentytwenty_nav_menu_social_icons', 10, 4 );
 590  
 591  /**
 592   * Classes
 593   */
 594  /**
 595   * Add No-JS Class.
 596   * If we're missing JavaScript support, the HTML element will have a no-js class.
 597   */
 598  function twentytwenty_no_js_class() {
 599  
 600      ?>
 601      <script>document.documentElement.className = document.documentElement.className.replace( 'no-js', 'js' );</script>
 602      <?php
 603  
 604  }
 605  
 606  add_action( 'wp_head', 'twentytwenty_no_js_class' );
 607  
 608  /**
 609   * Add conditional body classes.
 610   *
 611   * @param array $classes Classes added to the body tag.
 612   *
 613   * @return array $classes Classes added to the body tag.
 614   */
 615  function twentytwenty_body_classes( $classes ) {
 616  
 617      global $post;
 618      $post_type = isset( $post ) ? $post->post_type : false;
 619  
 620      // Check whether we're singular.
 621      if ( is_singular() ) {
 622          $classes[] = 'singular';
 623      }
 624  
 625      // Check whether the current page should have an overlay header.
 626      if ( is_page_template( array( 'templates/template-cover.php' ) ) ) {
 627          $classes[] = 'overlay-header';
 628      }
 629  
 630      // Check whether the current page has full-width content.
 631      if ( is_page_template( array( 'templates/template-full-width.php' ) ) ) {
 632          $classes[] = 'has-full-width-content';
 633      }
 634  
 635      // Check for enabled search.
 636      if ( true === get_theme_mod( 'enable_header_search', true ) ) {
 637          $classes[] = 'enable-search-modal';
 638      }
 639  
 640      // Check for post thumbnail.
 641      if ( is_singular() && has_post_thumbnail() ) {
 642          $classes[] = 'has-post-thumbnail';
 643      } elseif ( is_singular() ) {
 644          $classes[] = 'missing-post-thumbnail';
 645      }
 646  
 647      // Check whether we're in the customizer preview.
 648      if ( is_customize_preview() ) {
 649          $classes[] = 'customizer-preview';
 650      }
 651  
 652      // Check if posts have single pagination.
 653      if ( is_single() && ( get_next_post() || get_previous_post() ) ) {
 654          $classes[] = 'has-single-pagination';
 655      } else {
 656          $classes[] = 'has-no-pagination';
 657      }
 658  
 659      // Check if we're showing comments.
 660      if ( $post && ( ( 'post' === $post_type || comments_open() || get_comments_number() ) && ! post_password_required() ) ) {
 661          $classes[] = 'showing-comments';
 662      } else {
 663          $classes[] = 'not-showing-comments';
 664      }
 665  
 666      // Check if avatars are visible.
 667      $classes[] = get_option( 'show_avatars' ) ? 'show-avatars' : 'hide-avatars';
 668  
 669      // Slim page template class names (class = name - file suffix).
 670      if ( is_page_template() ) {
 671          $classes[] = basename( get_page_template_slug(), '.php' );
 672      }
 673  
 674      // Check for the elements output in the top part of the footer.
 675      $has_footer_menu = has_nav_menu( 'footer' );
 676      $has_social_menu = has_nav_menu( 'social' );
 677      $has_sidebar_1   = is_active_sidebar( 'sidebar-1' );
 678      $has_sidebar_2   = is_active_sidebar( 'sidebar-2' );
 679  
 680      // Add a class indicating whether those elements are output.
 681      if ( $has_footer_menu || $has_social_menu || $has_sidebar_1 || $has_sidebar_2 ) {
 682          $classes[] = 'footer-top-visible';
 683      } else {
 684          $classes[] = 'footer-top-hidden';
 685      }
 686  
 687      // Get header/footer background color.
 688      $header_footer_background = get_theme_mod( 'header_footer_background_color', '#ffffff' );
 689      $header_footer_background = strtolower( '#' . ltrim( $header_footer_background, '#' ) );
 690  
 691      // Get content background color.
 692      $background_color = get_theme_mod( 'background_color', 'f5efe0' );
 693      $background_color = strtolower( '#' . ltrim( $background_color, '#' ) );
 694  
 695      // Add extra class if main background and header/footer background are the same color.
 696      if ( $background_color === $header_footer_background ) {
 697          $classes[] = 'reduced-spacing';
 698      }
 699  
 700      return $classes;
 701  
 702  }
 703  
 704  add_filter( 'body_class', 'twentytwenty_body_classes' );
 705  
 706  /**
 707   * Archives
 708   */
 709  /**
 710   * Filters the archive title and styles the word before the first colon.
 711   *
 712   * @param string $title Current archive title.
 713   *
 714   * @return string $title Current archive title.
 715   */
 716  function twentytwenty_get_the_archive_title( $title ) {
 717  
 718      $regex = apply_filters(
 719          'twentytwenty_get_the_archive_title_regex',
 720          array(
 721              'pattern'     => '/(\A[^\:]+\:)/',
 722              'replacement' => '<span class="color-accent">$1</span>',
 723          )
 724      );
 725  
 726      if ( empty( $regex ) ) {
 727  
 728          return $title;
 729  
 730      }
 731  
 732      return preg_replace( $regex['pattern'], $regex['replacement'], $title );
 733  
 734  }
 735  
 736  add_filter( 'get_the_archive_title', 'twentytwenty_get_the_archive_title' );
 737  
 738  /**
 739   * Miscellaneous
 740   */
 741  /**
 742   * Toggle animation duration in milliseconds.
 743   *
 744   * @return integer Duration in milliseconds
 745   */
 746  function twentytwenty_toggle_duration() {
 747      /**
 748       * Filters the animation duration/speed used usually for submenu toggles.
 749       *
 750       * @since 1.0
 751       *
 752       * @param integer $duration Duration in milliseconds.
 753       */
 754      $duration = apply_filters( 'twentytwenty_toggle_duration', 250 );
 755  
 756      return $duration;
 757  }
 758  
 759  /**
 760   * Get unique ID.
 761   *
 762   * This is a PHP implementation of Underscore's uniqueId method. A static variable
 763   * contains an integer that is incremented with each call. This number is returned
 764   * with the optional prefix. As such the returned value is not universally unique,
 765   * but it is unique across the life of the PHP process.
 766   *
 767   * @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
 768   *
 769   * @staticvar int $id_counter
 770   *
 771   * @param string $prefix Prefix for the returned ID.
 772   * @return string Unique ID.
 773   */
 774  function twentytwenty_unique_id( $prefix = '' ) {
 775      static $id_counter = 0;
 776      if ( function_exists( 'wp_unique_id' ) ) {
 777          return wp_unique_id( $prefix );
 778      }
 779      return $prefix . (string) ++$id_counter;
 780  }


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7