BrianHenryIE / bh-wp-autologin-urls

Adds single-use passwords to WordPress emails' URLs for frictionless login. Adds magic email link to login screen.
GNU General Public License v2.0
44 stars 5 forks source link

PHP Fatal error: Uncaught TypeError: BrianHenryIE\WP_Autologin_URLs\WP_Private_Uploads\Admin\Admin_Meta_Boxes::add_meta_box(): Argument #2 ($post) must be of type WP_Post #25

Open sisaacrussell opened 6 months ago

sisaacrussell commented 6 months ago

Bug Report

Describe the current, buggy behavior

Viewing a WooCommerce order in the admin with HPOS enabled throws a fatal error:

PHP Fatal error: Uncaught TypeError: BrianHenryIE\WP_Autologin_URLs\WP_Private_Uploads\Admin\Admin_Meta_Boxes::add_meta_box(): Argument #2 ($post) must be of type WP_Post, Automattic\WooCommerce\Admin\Overrides\Order given, called in /wordpress/core/6.5.2/wp-includes/class-wp-hook.php on line 324 and defined in /srv/htdocs/wp-content/plugins/bh-wp-autologin-urls/vendor-prefixed/brianhenryie/bh-wp-private-uploads/src/admin/class-admin-meta-boxes.php:57 Stack trace: #0 /wordpress/core/6.5.2/wp-includes/class-wp-hook.php(324): BrianHenryIE\WP_Autologin_URLs\WP_Private_Uploads\Admin\Admin_Meta_Boxes->add_meta_box('woocommerce_pag...', Object(Automattic\WooCommerce\Admin\Overrides\Order)) #1 /wordpress/core/6.5.2/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #2 /wordpress/core/6.5.2/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /srv/htdocs/wp-content/plugins/woocommerce/src/Internal/Admin/Orders/Edit.php(165): do_action('add_meta_boxes', 'woocommerce_pag...', Object(Automattic\WooCommerce\Admin\Overrides\Order)) #4 /srv/htdocs/wp-content/plugins/woocommerce/src/Internal/Admin/Orders/PageController.php(350): Automattic\WooCommerce\Internal\Admin\Orders\Edit->setup(Object(Automattic\WooCommerce\Admin\Overrides\Order)) #5 /srv/htdocs/wp-content/plugins/woocommerce/src/Internal/Admin/Orders/PageController.php(366): Automattic\WooCommerce\Internal\Admin\Orders\PageController->prepare_order_edit_form() #6 /srv/htdocs/wp-content/plugins/woocommerce/src/Internal/Admin/Orders/PageController.php(167): Automattic\WooCommerce\Internal\Admin\Orders\PageController->setup_action_edit_order() #7 [internal function]: Automattic\WooCommerce\Internal\Admin\Orders\PageController->handle_load_page_action('') #8 /srv/htdocs/wp-content/plugins/woocommerce/src/Internal/Traits/AccessiblePrivateMethods.php(158): call_user_func_array(Array, Array) #9 /wordpress/core/6.5.2/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Internal\Admin\Orders\PageController->__call('handle_load_pag...', Array) #10 /wordpress/core/6.5.2/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array) #11 /wordpress/core/6.5.2/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #12 /wordpress/core/6.5.2/wp-admin/admin.php(237): do_action('load-woocommerc...') #13 {main} thrown in /srv/htdocs/wp-content/plugins/bh-wp-autologin-urls/vendor-prefixed/brianhenryie/bh-wp-private-uploads/src/admin/class-admin-meta-boxes.php on line 57\

Describe how other contributors can replicate this bug

https://developer.woocommerce.com/docs/hpos-extension-recipe-book/#h-apis-for-getting-setting-posts-and-postmeta this will likely be helpful though I'm sure you're familiar with it. For the short run, in my copy, I disabled this metabox functionality entirely (not sure what it's doing for custom uploads related to this plugin).

BrianHenryIE commented 6 months ago

Sorry about that. It should be fixed now, 2.4.1 and on WordPress.org.

When I said yesterday I had been trying to get more E2E tests running, it was actually the WooCommerce E2E suite I tried and failed to have run. Ideally that would have picked up the issue, so I'll definitely continue to work on that.

I think you're right that it's HPOS related because I had manually created an order while testing and hadn't encountered the bug.

The private uploads library is really just used here to protect the log files, but elsewhere it's used to upload files in the UI, e.g. to attach photos to orders, shipping labels to orders. By habit, I just add all hooks and then inside the functions I return early if they're not relevant, but I'll move the check to occur before the hook is added in future.