• Resolved Matt Pramschufer

    (@mattpramschufer)


    I get this fatal error every couple of days, we use the Stripe plugin by WooCommerce as well, so not sure if it is related to that plugin or WC in general. Figured I would pass it along.

    An error of type E_ERROR was caused in line 87 of the file /var/www/domain.com/wp-content/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsController.php. Error message: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, null given in /var/www/domain.com/wp-content/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsController.php:87
    Stack trace: 0 /var/www/domain.com/wp-content/plugins/woocommerce/src/Internal/Admin/Settings/PaymentsController.php(87): strpos(NULL, ‘Payments’) 1 /var/www/domain.com/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Internal\Admin\Settings\PaymentsController->add_menu(”) 2 /var/www/domain.com/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) 3 /var/www/domain.com/wp-includes/plugin.php(517): WP_Hook->do_action(Array) 4 /var/www/domain.com/wp-admin/includes/menu.php(161): do_action(‘admin_menu’, ”) 5 /var/www/domain.com/wp-admin/menu.php(423): require_once(‘/var/www/domain…’) 6 /var/www/domain.com/wp-admin/admin.php(159): require(‘/var/www/domain…’) 7 /var/www/domain.com/wp-admin/index.php(10): require_once(‘/var/www/domain…’) 8 {main}

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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!

    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    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;
    }
    }
    }
    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    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


    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    @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!

    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Fatal Error Adding Menu…’ is closed to new replies.