• Resolved gustavors

    (@gustavors)


    Hello
    I use AMP in summer Twenty Twenty theme website
    He always presented an error at the end of the site, after the footer, with the code belo. What can I do?

    https://gustavors.me/

    Fatal error: Uncaught Error: Call to undefined method DOMNodeList::count() in /home2/gustavors/public_html/wp-content/plugins/amp/includes/sanitizers/class-amp-core-theme-sanitizer.php:1597 Stack trace: #0 /home2/gustavors/public_html/wp-content/plugins/amp/includes/sanitizers/class-amp-core-theme-sanitizer.php(522): AMP_Core_Theme_Sanitizer->add_twentytwenty_modals(Array) #1 /home2/gustavors/public_html/wp-content/plugins/amp/includes/templates/class-amp-content-sanitizer.php(117): AMP_Core_Theme_Sanitizer->sanitize() #2 /home2/gustavors/public_html/wp-content/plugins/amp/includes/class-amp-theme-support.php(2275): AMP_Content_Sanitizer::sanitize_document(Object(DOMDocument), Array, Array) #3 /home2/gustavors/public_html/wp-content/plugins/amp/includes/class-amp-theme-support.php(1963): AMP_Theme_Support::prepare_response(‘<!DOCTYPE html>…’) #4 [internal function]: AMP_Theme_Support::finish_output_buffering(‘<!DOCTYPE html>…’, 9) #5 /home2/gustavors/public_html/wp-includes/functions.php(4483): ob_end_flush() #6 /home in /home2/gustavors/public_html/wp-content/plugins/amp/includes/sanitizers/class-amp-core-theme-sanitizer.php on line 1597

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    Thanks for reporting this. It appears you are using a PHP version older than 7.2; in that version DOMNodeList got the count() method because it became Countable: https://www.php.net/manual/en/class.domnodelist.php

    I’ve opened a PR to fix this in the plugin: https://github.com/ampproject/amp-wp/pull/3727

    In the mean time, the quick fix is for you to replace count() with length in class-amp-core-theme-sanitizer.php:

    diff --git a/includes/sanitizers/class-amp-core-theme-sanitizer.php b/includes/sanitizers/class-amp-core-theme-sanitizer.php
    index 83069132..8518f8d3 100644
    --- a/includes/sanitizers/class-amp-core-theme-sanitizer.php
    +++ b/includes/sanitizers/class-amp-core-theme-sanitizer.php
    @@ -1594,7 +1594,7 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer {
     	public function add_twentytwenty_modals() {
     		$modals = $this->xpath->query( "//*[ @class and contains( concat( ' ', normalize-space( @class ), ' ' ), ' cover-modal ' ) ]" );
     
    -		if ( false === $modals || 0 === $modals->count() ) {
    +		if ( false === $modals || 0 === $modals->length ) {
     			return;
     		}
     
    @@ -1672,7 +1672,7 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer {
     		$toggles = $this->xpath->query( '//*[ @data-toggle-target ]' );
     		$body_id = AMP_DOM_Utils::get_element_id( $this->get_body_node(), 'body' );
     
    -		if ( false === $toggles || 0 === $toggles->count() ) {
    +		if ( false === $toggles || 0 === $toggles->length ) {
     			return;
     		}
     
    
    Thread Starter gustavors

    (@gustavors)

    Many thanks for the reply!
    I will wait for the update.
    Glad to collaborate.

    Plugin Author Weston Ruter

    (@westonruter)

    @gustavors v1.4.1 was just released with this fix. You can just update the AMP plugin now to the latest version to fix the error.

    Thread Starter gustavors

    (@gustavors)

    Thanks! I just saw and updated.
    Another thing I just realized.
    In theme 2020, the burger menu was not opening with the click, either on desktop or mobile.
    Now, after the upgrade, it is working normally.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Error’ is closed to new replies.