GatoGraphQL / GatoGraphQL

Interact with all your data in WordPress using GraphQL

Home Page:https://gatographql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Notice(s): is_singular was called incorrectly & undefined index

thefrosty opened this issue · comments

Detailed description

Getting a couple PHP Notices when following the composer install steps.

is_singlular

PHP Notice:  is_singular 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://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in /usr/local/wordpress/wp-includes/functions.php on line 5458
[24-Jun-2021 16:30:32 UTC] PHP Stack trace:
[24-Jun-2021 16:30:32 UTC] PHP   1. {main}() /usr/local/wordpress/wp-admin/admin-ajax.php:0
[24-Jun-2021 16:30:32 UTC] PHP   2. require_once() /usr/local/wordpress/wp-admin/admin-ajax.php:22
[24-Jun-2021 16:30:32 UTC] PHP   3. require_once() /usr/local/wordpress/wp-load.php:50
[24-Jun-2021 16:30:32 UTC] PHP   4. require_once() /usr/local/wordpress/wp-config.php:151
[24-Jun-2021 16:30:32 UTC] PHP   5. do_action($hook_name = 'plugins_loaded') /usr/local/wordpress/wp-settings.php:441
[24-Jun-2021 16:30:32 UTC] PHP   6. WP_Hook->do_action($args = [0 => '']) /usr/local/wordpress/wp-includes/plugin.php:470
[24-Jun-2021 16:30:32 UTC] PHP   7. WP_Hook->apply_filters($value = '', $args = [0 => '']) /usr/local/wordpress/wp-includes/class-wp-hook.php:327
[24-Jun-2021 16:30:32 UTC] PHP   8. GraphQLAPI\GraphQLAPI\Plugin->bootApplication('') /usr/local/wordpress/wp-includes/class-wp-hook.php:303
[24-Jun-2021 16:30:32 UTC] PHP   9. PoP\Root\AppLoader::bootApplication($cacheContainerConfiguration = TRUE, $containerNamespace = '_v0.7.13_1624552110_admin') /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/src/Plugin.php:280
[24-Jun-2021 16:30:32 UTC] PHP  10. PoP\Engine\AppLoader::bootComponents() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/root/src/AppLoader.php:173
[24-Jun-2021 16:30:32 UTC] PHP  11. PoP\Root\Managers\ComponentManager::beforeBoot() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/engine/src/AppLoader.php:19
[24-Jun-2021 16:30:32 UTC] PHP  12. PoP\Root\Component::beforeBoot() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/root/src/Managers/ComponentManager.php:37
[24-Jun-2021 16:30:32 UTC] PHP  13. PoP\Root\Container\ServiceInstantiator->initializeServices() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/root/src/Component.php:59
[24-Jun-2021 16:30:32 UTC] PHP  14. GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\GraphiQLExplorerInCustomEndpointPublicClient\Overrides\Services\Clients\CustomEndpointGraphiQLWithExplorerClient->initialize() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/root/src/Container/ServiceInstantiator.php:28
[24-Jun-2021 16:30:32 UTC] PHP  15. GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\GraphiQLExplorerInCustomEndpointPublicClient\Overrides\Services\Clients\CustomEndpointGraphiQLWithExplorerClient->isClientDisabled() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/graphql-by-pop/graphql-clients-for-wp/src/Clients/AbstractClient.php:27
[24-Jun-2021 16:30:32 UTC] PHP  16. is_singular($post_types = 'graphql-endpoint') /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/src/Clients/CustomEndpointClientTrait.php:18
[24-Jun-2021 16:30:32 UTC] PHP  17. _doing_it_wrong($function = 'is_singular', $message = 'Conditional query tags do not work before the query is run. Before then, they always return false.', $version = '3.1.0') /usr/local/wordpress/wp-includes/query.php:765
[24-Jun-2021 16:30:32 UTC] PHP  18. trigger_error($message = 'is_singular 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://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.)', $error_type = 1024) /usr/local/wordpress/wp-includes/functions.php:5458

Undefined index

PHP Notice:  Undefined index:  in /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/migrate-component-model/migrate/kernel/strata/stratum-manager.php on line 42
[24-Jun-2021 16:37:16 UTC] PHP Stack trace:
[24-Jun-2021 16:37:16 UTC] PHP   1. {main}() /usr/local/wordpress/wp-admin/admin-ajax.php:0
[24-Jun-2021 16:37:16 UTC] PHP   2. require_once() /usr/local/wordpress/wp-admin/admin-ajax.php:22
[24-Jun-2021 16:37:16 UTC] PHP   3. require_once() /usr/local/wordpress/wp-load.php:50
[24-Jun-2021 16:37:16 UTC] PHP   4. require_once() /usr/local/wordpress/wp-config.php:151
[24-Jun-2021 16:37:16 UTC] PHP   5. do_action($hook_name = 'wp_loaded') /usr/local/wordpress/wp-settings.php:600
[24-Jun-2021 16:37:16 UTC] PHP   6. WP_Hook->do_action($args = [0 => '']) /usr/local/wordpress/wp-includes/plugin.php:470
[24-Jun-2021 16:37:16 UTC] PHP   7. WP_Hook->apply_filters($value = '', $args = [0 => '']) /usr/local/wordpress/wp-includes/class-wp-hook.php:327
[24-Jun-2021 16:37:16 UTC] PHP   8. PoP\EngineWP\LooseContracts\LooseContractResolutionSet->PoP\EngineWP\LooseContracts\{closure:/usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/engine-wp/src/LooseContracts/LooseContractResolutionSet.php:23-25}('') /usr/local/wordpress/wp-includes/class-wp-hook.php:303
[24-Jun-2021 16:37:16 UTC] PHP   9. PoP\HooksWP\HooksAPI->doAction($tag = 'popcms:boot') /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/engine-wp/src/LooseContracts/LooseContractResolutionSet.php:24
[24-Jun-2021 16:37:16 UTC] PHP  10. do_action($hook_name = 'popcms:boot') /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/hooks-wp/src/HooksAPI.php:40
[24-Jun-2021 16:37:16 UTC] PHP  11. WP_Hook->do_action($args = [0 => '']) /usr/local/wordpress/wp-includes/plugin.php:470
[24-Jun-2021 16:37:16 UTC] PHP  12. WP_Hook->apply_filters($value = '', $args = [0 => '']) /usr/local/wordpress/wp-includes/class-wp-hook.php:327
[24-Jun-2021 16:37:16 UTC] PHP  13. PoPSchema\UserStateAccessControl\Hooks\DisableDirectivesIfUserIsLoggedInConfigurableAccessControlForDirectivesInPrivateSchemaHookSet->cmsBoot('') /usr/local/wordpress/wp-includes/class-wp-hook.php:303
[24-Jun-2021 16:37:17 UTC] PHP  14. PoPSchema\UserStateAccessControl\Hooks\DisableDirectivesIfUserIsLoggedInConfigurableAccessControlForDirectivesInPrivateSchemaHookSet->enabled() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/access-control/src/Hooks/AbstractAccessControlForDirectivesHookSet.php:15
[24-Jun-2021 16:37:17 UTC] PHP  15. PoP\ComponentModel\State\ApplicationState::getVars() /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/pop-schema/user-state-access-control/src/Hooks/AbstractUserStateConfigurableAccessControlForDirectivesInPrivateSchemaHookSet.php:14
[24-Jun-2021 16:37:17 UTC] PHP  16. PoP\ComponentModel\StratumManager->getStrata($stratum = NULL) /usr/local/wordpress/wp-content/plugins/graphql-api-for-wp/vendor/getpop/component-model/src/State/ApplicationState.php:96

Context

WP_DEBUG=true

Your environment

Include as many relevant details about the environment you experienced the bug in and how to reproduce it.

Software Version
GraphQL API plugin 0.7.13
PHP 7.4
WordPress 5.7.2
Gutenberg NA

Running a stack trace in the is_singular error, I see it's attempting to run that conditional function on plugins_loaded which is too soon for WordPress' query functions.

CustomEndpointClientTrait::isClientDisabled

protected function isClientDisabled(): bool
    {
        error_log(print_r([current_filter(),wp_debug_backtrace_summary()], true));
        if (!\is_singular(GraphQLEndpointPostType::POST_TYPE)) {
            return true;
        }
        return parent::isClientDisabled();
    }

Output:

[24-Jun-2021 16:49:56 UTC] Array
(
    [0] => plugins_loaded
    [1] => require_once('wp-load.php'), 
require_once('wp-config.php'), require_once('wp-settings.php'), 
do_action('plugins_loaded'), WP_Hook->do_action, 
WP_Hook->apply_filters, GraphQLAPI\GraphQLAPI\Plugin->bootApplication, 
PoP\Root\AppLoader::bootApplication, PoP\Engine\AppLoader::bootComponents, 
PoP\Root\Managers\ComponentManager::beforeBoot, PoP\Root\Component::beforeBoot, 
PoP\Root\Container\ServiceInstantiator->initializeServices, 
GraphQLByPoP\GraphQLClientsForWP\Clients\AbstractClient->initialize, 
GraphQLAPI\GraphQLAPI\Clients\CustomEndpointVoyagerClient->isClientDisabled
)

The Undefined index is in PoP\ComponentModel\StratumManager::getStrata

Before

public function getStrata($stratum = null)
    {
        $stratum = $stratum ?? $this->selected_stratum;
        return $this->stratum_strata[$stratum];
    }

Fix (unknowing the expected return value...)

public function getStrata($stratum = null)
    {
        $stratum = $stratum ?? $this->selected_stratum;
        return $this->stratum_strata[$stratum] ?? null;
    }

I believe I have already fixed this error for the upcoming v0.8. You can download it under artifact "generated-plugins" here (it is still under development, but I believe it is stable enough; I suggest installing it on a DEV environment first, to be on the safe side):

https://github.com/leoloso/PoP/actions/runs/968077812

Actually wait, don't install it yet, the match operator downgrade is currently incomplete (I need to use the latest version of Rector) so it'll fail for PHP 7.4. I'll let you know.

Actually wait, don't install it yet, the match operator downgrade is currently incomplete (I need to use the latest version of Rector) so it'll fail for PHP 7.4. I'll let you know.

Fixed Rector now, working again for PHP 7.1.

Latest DEV release is the artifact here: https://github.com/leoloso/PoP/actions/runs/978119329#artifacts