Support

Account

Home Forums Bug Reports undefined function get_current_screen()

Solved

undefined function get_current_screen()

  • Hello,

    Wanting to report a possible bug. Was running ACF pro 5.3.10 and using a frontend form. I attempted to upgrade to 5.4.0 and on submission I am getting the following when submitting the frontend form:

    Fatal error: Call to undefined function get_current_screen() in /home/siteuser/public_html/wp-content/plugins/advanced-custom-fields-pro/api/api-helpers.php on line 3313

    Not sure if this is something to do with a custom function on my end or an issue within the plugin. For now, I’ve reverted back to 5.3.10 and everything is working again. Let me know if there’s anything you would like me to test.

  • I can confirm that I ran into the same problem just now working on a frontend form for a client. After I updated to Advanced Custom Fields PRO Version: 5.4.0 I got the same error when submitting the form:

    Backend fatal error: PHP Fatal error: Call to undefined function get_current_screen() in /advanced-custom-fields-pro/api/api-helpers.php on line 3313

    So I think the problem has nothing to do with your specific setup but is a generic problem that was introduced with the latest release of ACF. When I rolled the version back to Version: 5.3.8.1 everything was working fine as before. I will update my version to 5.3.10 since you indicate the problem is not present there.

    I hope a fix will be available soon since we don’t want to miss out on all the great new features that are included in 5.4.0 😉 Thanks in advance for solving this!

  • Confirming that this also happenned to me after i updated to v5.4 of ACF with the latest version of WP 4.5.3. In my setup, this specifically happens when the function wp_update_post() is called on a form submitted from the front-end. However when i revert back to my previous ACF version 5.3.9.2 …. all works fine and no issues. Hence i guess only when the upgrade happens.

    Hoping this can be resolved at the earliest.

    Thanks,
    Chris

    • Elliot

    • August 11, 2016 at 10:08 am

    Hi guys

    Thanks for the bug report.

    I have found and fixed hit bug and will release a new version later today. For now, please edit the api/api-helpers.php file ~line 3310 and replace the function acf_is_screen with this:

    
    function acf_is_screen( $id = '' ) {
    	
    	// bail early if not defined
    	if( !function_exists('get_current_screen') ) return false;
    	
    	
    	// vars
    	$current_screen = get_current_screen();
    	
    	
    	// bail early if no screen
    	if( !$current_screen ) return false;
    	
    	
    	// return
    	return ($id === $current_screen->id);
    	
    }
    

    Thanks
    Elliot

  • A form of this bug has resurfaced in yesterday’s 5.8.1 release.

    The new acf_is_block_editor function in api-helper.php should presumably also check if get_current_screen exists at the start (line 5051)

    I fixed it with the following code:

    function acf_is_block_editor() {
    	if( function_exists('get_current_screen') && method_exists(get_current_screen(), 'is_block_editor') ) {
    		return get_current_screen()->is_block_editor();
    	}
    	return false;
    }
    • dano23

    • June 5, 2019 at 6:41 am

    I can confirm that I am seeing the same bug with 5.8.1.

    Thanks for the suggested patch.

    • jcow

    • June 5, 2019 at 8:23 am

    Same thing here with 5.8.1. I just downgraded back to 5.8, and appears to be working again.

    • Elliot

    • June 5, 2019 at 10:53 am

    Hi all

    Thanks for the bug report.
    I suspect this issue is with “front-end” forms only, and will have this patched today 🙂

    • Elliot

    • June 5, 2019 at 4:54 pm

    Hi all,

    This bug has been patched, and the ACF PRO plugin files have been re-uploaded online.
    Please manually path this fix by editing the file “includes/api/api-helpers.php” and change the acf_is_block_editor() function on line ~5051 to:

    
    /**
     * acf_is_block_editor
     *
     * Returns true if the current screen uses the block editor.
     *
     * @date	13/12/18
     * @since	5.8.0
     *
     * @param	void
     * @return	bool
     */
    function acf_is_block_editor() {
    	if( function_exists('get_current_screen') ) {
    		$screen = get_current_screen();
    		if( method_exists($screen, 'is_block_editor') ) {
    			return $screen->is_block_editor();
    		}
    	}
    	return false;
    }
    
  • Hi Elliot,

    Is this not being applied through an update?
    With hundreds of sites using this and being affected, it is a very time-consuming process to manually change the files on all the sites.

    We use a system to manage all the sites and perform the updates and there is no new update showing with this update.

    Thanks

    • wibi

    • June 19, 2019 at 12:36 am

    True. That should be a part of an update.
    It took me 1h to check all website, and function before knowing it was an ACF bug.
    Elliot, maybe you can create a small update fix in 5.8.2 and publishing it quickly no ?

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.