[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> view-transitions.php (source)

   1  <?php
   2  /**
   3   * View Transitions API.
   4   *
   5   * @package WordPress
   6   * @subpackage View Transitions
   7   * @since 7.0.0
   8   */
   9  
  10  /**
  11   * Enqueues View Transitions CSS for the admin.
  12   *
  13   * To disable admin View Transitions, dequeue the `wp-view-transitions-admin` style at the
  14   * {@see 'admin_enqueue_scripts'} action, rather than unhooking this function.
  15   *
  16   * @since 7.0.0
  17   * @since 7.2.0 Called from wp-admin/admin-header.php instead of hooked to {@see 'admin_enqueue_scripts'}.
  18   */
  19  function wp_enqueue_view_transitions_admin_css(): void {
  20      wp_enqueue_style( 'wp-view-transitions-admin' );
  21  }
  22  
  23  /**
  24   * Gets the CSS for View Transitions in the admin.
  25   *
  26   * @since 7.0.0
  27   *
  28   * @return string The CSS.
  29   */
  30  function wp_get_view_transitions_admin_css(): string {
  31      $affix = SCRIPT_DEBUG ? '' : '.min';
  32      $path  = ABSPATH . "wp-admin/css/view-transitions{$affix}.css";
  33      return (string) file_get_contents( $path );
  34  }
  35  
  36  /**
  37   * Prints a render-blocking expectation so View Transitions capture a fully parsed admin menu.
  38   *
  39   * A cross-document view transition snapshots the incoming page at its first render, which can
  40   * happen before the `<body>` has finished parsing. The snapshot would then capture a partially
  41   * built page — for example an incomplete admin menu — and the transition animates to or from
  42   * the wrong state.
  43   *
  44   * The `expect` link blocks the first render until `#wpcontent` is parsed. Rendering is unblocked
  45   * as soon as the target's start tag is parsed, not its children, so the target is the element
  46   * right after the admin menu rather than the menu itself: once `#wpcontent` starts, the whole
  47   * menu has been parsed. Targeting an element near the end of the body would also work, but it
  48   * would delay the first render by the time it takes to parse all of the page content. The media
  49   * query limits the first-render delay to when view transitions can run, matching the
  50   * `@view-transition` rule in view-transitions.css. It does not detect whether a transition is
  51   * actually in progress, so a reload or a direct visit is also held until `#wpcontent` is parsed,
  52   * but since that element starts right after the admin menu, the delay is negligible.
  53   *
  54   * Nothing is printed unless the admin View Transitions style has already been printed, since
  55   * there is otherwise no transition to wait for. That style is only enqueued from
  56   * wp-admin/admin-header.php, so this also leaves out iframe screens such as Thickbox modals,
  57   * which have no `#wpcontent`: an `expect` link whose target never appears blocks the first
  58   * render until the whole document has been parsed.
  59   *
  60   * @since 7.2.0
  61   *
  62   * @link https://html.spec.whatwg.org/multipage/links.html#link-type-expect
  63   */
  64  function wp_print_view_transitions_render_blocking_link(): void {
  65      if ( ! wp_style_is( 'wp-view-transitions-admin', 'done' ) ) {
  66          return;
  67      }
  68  
  69      echo '<link rel="expect" href="#wpcontent" blocking="render" media="(prefers-reduced-motion: no-preference)">' . "\n";
  70  }


Generated : Wed Nov 11 08:20:02 2026 Cross-referenced by PHPXref