Okay
  Public Ticket #4516857
Fatal Error: MarketKing Redeclaring get_current_screen() (Conflicts with WordPress Core)
Closed

Comments

  • Mendel Rosenblum started the conversation

    Hi team,

    I'm experiencing a critical PHP fatal error caused by MarketKing redeclaring the core WordPress function get_current_screen(). This is breaking wp-admin on my live site.

    Full error:

    PHP Fatal error: Cannot redeclare function get_current_screen() (previously declared in /nas/content/live/tovahmarket/wp-content/plugins/marketking-multivendor-marketplace-for-woocommerce/public/dashboard/marketking-dashboard-login.php:2203) in /nas/content/live/tovahmarket/wp-admin/includes/screen.php on line 224
    

    It appears that MarketKing is defining get_current_screen() inside:

    /public/dashboard/marketking-dashboard-login.php (around line 2203)
    

    WordPress already defines this function inside core (wp-admin/includes/screen.php), so the plugin should not declare it again. Standard practice is to wrap such declarations in a conditional:

    if ( ! function_exists( 'get_current_screen' ) ) {    function get_current_screen() { ... }
    }
    

    This bug is causing a hard crash and locks me out of admin pages.

    Can you please issue a fix or provide a patched file?

    A temporary conditional wrapper works, but I’m trying to avoid modifying plugin files directly so updates don’t overwrite it.

    Please advise on the correct fix or provide an updated version of the plugin.

    Thanks!

  •  2,609
    WebWizards replied

    Hi Mendel,

    Thank you for purchasing our plugin and for the detailed report,

     

    We already use `if ( ! function_exists( 'get_current_screen' ) ) {` in our code - the reason we declare this (core) function is for 3rd party plugin compatibility in special situations. MarketKing's frontend vendor dashboard needs to integrate with many plugins, and for some of them to work correctly, we need to simulate an admin environment.

    What's unusual here and causing your issue is that the dashboard-login.php file is running in your admin area - this is a frontend-only template that should never load in wp-admin. There seems to be a problem with page detection that's causing this frontend template to load in your admin area.

    This likely relates to the vendor dashboard page setting (found in MarketKing → Settings → Vendor Dashboard: https://prnt.sc/_zyzFNX21ar_). It may be set to an admin page, some kind of null value, or just failing to detect the current page correctly for some reason.

     

    To solve this immediately:

    1. I've attached an updated MarketKing Core file that should resolve this. To update:
    - First deactivate your existing version of MarketKing Core
    - Upload and activate the attached

    2. If the attached doesn't solve this on its own, please add this code snippet to your site as well:

    add_filter('marketking_declare_get_current_screen','__return_false');

     

    Let me know if this resolves the issue for you,

    Kind regards,
    Stefan

  •  2,609
    WebWizards replied

    *attached

    Attached files:  marketking-core-2106.zip

  •   Mendel Rosenblum replied privately
  •  2,609
    WebWizards replied

    Hi Mendel,

    Thanks for the follow-up and for testing that,

     

    1. The update I made checks the `is_admin()` function, so for some reason `is_admin()` is returning false on your backend, OR our file gets loaded in an AJAX context where `is_admin()` doesn't work (this is normal in WP).

    2. The snippet with `add_filter('marketking_declare_get_current_screen','__return_false');` should be fine to use long-term. I don't anticipate other issues if you keep this in place.

    3. I'm not aware of anything specific that could be causing this, but I think there's some kind of conflict happening, though very hard to say exactly where.

     

    If you'd like, I can take a look into this in more detail and try to diagnose the root cause. For that, I'd need a backend login to the site or a staging clone site.

     

    Kind regards,
    Stefan