diff --git a/amp.php b/amp.php index 76164b750c1..73b7aed5a79 100644 --- a/amp.php +++ b/amp.php @@ -5,7 +5,7 @@ * Plugin URI: https://amp-wp.org * Author: AMP Project Contributors * Author URI: https://github.com/ampproject/amp-wp/graphs/contributors - * Version: 1.1.1 + * Version: 1.2-alpha * Text Domain: amp * Domain Path: /languages/ * License: GPLv2 or later @@ -14,108 +14,118 @@ */ /** - * Print admin notice regarding having an old version of PHP. + * Errors encountered while loading the plugin. * - * @since 0.7 + * This has to be a global for the same of PHP 5.2. + * + * @var \WP_Error $_amp_load_errors */ -function _amp_print_php_version_admin_notice() { - ?> -
-

- -

-
- add( + 'insufficient_php_version', + sprintf( + /* translators: %s: required PHP version */ + __( 'The AMP plugin requires PHP %s. Please contact your host to update your PHP version.', 'amp' ), + '5.4+' + ) + ); } -/** - * Print admin notice regarding DOM extension is not installed. - * - * @since 1.0 - */ -function _amp_print_php_dom_document_notice() { - ?> -
-

- -

-
- 0 ) { + foreach ( $_amp_missing_extensions as &$_amp_missing_extension ) { + $_amp_missing_extension = "$_amp_missing_extension"; // Not using array_map() w/ closure due to PHP 5.2 support. + } -/** - * Print admin notice regarding DOM extension is not installed. - * - * @since 1.0.1 - */ -function _amp_print_php_missing_iconv_notice() { - ?> -
-

- -

-
- add( + 'missing_extension', + sprintf( + /* translators: %s is list of missing extensions */ + _n( + 'The following PHP extension is missing: %s. Please contact your host to finish installation.', + 'The following PHP extensions are missing: %s. Please contact your host to finish installation.', + count( $_amp_missing_extensions ), + 'amp' + ), + implode( ', ', $_amp_missing_extensions ) + ) + ); } -if ( ! function_exists( 'iconv' ) ) { - add_action( 'admin_notices', '_amp_print_php_missing_iconv_notice' ); - return; +unset( $_amp_required_extensions, $_amp_missing_extensions, $_amp_required_extension, $_amp_missing_extension ); + +if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) || ! file_exists( __DIR__ . '/vendor/sabberworm/php-css-parser' ) || ! file_exists( __DIR__ . '/assets/js/amp-block-editor-toggle-compiled.js' ) ) { + $_amp_load_errors->add( + 'build_required', + sprintf( + /* translators: %s: composer install && npm install && npm run build */ + __( 'You appear to be running the AMP plugin from source. Please do %s to finish installation.', 'amp' ), // phpcs:ignore WordPress.Security.EscapeOutput + 'composer install && npm install && npm run build' + ) + ); } /** - * Print admin notice when composer install has not been performed. + * Displays an admin notice about why the plugin is unable to load. * - * @since 1.0 + * @since 1.1.2 + * @global \WP_Error $_amp_load_errors */ -function _amp_print_build_needed_notice() { +function _amp_show_load_errors_admin_notice() { + global $_amp_load_errors; ?>

- composer install && npm install && npm run build' - ); - ?> + +

errors ) ) { + add_action( 'admin_notices', '_amp_show_load_errors_admin_notice' ); + if ( defined( 'WP_CLI' ) && WP_CLI ) { + $messages = array( __( 'AMP plugin unable to initialize.', 'amp' ) ); + foreach ( array_keys( $_amp_load_errors->errors ) as $error_code ) { + $messages = array_merge( $messages, $_amp_load_errors->get_error_messages( $error_code ) ); + } + $message = implode( "\n * ", $messages ); + $message = str_replace( array( '', '' ), '`', $message ); + WP_CLI::warning( $message ); + } return; } define( 'AMP__FILE__', __FILE__ ); define( 'AMP__DIR__', dirname( __FILE__ ) ); -define( 'AMP__VERSION', '1.1.1' ); +define( 'AMP__VERSION', '1.2-alpha' ); /** * Print admin notice if plugin installed with incorrect slug (which impacts WordPress's auto-update system). @@ -262,14 +272,11 @@ function amp_init() { add_action( 'wp_loaded', 'amp_add_options_menu' ); add_action( 'wp_loaded', 'amp_admin_pointer' ); add_action( 'parse_query', 'amp_correct_query_when_is_front_page' ); + add_action( 'admin_bar_menu', 'amp_add_admin_bar_view_link', 100 ); // Redirect the old url of amp page to the updated url. add_filter( 'old_slug_redirect_url', 'amp_redirect_old_slug_to_new_url' ); - if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && version_compare( JETPACK__VERSION, '6.2-alpha', '<' ) ) { - require_once AMP__DIR__ . '/jetpack-helper.php'; - } - // Add actions for legacy post templates. add_action( 'wp', 'amp_maybe_add_actions' ); diff --git a/includes/sanitizers/class-amp-nav-menu-toggle-sanitizer.php b/includes/sanitizers/class-amp-nav-menu-toggle-sanitizer.php index af4eb43bf8b..0e8cd72e9d2 100644 --- a/includes/sanitizers/class-amp-nav-menu-toggle-sanitizer.php +++ b/includes/sanitizers/class-amp-nav-menu-toggle-sanitizer.php @@ -99,6 +99,11 @@ public function sanitize() { $script_el->appendChild( $this->dom->createTextNode( wp_json_encode( $expanded ) ) ); $state_el->appendChild( $script_el ); $nav_el->parentNode->insertBefore( $state_el, $nav_el ); + if ( 'body' === $nav_el->nodeName ) { + $nav_el->insertBefore( $state_el, $nav_el->firstChild ); + } else { + $nav_el->parentNode->insertBefore( $state_el, $nav_el ); + } $button_on = sprintf( "tap:AMP.setState({ $state_id: ! $state_id })" ); $button_el->setAttribute( 'on', $button_on ); diff --git a/readme.md b/readme.md index 480c52b421e..c0b4fcbf266 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ Enable AMP on your WordPress site, the WordPress way. **Contributors:** [automattic](https://profiles.wordpress.org/automattic), [xwp](https://profiles.wordpress.org/xwp), [google](https://profiles.wordpress.org/google), [westonruter](https://profiles.wordpress.org/westonruter), [ryankienstra](https://profiles.wordpress.org/ryankienstra), [batmoo](https://profiles.wordpress.org/batmoo), [stubgo](https://profiles.wordpress.org/stubgo), [albertomedina](https://profiles.wordpress.org/albertomedina), [tweetythierry](https://profiles.wordpress.org/tweetythierry), [joshuawold](https://profiles.wordpress.org/joshuawold), [postphotos](https://profiles.wordpress.org/postphotos) **Tags:** [amp](https://wordpress.org/plugins/tags/amp), [mobile](https://wordpress.org/plugins/tags/mobile) **Requires at least:** 4.9 -**Tested up to:** 5.1 +**Tested up to:** 5.2 **Stable tag:** 1.1.1 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 5.4 diff --git a/readme.txt b/readme.txt index 13e9de444bc..972b3010be4 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: automattic, xwp, google, westonruter, ryankienstra, batmoo, stubgo, albertomedina, tweetythierry, joshuawold, postphotos Tags: amp, mobile Requires at least: 4.9 -Tested up to: 5.1 +Tested up to: 5.2 Stable tag: 1.1.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html