Yes the latest update causes FATAL error:
PHP Fatal error: Uncaught Error: Non-static method WC_Legacy_REST_API_Plugin::hpos_is_enabled() cannot be called statically in /home/nginx/domains/example.com/public/wp-content/plugins/woocommerce-legacy-rest-api/includes/class-wc-legacy-rest-api-plugin.php:77
The issue arises because the hpos_is_enabled method is non-static, but it is being called statically within the maybe_add_hpos_incompatibility_admin_notice and maybe_remove_hpos_incompatibility_admin_notice methods. To fix this, we need to create an instance of the WC_Legacy_REST_API_Plugin class before calling the non-static hpos_is_enabled method.
Here’s how you can modify the maybe_add_hpos_incompatibility_admin_notice and maybe_remove_hpos_incompatibility_admin_notice methods to address this issue:
- Update
maybe_add_hpos_incompatibility_admin_notice Method:
REPLACE THIS:
private static function maybe_add_hpos_incompatibility_admin_notice() { if( ! self::hpos_is_enabled() || self::user_has_dismissed_admin_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ) ) { return false; } if ( ! WC_Admin_Notices::has_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ) ) { $features_page_url = admin_url( ‘admin.php?page=wc-settings&tab=advanced§ion=features’ ); WC_Admin_Notices::add_custom_notice( ‘legacy_rest_api_is_incompatible_with_hpos’, sprintf( wpautop( __( ‘โ <b>The Legacy REST API plugin and HPOS are both active on this site.</b><br/><br/>Please be aware that the WooCommerce Legacy REST API is <b>not</b> compatible with HPOS. <a target=”_blank” href=”%s”>Manage features</a>’, ‘woocommerce-legacy-rest-api’ ) > $features_page_url ) ); return true; } return false; }
WITH THIS:
private static function maybe_add_hpos_incompatibility_admin_notice() { $instance = new self(); // Create an instance of the class if( ! $instance->hpos_is_enabled() || self::user_has_dismissed_admin_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ) ) { return false; } if ( ! WC_Admin_Notices::has_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ) ) { $features_page_url = admin_url( ‘admin.php?page=wc-settings&tab=advanced§ion=features’ ); WC_Admin_Notices::add_custom_notice( ‘legacy_rest_api_is_incompatible_with_hpos’, sprintf( wpautop( __( ‘โ <b>The Legacy REST API plugin and HPOS are both active on this site.</b><br/><br/>Please be aware that the WooCommerce Legacy REST API is <b>not</b> compatible with HPOS. <a target=”_blank” href=”%s”>Manage features</a>’, ‘woocommerce-legacy-rest-api’ ) ), $features_page_url ) ); return true; } return false; }
- Update
maybe_remove_hpos_incompatibility_admin_notice Method:
REPLACE THIS:
private static function maybe_remove_hpos_incompatibility_admin_notice() { if ( WC_Admin_Notices::has_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ) && ! self::hpos_is_enabled() ) { self::remove_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ); } }
WITH THIS:
private static function maybe_remove_hpos_incompatibility_admin_notice() { $instance = new self(); // Create an instance of the class if ( WC_Admin_Notices::has_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ) && ! $instance->hpos_is_enabled() ) { self::remove_notice( ‘legacy_rest_api_is_incompatible_with_hpos’ ); } }
Good to know I am not the only one that experienced problems with the latest update.
Highlighted Changes to fix this issue while waiting for update to be released.
In maybe_add_hpos_incompatibility_admin_notice:
- Instance Creation:phpCopy code
$instance = new self(); // Create an instance of the class
- Calling Non-static Method:phpCopy code
if( ! $instance->hpos_is_enabled() || self::user_has_dismissed_admin_notice( 'legacy_rest_api_is_incompatible_with_hpos' ) ) {
In maybe_remove_hpos_incompatibility_admin_notice:
- Instance Creation:phpCopy code
$instance = new self(); // Create an instance of the class
- Calling Non-static Method:phpCopy code
if ( WC_Admin_Notices::has_notice( 'legacy_rest_api_is_incompatible_with_hpos' ) && ! $instance->hpos_is_enabled() ) {
These highlighted changes will resolve the error by correctly calling the non-static hpos_is_enabled method on an instance of the WC_Legacy_REST_API_Plugin class.
Thank you Newt. I can implement the fix but I am heading to bed now. I decided to deactivate the plugin for now via ftp and deal with it in the morning. ๐ Eric
Same error on all sites with the 1.0.2 version.
Same here, renamed the folder woocommerce-legacy-rest-api to retrieve my site.
Thanks a lot @newtlabs this wuick path, it works fine under php8.3
Also got an error.
[15-May-2024 09:53:58 UTC] PHP Fatal error: Uncaught Error: Non-static method WC_Legacy_REST_API_Plugin::hpos_is_enabled() cannot be called statically in /var/www/html/wordpress/wp-content/plugins/woocommerce-legacy-rest-api/includes/class-wc-legacy-rest-api-plugin.php:77
Stack trace:
#0 /var/www/html/wordpress/wp-content/plugins/woocommerce-legacy-rest-api/includes/class-wc-legacy-rest-api-plugin.php(28): WC_Legacy_REST_API_Plugin::maybe_add_hpos_incompatibility_admin_notice()
#1 /var/www/html/wordpress/wp-includes/class-wp-hook.php(324): WC_Legacy_REST_API_Plugin::on_woocommerce_init()
#2 /var/www/html/wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#3 /var/www/html/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action()
#4 /var/www/html/wordpress/wp-content/plugins/woocommerce/includes/class-woocommerce.php(812): do_action()
#5 /var/www/html/wordpress/wp-includes/class-wp-hook.php(324): WooCommerce->init()
#6 /var/www/html/wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#7 /var/www/html/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action()
#8 /var/www/html/wordpress/wp-settings.php(695): do_action()
#9 /var/www/html/wordpress/wp-config.php(132): require_once('...')
#10 /var/www/html/wordpress/wp-load.php(50): require_once('...')
#11 /var/www/html/wordpress/wp-blog-header.php(13): require_once('...')
#12 /var/www/html/wordpress/index.php(17): require('...')
#13 {main}
thrown in /var/www/html/wordpress/wp-content/plugins/woocommerce-legacy-rest-api/includes/class-wc-legacy-rest-api-plugin.php on line 77
Un errore di E_ERROR รจ stato causato nella linea 77
disabilitato plugin per il momento in attesa di aggiornamento …..
Same here ๐ What to do???
Al
(@alkis12)
Disable the plugin from ftp. Install 1 version back.
ir just wait for a fix ๐
-
This reply was modified 1 year, 10 months ago by
Al.
Installed the 1.0.2 update on 20 sites and it crashed every site!
Just installed v1.0.4….this version fixes the fatal error!
Keep on rocking ๐