Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce stylesheet prioritization when determining which to concatenate #2346

Merged
merged 14 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
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
27 changes: 17 additions & 10 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,23 +931,14 @@ function() {
PHP_INT_MAX
);

add_action( 'admin_bar_init', array( __CLASS__, 'init_admin_bar' ) );
add_action( 'wp_head', 'amp_add_generator_metadata', 20 );
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 0 ); // Enqueue before theme's styles.
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'dequeue_customize_preview_scripts' ), 1000 );
add_filter( 'customize_partial_render', array( __CLASS__, 'filter_customize_partial_render' ) );

add_action( 'wp_footer', 'amp_print_analytics' );

/*
* Disable admin bar because admin-bar.css (28K) and Dashicons (48K) alone
* combine to surpass the 50K limit imposed for the amp-custom style.
*/
if ( AMP_Options_Manager::get_option( 'disable_admin_bar' ) ) {
add_filter( 'show_admin_bar', '__return_false', 100 );
} else {
add_action( 'admin_bar_init', array( __CLASS__, 'init_admin_bar' ) );
}

/*
* Start output buffering at very low priority for sake of plugins and themes that use template_redirect
* instead of template_include.
Expand Down Expand Up @@ -1299,6 +1290,22 @@ function() {
41
);

// Convert admin bar bump callback into an inline style for admin-bar. See \WP_Admin_Bar::initialize().
if ( current_theme_supports( 'admin-bar' ) ) {
$admin_bar_args = get_theme_support( 'admin-bar' );
$header_callback = $admin_bar_args[0]['callback'];
} else {
$header_callback = '_admin_bar_bump_cb';
}
remove_action( 'wp_head', $header_callback );
if ( '__return_false' !== $header_callback ) {
ob_start();
call_user_func( $header_callback );
$style = ob_get_clean();
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $style ) ); // See wp_add_inline_style().
wp_add_inline_style( 'admin-bar', $data );
}

// Emulate customize support script in PHP, to assume Customizer.
add_filter(
'body_class',
Expand Down
2 changes: 0 additions & 2 deletions includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AMP_Options_Manager {
'analytics' => array(),
'auto_accept_sanitization' => true,
'accept_tree_shaking' => true,
'disable_admin_bar' => false,
'all_templates_supported' => true,
'supported_templates' => array( 'is_singular' ),
'enable_response_caching' => true,
Expand Down Expand Up @@ -137,7 +136,6 @@ public static function validate_options( $new_options ) {

$options['auto_accept_sanitization'] = ! empty( $new_options['auto_accept_sanitization'] );
$options['accept_tree_shaking'] = ! empty( $new_options['accept_tree_shaking'] );
$options['disable_admin_bar'] = ! empty( $new_options['disable_admin_bar'] );
$options['enable_amp_stories'] = ! empty( $new_options['enable_amp_stories'] );

// Validate post type support.
Expand Down
10 changes: 0 additions & 10 deletions includes/options/class-amp-options-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,6 @@ public function render_validation_handling() {
updateHiddenClasses();
})( jQuery );
</script>

<p>
<label for="disable_admin_bar">
<input id="disable_admin_bar" type="checkbox" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[disable_admin_bar]' ); ?>" <?php checked( AMP_Options_Manager::get_option( 'disable_admin_bar' ) ); ?>>
<?php esc_html_e( 'Disable admin bar on AMP pages.', 'amp' ); ?>
</label>
</p>
<p class="description">
<?php esc_html_e( 'An additional stylesheet is required to properly render the admin bar. If the additional stylesheet causes the total CSS to surpass 50KB then the admin bar should be disabled to prevent a validation error or an unstyled admin bar in AMP responses.', 'amp' ); ?>
</p>
</fieldset>
<?php
}
Expand Down
Loading