Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
291 stars 205 forks source link

Message "is_author was called <strong>incorrectly</strong>" with plugin restrict-user-access #615

Closed Genevieve-K closed 3 years ago

Genevieve-K commented 6 years ago

Message "PHP Notice: is_author was called incorrectly. Conditional query tags do not work before the query is run..."

Stack:

#1  is_author() called at [/var/www/html/wordpress/wp-content/plugins/co-authors-plus/co-authors-plus.php:1075]
#2  CoAuthors_Plus-&gt;fix_author_page( AND wp_3_posts.post_type = 'restriction' AND ((wp_3_posts.post_status = 'publish' OR wp_3_posts.post_status = 'future' OR wp_3_posts.post_status = 'draft'))wp_3_posts.post_date DESC) called at [/var/www/html/wordpress/wp-includes/class-wp-hook.php:286]
#3  WP_Hook-&gt;apply_filters(, Array ([0] =&gt;  AND wp_3_posts.post_type = 'restriction' AND ((wp_3_posts.post_status = 'publish' OR wp_3_posts.post_status = 'future' OR wp_3_posts.post_status = 'draft'))wp_3_posts.post_date DESC)) called at [/var/www/html/wordpress/wp-includes/class-wp-hook.php:310]
#4  WP_Hook-&gt;do_action(Array ([0] =&gt;  AND wp_3_posts.post_type = 'restriction' AND ((wp_3_posts.post_status = 'publish' OR wp_3_posts.post_status = 'future' OR wp_3_posts.post_status = 'draft'))wp_3_posts.post_date DESC)) called at [/var/www/html/wordpress/wp-includes/plugin.php:453]
#5  do_action(posts_selection,  AND wp_3_posts.post_type = 'restriction' AND ((wp_3_posts.post_status = 'publish' OR wp_3_posts.post_status = 'future' OR wp_3_posts.post_status = 'draft'))wp_3_posts.post_date DESC) called at [/var/www/html/wordpress/wp-includes/class-wp-query.php:2602]
#6  WP_Query-&gt;get_posts() called at [/var/www/html/wordpress/wp-includes/class-wp-query.php:3230]
#7  WP_Query-&gt;query(Array ([numberposts] =&gt; -1,[category] =&gt; 0,[orderby] =&gt; date,[order] =&gt; DESC,[include] =&gt; Array (),[exclude] =&gt; Array (),[meta_key] =&gt; ,[meta_value] =&gt; ,[post_type] =&gt; restriction,[suppress_filters] =&gt; 1,[post_status] =&gt; Array ([0] =&gt; publish,[1] =&gt; draft,[2] =&gt; future),[posts_per_page] =&gt; -1,[ignore_sticky_posts] =&gt; 1,[no_found_rows] =&gt; 1)) called at [/var/www/html/wordpress/wp-includes/post.php:1763]
#8  get_posts(Array ([numberposts] =&gt; -1,[post_type] =&gt; restriction,[post_status] =&gt; Array ([0] =&gt; publish,[1] =&gt; draft,[2] =&gt; future))) called at [/var/www/html/wordpress/wp-content/plugins/restrict-user-access/app.php:315]...

I took the last version of co-authors-plus.php, the issue is the same.

rebeccahum commented 5 years ago

@Genevieve-K Are you able to expand on where you are seeing this and the steps on reproducing?

benlk commented 5 years ago

With WP_DEBUG, I'm seeing this same error message in several places on every page, in the server log, and prefixed on the output of every wp-cli command.

$ wp plugin list
PHP Notice:  is_author 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://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in /Users/benlk/sites/publicsource/wp-includes/functions.php on line 4231
Notice: is_author 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://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in /Users/benlk/sites/publicsource/wp-includes/functions.php on line 4231
+------------------------------+----------+-----------+---------+
| name                         | status   | update    | version |
+------------------------------+----------+-----------+---------+
...

Disabling Co-Authors Plus fixes the problem:

$ wp plugin deactivate co-authors-plus
PHP Notice:  is_author 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://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in /Users/benlk/sites/publicsource/wp-includes/functions.php on line 4231
Notice: is_author 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://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in /Users/benlk/sites/publicsource/wp-includes/functions.php on line 4231
Plugin 'co-authors-plus' deactivated.
Success: Deactivated 1 of 1 plugins.
$ wp plugin list
+------------------------------+----------+-----------+---------+
| name                         | status   | update    | version |
+------------------------------+----------+-----------+---------+
...
Other plugins active at this time ``` $ wp plugin list +------------------------------+----------+-----------+---------+ | name | status | update | version | +------------------------------+----------+-----------+---------+ | akismet | active | available | 4.1 | | better-search-replace | active | none | 1.3.2 | | bwp-google-xml-sitemaps | active | none | 1.4.1 | | classic-editor | inactive | available | 1.3 | | client-hosting-manager | inactive | none | 1.0.0 | | co-authors-plus | inactive | none | 3.3.1 | | disqus-comment-system | inactive | none | 3.0.16 | | documentcloud | active | none | 0.4.3 | | doubleclick-for-wp | active | none | 0.3 | | genius | active | none | 0.0.6 | | google-authenticator | active | none | 0.48 | | gravityforms | active | none | 2.4.5.3 | | gravityformssubtotal | active | none | 1.0 | | gravityformsmailchimp | active | none | 4.5 | | gravityformsstripe | active | none | 2.5.4 | | hello | inactive | none | 1.6 | | insert-headers-and-footers | active | none | 1.4.3 | | news-match-popup-basics | inactive | none | 0.1.3 | | no-nonsense-google-analytics | active | none | 1.3 | | php-compatibility-checker | inactive | none | 1.4.7 | | popup-maker | active | none | 1.7.30 | | publish-to-apple-news | active | none | 1.4.3 | | redirection | active | available | 3.7.2 | | regenerate-thumbnails | inactive | none | 3.1.0 | | slack | active | none | 0.6.0 | | super-cool-ad-inserter | active | none | 0.2 | | taxonomy-converter | inactive | none | 1.1 | | term-debt-consolidator | inactive | none | 0.1.0 | | tweetable-text | active | none | 1.1 | | wordpress-importer | inactive | none | 0.6.4 | +------------------------------+----------+-----------+---------+ ```
benlk commented 5 years ago

Addendum: After disabling akismet better-search-replace bwp-google-xml-sitemaps tweetable-text slack publish-to-apple-news popup-maker no-nonsense-google-analytics insert-headers-and-footers gravityformsstripe gravityformsmailchimp gravityforms gravityformssubtotal, the message also went away, so this is probably the intersection of CAP and some other plugin.

rebeccahum commented 5 years ago

@benlk Are you able to pinpoint which plugin?

Oazar commented 5 years ago

Hello,

I am using co-autor plugin and have this problem as well on login page :

Notice: is_author was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /home/acania/public_html/2019/wp-includes/functions.php on line 4773

For me it is related to WP salt keys, the problem disppears when I remove salt keys from wp-config.php

benlk commented 5 years ago

@Oazar What plugins are active on that site? If you have access to run wp-cli commands, pasting the output from wp plugin list here would help.

Oazar commented 5 years ago

Hello Benlk an thanks for your help.

the theme is woffice and here are the plugins

[09-Oct-2019 18:59:46 UTC] Array ( [akismet/akismet.php] => Array ( [Name] => Akismet Anti-Spam [PluginURI] => https://akismet.com/ [Version] => 4.1.2 [Description] => Used by millions, Akismet is quite possibly the best way in the world to protect your blog from spam. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key. [Author] => Automattic [AuthorURI] => https://automattic.com/wordpress-plugins/ [TextDomain] => akismet [DomainPath] => [Network] => [Title] => Akismet Anti-Spam [AuthorName] => Automattic )

[ari-adminer/ari-adminer.php] => Array
    (
        [Name] => ARI Adminer
        [PluginURI] => http://wp-quiz.ari-soft.com/plugins/wordpress-adminer.html
        [Version] => 1.2.3
        [Description] => Powerful, compact and easy to use database manager plugin for WordPress.
        [Author] => ARI Soft
        [AuthorURI] => http://www.ari-soft.com
        [TextDomain] => ari-adminer
        [DomainPath] => /languages
        [Network] => 
        [Title] => ARI Adminer
        [AuthorName] => ARI Soft
    )

[bnfw/bnfw.php] => Array
    (
        [Name] => Better Notifications for WP
        [PluginURI] => https://wordpress.org/plugins/bnfw/
        [Version] => 1.7.5
        [Description] => Supercharge your WordPress notifications using a WYSIWYG editor and shortcodes. Default and new notifications available. Add more power with Add-ons.
        [Author] => Made with Fuel
        [AuthorURI] => https://betternotificationsforwp.com/
        [TextDomain] => bnfw
        [DomainPath] => /languages
        [Network] => 
        [Title] => Better Notifications for WP
        [AuthorName] => Made with Fuel
    )

[buddypress/bp-loader.php] => Array
    (
        [Name] => BuddyPress
        [PluginURI] => https://buddypress.org/
        [Version] => 5.0.0
        [Description] => BuddyPress adds community features to WordPress. Member Profiles, Activity Streams, Direct Messaging, Notifications, and more!
        [Author] => The BuddyPress Community
        [AuthorURI] => https://buddypress.org/
        [TextDomain] => buddypress
        [DomainPath] => /bp-languages/
        [Network] => 
        [Title] => BuddyPress
        [AuthorName] => The BuddyPress Community
    )

[bp-group-activities-notifier/bp-group-activities-notifier.php] => Array
    (
        [Name] => BuddyPress Group Activities Notifier
        [PluginURI] => https://buddydev.com/plugins/bp-group-activities-notifier/
        [Version] => 1.0.4
        [Description] => Notifies on any action in the group to all group members. I have tested with group join, group post update, forum post/reply. Should work with others too
        [Author] => BuddyDev Team
        [AuthorURI] => https://buddydev.com
        [TextDomain] => bp-group-activities-notifier
        [DomainPath] => 
        [Network] => 
        [Title] => BuddyPress Group Activities Notifier
        [AuthorName] => BuddyDev Team
    )

[wiz-em-send-email-group/send_email_activity.php] => Array
    (
        [Name] => BuddyPress Group Email Activity
        [PluginURI] => 
        [Version] => 1.0
        [Description] => Allows group members to receive email notifications for group activity.
        [Author] => Wizengo
        [AuthorURI] => 
        [TextDomain] => wiz-em-send-email-group
        [DomainPath] => 
        [Network] => 
        [Title] => BuddyPress Group Email Activity
        [AuthorName] => Wizengo
    )

[cache-enabler/cache-enabler.php] => Array
    (
        [Name] => Cache Enabler
        [PluginURI] => 
        [Version] => 1.3.4
        [Description] => Simple and fast WordPress disk caching plugin.
        [Author] => KeyCDN
        [AuthorURI] => https://www.keycdn.com
        [TextDomain] => cache-enabler
        [DomainPath] => 
        [Network] => 
        [Title] => Cache Enabler
        [AuthorName] => KeyCDN
    )

[classic-editor/classic-editor.php] => Array
    (
        [Name] => Classic Editor
        [PluginURI] => https://wordpress.org/plugins/classic-editor/
        [Version] => 1.5
        [Description] => Enables the WordPress classic editor and the old-style Edit Post screen with TinyMCE, Meta Boxes, etc. Supports the older plugins that extend this screen.
        [Author] => WordPress Contributors
        [AuthorURI] => https://github.com/WordPress/classic-editor/
        [TextDomain] => classic-editor
        [DomainPath] => /languages
        [Network] => 
        [Title] => Classic Editor
        [AuthorName] => WordPress Contributors
    )

[co-authors-plus/co-authors-plus.php] => Array
    (
        [Name] => Co-Authors Plus
        [PluginURI] => http://wordpress.org/extend/plugins/co-authors-plus/
        [Version] => 3.4
        [Description] => Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter.
        [Author] => Mohammad Jangda, Daniel Bachhuber, Automattic
        [AuthorURI] => 
        [TextDomain] => co-authors-plus
        [DomainPath] => 
        [Network] => 
        [Title] => Co-Authors Plus
        [AuthorName] => Mohammad Jangda, Daniel Bachhuber, Automattic
    )

[contact-form-7/wp-contact-form-7.php] => Array
    (
        [Name] => Contact Form 7
        [PluginURI] => https://contactform7.com/
        [Version] => 5.1.4
        [Description] => Just another contact form plugin. Simple but flexible.
        [Author] => Takayuki Miyoshi
        [AuthorURI] => https://ideasilo.wordpress.com/
        [TextDomain] => contact-form-7
        [DomainPath] => /languages/
        [Network] => 
        [Title] => Contact Form 7
        [AuthorName] => Takayuki Miyoshi
    )

[content-aware-sidebars/content-aware-sidebars.php] => Array
    (
        [Name] => Content Aware Sidebars
        [PluginURI] => https://dev.institute/wordpress-sidebars/
        [Version] => 3.9
        [Description] => Unlimited custom sidebars and widget areas for any post, page, category etc.
        [Author] => Joachim Jensen - DEV Institute
        [AuthorURI] => https://dev.institute
        [TextDomain] => content-aware-sidebars
        [DomainPath] => /lang/
        [Network] => 
        [Title] => Content Aware Sidebars
        [AuthorName] => Joachim Jensen - DEV Institute
    )

[countdown-timer-ultimate/countdown-timer.php] => Array
    (
        [Name] => Countdown Timer Ultimate
        [PluginURI] => https://www.wponlinesupport.com/plugins/
        [Version] => 1.2.3
        [Description] => Easy to add and display responsive Countdown timer on your website. Also work with Gutenberg shortcode block.
        [Author] => WP OnlineSupport
        [AuthorURI] => https://www.wponlinesupport.com/
        [TextDomain] => countdown-timer-ultimate
        [DomainPath] => /languages/
        [Network] => 
        [Title] => Countdown Timer Ultimate
        [AuthorName] => WP OnlineSupport
    )

[duplicate-post/duplicate-post.php] => Array
    (
        [Name] => Duplicate Post
        [PluginURI] => https://duplicate-post.lopo.it/
        [Version] => 3.2.3
        [Description] => Clone posts and pages.
        [Author] => Enrico Battocchi
        [AuthorURI] => https://lopo.it
        [TextDomain] => duplicate-post
        [DomainPath] => 
        [Network] => 
        [Title] => Duplicate Post
        [AuthorName] => Enrico Battocchi
    )

[mediapress/mediapress.php] => Array
    (
        [Name] => MediaPress
        [PluginURI] => https://buddydev.com/mediapress/
        [Version] => 1.4.6
        [Description] => MediaPress is the most powerful media plugin for BuddyPress . It allows uploading images(photos), videos, audios, documents
        [Author] => BuddyDev
        [AuthorURI] => https://buddydev.com
        [TextDomain] => mediapress
        [DomainPath] => /languages
        [Network] => 
        [Title] => MediaPress
        [AuthorName] => BuddyDev
    )

[nav-menu-roles/nav-menu-roles.php] => Array
    (
        [Name] => Nav Menu Roles
        [PluginURI] => http://www.kathyisawesome.com/449/nav-menu-roles/
        [Version] => 1.9.5
        [Description] => Hide custom menu items based on user roles.
        [Author] => Kathy Darling
        [AuthorURI] => http://www.kathyisawesome.com
        [TextDomain] => nav-menu-roles
        [DomainPath] => 
        [Network] => 
        [Title] => Nav Menu Roles
        [AuthorName] => Kathy Darling
    )

[peters-login-redirect/wplogin_redirect.php] => Array
    (
        [Name] => Peter's Login Redirect
        [PluginURI] => http://www.theblog.ca/wplogin-redirect
        [Version] => 2.9.4
        [Description] => Redirect users to different locations after logging in. Define a set of rules for specific users, user with specific roles, users with specific capabilities, and a blanket rule for all other users. This is all managed in Settings > Login/logout redirects.
        [Author] => Peter Keung
        [AuthorURI] => http://www.theblog.ca
        [TextDomain] => peters-login-redirect
        [DomainPath] => /languages/
        [Network] => 
        [Title] => Peter's Login Redirect
        [AuthorName] => Peter Keung
    )

[restrict-user-access/restrict-user-access.php] => Array
    (
        [Name] => Restrict User Access
        [PluginURI] => https://dev.institute/wordpress-memberships/
        [Version] => 1.1.2
        [Description] => Easily restrict content and contexts to provide premium access for specific User Levels.
        [Author] => Joachim Jensen
        [AuthorURI] => https://dev.institute
        [TextDomain] => restrict-user-access
        [DomainPath] => 
        [Network] => 
        [Title] => Restrict User Access
        [AuthorName] => Joachim Jensen
    )

[nextend-smart-slider3-pro/nextend-smart-slider3-pro.php] => Array
    (
        [Name] => Smart Slider 3 Pro
        [PluginURI] => https://smartslider3.com/
        [Version] => 3.3.22
        [Description] => The perfect all-in-one responsive slider solution for WordPress.
        [Author] => Nextend
        [AuthorURI] => http://nextendweb.com
        [TextDomain] => nextend-smart-slider3-pro
        [DomainPath] => 
        [Network] => 
        [Title] => Smart Slider 3 Pro
        [AuthorName] => Nextend
    )

[ticker-ultimate/wp-ticker.php] => Array
    (
        [Name] => Ticker Ultimate
        [PluginURI] => 
        [Version] => 1.2.4
        [Description] => Ultimate Ticker Plugin : Add and display horizontal or vertical tickers on your website that work with WordPress posts and Custom Post Type with the help of shortcode. Also work with Gutenberg shortcode block.
        [Author] => WP OnlineSupport
        [AuthorURI] => https://www.wponlinesupport.com/
        [TextDomain] => ticker-ultimate
        [DomainPath] => /languages/
        [Network] => 
        [Title] => Ticker Ultimate
        [AuthorName] => WP OnlineSupport
    )

[translatepress-multilingual/index.php] => Array
    (
        [Name] => TranslatePress - Multilingual
        [PluginURI] => https://translatepress.com/
        [Version] => 1.5.9
        [Description] => Experience a better way of translating your WordPress site using a visual front-end translation editor, with full support for WooCommerce and site builders.
        [Author] => Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
        [AuthorURI] => https://cozmoslabs.com/
        [TextDomain] => translatepress-multilingual
        [DomainPath] => /languages
        [Network] => 
        [Title] => TranslatePress - Multilingual
        [AuthorName] => Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
    )

[unyson/unyson.php] => Array
    (
        [Name] => Unyson
        [PluginURI] => http://unyson.io/
        [Version] => 2.7.22
        [Description] => A free drag & drop framework that comes with a bunch of built in extensions that will help you develop premium themes fast & easy.
        [Author] => ThemeFuse
        [AuthorURI] => http://themefuse.com
        [TextDomain] => fw
        [DomainPath] => /framework/languages
        [Network] => 
        [Title] => Unyson
        [AuthorName] => ThemeFuse
    )

[user-role-editor/user-role-editor.php] => Array
    (
        [Name] => User Role Editor
        [PluginURI] => https://www.role-editor.com
        [Version] => 4.52
        [Description] => Change/add/delete WordPress user roles and capabilities.
        [Author] => Vladimir Garagulya
        [AuthorURI] => https://www.role-editor.com
        [TextDomain] => user-role-editor
        [DomainPath] => /lang/
        [Network] => 
        [Title] => User Role Editor
        [AuthorName] => Vladimir Garagulya
    )

[wiz-em/wiz-em.php] => Array
    (
        [Name] => Wizengo Esprit Manager
        [PluginURI] => 
        [Version] => 2.0.0
        [Description] => Fonctionnalités.
        [Author] => Anthony Wizengo
        [AuthorURI] => 
        [TextDomain] => wiz-em
        [DomainPath] => 
        [Network] => 
        [Title] => Wizengo Esprit Manager
        [AuthorName] => Anthony Wizengo
    )

[wordpress-importer/wordpress-importer.php] => Array
    (
        [Name] => WordPress Importer
        [PluginURI] => https://wordpress.org/plugins/wordpress-importer/
        [Version] => 0.6.4
        [Description] => Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
        [Author] => wordpressdotorg
        [AuthorURI] => https://wordpress.org/
        [TextDomain] => wordpress-importer
        [DomainPath] => 
        [Network] => 
        [Title] => WordPress Importer
        [AuthorName] => wordpressdotorg
    )

[wp-optimize/wp-optimize.php] => Array
    (
        [Name] => WP-Optimize - Clean, Compress, Cache
        [PluginURI] => https://getwpo.com
        [Version] => 3.0.12
        [Description] => WP-Optimize makes your site fast and efficient. It cleans the database, compresses images and caches pages. Fast sites attract more traffic and users.
        [Author] => David Anderson, Ruhani Rabin, Team Updraft
        [AuthorURI] => https://updraftplus.com
        [TextDomain] => wp-optimize
        [DomainPath] => /languages
        [Network] => 
        [Title] => WP-Optimize - Clean, Compress, Cache
        [AuthorName] => David Anderson, Ruhani Rabin, Team Updraft
benlk commented 5 years ago
$ diff -y benlk oazar 
better-search-replace                         | akismet
bwp-google-xml-sitemaps                       | ari-adminer
                                  > bnfw
                                  > buddypress
                                  > bp-group-activities-notifier
                                  > wiz-em-send-email-group
                                  > cache-enabler
                                  > classic-editor
co-authors-plus                         co-authors-plus
gravityforms                              | contact-form-7
gravityformsmailchimp                         | content-aware-sidebars
gravityformsstripe                        | countdown-timer-ultimate
gravityformssubtotal                          | duplicate-post
insert-headers-and-footers                    | mediapress
no-nonsense-google-analytics                      | nav-menu-roles
popup-maker                           | peters-login-redirect
publish-to-apple-news                         | restrict-user-access
slack                                 | nextend-smart-slider3-pro
tweetable-text                            | ticker-ultimate
                                  > translatepress-multilingual
                                  > unyson
                                  > user-role-editor
                                  > wiz-em
                                  > wordpress-importer
                                  > wp-optimize

There are no overlapping plugins between our two installs, besides CAP.

Oazar commented 5 years ago

So ? anything I can do about this ?

danjaworsky commented 3 years ago

Hi, I'm getting the same error and it's being called with the Woocommerce Memberships plugin.

rebeccahum commented 3 years ago

@nielslange Might be worth adding some defensive coding in CAP to prevent this notice from being thrown. Can you look into this please?

rebeccahum commented 3 years ago

Also, this notice usually occurs when get_posts() or WP_Query is called too early (which seem to be stemming from other plugins). I was able to reproduce with WC Memberships, stacktrace:

#0 CoAuthors_Plus->fix_author_page( AND wp_posts.post_author IN (1) AND wp_posts.post_type = 'wc_user_membership' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))wp_posts.post_date DESC) called at [/srv/www/example/public_html/wp-includes/class-wp-hook.php:292] #1 WP_Hook->apply_filters(, Array ([0] => AND wp_posts.post_author IN (1) AND wp_posts.post_type = 'wc_user_membership' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))wp_posts.post_date DESC)) called at [/srv/www/example/public_html/wp-includes/class-wp-hook.php:316] #2 WP_Hook->do_action(Array ([0] => AND wp_posts.post_author IN (1) AND wp_posts.post_type = 'wc_user_membership' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))wp_posts.post_date DESC)) called at [/srv/www/example/public_html/wp-includes/plugin.php:484] #3 do_action(posts_selection, AND wp_posts.post_author IN (1) AND wp_posts.post_type = 'wc_user_membership' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))wp_posts.post_date DESC) called at [/srv/www/example/public_html/wp-includes/class-wp-query.php:2799] #4 WP_Query->get_posts() called at [/srv/www/example/public_html/wp-includes/class-wp-query.php:3465] #5 WP_Query->query(Array ([numberposts] => 5,[category] => 0,[orderby] => date,[order] => DESC,[include] => Array (),[exclude] => Array (),[meta_key] => ,[meta_value] => ,[post_type] => wc_user_membership,[suppress_filters] => 1,[author] => 1,[post_status] => any,[nopaging] => 1,[posts_per_page] => 5,[ignore_sticky_posts] => 1,[no_found_rows] => 1)) called at [/srv/www/example/public_html/wp-includes/post.php:2153] #6 get_posts(Array ([author] => 1,[post_type] => wc_user_membership,[post_status] => any,[nopaging] => 1)) called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/includes/class-wc-memberships-user-memberships.php:322] #7 WC_Memberships_User_Memberships->get_user_memberships(1, Array ([status] => any)) called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/includes/functions/wc-memberships-functions-user-memberships.php:56] #8 wc_memberships_get_user_memberships() called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/includes/functions/wc-memberships-functions-members-area.php:93] #9 wc_memberships_get_members_area_endpoint() called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/includes/frontend/My_Account/Members_Area.php:69] #10 SkyVerge\WooCommerce\Memberships\Frontend\My_Account\Members_Area->__construct() called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:810] #11 SkyVerge\WooCommerce\PluginFramework\v5_10_2\SV_WC_Plugin->load_class(/includes/frontend/My_Account/Members_Area.php, SkyVerge\WooCommerce\Memberships\Frontend\My_Account\Members_Area) called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/includes/frontend/My_Account.php:53] #12 SkyVerge\WooCommerce\Memberships\Frontend\My_Account->__construct() called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:810] #13 SkyVerge\WooCommerce\PluginFramework\v5_10_2\SV_WC_Plugin->load_class(/includes/frontend/My_Account.php, SkyVerge\WooCommerce\Memberships\Frontend\My_Account) called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/includes/frontend/class-wc-memberships-frontend.php:61] #14 WC_Memberships_Frontend->__construct() called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:810] #15 SkyVerge\WooCommerce\PluginFramework\v5_10_2\SV_WC_Plugin->load_class(/includes/frontend/class-wc-memberships-frontend.php, WC_Memberships_Frontend) called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/class-wc-memberships.php:355] #16 WC_Memberships->frontend_includes() called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/class-wc-memberships.php:282] #17 WC_Memberships->includes() called at [/srv/www/example/public_html/wp-content/plugins/woocommerce-memberships/class-wc-memberships.php:161] #18 WC_Memberships->init_plugin() called at [/srv/www/example/public_html/wp-includes/class-wp-hook.php:292] #19 WP_Hook->apply_filters(, Array ([0] => )) called at [/srv/www/example/public_html/wp-includes/class-wp-hook.php:316] #20 WP_Hook->do_action(Array ([0] => )) called at [/srv/www/example/public_html/wp-includes/plugin.php:484] #21 do_action(plugins_loaded) called at [/srv/www/example/public_html/wp-settings.php:423] #22 require_once(/srv/www/example/public_html/wp-settings.php) called at [/srv/www/example/public_html/wp-config.php:81] #23 require_once(/srv/www/example/public_html/wp-config.php) called at [/srv/www/example/public_html/wp-load.php:37] #24 require_once(/srv/www/example/public_html/wp-load.php) called at [/srv/www/example/public_html/wp-blog-header.php:13] #25 require(/srv/www/example/public_html/wp-blog-header.php) called at [/srv/www/example/public_html/index.php:17]
nielslange commented 3 years ago

@nielslange Might be worth adding some defensive coding in CAP to prevent this notice from being thrown. Can you look into this please?

@rebeccahum I'll look into this issue the next days.

nielslange commented 3 years ago

@rebeccahum I looked up this issue and could reproduce it using WooCommerce Memberships. AFAICS, the problem is triggered by

https://github.com/Automattic/Co-Authors-Plus/blob/b728b0850c17e5c3f0fce37a6345af20e0939af7/co-authors-plus.php#L113

Removing this call, does not affect the unit tests, but the posts_selection action seems to be used for caching.

What are your thoughts on removing this call? I also looked in defensive programming, but couldn't find an option doing so.

rebeccahum commented 3 years ago

@nielslange We don't want to remove that action since that would directly affect functionality on CAP.

Why do you think the error is being triggered?

nielslange commented 3 years ago

Why do you think the error is being triggered?

I'd say the error is triggered as other plugins, e.g. WooCommerce Memberships trigger the CAP action too early. Above, you mentioned defensive coding, but I cannot come up with a defensive coding strategy in this particular case. I looked up various options, but couldn't find something suitable.

rebeccahum commented 3 years ago

@nielslange Since the CAP action is being triggered too early, what is being expected from it that is not there when it gets triggered by another plugin?

nielslange commented 3 years ago

AFAICS, posts are expected by the time the WooCommerce Memberships triggers the CAP action. The corresponding section can be found in https://github.com/woocommerce/woocommerce-memberships/blob/4fa2efd45c5fe19803ce10b344c4c040cea5f1cf/includes/class-wc-memberships-user-memberships.php#L322:

$posts = get_posts( $posts_args );

I was thinking about checking if WP_Query exists and/or if posts exist. So far, I wasn't able to come up with something that is working. I wonder if I'm looking in the wrong direction. 🤔

rebeccahum commented 3 years ago

I was thinking about checking if WP_Query exists and/or if posts exist.

@nielslange That's a good thought direction! In the error message, it says:

Conditional query tags do not work before the query is run.

What does that tell you about what is actually there when it is being run?

nielslange commented 3 years ago

What does that tell you about what is actually there when it is being run?

@rebeccahum Based on that message, I'd say that there's no query, which would be required. I do have to admit that I don't know how to solve this problem, though.

rebeccahum commented 3 years ago

@nielslange So if there is no query, what type of defensive coding would you want to employ?

lkraav commented 3 years ago

Another WCM user here with this notice generating massive log spam: 65 k notices in 3 days.

Although cause is already mostly identified in above comments, an additional quality stack trace probably doesn't hurt https://sentry.io/share/issue/06b09e81cd774197913c8965cd811ad4/

If you're using any conditionals like is_author(), any relevant functionality they guard should avoid any business before wp action.

So how about simply


public function fix_author_page( $selection ) {

                if ( ! did_action( 'wp' ) ) {
                        return;
                }

                if ( ! is_author() ) {
                        return;
                }

                ...
}
nielslange commented 3 years ago

Thanks for your suggestion, @lkraav. I already went a different route last week and just pushed the changes. Nevertheless, your suggestion is much appreciated.