Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Enabling users feature breaks customers REST endpoint #2424

Closed
anoblet opened this issue Oct 22, 2021 · 10 comments
Closed

BUG: Enabling users feature breaks customers REST endpoint #2424

anoblet opened this issue Oct 22, 2021 · 10 comments

Comments

@anoblet
Copy link

anoblet commented Oct 22, 2021

Describe the bug

After enabling the users feature, when trying to GET from the /customers REST endpoint we receive the error:

Fatal error: Uncaught Error: Argument 2 passed to ConversionXL\Institute\Plugin\Integrations\ElasticPress::ConversionXL\Institute\Plugin\Integrations\{closure}() must be an instance of WP_Query, instance of WP_User_Query given, called in /workspaces/cxl-wpstarter/public/wp/wp-includes/class-wp-hook.php on line 292
in /workspaces/cxl-wpstarter/public/wp-content/plugins/conversionxl-institute/src/Plugin/Integrations/ElasticPress.php on line 31

Disabling the users feature allow us to perform this request without error.

Steps to Reproduce

  1. Enable users feature - wp elasticpress activate-feature users
  2. Index - wp elasticpress index
  3. Perform a GET request for /wp-json/wc/v3/customers

Expected behavior
We get a list of customers

Screenshots
_C__Users_Andrew_Web%20Development_Error html

Environment information

  • Device: Surface Book 2
  • OS: Windows 11
  • Browser and version: Chrome 94.0.4606.81
  • WordPress version: 5.7
Site Health Info: ` ### wp-core ###

version: 5.7
site_language: en_US
user_language: en_US
timezone: +00:00
permalink: /%postname%/
https_status: false
multisite: false
user_registration: 0
blog_public: 1
default_comment_status: open
environment_type: production
user_count: 80
dotorg_communication: true

wp-paths-sizes

wordpress_path: /workspaces/cxl-wpstarter/public/wp
wordpress_size: 50.28 MB (52718585 bytes)
uploads_path: /workspaces/cxl-wpstarter/public/wp-content/uploads
uploads_size: 0.00 B (0 bytes)
themes_path: /workspaces/cxl-wpstarter/public/wp-content/themes
themes_size: 288.02 MB (302008984 bytes)
plugins_path: /workspaces/cxl-wpstarter/public/wp-content/plugins
plugins_size: 234.93 MB (246341939 bytes)
database_size: 134.73 MB (141278734 bytes)
total_size: 707.96 MB (742348242 bytes)

wp-active-theme

name: CXL Institute (conversionxl-institute)
version: 2021.03.04
author: leho@cxl.com
author_website: (undefined)
parent_theme: Hybrid Base Dynamic (CXL Institute) (hybrid-base-dynamic-conversionxl-institute)
theme_features: core-block-patterns, theme-layouts, hybrid-core-template-hierarchy, get-the-image, breadcrumb-trail, cleaner-gallery, automatic-feed-links, post-formats, post-thumbnails, menus, pure-css, align-wide, sensei, woocommerce, woocommerce-subscriptions, title-tag, html5, widgets
theme_path: /workspaces/cxl-wpstarter/public/wp-content/themes/conversionxl-institute

wp-parent-theme

name: Hybrid Base Dynamic (CXL Institute) (hybrid-base-dynamic-conversionxl-institute)
version: 2020.09.17
author: Justin Tadlock, Leho Kraav
author_website: https://conversionxl.com/institute/
theme_path: /workspaces/cxl-wpstarter/public/wp-content/themes/hybrid-base-dynamic-conversionxl-institute

wp-plugins-active (26)

AutomateWoo: version: 5.3.0, author: WooCommerce
CXL Institute: version: 2020.08.23, author: Leho Kraav
Debug Bar ElasticPress: version: 2.1.0, author: 10up
Disable All WordPress Updates: version: 1.6.7, author: Oliver Schlöbe
Disable Emojis (GDPR friendly): version: 1.7.2, author: Ryan Hellyer
ElasticPress: version: 3.6.3, author: 10up
FacetWP: version: 3.7.4, author: FacetWP, LLC
Hybrid Core (4.0) - restore schema.org support: version: 2017.12.21, author: Leho Kraav
Less Rewrite Rules: version: 2015.05.01, author: Leho Kraav
Nav Menu Collapse: version: 2.1.0, author: Robert Noakes
Post Meta Inspector: version: 1.1.1, author: Daniel Bachhuber, Automattic
Pure CSS Theme Features: version: 1.6.2pl20161003, author: Leho Kraav
Query Monitor: version: 3.6.7, author: John Blackbourn
Remove jQuery Migrate: version: 1.0.2, author: Hendy Tarnando
REST API Log: version: 1.6.8, author: Pete Nelson
Sensei LMS: version: 2.4.0, author: Automattic
Sensei LMS Course Progress: version: 2.0.3, author: Automattic
Stream: version: 3.6.2, author: XWP
Teams for WooCommerce Memberships: version: 1.5.2, author: SkyVerge
User Switching: version: 1.5.6, author: John Blackbourn & contributors
WooCommerce: version: 4.9.2, author: Automattic
WooCommerce Memberships: version: 1.21.4, author: SkyVerge
WooCommerce Sequential Order Numbers: version: 1.9.5, author: SkyVerge
WooCommerce Stripe Gateway: version: 4.9.0, author: WooCommerce
WooCommerce Subscriptions: version: 3.0.13, author: WooCommerce
WordPress Bug #14050 Hotfix: version: 2016.03.15, author: Leho Kraav

wp-plugins-inactive (12)

BadgeOS (git): version: 1.4.11, author: LearningTimes
BadgeOS Sensei Add-On: version: 1.0.4, author: Credly
Classic Editor: version: 1.6, author: WordPress Contributors
CXL JWPlayer: version: 2020.06.02, author: Kyle Brodeur, Paul Kirspuu, Leho Kraav
FacetWP - Relevanssi integration: version: 0.7.2, author: FacetWP, LLC
Gutenberg: version: 10.1.1, author: Gutenberg Team
Pco Kint: version: 1.0.10, author: Peytz & Co (Patrick Hesselberg)
Relevanssi Always Exclude Private Posts: version: 2016.08.30, author: Leho Kraav
Relevanssi Premium: version: 2.14.4, author: Mikko Saari
Rename wp-login.php: version: 2.6.0, author: Ella van Durpe
Toolbar Theme Switcher: version: 1.4, author: Andrey "Rarst" Savchenko
Yoast SEO Premium: version: 15.9, author: Team Yoast

wp-media

image_editor: false
imagick_module_version: Not available
imagemagick_version: Not available
file_uploads: File uploads is turned off
post_max_size: 8M
upload_max_filesize: 2M
max_effective_size: 2 MB
max_file_uploads: 20
gd_version: not available
ghostscript_version: not available

wp-server

server_architecture: Linux 5.4.72-microsoft-standard-WSL2 x86_64
httpd_software: PHP 7.4.21 Development Server
php_version: 7.4.21 64bit
php_sapi: cli-server
max_input_variables: 1000
time_limit: 30
memory_limit: -1
max_input_time: 60
upload_max_filesize: 2M
php_post_max_size: 8M
curl_version: 7.64.0 OpenSSL/1.1.1d
suhosin: false
imagick_availability: false
pretty_permalinks: false

wp-database

extension: mysqli
server_version: 10.3.29-MariaDB-0+deb10u1
client_version: mysqlnd 7.4.21

wp-constants

WP_HOME: http://localhost:8080
WP_SITEURL: http://localhost:8080/wp
WP_CONTENT_DIR: /workspaces/cxl-wpstarter/public/wp-content
WP_PLUGIN_DIR: /workspaces/cxl-wpstarter/public/wp-content/plugins
WP_MEMORY_LIMIT: 40M
WP_MAX_MEMORY_LIMIT: -1
WP_DEBUG: false
WP_DEBUG_DISPLAY: false
WP_DEBUG_LOG: true
SCRIPT_DEBUG: false
WP_CACHE: false
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_LOCAL_DEV: undefined
DB_CHARSET: utf8
DB_COLLATE: undefined

wp-filesystem

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable

epio_autosuggest

wp-starter

autoload-path: /workspaces/cxl-wpstarter/public/vendor/autoload.php
base-path: /workspaces/cxl-wpstarter
env-cache-file: /workspaces/cxl-wpstarter/.env.cached.php
env-cache-enabled: true
cached-env: true
env-type: development
env-php-file: undefined
early-hooks-file: undefined
wp-env-type: production
ssl_fix: false
register-core-themes: false

`

Additional context

@anoblet anoblet added the bug Something isn't working label Oct 22, 2021
@anoblet anoblet changed the title BUG: Enabling users feature breaks /customers endpoint BUG: Enabling users feature breaks customers REST endpoint Oct 22, 2021
@lkraav
Copy link

lkraav commented Oct 25, 2021

Hmm, just remove the strong WP_Query type for time being, then, so it'll accept anything.

@anoblet
Copy link
Author

anoblet commented Oct 29, 2021

@lkraav When I remove the WP_Query type, the request returns an empty array. No errors in the console or in the server logs.

@anoblet
Copy link
Author

anoblet commented Oct 29, 2021

The orders endpoint also returns an empty array when enabling the protected_content feature.

@oscarssanchez
Copy link
Contributor

Hey @anoblet ,

I actually get the same empty array with ElasticPress turned off, can you confirm/deny the same on your end?

As for wp-json/wc/v3/orders with protected content enabled I don't have any problems. I am using the latest version of ElasticPress and latest version of Woocommerce. Can you try updating Woocommerce? as it seems it is far behind 5.8.0

@anoblet
Copy link
Author

anoblet commented Nov 2, 2021

@oscarssanchez

I removed the strong type from ElasticPress.php and investigated a little further and found that there is a problem with the orderby parameter in the request.

Users feature enabled:

/wp-json/wc/v3/customers?order=desc&orderby=id&page=1&per_page=50 (Empty)
/wp-json/wc/v3/customers?order=desc&page=1&per_page=50 (Works)

Protected Content feature enabled:

/wp-json/wc/v3/orders?customer=80&order=desc&orderby=id&page=1&per_page=50 (Empty)
/wp-json/wc/v3/orders?customer=80&order=desc&page=1&per_page=50 (Works)

If either feature is disabled, or the orderby parameter is not supplied, the request will work.

@lkraav
Copy link

lkraav commented Nov 3, 2021

Maybe related @anoblet #2435

@anoblet
Copy link
Author

anoblet commented Nov 3, 2021

@lkraav That's a great find!

I wonder if a similar fix could work for the orders endpoint?

@anoblet
Copy link
Author

anoblet commented Nov 4, 2021

@lkraav I tried the fix in that PR and still got an empty result set when using the orderby parameter.

@oscarssanchez
Copy link
Contributor

I can confirm the bug happens with the orderby parameter!

@oscarssanchez oscarssanchez added confirmed bug and removed bug Something isn't working labels Nov 9, 2021
@mckdemps mckdemps added this to the 3.6.5 milestone Nov 23, 2021
@oscarssanchez
Copy link
Contributor

oscarssanchez commented Nov 25, 2021

Hi @anoblet ,

Long story short, the problem seems to be related to Woocommerce. I have opened woocommerce/woocommerce#31294 in regard.

This ends up adding "**" to the WP_User_Query() which in turn will format the EP query to a match query instead of a match_all (which by the way should also not be triggered by default, as ep_integrate won't be set to true unless there's a search param, or you explicitly set the ep_integrate param to true)

You could probably use something like this as a workaround until that issue is fixed:

add_filter(
	'woocommerce_rest_customer_query',
	function ( $wp_user_query_args ) {
		if ( '**' === $wp_user_query_args['search'] ) {
			unset( $wp_user_query_args['search'] );
		}
		return $wp_user_query_args;
	}
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants