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

Fix/864 remove sizes #1045

Closed
wants to merge 216 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
216 commits
Select commit Hold shift + click to select a range
8778ecf
Issue #842: Begin to validate plugins.
Feb 17, 2018
9eccf44
Issue #842: Align equals signs to prevent failed Travis build.
Feb 17, 2018
0d5e50d
Issue #842: Begin plugin callback validation.
Feb 19, 2018
f0c864c
Issue #842: Handle 'Closure' callbacks in get_plugin().
Feb 19, 2018
6c2bbec
Issue #842: Correct an issue in failed Travis build.
Feb 19, 2018
f77e022
Issue #842: Process comments for invalid plugin output.
Feb 20, 2018
780b746
Issue #842: Align equals signs to correct Travis issue.
Feb 20, 2018
33456a7
Issue #842: Output validation errors in header.
Feb 20, 2018
3c47072
Issue #842: Remove list() in favor of array access.
Feb 20, 2018
afdefdf
Issue #842: Align arrows vertically, remove extra constant.
Feb 20, 2018
6c587e2
Issue #842: Use the constant CALLBACK_KEY.
Feb 20, 2018
79856bc
Issue #842: Modify how callback function is called.
Feb 20, 2018
0484bd9
Replace hooks after iterating to prevent infinite loop in PHP<=5.4
westonruter Feb 21, 2018
7a06be3
Issue #842: Remove 'static' from methods, add assertions.
Feb 21, 2018
ab653e8
Issue #842: Register validation error post type.
Feb 21, 2018
ba46389
Issue #842: Store the validation errors in CPT.
Feb 22, 2018
8317283
Issue #842: Store the error URL in metadata.
Feb 22, 2018
4955686
Issue #842: Rename function to register_post_type().
Feb 23, 2018
fda14ea
Issue #842: Rename function to should_validate_front_end().
Feb 23, 2018
f1bf9f3
Issue #842: Change how nodes are processed.
Feb 23, 2018
3d1e6e3
Issue #842: Rename function to capture_current_source().
Feb 23, 2018
74a46f7
Issue #841: Rename property $current_source.
Feb 23, 2018
32a58fc
Issue #842: Change $current_sources to a stack.
Feb 24, 2018
66ab20d
Issue #842: Move get_plugin() into get_source().
Feb 24, 2018
87df66a
Issue #842: Change how the post meta is updated.
Feb 24, 2018
76ec4df
Issue #842: Add the source type to the comment.
Feb 24, 2018
ea16d64
Issue #842: Accommodate plugins and themes in get_source().
Feb 24, 2018
54e15cf
Issue #842: Remove the end of the plugin name.
Feb 24, 2018
7e049ae
Issue #842: Merge in develop, resolve conflicts.
Feb 26, 2018
0263e58
Use name instead of source; pass sources as arg in callback; improve …
westonruter Feb 27, 2018
4d0569f
Issue #842: Display warning on plugin activation.
Feb 28, 2018
fe0e6cc
Harden detection of validation errors caused by plugins
westonruter Mar 1, 2018
1e38e5d
Use add_post_meta() without update_post_meta() to log URL having vali…
westonruter Mar 1, 2018
8684ad1
Issue #842: Output validation errors in a post table.
Mar 1, 2018
0728a1e
Issue #842: Correct Travis issue and use constant.
Mar 1, 2018
2228520
Issue #842: Improve post actions, prevent muliple plugins.
Mar 1, 2018
c2664ca
Issue #842: Add a bulk action 're-check' linkon edit.php.
Mar 1, 2018
d2b033c
Issue #842: Prevent showing the same source multiple times.
Mar 1, 2018
a39e073
added host validation for urls
Mar 1, 2018
843760a
added host validation for urls
Mar 1, 2018
f78ac49
added host validation for urls
Mar 1, 2018
816b77d
Add validation reporting of invalid shortcodes
westonruter Mar 1, 2018
2715cf1
Implement 'Re-check' bulk action.
Mar 2, 2018
76e2be5
Refactor how sources are determined for validation
westonruter Mar 2, 2018
975f364
Fix PHP 5.3 compatibility re: using self in closure; fix tests
westonruter Mar 2, 2018
4f6dcc2
added tests and follow the spec
Mar 2, 2018
5279dd7
Implement inline 'Re-check' action.
Mar 2, 2018
e79635e
Change spelling of re-check to recheck.
Mar 2, 2018
ee302fa
Use singular and plural in plugins.php warning.
Mar 2, 2018
2979969
Add a 'more details' link to the plugins.php warning.
Mar 2, 2018
ddd97ea
Refactor removed_nodes into more general validation_errors to allow f…
westonruter Mar 2, 2018
7c5402e
Schedule a twice daily cron event to check for validity.
Mar 2, 2018
9805f82
Address Travis error: Use a specific key, not array_shift().
Mar 2, 2018
8c4906e
Rename reset_validation_errors() to reset_validation_results().
Mar 2, 2018
c9806d9
Hide the 'Add New' link on the validation page.
Mar 2, 2018
26d773e
Rename validate_markup to handle_validate_request().
Mar 3, 2018
a341e79
Remove ERROR_KEY, and check if $validation_errors is empty().
Mar 3, 2018
f899646
Remove 2 extra conditional blocks for call_user_func_array().
Mar 3, 2018
1badf73
Prevent duplication of 'meta_input'
Mar 3, 2018
76093b6
Improve validation status post list table
westonruter Mar 3, 2018
73e5ac9
Improve handling of URLs associated with a given validation error post
westonruter Mar 3, 2018
b981d10
Ensure wrapped_callback adds source comments when multi-line elements…
westonruter Mar 3, 2018
469d7f2
Remove create_posts cap to hide Add New link for Validation Status posts
westonruter Mar 3, 2018
b0c3389
Use first URL as validation status post title; add column for (additi…
westonruter Mar 3, 2018
e20f10d
Prevent storing validation status when frontend requested in debug mode
westonruter Mar 3, 2018
6972d5c
Remove the 'Publish' meta box from the CPT post.php page.
Mar 3, 2018
1fbc9c6
Add debug row action to load frontend with validation but without inv…
westonruter Mar 4, 2018
1b4db07
Remove source comments before rendering when validating without debug…
westonruter Mar 4, 2018
907b054
Indicate that plugin with invalid markup *may* be invalid
westonruter Mar 4, 2018
be82b04
Add meta box on post.php in place of 'Publish' box.
Mar 4, 2018
fb20b71
Accomodate the 'amp-wp' directory of the plugin.
Mar 4, 2018
21195d3
Specify PROJECT_SLUG instead of accomodating the 'amp-wp' directory o…
westonruter Mar 5, 2018
b6bcaa8
Add full-width meta box on CPT post.php page.
Mar 5, 2018
1e0c32b
Don't esc_html() the <code> element.
Mar 5, 2018
1aed8fb
Omit AMP endpoint or query var when AMP is canonical
westonruter Mar 5, 2018
a18a8c1
Upon plugin activation, validate the most recently-published post (in…
westonruter Mar 5, 2018
51fc2fa
Fix initialization of theme support with paired mode
westonruter Mar 5, 2018
b8fed2e
added test cases and checks
Mar 5, 2018
5a6ae74
solved linting issues
Mar 5, 2018
2067992
removed too generic check
Mar 5, 2018
932b70d
Tweak validation status meta boxes
westonruter Mar 5, 2018
b8be81c
Only set transient when doing validation after plugin activation
westonruter Mar 5, 2018
15b291c
Include invalid element's attributes as context in validation errors
westonruter Mar 5, 2018
7ad03bd
Re-use existing validation status post when re-check results in change
westonruter Mar 5, 2018
81dcb8e
Display the URLs at the bottom of the CPT post.php page.
Mar 5, 2018
72b5981
Address Travis error by aligning => vertically.
Mar 5, 2018
0f8c848
Show pseudo markup for which element or attribute was removed
westonruter Mar 5, 2018
0ffd14a
Supply the actual URL to re-check in the inline re-check link
westonruter Mar 5, 2018
b33edc9
Add debug links with each URL and in status meta box
westonruter Mar 5, 2018
dd9d629
Add count of how many valiation error posts there are in the admin menu
westonruter Mar 6, 2018
e6d12c8
Add AMP Validation Errors to the Dashboard At a Glance widget
westonruter Mar 6, 2018
331d152
deleted generated file changes
Mar 6, 2018
376e3cd
WIP: Report errors with script enqueues
westonruter Mar 6, 2018
f5568fa
Add initial validation error source reporting for enqueued scripts
westonruter Mar 6, 2018
4651a6a
Add more robust way of detecting source for each enqueued style and s…
westonruter Mar 7, 2018
23065f5
Improve validation error reporting for stylesheets
westonruter Mar 7, 2018
454b285
improved protocol checks
Mar 7, 2018
ba9365a
Pull out REST API endpoint and cron validation for 0.7 release
westonruter Mar 7, 2018
1c6a25d
Incorporate post frontend URL's validation status with content valida…
westonruter Mar 7, 2018
1357330
Prevent schema.org duplicates
oscarssanchez Mar 7, 2018
7a3e497
Simplify splitting a string by commas
westonruter Mar 8, 2018
56ee90a
Add a test for attribute conversion on long iframe srcdocs
christianc1 Mar 8, 2018
18ecea1
Fix phpcs sniffs in backtrack limit tests
christianc1 Mar 8, 2018
b1bdae9
Fix the rest of the sniffs in the backtack limit tests
christianc1 Mar 8, 2018
0efc859
Ensure illegal values for overflow-x and overflow-y are sanitized
westonruter Mar 8, 2018
da5f4ad
Recheck the validation status of a post on frontend after saving when…
westonruter Mar 8, 2018
bf82b8d
Un-trash validation post status to re-use instead of adding new post …
westonruter Mar 8, 2018
1548d37
Rename should_validate_front_end to should_validate_response
westonruter Mar 8, 2018
df7db64
Merge pull request #971 from Automattic/add/842-plugin-validation
westonruter Mar 8, 2018
ea52b1e
added urldecode
Mar 8, 2018
aca760d
added urldecode
Mar 8, 2018
3ced093
added urldecode
Mar 8, 2018
c7c227b
remove AMP_WP_Utils class and tests
Mar 8, 2018
65b88f7
replace AMP_WP_Utils::parse_url() with wp_parse_url()
Mar 8, 2018
944bbf9
replace parse_url() with wp_parse_url()
Mar 8, 2018
0c6bd93
bump minimum required version to 4.8
Mar 8, 2018
a5eeba0
suppress PHPCS warning for show_admin_bar
Mar 8, 2018
790dec8
Revert composer changes to be considered in separate PR
westonruter Mar 8, 2018
8e6698b
Add test for link with scheme-less URL having bad URL
westonruter Mar 8, 2018
a04782a
Skip composer install on PHP 5.3 due to phpcs not being available
westonruter Mar 8, 2018
3604c6e
Update readme with changelog entry for URL host name validation
westonruter Mar 8, 2018
0d9d50a
Add test URL host name validity test for encoded host
westonruter Mar 8, 2018
d0f4f01
Merge pull request #983 from rubengonzalezmrf/develop
westonruter Mar 8, 2018
da3a779
Eliminate use of safecss_filter_attr() in processing style attributes…
westonruter Mar 8, 2018
c66bfc4
Prevent schema.org duplicates
oscarssanchez Mar 9, 2018
05384f2
Remove greedy whitespace tokens from attribute regex
christianc1 Mar 9, 2018
8079fcd
Merge pull request #1004 from Automattic/fix/style-attribute-processing
westonruter Mar 9, 2018
65fcf5a
suppress PHPCS warning for show_admin_bar
Mar 8, 2018
0c8fcd2
remove parens from require_once statement
Mar 8, 2018
e04ce22
use strict comparisons in AMP_Tag_And_Attribute_Sanitizer_Attr_Spec_R…
Mar 8, 2018
78e64f4
tests: declare visiblity for functions
Mar 8, 2018
805a491
explicitly declare visibility on embed class functions
Mar 8, 2018
df77083
fix WordPress.Classes.ClassInstantiation.MissingParenthesis error
Mar 8, 2018
5033910
Wrap registered widgets in callbacks to track widget validation errors
westonruter Mar 10, 2018
c42dd3c
Set AMP_QUERY_VAR fallback when AMP is inactive
mjangda Mar 2, 2018
d024c4c
Introduce amp_get_slug() to replace AMP_QUERY_VAR
westonruter Mar 2, 2018
be6a78a
avoid double-calling rawurlencode() on $data in jetpack_amp_build_sta…
Mar 8, 2018
6d5fcc1
Re-work filter/action hook wrapping to happen just-in-time
westonruter Mar 11, 2018
67de7c3
Schema.org prevent duplicates
oscarssanchez Mar 11, 2018
e2c5b19
Merge pull request #1012 from Automattic/add/widget-validation-reporting
westonruter Mar 12, 2018
51664cf
Facilitate using AMP components outside of AMP documents (dirty AMP)
westonruter Mar 12, 2018
0154620
Move any AMP component scripts from body into head
westonruter Mar 12, 2018
c402da5
Merge pull request #986 from Automattic/add/QUERY_VAR-fallback
westonruter Mar 12, 2018
82e27ff
Improve registration and printing of AMP scripts
westonruter Mar 12, 2018
6bedf70
Add missing version for amp-default style
westonruter Mar 12, 2018
839d7ff
Merge pull request #1013 from Automattic/add/amp-script-enqueues
westonruter Mar 12, 2018
c76231c
Prevent showing details link on edit post screen if validation_status…
westonruter Mar 12, 2018
3969884
Remove test of amp bind conversion of 10000 table rows
christianc1 Mar 12, 2018
ce4df66
Refactor string concatenation to sprintf format
christianc1 Mar 12, 2018
2cf4ff9
Remove unnecessary variable assignment from unit test
christianc1 Mar 12, 2018
82d8421
Add amp_convert_bind_attributes filter to allow for skip bind attribu…
christianc1 Mar 12, 2018
f6ea414
On regex engine errors in amp bind conversions, return passed html to…
christianc1 Mar 12, 2018
924d251
Keep track of the callbacks run (and their sources) when a filter is …
westonruter Mar 12, 2018
3f19d03
Merge pull request #1015 from Automattic/fix/validation-post-details-…
westonruter Mar 12, 2018
fda9f87
Merge branch 'develop' into add/962-prevent-schema-duplicates
westonruter Mar 13, 2018
ab0ae8a
Merge pull request #992 from oscarssanchez/add/962-prevent-schema-dup…
westonruter Mar 13, 2018
3f3687f
Merge pull request #1016 from Automattic/add/filter-source-stack
westonruter Mar 13, 2018
e94009d
Refactor attribute conversion tests to use assertion
christianc1 Mar 13, 2018
5f57eac
Remove unnecessary conditional filter
christianc1 Mar 13, 2018
e171a57
Add inline docs hinting at potential backtrack limit error
christianc1 Mar 13, 2018
50602b4
Merge pull request #994 from christianc1/fix/993-preg-backtrack-limit…
westonruter Mar 13, 2018
5bbd027
Begin script to create Gutenberg test page.
Mar 13, 2018
ad86261
Correct regex pattern, improve DocBlock.
Mar 13, 2018
09e6cf5
Allow running bash script from plugin root.
Mar 13, 2018
5352b41
Add documentation to contributing.md.
Mar 13, 2018
90a0d34
Merge branch 'fix/admin-bar' of https://github.com/paulschreiber/amp-…
Mar 13, 2018
a6cc4ae
add docblock comments to AMP_Base_Embed_Handler
Mar 13, 2018
beeb979
add docblock comments to test-amp-image-dimension-extractor
Mar 13, 2018
be48de3
add docblock comments to AMP_Twitter_Embed_Handler
Mar 13, 2018
934fd3e
end jetpack-helper inline comment with period
Mar 13, 2018
15bb4ad
add docblock comments to AMP_DailyMotion_Embed_Handler
Mar 13, 2018
3e1eb2e
add docblock comments to AMP_YouTube_Embed_Handler
Mar 13, 2018
d8f97f2
add docblock comments to AMP_Vimeo_Embed_Handler
Mar 13, 2018
0611743
add docblock comments to AMP_WP_Utils_Parse_Url_Test
Mar 13, 2018
820b79a
Add permutations of Gutenberg blocks.
Mar 13, 2018
ab803a1
Make title correspond to path, add bash script echo statements.
Mar 13, 2018
d6244cc
Create a test reusable block, reduce heading size.
Mar 13, 2018
4e2093e
Remove extra tab in content.
Mar 14, 2018
3e41cca
Throw exception if no fixtures are found.
Mar 14, 2018
44b9fdd
Use AMP namespace for functions in create-gutenberg-test-post.php
westonruter Mar 14, 2018
66e12d7
Merge pull request #1018 from Automattic/add/845-gutenberg-test-script
westonruter Mar 14, 2018
412e977
Add handler for Gutenberg Categories block.
miina Mar 15, 2018
ba87e20
Add better method comment.
miina Mar 15, 2018
0a85c06
Add test file.
miina Mar 15, 2018
1561d31
Move enqueuing of assets to 'wp_enqueue_scripts'.
Mar 15, 2018
d2d5404
Remove check for is_amp_endpoint().
Mar 15, 2018
919b84b
Make is_amp_endpoint() false for 3 conditions:
Mar 16, 2018
0c0a2b4
Merge pull request #1023 from Automattic/fix/assets-enqueued-on-admin
westonruter Mar 17, 2018
8703c29
Revert "suppress PHPCS warning for show_admin_bar"
westonruter Mar 17, 2018
ac33200
Fix ValidVariableName.NotSnakeCaseMemberVar, CommentedOutCode.Found, …
westonruter Mar 17, 2018
79526a4
Merge pull request #1002 from paulschreiber/fix/admin-bar
westonruter Mar 17, 2018
4822f7e
Merge branch '0.7' of https://github.com/Automattic/amp-wp into develop
westonruter Mar 17, 2018
59bbbbb
Revert "bump minimum required version to 4.8"
paulschreiber Mar 18, 2018
745eb87
Revert "remove AMP_WP_Utils class and tests"
paulschreiber Mar 18, 2018
6690c67
Merge branch 'develop' into fix/parse-url
paulschreiber Mar 18, 2018
4f49291
mark AMP_WP_Utils::parse_url as deprecated
paulschreiber Mar 18, 2018
3d75fe3
Rename block handler class. Use unregister_embed. Fix tests.
miina Mar 19, 2018
93f77fc
Try fixing tests.
miina Mar 19, 2018
a9ae03b
Merge pull request #1022 from Automattic/add/1010-gutenberg_core_bloc…
westonruter Mar 19, 2018
de3f263
Remove tests for deprecated AMP_WP_Utils class
westonruter Mar 19, 2018
0bd1d58
Merge pull request #995 from paulschreiber/fix/parse-url
westonruter Mar 19, 2018
fb649cc
add amp-redirect if amp-live-list is not declared
DavidCramer Mar 20, 2018
6f00f20
Add message to response based on comment approval
DavidCramer Mar 20, 2018
a0fce3f
Fix and refactor XHR handling
westonruter Mar 21, 2018
1e32d6c
Add validation for __amp_source_origin
westonruter Mar 21, 2018
5c96324
Use scheme-less URL for redirect if non-HTTPS
westonruter Mar 21, 2018
8da1a36
Improve comments regarding XHR handling
westonruter Mar 21, 2018
f957712
Merge pull request #1029 from Automattic/add/1028-amp-live-list-opt-in
westonruter Mar 21, 2018
b1fbc6d
Merge branch '0.7' of https://github.com/Automattic/amp-wp into develop
westonruter Mar 21, 2018
1e44b5a
Do not enqueue amp-runtime unless AMP endpoint
westonruter Mar 21, 2018
cf712b0
Prevent handling XHR request if _wp_amp_action_xhr_converted query va…
westonruter Mar 21, 2018
213d195
Ensure comment submission on AMP post redirects back to AMP and not n…
westonruter Mar 22, 2018
7870892
Merge pull request #1033 from Automattic/fix/paired-mode-xhr
westonruter Mar 22, 2018
a9fd97b
Merge branch '0.7' of https://github.com/Automattic/amp-wp into develop
westonruter Mar 22, 2018
103dd81
864 - Use intrinsic as default layout for images
mehigh Mar 29, 2018
ab4c636
Merge branch 'develop' into fix/864-remove-sizes
mehigh Mar 29, 2018
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
1 change: 1 addition & 0 deletions .dev-lib
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PATH_EXCLUDES_PATTERN=includes/lib/
DEFAULT_BASE_BRANCH=develop
ASSETS_DIR=wp-assets
PROJECT_SLUG=amp

function after_wp_install {
echo "Installing REST API..."
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ cache:
matrix:
include:
- php: "5.3"
env: WP_VERSION=latest DEV_LIB_SKIP=phpcs
env: WP_VERSION=latest DEV_LIB_SKIP=composer,phpcs
- php: "5.3"
env: WP_VERSION=4.7 DEV_LIB_SKIP=phpcs
env: WP_VERSION=4.7 DEV_LIB_SKIP=composer,phpcs
- php: "5.4"
env: WP_VERSION=latest
- php: "5.4"
Expand Down
43 changes: 22 additions & 21 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function amp_deactivate() {
// We need to manually remove the amp endpoint
global $wp_rewrite;
foreach ( $wp_rewrite->endpoints as $index => $endpoint ) {
if ( AMP_QUERY_VAR === $endpoint[1] ) {
if ( amp_get_slug() === $endpoint[1] ) {
unset( $wp_rewrite->endpoints[ $index ] );
break;
}
Expand All @@ -64,6 +64,15 @@ function amp_deactivate() {
flush_rewrite_rules();
}

/*
* Register AMP scripts regardless of whether AMP is enabled or it is the AMP endpoint
* for the sake of being able to use AMP components on non-AMP documents ("dirty AMP").
*/
add_action( 'wp_default_scripts', 'amp_register_default_scripts' );

// Ensure async and custom-element/custom-template attributes are present on script tags.
add_filter( 'script_loader_tag', 'amp_filter_script_loader_tag', PHP_INT_MAX, 2 );

/**
* Set up AMP.
*
Expand All @@ -73,20 +82,12 @@ function amp_deactivate() {
* @since 0.6
*/
function amp_after_setup_theme() {
amp_get_slug(); // Ensure AMP_QUERY_VAR is set.

if ( false === apply_filters( 'amp_is_enabled', true ) ) {
return;
}

if ( ! defined( 'AMP_QUERY_VAR' ) ) {
/**
* Filter the AMP query variable.
*
* @since 0.3.2
* @param string $query_var The AMP query variable.
*/
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
}

add_action( 'init', 'amp_init', 0 ); // Must be 0 because widgets_init happens at init priority 1.
}
add_action( 'after_setup_theme', 'amp_after_setup_theme', 5 );
Expand All @@ -107,11 +108,11 @@ function amp_init() {

load_plugin_textdomain( 'amp', false, plugin_basename( AMP__DIR__ ) . '/languages' );

add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_rewrite_endpoint( amp_get_slug(), EP_PERMALINK );

AMP_Validation_Utils::init();
AMP_Theme_Support::init();
AMP_Post_Type_Support::add_post_type_support();
AMP_Validation_Utils::init();
add_filter( 'request', 'amp_force_query_var_value' );
add_action( 'admin_init', 'AMP_Options_Manager::register_settings' );
add_action( 'wp_loaded', 'amp_post_meta_box' );
Expand All @@ -132,8 +133,8 @@ function amp_init() {
// Make sure the `amp` query var has an explicit value.
// Avoids issues when filtering the deprecated `query_string` hook.
function amp_force_query_var_value( $query_vars ) {
if ( isset( $query_vars[ AMP_QUERY_VAR ] ) && '' === $query_vars[ AMP_QUERY_VAR ] ) {
$query_vars[ AMP_QUERY_VAR ] = 1;
if ( isset( $query_vars[ amp_get_slug() ] ) && '' === $query_vars[ amp_get_slug() ] ) {
$query_vars[ amp_get_slug() ] = 1;
}
return $query_vars;
}
Expand Down Expand Up @@ -202,7 +203,7 @@ function amp_correct_query_when_is_front_page( WP_Query $query ) {
$query->is_home()
&&
// Is AMP endpoint.
false !== $query->get( AMP_QUERY_VAR, false )
false !== $query->get( amp_get_slug(), false )
&&
// Is query not yet fixed uo up to be front page.
! $query->is_front_page()
Expand All @@ -214,7 +215,7 @@ function amp_correct_query_when_is_front_page( WP_Query $query ) {
get_option( 'page_on_front' )
&&
// See line in WP_Query::parse_query() at <https://github.com/WordPress/wordpress-develop/blob/0baa8ae/src/wp-includes/class-wp-query.php#L961>.
0 === count( array_diff( array_keys( wp_parse_args( $query->query ) ), array( AMP_QUERY_VAR, 'preview', 'page', 'paged', 'cpage' ) ) )
0 === count( array_diff( array_keys( wp_parse_args( $query->query ) ), array( amp_get_slug(), 'preview', 'page', 'paged', 'cpage' ) ) )
);
if ( $is_front_page_query ) {
$query->is_home = false;
Expand Down Expand Up @@ -304,9 +305,9 @@ function amp_render_post( $post ) {
* which is not ideal for any code that expects to run in an AMP context.
* Let's force the value to be true while we render AMP.
*/
$was_set = isset( $wp_query->query_vars[ AMP_QUERY_VAR ] );
$was_set = isset( $wp_query->query_vars[ amp_get_slug() ] );
if ( ! $was_set ) {
$wp_query->query_vars[ AMP_QUERY_VAR ] = true;
$wp_query->query_vars[ amp_get_slug() ] = true;
}

// Prevent New Relic from causing invalid AMP responses due the NREUM script it injects after the meta charset.
Expand All @@ -328,7 +329,7 @@ function amp_render_post( $post ) {
$template->load();

if ( ! $was_set ) {
unset( $wp_query->query_vars[ AMP_QUERY_VAR ] );
unset( $wp_query->query_vars[ amp_get_slug() ] );
}
}

Expand Down Expand Up @@ -359,7 +360,7 @@ function _amp_bootstrap_customizer() {
function amp_redirect_old_slug_to_new_url( $link ) {

if ( is_amp_endpoint() ) {
$link = trailingslashit( trailingslashit( $link ) . AMP_QUERY_VAR );
$link = trailingslashit( trailingslashit( $link ) . amp_get_slug() );
}

return $link;
Expand Down
175 changes: 175 additions & 0 deletions bin/create-gutenberg-test-post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php
/**
* Creates a post to test all Gutenberg blocks.
*
* @codeCoverageIgnore
* @package AMP
*/

namespace AMP;

/**
* Gets many of the Gutenberg fixture blocks in blocks/tests/fixtures/.
*
* @throws \Exception If this is script is not run inside the plugin directory, or if it doesn't have .html fixtures.
* @return string $content Post content with all Gutenberg blocks.
*/
function get_test_block_fixtures() {
$gutenberg_dir = dirname( dirname( __DIR__ ) ) . '/gutenberg';
$content = get_test_block_permutations();
if ( ! is_dir( $gutenberg_dir ) ) {
$gutenberg_dir = dirname( $gutenberg_dir );
if ( ! is_dir( $gutenberg_dir ) ) {
throw new \Exception( 'Please run this script from the AMP plugin root.' );
}
}

$fixtures_dir = $gutenberg_dir . '/blocks/test/fixtures';
if ( ! is_dir( $fixtures_dir ) ) {
throw new \Exception( "Test files not found in the Gutenberg plugin. You may need to clone the plugin repo: \nhttps://github.com/WordPress/gutenberg.git" );
}

foreach ( glob( $fixtures_dir . '/*.html' ) as $file ) {
if ( ! preg_match( '/(serialized|embed|shortcode|custom-text-teaser|core__block)/', $file ) ) {
// Add the block's title.
preg_match( ':core__(?P<block>.+)\.html:s', basename( $file ), $matches );
if ( isset( $matches['block'] ) ) {
$content .= sprintf( '<h1>%s</h1>', $matches['block'] );
}
$content .= file_get_contents( $file ); // @codingStandardsIgnoreLine: file_get_contents_file_get_contents, file_system_read_file_get_contents.
}
}

// Replace broken URLs in fixture files.
$content = str_replace( 'http://google.com/hi.png', 'https://cldup.com/-3VMmmrPm9.jpg', $content );
$content = str_replace( 'https://awesome-fake.video/file.mp4', 'https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4', $content );
return $content;
}

/**
* Gets the Gutenberg block permutations.
*
* These are mostly copied from gutenberg/blocks/test/fixtures/, and slightly modified.
* Embeds and shortcodes are tested in a separate script, so this does not have have many.
*
* @return string $content The blocks as HTML.
*/
function get_test_block_permutations() {
$blocks = array(
array(
'title' => '(Reusable) Block With Video',
'content' => sprintf( '<!-- wp:block {"ref":%d} /-->', create_test_reusable_block() ),
),
array(
'title' => 'Categories With Dropdown',
'content' => '<!-- wp:core/categories {"showPostCounts":false,"displayAsDropdown":true,"showHierarchy":false} /-->',
),
array(
'title' => 'Columns, With 2 Columns',
'content' => '<!-- wp:core/columns {"columns":2} --><div class="wp-block-columns has-2-columns"><!-- wp:core/paragraph {"layout":"column-1"} --><p class="layout-column-1">Column One, Paragraph One</p><!-- /wp:core/paragraph --><!-- wp:core/paragraph {"layout":"column-1"} --><p class="layout-column-1">Column One, Paragraph Two</p><!-- /wp:core/paragraph --><!-- wp:core/paragraph {"layout":"column-2"} --><p class="layout-column-2">Column Two, Paragraph One</p><!-- /wp:core/paragraph --></div><!-- /wp:core/columns -->',
),
array(
'title' => 'Cover Image With Fixed Background',
'content' => '<!-- wp:core/cover-image {"url":"https://cldup.com/uuUqE_dXzy.jpg","dimRatio":40} --><section class="wp-block-cover-image has-background-dim-40 has-background-dim has-parallax" style="background-image:url(https://cldup.com/uuUqE_dXzy.jpg)"><h2>Guten Berg!</h2></section><!-- /wp:core/cover-image -->',
),
array(
'title' => 'WordPress Embed',
'content' => '<!-- wp:core-embed/wordpress {"url":"https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/"} --><figure class="wp-block-embed-wordpress wp-block-embed">https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/<figcaption>Embedded content from WordPress</figcaption></figure><!-- /wp:core-embed/wordpress -->',
),
array(
'title' => 'YouTube Embed',
'content' => '<!-- wp:core-embed/youtube {"url":"https://www.youtube.com/watch?v=GGS-tKTXw4Y"} --><figure class="wp-block-embed-youtube wp-block-embed">https://www.youtube.com/watch?v=GGS-tKTXw4Y<figcaption>Embedded content from youtube</figcaption></figure><!-- /wp:core-embed/youtube -->',
),
array(
'title' => 'Twitter Embed',
'content' => '<!-- wp:core-embed/twitter {"url":"https://twitter.com/AMPhtml/status/963443140005957632"} --><figure class="wp-block-embed-twitter wp-block-embed">https://twitter.com/AMPhtml/status/963443140005957632<figcaption>We are Automattic</figcaption></figure><!-- /wp:core-embed/twitter -->',
),
array(
'title' => 'Gallery With 3 Columns',
'content' => '<!-- wp:core/gallery --><ul class="wp-block-gallery alignnone columns-3 is-cropped"><li class="blocks-gallery-item"><figure><img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /></figure></li><li class="blocks-gallery-item"><figure><img src="https://cldup.com/-3VMmmrPm9.jpg" alt="title" /></figure></li><li class="blocks-gallery-item"><figure><img src="https://cldup.com/aMbxBM0zAi.jpg" alt="title" /></figure></li></ul><!-- /wp:core/gallery -->',
),
array(
'title' => 'Audio Shortcode',
'content' => '<!-- wp:core/shortcode -->[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]<!-- /wp:core/shortcode -->',
),
array(
'title' => 'Caption Shortcode',
'content' => '<!-- wp:core/shortcode -->[caption width=150]This is a caption[/caption]<!-- /wp:core/shortcode -->',
),
);

$content = '';
foreach ( $blocks as $block ) {
$content .= sprintf( '<h2>%s</h2>', $block['title'] );
$content .= $block['content'];
}

return $content;
}

/**
* Creates a reusable block with a video.
*
* Reusable blocks are stored in custom post types.
* This creates one, and returns the ID on success.
*
* @return int|\WP_Error $post_id The post ID where the reusable block is stored, and 0 or WP_Error in case of failure.
*/
function create_test_reusable_block() {
return wp_insert_post( array(
'post_type' => 'wp_block',
'post_title' => 'Test Reusable Block',
'post_content' => '<!-- wp:core/video --><figure class="wp-block-video"><video src="https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4" controls=""></video></figure><!-- /wp:core/video -->',
'post_status' => 'publish',
) );
}

/**
* Creates a Gutenberg test post (page).
*
* @throws \Exception If there is an error in creating the test page.
* @param string $content The content to add to the post.
* @return int Page ID.
*/
function create_gutenberg_test_post( $content ) {
$slug = 'amp-test-gutenberg-blocks';
$title = 'AMP Test Gutenberg Blocks';
$page = get_page_by_path( "/{$slug}/" );
$failure_message = 'The test page could not be added, please try again.';
if ( $page ) {
$page_id = $page->ID;
} else {
$page_id = wp_insert_post( array(
'post_name' => $slug,
'post_title' => $title,
'post_type' => 'page',
) );

if ( ! $page_id || is_wp_error( $page_id ) ) {
throw new \Exception( $failure_message );
}
}

$update = wp_update_post( array(
'ID' => $page_id,
'post_content' => $content,
) );

if ( ! $update ) {
throw new \Exception( $failure_message );
}
return $update;
}

// Bootstrap.
if ( defined( 'WP_CLI' ) ) {
try {
$post_id = create_gutenberg_test_post( get_test_block_fixtures() );
\WP_CLI::success( sprintf( 'The test page is at: %s', \amp_get_permalink( $post_id ) . '#development=1' ) );
} catch ( \Exception $e ) {
\WP_CLI::error( $e->getMessage() );
}
} else {
echo "This script should be run WP-CLI via: wp eval-file bin/create-gutenberg-test-post.php\n";
exit( 1 );
}
32 changes: 32 additions & 0 deletions bin/create-gutenberg-test-post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e
cd "$(dirname "$0")"

BIN_PATH="$(pwd)"
PROJECT_PATH=$(dirname $PWD)
PLUGINS_PATH=$(dirname $PROJECT_PATH)
GUTENBERG_PATH=$PLUGINS_PATH/gutenberg

# Clone the Gutenberg plugin, or pull the master branch if it's already present.
if [[ ! -e $GUTENBERG_PATH ]]; then
cd $PLUGINS_PATH
echo "This needs to clone the Gutenberg plugin into your plugins directory, as it looks like it's not there."
read -p "Is that alright? y/n " -r
if [[ $REPLY =~ [Yy] ]]; then
git clone https://github.com/WordPress/gutenberg.git
wp plugin activate gutenberg
echo "The Gutenberg plugin is cloned. Please follow the build steps:"
echo "https://github.com/WordPress/gutenberg/blob/master/CONTRIBUTING.md"
else
echo "Exiting script."
exit 1
fi
else
cd $GUTENBERG_PATH
if [ 'master' == $( git rev-parse --abbrev-ref HEAD ) ]; then
git pull origin master
fi
fi

cd $PROJECT_PATH
wp eval-file bin/create-gutenberg-test-post.php
8 changes: 8 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ To run it:
3. run `wp eval-file bin/create-comments-on-test-post.php`
4. go to the URL that is output in the command line

## Testing Gutenberg Block Support

The following script creates a post with all core Gutenberg blocks. To run it:
1. `ssh` into an environment like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV)
2. `cd` to the root of this plugin
3. run `bash bin/create-gutenberge-test-post.sh`
4. go to the URL that is output in the command line

## PHPUnit Testing

Please run these tests in an environment with WordPress unit tests installed, like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV).
Expand Down
2 changes: 1 addition & 1 deletion dev-lib
2 changes: 1 addition & 1 deletion includes/admin/class-amp-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function add_customizer_scripts() {

wp_add_inline_script( 'amp-customize-controls', sprintf( 'ampCustomizeControls.boot( %s );',
wp_json_encode( array(
'queryVar' => AMP_QUERY_VAR,
'queryVar' => amp_get_slug(),
'panelId' => self::PANEL_ID,
'ampUrl' => amp_admin_get_preview_permalink(),
'l10n' => array(
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/class-amp-post-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function enqueue_admin_assets() {
);
wp_add_inline_script( self::ASSETS_HANDLE, sprintf( 'ampPostMetaBox.boot( %s );',
wp_json_encode( array(
'previewLink' => esc_url_raw( add_query_arg( AMP_QUERY_VAR, '', get_preview_post_link( $post ) ) ),
'previewLink' => esc_url_raw( add_query_arg( amp_get_slug(), '', get_preview_post_link( $post ) ) ),
'canonical' => amp_is_canonical(),
'enabled' => post_supports_amp( $post ),
'canSupport' => count( AMP_Post_Type_Support::get_support_errors( $post ) ) === 0,
Expand Down Expand Up @@ -237,7 +237,7 @@ public function preview_post_link( $link ) {
);

if ( $is_amp ) {
$link = add_query_arg( AMP_QUERY_VAR, true, $link );
$link = add_query_arg( amp_get_slug(), true, $link );
}

return $link;
Expand Down
Loading