Skip to content

Commit

Permalink
Add apple_touch_startup_image filter
Browse files Browse the repository at this point in the history
This adds an apple_touch_startup_image filter for plugins/themes to
adjust the rel="apple-touch-startup-image" link tags outputted. This
allows more images to be added, with an applicable media attribute for
each image.

Fixes #586.
  • Loading branch information
jefferyto committed Aug 11, 2021
1 parent 4aa2b8a commit 3cf7846
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions wp-includes/class-wp-web-app-manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,51 @@ public function manifest_link_and_meta() {
?>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">

<?php
$icons = isset( $manifest['icons'] ) ? $manifest['icons'] : array();
usort( $icons, array( $this, 'sort_icons_callback' ) );
$icon = array_shift( $icons );
?>
<?php if ( ! empty( $icon ) ) : ?>
<link rel="apple-touch-startup-image" href="<?php echo esc_url( $icon['src'] ); ?>">
<?php endif; ?>
<?php

$images = array();
if ( ! empty( $icon ) ) {
$images[] = array( 'href' => $icon['src'] );
}

/**
* Filters splash screen images for Safari on iOS.
*
* @param array $images {
* Array of splash screen images and their attributes.
*
* @type array ...$0 {
* Array of splash screen image attributes.
*
* @type string $href URL of splash screen image. Required.
* @type string $media Media query for when the splash screen image should be used.
* }
* }
*/
$images = apply_filters( 'apple_touch_startup_image', $images );

foreach ( $images as $key => $image ) {
if ( ! is_array( $image ) ) {
continue;
}

$url = isset( $image['href'] ) ? esc_url( $image['href'], array( 'http', 'https' ) ) : '';
if ( ! $url ) {
continue;
}

$html = sprintf( 'rel="apple-touch-startup-image" href="%s"', $url );
if ( isset( $image['media'] ) ) {
$html .= sprintf( ' media="%s"', esc_attr( $image['media'] ) );
}
?>
<link <?php echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php
}
break;
endswitch;
?>
Expand Down

0 comments on commit 3cf7846

Please sign in to comment.