• Resolved schwifty5

    (@schwifty5)


    I am adding virtual pages programmatically like seen here: https://gist.github.com/gmazzap/1efe17a8cb573e19c086

    Sadly on the virtual pages the AMP plugin is creating a php notice of a too early called is_amp_endpoint() function:

    Notice: is_amp_endpoint was called incorrectly. is_amp_endpoint() was called before the parse_query hook was called.

    Could you please look into this for a fix or give me a hint for a local fix.

    Thanks alot.

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

    (@westonruter)

    I don’t see any instance of is_amp_endpoint() in your Gist. Can you share the stack trace?

    Thread Starter schwifty5

    (@schwifty5)

    The early function call is not in my code, it probably is in the AMP plugin itself?

    Plugin Author Weston Ruter

    (@westonruter)

    Please share the error stack trace as that will indicate what part of your code is causing it to be called.

    Thread Starter schwifty5

    (@schwifty5)

    Hi,

    this is the stack trace for the php notice:

    [0] => Array(
    [function] => {closure}
    )
    
    [1] => Array(
    [file] => /var/www/html/web/wp/wp-includes/functions.php
    [line] => 4986
    [function] => trigger_error
    )
    
    [2] => Array(
    [file] => /var/www/html/web/app/plugins/amp/includes/amp-helper-functions.php
    [line] => 273
    [function] => _doing_it_wrong
    )
    
    [3] => Array(
    [file] => /var/www/html/web/app/plugins/amp/amp.php
    [line] => 454
    [function] => is_amp_endpoint
    )
    
    [4] => Array(
    [file] => /var/www/html/web/wp/wp-includes/class-wp-hook.php
    [line] => 288
    [function] => amp_maybe_add_actions
    )
    
    [5] => Array
            (
                [file] => /var/www/html/web/wp/wp-includes/class-wp-hook.php
                [line] => 312
                [function] => apply_filters
    )
    
    [6] => Array(
    [file] => /var/www/html/web/wp/wp-includes/plugin.php
    [line] => 478
    [function] => do_action
    )
    
    [7] => Array
            (
                [file] => /var/www/html/web/app/mu-plugins/plugin-name/includes/Core/VirtualPages/Controller.class.php
                [line] => 31
                [function] => do_action
    )
    
    [8] => Array
            (
                [file] => /var/www/html/web/wp/wp-includes/class-wp-hook.php
                [line] => 290
                [function] => dispatch
    )
    
    [9] => Array
            (
                [file] => /var/www/html/web/wp/wp-includes/plugin.php
                [line] => 206
                [function] => apply_filters
    )
    
    [10] => Array
            (
                [file] => /var/www/html/web/wp/wp-includes/class-wp.php
                [line] => 145
                [function] => apply_filters
    )
    
    [11] => Array
            (
                [file] => /var/www/html/web/wp/wp-includes/class-wp.php
                [line] => 729
                [function] => parse_request
    )
    
    [12] => Array
            (
                [file] => /var/www/html/web/wp/wp-includes/functions.php
                [line] => 1255
                [function] => main
    )
    
    [13] => Array
            (
                [file] => /var/www/html/web/wp/wp-blog-header.php
                [line] => 16
                [function] => wp
    )
    
    [14] => Array
            (
                [file] => /var/www/html/web/index.php
                [line] => 5
                [function] => require
    )
    

    I already disabled every plugin (except AMP Plugin) and switched the theme (even though it doesnt contain any is_amp_endpoint() call anyways.

    I redacted the args of the stack trace for readability and to prevent leaking of sensible data. If you need the full stack trace with arguments please let me know how to share it with you privately.

    If you are wondering about the file paths: They are from my WP Bedrock setup, but this should not cause the issue here.

    // Edit: Added all steps of stack trace, previous one was truncated.

    • This reply was modified 5 years ago by schwifty5.
    Thread Starter schwifty5

    (@schwifty5)

    Index 7 of the stack trace is refering to this line btw: https://gist.github.com/gmazzap/1efe17a8cb573e19c086#file-controller-php-L34

    Plugin Author Weston Ruter

    (@westonruter)

    OK, your custom router code is doing the parse_request action and wp action, but it is not also doing the parse_query action. That is resulting in the notice:

    https://github.com/ampproject/amp-wp/blob/756d24dc61aa5fb513e554ea6c64c6cdb34ccc2e/includes/amp-helper-functions.php#L262-L275

    Add a do_action( 'parse_query', $wp ); as well, and that should eliminate the notice.

    Thread Starter schwifty5

    (@schwifty5)

    Thank you, this has indeed solved the issue.

    The dispatch function of my controller now looks like this (is this the correct order / params?):

    
    function dispatch($bool, \WP $wp) {
            if ($this->checkRequest() && $this->matched instanceof Page) {
                global $wp_query;
                $this->loader->init($this->matched);
                $wp->virtual_page = $this->matched;
                do_action('parse_request', $wp);
                do_action('parse_query', $wp_query);
                $this->setupQuery();
                do_action('wp', $wp);
                $this->loader->load();
                $this->handleExit();
            }
            return $bool;
        }
    

    Thanks for that awesome and rapid support!

    Plugin Author Weston Ruter

    (@westonruter)

    Yes, that looks good.

    We’d appreciate a plugin review!

    Thread Starter schwifty5

    (@schwifty5)

    Thanks so much. Happy to leave you a very well deserved review.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘is_amp_endpoint was called incorrectly’ is closed to new replies.