Last active
January 18, 2020 23:24
-
-
Save westonruter/7ce1e6270aa5b1bd9e66a3f0adf93b07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Add Assets before wp_enqueue_scripts | |
* Description: Test case to debug AMP plugin source attribution problems. | |
* Author: Weston Ruter | |
* Author URI: https://weston.ruter.net/ | |
* Plugin URI: https://amp-wp.org | |
* License: GPLv2 or later | |
*/ | |
namespace Add_Assets_Before_WP_Enqueue_Scripts; | |
/** | |
* Register styles. | |
* | |
* @param \WP_Styles $styles Styles. | |
*/ | |
function register_styles( \WP_Styles $styles ) { | |
$styles->add( | |
'stylesheet-registered-at-default-styles', | |
plugin_dir_url( __FILE__ ) . 'stylesheet-registered-at-default-styles.css' | |
); | |
} | |
add_action( 'wp_default_styles', __NAMESPACE__ . '\register_styles' ); | |
/** | |
* Register scripts. | |
* | |
* @param \WP_Scripts $scripts Scripts. | |
*/ | |
function register_scripts( \WP_Scripts $scripts ) { | |
$scripts->add( | |
'script-registered-at-default-scripts', | |
plugin_dir_url( __FILE__ ) . 'script-registered-at-default-scripts.js' | |
); | |
} | |
add_action( 'wp_default_scripts', __NAMESPACE__ . '\register_scripts' ); | |
/** | |
* Enqueue styles at init. | |
*/ | |
function enqueue_stylesheet_at_init() { | |
global $pagenow; | |
if ( is_admin() || 'index.php' !== $pagenow ) { | |
return; | |
} | |
wp_enqueue_style( | |
'stylesheet-enqueued-at-init', | |
plugin_dir_url( __FILE__ ) . 'stylesheet-enqueued-at-init.css', | |
[], | |
'0.1' | |
); | |
wp_enqueue_style( 'stylesheet-registered-at-default-styles' ); | |
wp_enqueue_script( | |
'script-enqueued-at-init', | |
plugin_dir_url( __FILE__ ) . 'script-enqueued-at-init.js', | |
[], | |
'0.1', | |
true | |
); | |
wp_enqueue_script( 'script-registered-at-default-scripts' ); | |
} | |
add_action( 'init', __NAMESPACE__ . '\enqueue_stylesheet_at_init', 100 ); | |
/** | |
* Add inline style. | |
*/ | |
function add_inline_theme_stylesheet() { | |
wp_enqueue_style( 'stylesheet-enqueued-normally' ); | |
wp_enqueue_style( | |
'script-enqueued-normally', | |
plugin_dir_url( __FILE__ ) . 'stylesheet-enqueued-normally.css', | |
[], | |
'0.1' | |
); | |
wp_enqueue_script( 'script-enqueued-normally' ); | |
wp_enqueue_script( | |
'script-enqueued-normally', | |
plugin_dir_url( __FILE__ ) . 'script-enqueued-normally.js', | |
[], | |
'0.1', | |
true | |
); | |
wp_add_inline_style( get_stylesheet() . '-style', 'body { border-left: solid 50px lime; }' ); | |
} | |
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\add_inline_theme_stylesheet', 11 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.info('script-enqueued-at-init'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.info('script-enqueued-normally'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.info('script-registered-at-default-scripts'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
border-right: solid 50px blue !important; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
border-bottom: solid 50px yellow !important; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
border-top: solid 50px red !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment