• Resolved apavlov2

    (@apavlov2)


    How to reproduce:
    1) Enable PHP logging to E_ALL. you can add this to your wp-config.php -> ini_set( ‘display_errors’, E_ALL );
    2) Visit the page with the plugin enabled.

    Root cause:
    The ‘woocommerce_currency_symbol’ filter is being instantiated in the constructor that is being called before the theme is initialized, therefore the woocommerce ‘is_account_page’ function called within the ‘woocommerce_currency_symbol’ causes the above error.

    To confirm this check line 248 in classes/woocs_after_33.php to confirm is in the __construct function, then go to line 1421 where the ‘is_account_page’ is called.

    I don’t have a valid workaround suggestion for the moment, but let me know if there are issues addressing this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support mediawebster

    (@mediawebster)

    Hello

    In file – \wp-content\plugins\woocommerce-currency-switcher\classes\woocs_after_33.php –
    change line( 1421 ):
    if (function_exists('is_account_page') AND ( is_order_received_page() || is_account_page())) {

    And do test please

    Thread Starter apavlov2

    (@apavlov2)

    Hello,

    this didn’t address the root cause of the issue, in fact it didn’t remove the warning at all.

    Here’s the full Warning message:
    Notice: is_page was called <strong>incorrectly</strong>. Conditional query tags do not work before the query is run. Before then, they always return false. Please see <a href="https://ww.wp.xz.cn/support/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.)

    Note that is_page is called inside the is_account_page function.
    The issue is caused because is_account_page is called before the template_redirect action is executed, and that’s the issue.

    Conceptually you should check if template_redirect has been called before using is_account_page, which is defined in the previous step since WooCommerce is a plugin and loads before this plugin. So the function exists, but if somebody calls ‘woocommerce_currency_symbol’ before the $wp_query is initialized, it will throw the warning.

    The problem with the code of the function is the following:

    
            global $wp_query;
            
            if (!isset($wp_query)) {
                if (is_order_received_page() || is_account_page()) {
                    if (apply_filters('woocs_currency_symbol_on_order', false)) {
                        return $currency_symbol;
                    }
                }
            }
    

    Why is it an issue?
    Because when the $wp_query is not set, both ‘is_order_received_page’ and ‘is_account_page’ use the ‘is_page’ core function which is defined in the wp-includes/query.php as this:

    function is_page( $page = '' ) {
    	global $wp_query;
    
    	if ( ! isset( $wp_query ) ) {
    		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
    		return false;
    	}
    
    	return $wp_query->is_page( $page );
    }

    This means that if the $wp_query is not defined when we call is_page, the notice of doing it wrong will be thrown, and both functions will return false, making the code in the nested if statements not execute.

    A possible solution would be changing the code to:

    
            global $wp_query;
    
            if (!isset($wp_query)) {
                return $currency_symbol;
            }
    

    Let me know if this was helpful.

    Plugin Support mediawebster

    (@mediawebster)

    Hello

    Thank you for cooperation

    I’ll pass your message to developers

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Plugin throws Notice: is_page was called incorrectly.’ is closed to new replies.