Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Admin PWA
  • Loading branch information
ellatrix committed Jun 30, 2021
commit 8807607cc95f5abc445005c130b0ecb0109989ac
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,12 @@
"markdown_source": "../packages/e2e-tests/README.md",
"parent": "packages"
},
{
"title": "@wordpress/edit-dashboard",
"slug": "packages-edit-dashboard",
"markdown_source": "../packages/edit-dashboard/README.md",
"parent": "packages"
},
{
"title": "@wordpress/edit-navigation",
"slug": "packages-edit-navigation",
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/navigation-page.php';
require __DIR__ . '/experiments-page.php';
require __DIR__ . '/global-styles.php';
require __DIR__ . '/pwa.php';

require __DIR__ . '/block-supports/generated-classname.php';
require __DIR__ . '/block-supports/elements.php';
Expand Down
45 changes: 45 additions & 0 deletions lib/manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Progressive Web App Manifest
*
* @package gutenberg
*/

global $_wp_admin_css_colors;

$color_scheme = get_user_option( 'admin_color' );
$colors = $_wp_admin_css_colors[ $color_scheme ]->colors;
$admin_bar_color = $colors[0];
$body_background = '#f1f1f1';

$icon_sizes = array( 32, 180, 192, 270, 512 );

// Ideally we have the WordPress logo as the default app logo in the sizes
// below.
$icons = array();

if ( has_site_icon() ) {
$type = wp_check_filetype( get_site_icon_url() );

foreach ( $icon_sizes as $size ) {
$icons[] = array(
'src' => get_site_icon_url( $size ),
'sizes' => $size . 'x' . $size,
'type' => $type['type'],
);
}
}

wp_send_json(
array(
'name' => get_bloginfo( 'name' ),
'icons' => $icons,
'background_color' => $body_background,
'theme_color' => $admin_bar_color,
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => admin_url(),
// Open front-end, login page, and any external URLs in a browser modal.
'scope' => admin_url(),
)
);
27 changes: 27 additions & 0 deletions lib/pwa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Progressive Web App
*
* @package gutenberg
*/

add_filter(
'admin_head',
function() {
// Move to the wp-admin folder when merging with core.
$manifest_url = admin_url() . '/?manifest';
echo '<link rel="manifest" href="' . $manifest_url . '">';
}
);

add_filter(
'load-index.php',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PWA plugin makes use of admin-ajax.php for serving the service worker which also works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we could do that too :)

function() {
if ( ! isset( $_GET['manifest'] ) ) {
return;
}

require_once __DIR__ . '/manifest.php';
exit;
}
);