Hi @mattpramschufer ,
Thanks for sharing the error details. The issue occurs because the code is trying to use strpos() on a value that is null instead of a string, which causes the fatal error.
This might happen if any plugin or custom code is modifying or adding admin menu items in a way that results in incomplete or unexpected menu data.
To help narrow down the cause, could you please let us know if you have any customizations affecting admin menus?
Also, since you mentioned using the Stripe plugin, please try temporarily deactivating it to see if the error persists without it.
This will help us determine whether the issue is related to the Stripe plugin or another part of your setup.
Looking forward to your update!
Thanks for the reply @mahfuzurwp
I was able to fix the error by updating the payments controller to properly check if $menu_item[0] and $menu_item[2] were actually set, before trying to run strpos on it. Figured you might want to pass onto devs.
Replaced:
if ( $this->store_has_providers_with_incentive() ) {
$badge = ' <span class="wcpay-menu-badge awaiting-mod count-1"><span class="plugin-count">1</span></span>';
foreach ( $menu as $index => $menu_item ) {
// Only add the badge markup if not already present and the menu item is the Payments menu item.
if ( 0 === strpos( $menu_item[0], $menu_title )
&& $menu_path === $menu_item[2]
&& false === strpos( $menu_item[0], $badge ) ) {
$menu[ $index ][0] .= $badge; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
// One menu item with a badge is more than enough.
break;
}
}
}
With this:
if ( $this->store_has_providers_with_incentive() ) {
$badge = ' <span class="wcpay-menu-badge awaiting-mod count-1"><span class="plugin-count">1</span></span>';
foreach ( $menu as $index => $menu_item ) {
// Ensure $menu_item[0] is a string before using strpos
if ( isset( $menu_item[0], $menu_item[2] )
&& is_string( $menu_item[0] )
&& 0 === strpos( $menu_item[0], $menu_title )
&& $menu_path === $menu_item[2]
&& false === strpos( $menu_item[0], $badge ) ) {
$menu[ $index ][0] .= $badge; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
// One menu item with a badge is more than enough.
break;
}
}
}
Hi there!
Thank you for sharing the code snippet with us. To clarify, this specific code is not part of the WooCommerce core plugin itself. The code you posted appears to be related to displaying a badge in the WordPress admin menu, and the badge class wcpay-menu-badge along with references to store_has_providers_with_incentive() and “Payments menu” indicate it likely belongs to payment plugin you are using.
In that case, I suggest reaching out to the payment plugin’s support team and informing them about the issue you’re facing. They’ll be able to investigate further and help you resolve it.
If you’re using the WooCommerce Stripe Gateway plugin, you can create a support ticket here:
👉 https://wordpress.org/support/plugin/woocommerce-gateway-stripe/#new-topic-0
@shahzeenfarooq technically the code IS part of the WooCommerce plugin, as it appears in
/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsController.php:87
but you are correct this block of code relies on third-party data. That being said, the $menu_item variables should still be properly validated so it doesn’t throw a fatal error when a third-party incorrectly passes data to it. 🙂 I will reach out to the Stripe Gateway folks and let them know.
Thanks for the quick replies, and I hope you have a great weekend!
Hi @mattpramschufer
Sorry for the confusion. I’ve checked the PaymentsController.php file and can confirm that the code you shared does exist in the WooCommerce core file.
However, it looks like another plugin (or custom code) is adding a top-level menu item with an empty or null title before WooCommerce runs its add_menu() function. This is likely what’s causing the error.
The best approach would be to contact the support team of the plugin you suspect is responsible.
In the meantime, I recommend deactivating all plugins except WooCommerce and the Stripe plugin, and then checking if the issue persists. This will help identify if another plugin is interfering.