[ 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      $page_template = get_page_template_slug( $post_id );
 236  
 237      /**
 238       * Filters post types array
 239       *
 240       * This filter can be used to hide post meta information of post, page or custom post type registerd by child themes or plugins
 241       *
 242       * @since 1.0.0
 243       *
 244       * @param array Array of post types
 245       */
 246      $disallowed_post_types = apply_filters( 'twentytwenty_disallowed_post_types_for_meta_output', array( 'page' ) );
 247      // Check whether the post type is allowed to output post meta.
 248      if ( in_array( get_post_type( $post_id ), $disallowed_post_types, true ) ) {
 249          return;
 250      }
 251  
 252      $post_meta_wrapper_classes = '';
 253      $post_meta_classes         = '';
 254  
 255      // Get the post meta settings for the location specified.
 256      if ( 'single-top' === $location ) {
 257          /**
 258          * Filters post meta info visibility
 259          *
 260          * Use this filter to hide post meta information like Author, Post date, Comments, Is sticky status
 261          *
 262          * @since 1.0.0
 263          *
 264          * @param array $args {
 265          *  @type string 'author'
 266          *  @type string 'post-date'
 267          *  @type string 'comments'
 268          *  @type string  'sticky'
 269          * }
 270          */
 271          $post_meta                 = apply_filters(
 272              'twentytwenty_post_meta_location_single_top',
 273              array(
 274                  'author',
 275                  'post-date',
 276                  'comments',
 277                  'sticky',
 278              )
 279          );
 280          $post_meta_wrapper_classes = ' post-meta-single post-meta-single-top';
 281  
 282      } elseif ( 'single-bottom' === $location ) {
 283  
 284          /**
 285          * Filters post tags visibility
 286          *
 287          * Use this filter to hide post tags
 288          *
 289          * @since 1.0.0
 290          *
 291          * @param array $args {
 292          *   @type string 'tags'
 293          * }
 294          */
 295          $post_meta                 = apply_filters(
 296              'twentytwenty_post_meta_location_single_bottom',
 297              array(
 298                  'tags',
 299              )
 300          );
 301          $post_meta_wrapper_classes = ' post-meta-single post-meta-single-bottom';
 302  
 303      }
 304  
 305      // If the post meta setting has the value 'empty', it's explicitly empty and the default post meta shouldn't be output.
 306      if ( $post_meta && ! in_array( 'empty', $post_meta, true ) ) {
 307  
 308          // Make sure we don't output an empty container.
 309          $has_meta = false;
 310  
 311          global $post;
 312          $the_post = get_post( $post_id );
 313          setup_postdata( $the_post );
 314  
 315          ob_start();
 316  
 317          ?>
 318  
 319          <div class="post-meta-wrapper<?php echo esc_attr( $post_meta_wrapper_classes ); ?>">
 320  
 321              <ul class="post-meta<?php echo esc_attr( $post_meta_classes ); ?>">
 322  
 323                  <?php
 324  
 325                  /**
 326                   * Fires before post meta html display.
 327                   *
 328                   * Allow output of additional post meta info to be added by child themes and plugins.
 329                   *
 330                   * @since 1.0.0
 331                   *
 332                   * @param int   $post_ID Post ID.
 333                   */
 334                  do_action( 'twentytwenty_start_of_post_meta_list', $post_id );
 335  
 336                  // Author.
 337                  if ( in_array( 'author', $post_meta, true ) ) {
 338  
 339                      $has_meta = true;
 340                      ?>
 341                      <li class="post-author meta-wrapper">
 342                          <span class="meta-icon">
 343                              <span class="screen-reader-text"><?php _e( 'Post author', 'twentytwenty' ); ?></span>
 344                              <?php twentytwenty_the_theme_svg( 'user' ); ?>
 345                          </span>
 346                          <span class="meta-text">
 347                              <?php
 348                              printf(
 349                                  /* translators: %s: Author name */
 350                                  __( 'By %s', 'twentytwenty' ),
 351                                  '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author_meta( 'display_name' ) ) . '</a>'
 352                              );
 353                              ?>
 354                          </span>
 355                      </li>
 356                      <?php
 357  
 358                  }
 359  
 360                  // Post date.
 361                  if ( in_array( 'post-date', $post_meta, true ) ) {
 362  
 363                      $has_meta = true;
 364                      ?>
 365                      <li class="post-date">
 366                          <a class="meta-wrapper" href="<?php the_permalink(); ?>">
 367                              <span class="meta-icon">
 368                                  <span class="screen-reader-text"><?php _e( 'Post date', 'twentytwenty' ); ?></span>
 369                                  <?php twentytwenty_the_theme_svg( 'calendar' ); ?>
 370                              </span>
 371                              <span class="meta-text">
 372                                  <?php the_time( get_option( 'date_format' ) ); ?>
 373                              </span>
 374                          </a>
 375                      </li>
 376                      <?php
 377  
 378                  }
 379  
 380                  // Categories.
 381                  if ( in_array( 'categories', $post_meta, true ) && has_category() ) {
 382  
 383                      $has_meta = true;
 384                      ?>
 385                      <li class="post-categories meta-wrapper">
 386                          <span class="meta-icon">
 387                              <span class="screen-reader-text"><?php _e( 'Categories', 'twentytwenty' ); ?></span>
 388                              <?php twentytwenty_the_theme_svg( 'folder' ); ?>
 389                          </span>
 390                          <span class="meta-text">
 391                              <?php _ex( 'In', 'A string that is output before one or more categories', 'twentytwenty' ); ?> <?php the_category( ', ' ); ?>
 392                          </span>
 393                      </li>
 394                      <?php
 395  
 396                  }
 397  
 398                  // Tags.
 399                  if ( in_array( 'tags', $post_meta, true ) && has_tag() ) {
 400  
 401                      $has_meta = true;
 402                      ?>
 403                      <li class="post-tags meta-wrapper">
 404                          <span class="meta-icon">
 405                              <span class="screen-reader-text"><?php _e( 'Tags', 'twentytwenty' ); ?></span>
 406                              <?php twentytwenty_the_theme_svg( 'tag' ); ?>
 407                          </span>
 408                          <span class="meta-text">
 409                              <?php the_tags( '', ', ', '' ); ?>
 410                          </span>
 411                      </li>
 412                      <?php
 413  
 414                  }
 415  
 416                  // Comments link.
 417                  if ( in_array( 'comments', $post_meta, true ) && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
 418  
 419                      $has_meta = true;
 420                      ?>
 421                      <li class="post-comment-link meta-wrapper">
 422                          <span class="meta-icon">
 423                              <?php twentytwenty_the_theme_svg( 'comment' ); ?>
 424                          </span>
 425                          <span class="meta-text">
 426                              <?php comments_popup_link(); ?>
 427                          </span>
 428                      </li>
 429                      <?php
 430  
 431                  }
 432  
 433                  // Sticky.
 434                  if ( in_array( 'sticky', $post_meta, true ) && is_sticky() ) {
 435  
 436                      $has_meta = true;
 437                      ?>
 438                      <li class="post-sticky meta-wrapper">
 439                          <span class="meta-icon">
 440                              <?php twentytwenty_the_theme_svg( 'bookmark' ); ?>
 441                          </span>
 442                          <span class="meta-text">
 443                              <?php _e( 'Sticky post', 'twentytwenty' ); ?>
 444                          </span>
 445                      </li>
 446                      <?php
 447  
 448                  }
 449  
 450                  /**
 451                   * Fires after post meta html display.
 452                   *
 453                   * Allow output of additional post meta info to be added by child themes and plugins.
 454                   *
 455                   * @since 1.0.0
 456                   *
 457                   * @param int   $post_ID Post ID.
 458                   */
 459                  do_action( 'twentytwenty_end_of_post_meta_list', $post_id );
 460  
 461                  ?>
 462  
 463              </ul><!-- .post-meta -->
 464  
 465          </div><!-- .post-meta-wrapper -->
 466  
 467          <?php
 468  
 469          wp_reset_postdata();
 470  
 471          $meta_output = ob_get_clean();
 472  
 473          // If there is meta to output, return it.
 474          if ( $has_meta && $meta_output ) {
 475  
 476              return $meta_output;
 477  
 478          }
 479      }
 480  
 481  }
 482  
 483  /**
 484   * Menus
 485   */
 486  /**
 487   * Filter Classes of wp_list_pages items to match menu items.
 488   * Filter the class applied to wp_list_pages() items with children to match the menu class, to simplify.
 489   * styling of sub levels in the fallback. Only applied if the match_menu_classes argument is set.
 490   *
 491   * @param array  $css_class CSS Class names.
 492   * @param string $item Comment.
 493   * @param int    $depth Depth of the current comment.
 494   * @param array  $args An array of arguments.
 495   * @param string $current_page Whether or not the item is the current item.
 496   *
 497   * @return array $css_class CSS Class names.
 498   */
 499  function twentytwenty_filter_wp_list_pages_item_classes( $css_class, $item, $depth, $args, $current_page ) {
 500  
 501      // Only apply to wp_list_pages() calls with match_menu_classes set to true.
 502      $match_menu_classes = isset( $args['match_menu_classes'] );
 503  
 504      if ( ! $match_menu_classes ) {
 505          return $css_class;
 506      }
 507  
 508      // Add current menu item class.
 509      if ( in_array( 'current_page_item', $css_class, true ) ) {
 510          $css_class[] = 'current-menu-item';
 511      }
 512  
 513      // Add menu item has children class.
 514      if ( in_array( 'page_item_has_children', $css_class, true ) ) {
 515          $css_class[] = 'menu-item-has-children';
 516      }
 517  
 518      return $css_class;
 519  
 520  }
 521  
 522  add_filter( 'page_css_class', 'twentytwenty_filter_wp_list_pages_item_classes', 10, 5 );
 523  
 524  /**
 525   * Add a Sub Nav Toggle to the Expanded Menu and Mobile Menu.
 526   *
 527   * @param stdClass $args An array of arguments.
 528   * @param string   $item Menu item.
 529   * @param int      $depth Depth of the current menu item.
 530   *
 531   * @return stdClass $args An object of wp_nav_menu() arguments.
 532   */
 533  function twentytwenty_add_sub_toggles_to_main_menu( $args, $item, $depth ) {
 534  
 535      // Add sub menu toggles to the Expanded Menu with toggles.
 536      if ( isset( $args->show_toggles ) && $args->show_toggles ) {
 537  
 538          // Wrap the menu item link contents in a div, used for positioning.
 539          $args->before = '<div class="ancestor-wrapper">';
 540          $args->after  = '';
 541  
 542          // Add a toggle to items with children.
 543          if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
 544  
 545              $toggle_target_string = '.menu-modal .menu-item-' . $item->ID . ' > .sub-menu';
 546              $toggle_duration      = twentytwenty_toggle_duration();
 547  
 548              // Add the sub menu toggle.
 549              $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>';
 550  
 551          }
 552  
 553          // Close the wrapper.
 554          $args->after .= '</div><!-- .ancestor-wrapper -->';
 555  
 556          // Add sub menu icons to the primary menu without toggles.
 557      } elseif ( 'primary' === $args->theme_location ) {
 558          if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
 559              $args->after = '<span class="icon"></span>';
 560          } else {
 561              $args->after = '';
 562          }
 563      }
 564  
 565      return $args;
 566  
 567  }
 568  
 569  add_filter( 'nav_menu_item_args', 'twentytwenty_add_sub_toggles_to_main_menu', 10, 3 );
 570  
 571  /**
 572   * Display SVG icons in social links menu.
 573   *
 574   * @param  string  $item_output The menu item output.
 575   * @param  WP_Post $item        Menu item object.
 576   * @param  int     $depth       Depth of the menu.
 577   * @param  array   $args        wp_nav_menu() arguments.
 578   * @return string  $item_output The menu item output with social icon.
 579   */
 580  function twentytwenty_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
 581      // Change SVG icon inside social links menu if there is supported URL.
 582      if ( 'social' === $args->theme_location ) {
 583          $svg = TwentyTwenty_SVG_Icons::get_social_link_svg( $item->url );
 584          if ( empty( $svg ) ) {
 585              $svg = twentytwenty_get_theme_svg( 'link' );
 586          }
 587          $item_output = str_replace( $args->link_after, '</span>' . $svg, $item_output );
 588      }
 589  
 590      return $item_output;
 591  }
 592  
 593  add_filter( 'walker_nav_menu_start_el', 'twentytwenty_nav_menu_social_icons', 10, 4 );
 594  
 595  /**
 596   * Classes
 597   */
 598  /**
 599   * Add No-JS Class.
 600   * If we're missing JavaScript support, the HTML element will have a no-js class.
 601   */
 602  function twentytwenty_no_js_class() {
 603  
 604      ?>
 605      <script>document.documentElement.className = document.documentElement.className.replace( 'no-js', 'js' );</script>
 606      <?php
 607  
 608  }
 609  
 610  add_action( 'wp_head', 'twentytwenty_no_js_class' );
 611  
 612  /**
 613   * Add conditional body classes.
 614   *
 615   * @param array $classes Classes added to the body tag.
 616   *
 617   * @return array $classes Classes added to the body tag.
 618   */
 619  function twentytwenty_body_classes( $classes ) {
 620  
 621      global $post;
 622      $post_type = isset( $post ) ? $post->post_type : false;
 623  
 624      // Check whether we're singular.
 625      if ( is_singular() ) {
 626          $classes[] = 'singular';
 627      }
 628  
 629      // Check whether the current page should have an overlay header.
 630      if ( is_page_template( array( 'templates/template-cover.php' ) ) ) {
 631          $classes[] = 'overlay-header';
 632      }
 633  
 634      // Check whether the current page has full-width content.
 635      if ( is_page_template( array( 'templates/template-full-width.php' ) ) ) {
 636          $classes[] = 'has-full-width-content';
 637      }
 638  
 639      // Check for enabled search.
 640      if ( true === get_theme_mod( 'enable_header_search', true ) ) {
 641          $classes[] = 'enable-search-modal';
 642      }
 643  
 644      // Check for post thumbnail.
 645      if ( is_singular() && has_post_thumbnail() ) {
 646          $classes[] = 'has-post-thumbnail';
 647      } elseif ( is_singular() ) {
 648          $classes[] = 'missing-post-thumbnail';
 649      }
 650  
 651      // Check whether we're in the customizer preview.
 652      if ( is_customize_preview() ) {
 653          $classes[] = 'customizer-preview';
 654      }
 655  
 656      // Check if posts have single pagination.
 657      if ( is_single() && ( get_next_post() || get_previous_post() ) ) {
 658          $classes[] = 'has-single-pagination';
 659      } else {
 660          $classes[] = 'has-no-pagination';
 661      }
 662  
 663      // Check if we're showing comments.
 664      if ( $post && ( ( 'post' === $post_type || comments_open() || get_comments_number() ) && ! post_password_required() ) ) {
 665          $classes[] = 'showing-comments';
 666      } else {
 667          $classes[] = 'not-showing-comments';
 668      }
 669  
 670      // Check if avatars are visible.
 671      $classes[] = get_option( 'show_avatars' ) ? 'show-avatars' : 'hide-avatars';
 672  
 673      // Slim page template class names (class = name - file suffix).
 674      if ( is_page_template() ) {
 675          $classes[] = basename( get_page_template_slug(), '.php' );
 676      }
 677  
 678      // Check for the elements output in the top part of the footer.
 679      $has_footer_menu = has_nav_menu( 'footer' );
 680      $has_social_menu = has_nav_menu( 'social' );
 681      $has_sidebar_1   = is_active_sidebar( 'sidebar-1' );
 682      $has_sidebar_2   = is_active_sidebar( 'sidebar-2' );
 683  
 684      // Add a class indicating whether those elements are output.
 685      if ( $has_footer_menu || $has_social_menu || $has_sidebar_1 || $has_sidebar_2 ) {
 686          $classes[] = 'footer-top-visible';
 687      } else {
 688          $classes[] = 'footer-top-hidden';
 689      }
 690  
 691      // Get header/footer background color.
 692      $header_footer_background = get_theme_mod( 'header_footer_background_color', '#ffffff' );
 693      $header_footer_background = strtolower( '#' . ltrim( $header_footer_background, '#' ) );
 694  
 695      // Get content background color.
 696      $background_color = get_theme_mod( 'background_color', 'f5efe0' );
 697      $background_color = strtolower( '#' . ltrim( $background_color, '#' ) );
 698  
 699      // Add extra class if main background and header/footer background are the same color.
 700      if ( $background_color === $header_footer_background ) {
 701          $classes[] = 'reduced-spacing';
 702      }
 703  
 704      return $classes;
 705  
 706  }
 707  
 708  add_filter( 'body_class', 'twentytwenty_body_classes' );
 709  
 710  /**
 711   * Archives
 712   */
 713  /**
 714   * Filters the archive title and styles the word before the first colon.
 715   *
 716   * @param string $title Current archive title.
 717   *
 718   * @return string $title Current archive title.
 719   */
 720  function twentytwenty_get_the_archive_title( $title ) {
 721  
 722      $regex = apply_filters(
 723          'twentytwenty_get_the_archive_title_regex',
 724          array(
 725              'pattern'     => '/(\A[^\:]+\:)/',
 726              'replacement' => '<span class="color-accent">$1</span>',
 727          )
 728      );
 729  
 730      if ( empty( $regex ) ) {
 731  
 732          return $title;
 733  
 734      }
 735  
 736      return preg_replace( $regex['pattern'], $regex['replacement'], $title );
 737  
 738  }
 739  
 740  add_filter( 'get_the_archive_title', 'twentytwenty_get_the_archive_title' );
 741  
 742  /**
 743   * Miscellaneous
 744   */
 745  /**
 746   * Toggle animation duration in milliseconds.
 747   *
 748   * @return integer Duration in milliseconds
 749   */
 750  function twentytwenty_toggle_duration() {
 751      /**
 752       * Filters the animation duration/speed used usually for submenu toggles.
 753       *
 754       * @since 1.0
 755       *
 756       * @param integer $duration Duration in milliseconds.
 757       */
 758      $duration = apply_filters( 'twentytwenty_toggle_duration', 250 );
 759  
 760      return $duration;
 761  }
 762  
 763  /**
 764   * Get unique ID.
 765   *
 766   * This is a PHP implementation of Underscore's uniqueId method. A static variable
 767   * contains an integer that is incremented with each call. This number is returned
 768   * with the optional prefix. As such the returned value is not universally unique,
 769   * but it is unique across the life of the PHP process.
 770   *
 771   * @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
 772   *
 773   * @staticvar int $id_counter
 774   *
 775   * @param string $prefix Prefix for the returned ID.
 776   * @return string Unique ID.
 777   */
 778  function twentytwenty_unique_id( $prefix = '' ) {
 779      static $id_counter = 0;
 780      if ( function_exists( 'wp_unique_id' ) ) {
 781          return wp_unique_id( $prefix );
 782      }
 783      return $prefix . (string) ++$id_counter;
 784  }


Generated: Fri Oct 25 08:20:01 2019 Cross-referenced by PHPXref 0.7