diff --git a/docs/class/AMP_Base_Embed_Handler.md b/docs/class/AMP_Base_Embed_Handler.md index a8994fcc516..81c42e6ee7a 100644 --- a/docs/class/AMP_Base_Embed_Handler.md +++ b/docs/class/AMP_Base_Embed_Handler.md @@ -9,9 +9,11 @@ Class AMP_Base_Embed_Handler * [`__construct`](../method/AMP_Base_Embed_Handler/__construct.md) - Constructor. * [`get_scripts`](../method/AMP_Base_Embed_Handler/get_scripts.md) - Get mapping of AMP component names to AMP script URLs. * [`match_element_attributes`](../method/AMP_Base_Embed_Handler/match_element_attributes.md) - Get regex pattern for matching HTML attributes from a given tag name. +* [`get_child_elements`](../method/AMP_Base_Embed_Handler/get_child_elements.md) - Get all child elements of the specified element. +* [`unwrap_p_element`](../method/AMP_Base_Embed_Handler/unwrap_p_element.md) - Replace an element's parent with itself if the parent is a <p> tag which has no attributes and has no other children. ### Source -:link: [includes/embeds/class-amp-base-embed-handler.php:15](/includes/embeds/class-amp-base-embed-handler.php#L15-L112) +:link: [includes/embeds/class-amp-base-embed-handler.php:15](/includes/embeds/class-amp-base-embed-handler.php#L15-L154)
Show Code @@ -102,7 +104,7 @@ abstract class AMP_Base_Embed_Handler { implode( '', array_map( - function ( $attr_name ) { + static function ( $attr_name ) { return sprintf( '(?=[^>]*?%1$s="(?P<%1$s>[^"]+)")?', preg_quote( $attr_name, '/' ) ); }, $attribute_names @@ -114,6 +116,48 @@ abstract class AMP_Base_Embed_Handler { } return wp_array_slice_assoc( $matches, $attribute_names ); } + + /** + * Get all child elements of the specified element. + * + * @since 2.0.6 + * + * @param DOMElement $node Element. + * @return DOMElement[] Array of child elements for specified element. + */ + protected function get_child_elements( DOMElement $node ) { + return array_filter( + iterator_to_array( $node->childNodes ), + static function ( DOMNode $child ) { + return $child instanceof DOMElement; + } + ); + } + + /** + * Replace an element's parent with itself if the parent is a

tag which has no attributes and has no other children. + * + * This usually happens while `wpautop()` processes the element. + * + * @since 2.0.6 + * @see AMP_Tag_And_Attribute_Sanitizer::remove_node() + * + * @param DOMElement $node Node. + */ + protected function unwrap_p_element( DOMElement $node ) { + $parent_node = $node->parentNode; + if ( + $parent_node instanceof DOMElement + && + 'p' === $parent_node->tagName + && + false === $parent_node->hasAttributes() + && + 1 === count( $this->get_child_elements( $parent_node ) ) + ) { + $parent_node->parentNode->replaceChild( $node, $parent_node ); + } + } } ``` diff --git a/docs/class/AMP_Base_Sanitizer.md b/docs/class/AMP_Base_Sanitizer.md index 01453a21a72..f74a60d2e8e 100644 --- a/docs/class/AMP_Base_Sanitizer.md +++ b/docs/class/AMP_Base_Sanitizer.md @@ -33,7 +33,7 @@ Class AMP_Base_Sanitizer * [`get_validate_response_data`](../method/AMP_Base_Sanitizer/get_validate_response_data.md) - Get data that is returned in validate responses. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:16](/includes/sanitizers/class-amp-base-sanitizer.php#L16-L802) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:16](/includes/sanitizers/class-amp-base-sanitizer.php#L16-L803)

Show Code @@ -347,6 +347,7 @@ abstract class AMP_Base_Sanitizer { $attributes['style'] = $this->reassemble_style_string( $styles ); } $attributes['layout'] = 'fill'; + unset( $attributes['height'], $attributes['width'] ); return $attributes; } diff --git a/docs/docs.json b/docs/docs.json index d728aaee7de..29b8045b75a 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -1,5 +1,5 @@ { - "3": { + "0": { "file": { "description": "Class AMP_Customizer_Design_Settings", "long_description": "", @@ -55,7 +55,7 @@ } ] }, - "4": { + "1": { "file": { "description": "Class AMP_Customizer_Settings", "long_description": "", @@ -99,7 +99,7 @@ } ] }, - "9": { + "6": { "file": { "description": "Class AMP_Links_Sanitizer.", "long_description": "", @@ -116,8 +116,8 @@ "hooks": [ { "name": "amp_to_amp_linking_element_excluded", - "line": 182, - "end_line": 182, + "line": 204, + "end_line": 204, "type": "filter", "arguments": [ "$excluded", @@ -166,7 +166,7 @@ } ] }, - "29": { + "26": { "file": { "description": "Class AMP_Base_Sanitizer", "long_description": "", @@ -184,7 +184,7 @@ "name": "AMP_Base_Sanitizer", "namespace": "global", "line": 16, - "end_line": 802, + "end_line": 803, "final": false, "abstract": true, "extends": "", @@ -816,7 +816,7 @@ "Document": "\\AmpProject\\Dom\\Document" }, "line": 283, - "end_line": 357, + "end_line": 358, "final": false, "abstract": false, "static": false, @@ -876,8 +876,8 @@ "name": "reassemble_style_string", "class": "\\AMP_Base_Sanitizer", "static": false, - "line": 335, - "end_line": 335 + "line": 336, + "end_line": 336 } ] } @@ -889,8 +889,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 378, - "end_line": 384, + "line": 379, + "end_line": 385, "final": false, "abstract": false, "static": false, @@ -959,8 +959,8 @@ "functions": [ { "name": "trim", - "line": 380, - "end_line": 380 + "line": 381, + "end_line": 381 } ] } @@ -972,8 +972,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 395, - "end_line": 410, + "line": 396, + "end_line": 411, "final": false, "abstract": false, "static": false, @@ -1023,13 +1023,13 @@ "functions": [ { "name": "strtok", - "line": 396, - "end_line": 396 + "line": 397, + "end_line": 397 }, { "name": "set_url_scheme", - "line": 405, - "end_line": 405 + "line": 406, + "end_line": 406 } ] } @@ -1041,8 +1041,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 421, - "end_line": 424, + "line": 422, + "end_line": 425, "final": false, "abstract": false, "static": false, @@ -1074,8 +1074,8 @@ "functions": [ { "name": "_deprecated_function", - "line": 422, - "end_line": 422, + "line": 423, + "end_line": 423, "deprecation_version": "1.5" } ], @@ -1084,8 +1084,8 @@ "name": "isActiveForDocument", "class": "\\AmpProject\\DevMode", "static": true, - "line": 423, - "end_line": 423 + "line": 424, + "end_line": 424 } ] } @@ -1097,8 +1097,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 436, - "end_line": 439, + "line": 437, + "end_line": 440, "final": false, "abstract": false, "static": false, @@ -1144,8 +1144,8 @@ "functions": [ { "name": "_deprecated_function", - "line": 437, - "end_line": 437, + "line": 438, + "end_line": 438, "deprecation_version": "1.5" } ], @@ -1154,8 +1154,8 @@ "name": "hasExemptionForNode", "class": "\\AmpProject\\DevMode", "static": true, - "line": 438, - "end_line": 438 + "line": 439, + "end_line": 439 } ] } @@ -1167,8 +1167,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 449, - "end_line": 452, + "line": 450, + "end_line": 453, "final": false, "abstract": false, "static": false, @@ -1210,8 +1210,8 @@ "functions": [ { "name": "_deprecated_function", - "line": 450, - "end_line": 450, + "line": 451, + "end_line": 451, "deprecation_version": "1.5" } ], @@ -1220,8 +1220,8 @@ "name": "isExemptFromValidation", "class": "\\AmpProject\\DevMode", "static": true, - "line": 451, - "end_line": 451 + "line": 452, + "end_line": 452 } ] } @@ -1233,8 +1233,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 466, - "end_line": 488, + "line": 467, + "end_line": 489, "final": false, "abstract": false, "static": false, @@ -1291,34 +1291,34 @@ "name": "isExemptFromValidation", "class": "\\AmpProject\\DevMode", "static": true, - "line": 467, - "end_line": 467 + "line": 468, + "end_line": 468 }, { "name": "should_sanitize_validation_error", "class": "\\AMP_Base_Sanitizer", "static": false, - "line": 476, - "end_line": 476 + "line": 477, + "end_line": 477 }, { "name": "removeChild", "class": "$node->parentNode", "static": false, - "line": 483, - "end_line": 483 + "line": 484, + "end_line": 484 } ], "functions": [ { "name": "in_array", - "line": 472, - "end_line": 472 + "line": 473, + "end_line": 473 }, { "name": "compact", - "line": 476, - "end_line": 476 + "line": 477, + "end_line": 477 } ] } @@ -1330,8 +1330,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 504, - "end_line": 532, + "line": 505, + "end_line": 533, "final": false, "abstract": false, "static": false, @@ -1414,41 +1414,41 @@ "name": "isExemptFromValidation", "class": "\\AmpProject\\DevMode", "static": true, - "line": 505, - "end_line": 505 + "line": 506, + "end_line": 506 }, { "name": "getAttributeNode", "class": "$element", "static": false, - "line": 510, - "end_line": 510 + "line": 511, + "end_line": 511 }, { "name": "should_sanitize_validation_error", "class": "\\AMP_Base_Sanitizer", "static": false, - "line": 520, - "end_line": 520 + "line": 521, + "end_line": 521 }, { "name": "removeAttributeNode", "class": "$element", "static": false, - "line": 527, - "end_line": 527 + "line": 528, + "end_line": 528 } ], "functions": [ { "name": "is_string", - "line": 509, - "end_line": 509 + "line": 510, + "end_line": 510 }, { "name": "compact", - "line": 520, - "end_line": 520 + "line": 521, + "end_line": 521 } ] } @@ -1460,8 +1460,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 543, - "end_line": 549, + "line": 544, + "end_line": 550, "final": false, "abstract": false, "static": false, @@ -1515,13 +1515,13 @@ "functions": [ { "name": "is_callable", - "line": 544, - "end_line": 544 + "line": 545, + "end_line": 545 }, { "name": "call_user_func", - "line": 548, - "end_line": 548 + "line": 549, + "end_line": 549 } ], "methods": [ @@ -1529,8 +1529,8 @@ "name": "prepare_validation_error", "class": "\\AMP_Base_Sanitizer", "static": false, - "line": 547, - "end_line": 547 + "line": 548, + "end_line": 548 } ] } @@ -1542,8 +1542,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 566, - "end_line": 638, + "line": 567, + "end_line": 639, "final": false, "abstract": false, "static": false, @@ -1595,61 +1595,61 @@ "name": "hasAttribute", "class": "$node", "static": false, - "line": 598, - "end_line": 598 + "line": 599, + "end_line": 599 }, { "name": "hasAttribute", "class": "$node", "static": false, - "line": 602, - "end_line": 602 + "line": 603, + "end_line": 603 }, { "name": "hasAttribute", "class": "$node", "static": false, - "line": 602, - "end_line": 602 + "line": 603, + "end_line": 603 }, { "name": "hasAttributes", "class": "$node->parentNode", "static": false, - "line": 623, - "end_line": 623 + "line": 624, + "end_line": 624 } ], "functions": [ { "name": "strpos", - "line": 608, - "end_line": 608 - }, - { - "name": "add_query_arg", "line": 609, "end_line": 609 }, { - "name": "strpos", + "name": "add_query_arg", "line": 610, "end_line": 610 }, { - "name": "add_query_arg", + "name": "strpos", "line": 611, "end_line": 611 }, + { + "name": "add_query_arg", + "line": 612, + "end_line": 612 + }, { "name": "preg_match", - "line": 619, - "end_line": 619 + "line": 620, + "end_line": 620 }, { "name": "trim", - "line": 630, - "end_line": 630 + "line": 631, + "end_line": 631 } ] } @@ -1661,8 +1661,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 648, - "end_line": 663, + "line": 649, + "end_line": 664, "final": false, "abstract": false, "static": false, @@ -1711,15 +1711,15 @@ "name": "hasAttribute", "class": "$element", "static": false, - "line": 658, - "end_line": 658 + "line": 659, + "end_line": 659 }, { "name": "removeAttribute", "class": "$element", "static": false, - "line": 659, - "end_line": 659 + "line": 660, + "end_line": 660 } ] } @@ -1731,8 +1731,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 671, - "end_line": 687, + "line": 672, + "end_line": 688, "final": false, "abstract": false, "static": false, @@ -1771,15 +1771,15 @@ "name": "get_node_attributes_as_assoc_array", "class": "\\AMP_DOM_Utils", "static": true, - "line": 677, - "end_line": 677 + "line": 678, + "end_line": 678 } ], "functions": [ { "name": "filter_var", - "line": 681, - "end_line": 681 + "line": 682, + "end_line": 682 } ] } @@ -1791,8 +1791,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 696, - "end_line": 704, + "line": 697, + "end_line": 705, "final": false, "abstract": false, "static": false, @@ -1846,8 +1846,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 714, - "end_line": 740, + "line": 715, + "end_line": 741, "final": false, "abstract": false, "static": false, @@ -1912,22 +1912,22 @@ "name": "setAttribute", "class": "$node->parentNode", "static": false, - "line": 722, - "end_line": 722 + "line": 723, + "end_line": 723 }, { "name": "setAttribute", "class": "$node->parentNode", "static": false, - "line": 729, - "end_line": 729 + "line": 730, + "end_line": 730 }, { "name": "setAttribute", "class": "$node->parentNode", "static": false, - "line": 732, - "end_line": 732 + "line": 733, + "end_line": 733 } ] } @@ -1939,8 +1939,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 748, - "end_line": 762, + "line": 749, + "end_line": 763, "final": false, "abstract": false, "static": false, @@ -1977,43 +1977,43 @@ "functions": [ { "name": "trim", - "line": 750, - "end_line": 750 + "line": 751, + "end_line": 751 }, { "name": "preg_split", - "line": 751, - "end_line": 751 + "line": 752, + "end_line": 752 }, { "name": "count", - "line": 753, - "end_line": 753 + "line": 754, + "end_line": 754 }, { "name": "array_pop", - "line": 755, - "end_line": 755 + "line": 756, + "end_line": 756 }, { "name": "array_chunk", - "line": 758, - "end_line": 758 + "line": 759, + "end_line": 759 }, { "name": "array_combine", - "line": 761, - "end_line": 761 + "line": 762, + "end_line": 762 }, { "name": "array_column", - "line": 761, - "end_line": 761 + "line": 762, + "end_line": 762 }, { "name": "array_column", - "line": 761, - "end_line": 761 + "line": 762, + "end_line": 762 } ] } @@ -2025,8 +2025,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 770, - "end_line": 789, + "line": 771, + "end_line": 790, "final": false, "abstract": false, "static": false, @@ -2063,23 +2063,23 @@ "functions": [ { "name": "is_array", - "line": 771, - "end_line": 771 + "line": 772, + "end_line": 772 }, { "name": "array_filter", - "line": 776, - "end_line": 776 + "line": 777, + "end_line": 777 }, { "name": "array_reduce", - "line": 778, - "end_line": 788 + "line": 779, + "end_line": 789 }, { "name": "array_keys", - "line": 779, - "end_line": 779 + "line": 780, + "end_line": 780 } ] } @@ -2091,8 +2091,8 @@ "DevMode": "\\AmpProject\\DevMode", "Document": "\\AmpProject\\Dom\\Document" }, - "line": 799, - "end_line": 801, + "line": 800, + "end_line": 802, "final": false, "abstract": false, "static": false, @@ -2132,7 +2132,7 @@ ], "hooks": [] }, - "34": { + "31": { "file": { "description": "Callbacks for adding AMP-related things to the main theme.", "long_description": "", @@ -2227,7 +2227,7 @@ ], "hooks": [] }, - "35": { + "32": { "file": { "description": "Class AMP_Theme_Support", "long_description": "", @@ -2364,7 +2364,7 @@ } } }, - "36": { + "33": { "file": { "description": "Callbacks for adding AMP-related things to the admin.", "long_description": "", @@ -2440,7 +2440,7 @@ } } }, - "38": { + "35": { "file": { "description": "Class AMP_Template_Customizer", "long_description": "", @@ -2609,7 +2609,7 @@ } } }, - "42": { + "39": { "file": { "description": "AMP Helper Functions", "long_description": "", @@ -2782,6 +2782,16 @@ "hooks": [], "uses": { "functions": [ + { + "name": "wp_doing_cron", + "line": 413, + "end_line": 413 + }, + { + "name": "defined", + "line": 413, + "end_line": 413 + }, { "name": "is_admin", "line": 413, @@ -4624,7 +4634,7 @@ } } }, - "46": { + "43": { "file": { "description": "Class AMP_Image_Dimension_Extractor", "long_description": "", @@ -4744,7 +4754,7 @@ } ] }, - "53": { + "50": { "file": { "description": "AMP_Post_Template class.", "long_description": "", @@ -4958,7 +4968,7 @@ } } }, - "63": { + "60": { "file": { "description": "Class AMP_Base_Embed_Handler", "long_description": "Used by some children.", @@ -4976,7 +4986,7 @@ "name": "AMP_Base_Embed_Handler", "namespace": "global", "line": 15, - "end_line": 112, + "end_line": 154, "final": false, "abstract": true, "extends": "", @@ -5290,6 +5300,136 @@ } ] } + }, + { + "name": "get_child_elements", + "namespace": "", + "aliases": [], + "line": 121, + "end_line": 128, + "final": false, + "abstract": false, + "static": false, + "visibility": "protected", + "arguments": [ + { + "name": "$node", + "default": null, + "type": "\\DOMElement" + } + ], + "doc": { + "description": "Get all child elements of the specified element.", + "long_description": "", + "tags": [ + { + "name": "since", + "content": "2.0.6" + }, + { + "name": "param", + "content": "Element.", + "types": [ + "\\DOMElement" + ], + "variable": "$node" + }, + { + "name": "return", + "content": "Array of child elements for specified element.", + "types": [ + "\\DOMElement[]" + ] + } + ] + }, + "uses": { + "functions": [ + { + "name": "array_filter", + "line": 122, + "end_line": 127 + }, + { + "name": "iterator_to_array", + "line": 123, + "end_line": 123 + } + ] + } + }, + { + "name": "unwrap_p_element", + "namespace": "", + "aliases": [], + "line": 140, + "end_line": 153, + "final": false, + "abstract": false, + "static": false, + "visibility": "protected", + "arguments": [ + { + "name": "$node", + "default": null, + "type": "\\DOMElement" + } + ], + "doc": { + "description": "Replace an element's parent with itself if the parent is a

tag which has no attributes and has no other children.", + "long_description": "This usually happens while `wpautop()` processes the element.", + "tags": [ + { + "name": "since", + "content": "2.0.6" + }, + { + "name": "see", + "content": "", + "refers": "AMP_Tag_And_Attribute_Sanitizer::remove_node()" + }, + { + "name": "param", + "content": "Node.", + "types": [ + "\\DOMElement" + ], + "variable": "$node" + } + ] + }, + "uses": { + "methods": [ + { + "name": "hasAttributes", + "class": "$parent_node", + "static": false, + "line": 147, + "end_line": 147 + }, + { + "name": "get_child_elements", + "class": "\\AMP_Base_Embed_Handler", + "static": false, + "line": 149, + "end_line": 149 + }, + { + "name": "replaceChild", + "class": "$parent_node->parentNode", + "static": false, + "line": 151, + "end_line": 151 + } + ], + "functions": [ + { + "name": "count", + "line": 149, + "end_line": 149 + } + ] + } } ], "doc": { @@ -5306,7 +5446,7 @@ ], "hooks": [] }, - "80": { + "77": { "file": { "description": "AMP Post type support.", "long_description": "", @@ -5435,7 +5575,7 @@ } ] }, - "81": { + "78": { "file": { "description": "Class AMP_HTTP", "long_description": "", @@ -5476,7 +5616,7 @@ } ] }, - "87": { + "84": { "file": { "description": "Class AMP_Validation_Manager", "long_description": "", @@ -5578,7 +5718,7 @@ } ] }, - "88": { + "85": { "file": { "description": "Class AMP_Validation_Error_Taxonomy", "long_description": "", @@ -5714,7 +5854,7 @@ } ] }, - "90": { + "87": { "file": { "description": "Deprecated functions.", "long_description": "", @@ -6185,7 +6325,7 @@ } ] }, - "117": { + "110": { "file": { "description": "Functions for managing legacy templates", "long_description": "", @@ -6246,7 +6386,7 @@ ], "hooks": [] }, - "127": { + "117": { "file": { "description": "Class MobileRedirection.", "long_description": "", @@ -6398,7 +6538,7 @@ } ] }, - "136": { + "126": { "file": { "description": "Fetches and formats data for AMP reader themes.", "long_description": "", @@ -6428,12 +6568,12 @@ }, { "name": "", - "line": 389, + "line": 392, "type": "Require Once" }, { "name": "", - "line": 393, + "line": 396, "type": "Require Once" } ], @@ -6464,7 +6604,7 @@ } ] }, - "138": { + "128": { "file": { "description": "Class OptionsMenu", "long_description": "", @@ -6515,7 +6655,7 @@ } ] }, - "156": { + "146": { "file": { "description": "Class MonitorCssTransientCaching.", "long_description": "", @@ -6586,7 +6726,7 @@ } ] }, - "161": { + "151": { "file": { "description": "Class UserAccess.", "long_description": "", diff --git a/docs/function/amp_is_available.md b/docs/function/amp_is_available.md index a64817e40ad..04c2f7c2536 100644 --- a/docs/function/amp_is_available.md +++ b/docs/function/amp_is_available.md @@ -21,8 +21,8 @@ Determine whether AMP is available for the current URL. function amp_is_available() { global $pagenow, $wp_query; - // Short-circuit for admin requests or requests to non-frontend pages. - if ( is_admin() || in_array( $pagenow, [ 'wp-login.php', 'wp-signup.php', 'wp-activate.php', 'repair.php' ], true ) ) { + // Short-circuit for cron, CLI, admin requests or requests to non-frontend pages. + if ( wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) || is_admin() || in_array( $pagenow, [ 'wp-login.php', 'wp-signup.php', 'wp-activate.php', 'repair.php' ], true ) ) { return false; } diff --git a/docs/hook/amp_to_amp_linking_element_excluded.md b/docs/hook/amp_to_amp_linking_element_excluded.md index c57c6f43688..707a6585968 100644 --- a/docs/hook/amp_to_amp_linking_element_excluded.md +++ b/docs/hook/amp_to_amp_linking_element_excluded.md @@ -17,7 +17,7 @@ The element may be either a link (`a` or `area`) or a `form`. ### Source -:link: [includes/sanitizers/class-amp-link-sanitizer.php:182](/includes/sanitizers/class-amp-link-sanitizer.php#L182) +:link: [includes/sanitizers/class-amp-link-sanitizer.php:204](/includes/sanitizers/class-amp-link-sanitizer.php#L204)

Show Code diff --git a/docs/method/AMP_Base_Embed_Handler/get_child_elements.md b/docs/method/AMP_Base_Embed_Handler/get_child_elements.md new file mode 100644 index 00000000000..bc3b76a7357 --- /dev/null +++ b/docs/method/AMP_Base_Embed_Handler/get_child_elements.md @@ -0,0 +1,35 @@ +## Method `AMP_Base_Embed_Handler::get_child_elements()` + +```php +protected function get_child_elements( \DOMElement $node ); +``` + +Get all child elements of the specified element. + +### Arguments + +* `\DOMElement $node` - Element. + +### Return value + +`\DOMElement[]` - Array of child elements for specified element. + +### Source + +:link: [includes/embeds/class-amp-base-embed-handler.php:121](/includes/embeds/class-amp-base-embed-handler.php#L121-L128) + +
+Show Code + +```php +protected function get_child_elements( DOMElement $node ) { + return array_filter( + iterator_to_array( $node->childNodes ), + static function ( DOMNode $child ) { + return $child instanceof DOMElement; + } + ); +} +``` + +
diff --git a/docs/method/AMP_Base_Embed_Handler/match_element_attributes.md b/docs/method/AMP_Base_Embed_Handler/match_element_attributes.md index 949864b796c..3dfadf1398b 100644 --- a/docs/method/AMP_Base_Embed_Handler/match_element_attributes.md +++ b/docs/method/AMP_Base_Embed_Handler/match_element_attributes.md @@ -31,7 +31,7 @@ protected function match_element_attributes( $html, $tag_name, $attribute_names implode( '', array_map( - function ( $attr_name ) { + static function ( $attr_name ) { return sprintf( '(?=[^>]*?%1$s="(?P<%1$s>[^"]+)")?', preg_quote( $attr_name, '/' ) ); }, $attribute_names diff --git a/docs/method/AMP_Base_Embed_Handler/unwrap_p_element.md b/docs/method/AMP_Base_Embed_Handler/unwrap_p_element.md new file mode 100644 index 00000000000..3ddde16d0ed --- /dev/null +++ b/docs/method/AMP_Base_Embed_Handler/unwrap_p_element.md @@ -0,0 +1,39 @@ +## Method `AMP_Base_Embed_Handler::unwrap_p_element()` + +```php +protected function unwrap_p_element( \DOMElement $node ); +``` + +Replace an element's parent with itself if the parent is a <p> tag which has no attributes and has no other children. + +This usually happens while `wpautop()` processes the element. + +### Arguments + +* `\DOMElement $node` - Node. + +### Source + +:link: [includes/embeds/class-amp-base-embed-handler.php:140](/includes/embeds/class-amp-base-embed-handler.php#L140-L153) + +
+Show Code + +```php +protected function unwrap_p_element( DOMElement $node ) { + $parent_node = $node->parentNode; + if ( + $parent_node instanceof DOMElement + && + 'p' === $parent_node->tagName + && + false === $parent_node->hasAttributes() + && + 1 === count( $this->get_child_elements( $parent_node ) ) + ) { + $parent_node->parentNode->replaceChild( $node, $parent_node ); + } +} +``` + +
diff --git a/docs/method/AMP_Base_Sanitizer/add_or_append_attribute.md b/docs/method/AMP_Base_Sanitizer/add_or_append_attribute.md index 14721aa57ed..82a8e3c21e8 100644 --- a/docs/method/AMP_Base_Sanitizer/add_or_append_attribute.md +++ b/docs/method/AMP_Base_Sanitizer/add_or_append_attribute.md @@ -17,7 +17,7 @@ Adds key and value to list of attributes, or if the key already exists in the ar ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:378](/includes/sanitizers/class-amp-base-sanitizer.php#L378-L384) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:379](/includes/sanitizers/class-amp-base-sanitizer.php#L379-L385)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/clean_up_after_attribute_removal.md b/docs/method/AMP_Base_Sanitizer/clean_up_after_attribute_removal.md index fc113517c2c..071950983fe 100644 --- a/docs/method/AMP_Base_Sanitizer/clean_up_after_attribute_removal.md +++ b/docs/method/AMP_Base_Sanitizer/clean_up_after_attribute_removal.md @@ -13,7 +13,7 @@ Cleans up artifacts after the removal of an attribute node. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:648](/includes/sanitizers/class-amp-base-sanitizer.php#L648-L663) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:649](/includes/sanitizers/class-amp-base-sanitizer.php#L649-L664)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/filter_attachment_layout_attributes.md b/docs/method/AMP_Base_Sanitizer/filter_attachment_layout_attributes.md index 73449b2cd53..486cab91b32 100644 --- a/docs/method/AMP_Base_Sanitizer/filter_attachment_layout_attributes.md +++ b/docs/method/AMP_Base_Sanitizer/filter_attachment_layout_attributes.md @@ -18,7 +18,7 @@ Set attributes to node's parent element according to layout. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:714](/includes/sanitizers/class-amp-base-sanitizer.php#L714-L740) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:715](/includes/sanitizers/class-amp-base-sanitizer.php#L715-L741)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/filter_data_amp_attributes.md b/docs/method/AMP_Base_Sanitizer/filter_data_amp_attributes.md index 7799ecf91a5..27d1bb3b905 100644 --- a/docs/method/AMP_Base_Sanitizer/filter_data_amp_attributes.md +++ b/docs/method/AMP_Base_Sanitizer/filter_data_amp_attributes.md @@ -17,7 +17,7 @@ Set AMP attributes. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:696](/includes/sanitizers/class-amp-base-sanitizer.php#L696-L704) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:697](/includes/sanitizers/class-amp-base-sanitizer.php#L697-L705)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/get_data_amp_attributes.md b/docs/method/AMP_Base_Sanitizer/get_data_amp_attributes.md index 7679dea0d9e..3d805e9d7b6 100644 --- a/docs/method/AMP_Base_Sanitizer/get_data_amp_attributes.md +++ b/docs/method/AMP_Base_Sanitizer/get_data_amp_attributes.md @@ -16,7 +16,7 @@ Get data-amp-* values from the parent node 'figure' added by editor bl ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:671](/includes/sanitizers/class-amp-base-sanitizer.php#L671-L687) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:672](/includes/sanitizers/class-amp-base-sanitizer.php#L672-L688)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/get_validate_response_data.md b/docs/method/AMP_Base_Sanitizer/get_validate_response_data.md index 2a4db6928ad..4d2433f603d 100644 --- a/docs/method/AMP_Base_Sanitizer/get_validate_response_data.md +++ b/docs/method/AMP_Base_Sanitizer/get_validate_response_data.md @@ -14,7 +14,7 @@ The array returned is merged with the overall validate response data. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:799](/includes/sanitizers/class-amp-base-sanitizer.php#L799-L801) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:800](/includes/sanitizers/class-amp-base-sanitizer.php#L800-L802)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/has_dev_mode_exemption.md b/docs/method/AMP_Base_Sanitizer/has_dev_mode_exemption.md index 167a97a8aad..bf807d43aa1 100644 --- a/docs/method/AMP_Base_Sanitizer/has_dev_mode_exemption.md +++ b/docs/method/AMP_Base_Sanitizer/has_dev_mode_exemption.md @@ -18,7 +18,7 @@ Check whether a node is exempt from validation during dev mode. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:436](/includes/sanitizers/class-amp-base-sanitizer.php#L436-L439) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:437](/includes/sanitizers/class-amp-base-sanitizer.php#L437-L440)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/is_document_in_dev_mode.md b/docs/method/AMP_Base_Sanitizer/is_document_in_dev_mode.md index 9399872f7e4..052ed454fc1 100644 --- a/docs/method/AMP_Base_Sanitizer/is_document_in_dev_mode.md +++ b/docs/method/AMP_Base_Sanitizer/is_document_in_dev_mode.md @@ -14,7 +14,7 @@ Check whether the document of a given node is in dev mode. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:421](/includes/sanitizers/class-amp-base-sanitizer.php#L421-L424) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:422](/includes/sanitizers/class-amp-base-sanitizer.php#L422-L425)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/is_exempt_from_validation.md b/docs/method/AMP_Base_Sanitizer/is_exempt_from_validation.md index 870aeb3e067..f569119ce74 100644 --- a/docs/method/AMP_Base_Sanitizer/is_exempt_from_validation.md +++ b/docs/method/AMP_Base_Sanitizer/is_exempt_from_validation.md @@ -18,7 +18,7 @@ Check whether a certain node should be exempt from validation. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:449](/includes/sanitizers/class-amp-base-sanitizer.php#L449-L452) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:450](/includes/sanitizers/class-amp-base-sanitizer.php#L450-L453)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/maybe_enforce_https_src.md b/docs/method/AMP_Base_Sanitizer/maybe_enforce_https_src.md index 2c0ee9a1a66..8958e4808d2 100644 --- a/docs/method/AMP_Base_Sanitizer/maybe_enforce_https_src.md +++ b/docs/method/AMP_Base_Sanitizer/maybe_enforce_https_src.md @@ -19,7 +19,7 @@ If not required, the implementing class may want to try and force https instead. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:395](/includes/sanitizers/class-amp-base-sanitizer.php#L395-L410) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:396](/includes/sanitizers/class-amp-base-sanitizer.php#L396-L411)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/parse_style_string.md b/docs/method/AMP_Base_Sanitizer/parse_style_string.md index d22d241423f..88591c6f818 100644 --- a/docs/method/AMP_Base_Sanitizer/parse_style_string.md +++ b/docs/method/AMP_Base_Sanitizer/parse_style_string.md @@ -16,7 +16,7 @@ Parse a style string into an associative array of style attributes. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:748](/includes/sanitizers/class-amp-base-sanitizer.php#L748-L762) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:749](/includes/sanitizers/class-amp-base-sanitizer.php#L749-L763)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/prepare_validation_error.md b/docs/method/AMP_Base_Sanitizer/prepare_validation_error.md index 4d80354fd03..768641b9f0d 100644 --- a/docs/method/AMP_Base_Sanitizer/prepare_validation_error.md +++ b/docs/method/AMP_Base_Sanitizer/prepare_validation_error.md @@ -17,7 +17,7 @@ Prepare validation error. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:566](/includes/sanitizers/class-amp-base-sanitizer.php#L566-L638) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:567](/includes/sanitizers/class-amp-base-sanitizer.php#L567-L639)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/reassemble_style_string.md b/docs/method/AMP_Base_Sanitizer/reassemble_style_string.md index 1bff4239c08..156dd65ba9d 100644 --- a/docs/method/AMP_Base_Sanitizer/reassemble_style_string.md +++ b/docs/method/AMP_Base_Sanitizer/reassemble_style_string.md @@ -16,7 +16,7 @@ Reassemble a style string that can be used in a 'style' attribute. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:770](/includes/sanitizers/class-amp-base-sanitizer.php#L770-L789) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:771](/includes/sanitizers/class-amp-base-sanitizer.php#L771-L790)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/remove_invalid_attribute.md b/docs/method/AMP_Base_Sanitizer/remove_invalid_attribute.md index 25f39d60bf4..10850b4d93a 100644 --- a/docs/method/AMP_Base_Sanitizer/remove_invalid_attribute.md +++ b/docs/method/AMP_Base_Sanitizer/remove_invalid_attribute.md @@ -21,7 +21,7 @@ Also, calls the mutation callback for it. This tracks all the attributes that we ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:504](/includes/sanitizers/class-amp-base-sanitizer.php#L504-L532) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:505](/includes/sanitizers/class-amp-base-sanitizer.php#L505-L533)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/remove_invalid_child.md b/docs/method/AMP_Base_Sanitizer/remove_invalid_child.md index 064d6dd4db7..d621cffcfa3 100644 --- a/docs/method/AMP_Base_Sanitizer/remove_invalid_child.md +++ b/docs/method/AMP_Base_Sanitizer/remove_invalid_child.md @@ -19,7 +19,7 @@ Also, calls the mutation callback for it. This tracks all the nodes that were re ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:466](/includes/sanitizers/class-amp-base-sanitizer.php#L466-L488) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:467](/includes/sanitizers/class-amp-base-sanitizer.php#L467-L489)
Show Code diff --git a/docs/method/AMP_Base_Sanitizer/set_layout.md b/docs/method/AMP_Base_Sanitizer/set_layout.md index 994bf0ccb34..4db1de98b1f 100644 --- a/docs/method/AMP_Base_Sanitizer/set_layout.md +++ b/docs/method/AMP_Base_Sanitizer/set_layout.md @@ -16,7 +16,7 @@ Sets the layout, and possibly the 'height' and 'width' attri ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:283](/includes/sanitizers/class-amp-base-sanitizer.php#L283-L357) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:283](/includes/sanitizers/class-amp-base-sanitizer.php#L283-L358)
Show Code @@ -60,6 +60,7 @@ public function set_layout( $attributes ) { $attributes['style'] = $this->reassemble_style_string( $styles ); } $attributes['layout'] = 'fill'; + unset( $attributes['height'], $attributes['width'] ); return $attributes; } // Apply fill layout if width & height are 100%. diff --git a/docs/method/AMP_Base_Sanitizer/should_sanitize_validation_error.md b/docs/method/AMP_Base_Sanitizer/should_sanitize_validation_error.md index c56254ccaf5..dea5e038069 100644 --- a/docs/method/AMP_Base_Sanitizer/should_sanitize_validation_error.md +++ b/docs/method/AMP_Base_Sanitizer/should_sanitize_validation_error.md @@ -17,7 +17,7 @@ Check whether or not sanitization should occur in response to validation error. ### Source -:link: [includes/sanitizers/class-amp-base-sanitizer.php:543](/includes/sanitizers/class-amp-base-sanitizer.php#L543-L549) +:link: [includes/sanitizers/class-amp-base-sanitizer.php:544](/includes/sanitizers/class-amp-base-sanitizer.php#L544-L550)
Show Code diff --git a/docs/method/README.md b/docs/method/README.md index 70c953941d4..93e0a275784 100644 --- a/docs/method/README.md +++ b/docs/method/README.md @@ -1,10 +1,12 @@ ## Methods * [`AMP_Base_Embed_Handler::__construct()`](AMP_Base_Embed_Handler/__construct.md) - Constructor. +* [`AMP_Base_Embed_Handler::get_child_elements()`](AMP_Base_Embed_Handler/get_child_elements.md) - Get all child elements of the specified element. * [`AMP_Base_Embed_Handler::get_scripts()`](AMP_Base_Embed_Handler/get_scripts.md) - Get mapping of AMP component names to AMP script URLs. * [`AMP_Base_Embed_Handler::match_element_attributes()`](AMP_Base_Embed_Handler/match_element_attributes.md) - Get regex pattern for matching HTML attributes from a given tag name. * [`AMP_Base_Embed_Handler::register_embed()`](AMP_Base_Embed_Handler/register_embed.md) - Registers embed. * [`AMP_Base_Embed_Handler::unregister_embed()`](AMP_Base_Embed_Handler/unregister_embed.md) - Unregisters embed. +* [`AMP_Base_Embed_Handler::unwrap_p_element()`](AMP_Base_Embed_Handler/unwrap_p_element.md) - Replace an element's parent with itself if the parent is a <p> tag which has no attributes and has no other children. * [`AMP_Base_Sanitizer::__construct()`](AMP_Base_Sanitizer/__construct.md) - AMP_Base_Sanitizer constructor. * [`AMP_Base_Sanitizer::add_buffering_hooks()`](AMP_Base_Sanitizer/add_buffering_hooks.md) - Add filters to manipulate output during output buffering before the DOM is constructed. * [`AMP_Base_Sanitizer::add_or_append_attribute()`](AMP_Base_Sanitizer/add_or_append_attribute.md) - Adds or appends key and value to list of attributes