• Hi Staff,

    I’m a developer of VikWP company and I’m reaching you to report an issue that occurs with almost all our plugins.

    Sometimes our plugins need to instantiate an editor within the “init” hook, where the get_current_screen function is not yet available. Here’s the code that’s causing the issue:

    
    // @file class-editor.php
    public function is_post_editor_page() {
        if ( ! is_admin() ) {
            return false;
        }
    
        $screen = get_current_screen();
    
        return $screen->parent_base === 'edit';
    }
    

    Since the get_current_screen function doesn’t exist yet, we strongly suggest you to check that before using it. The example below should be able to fix the reported issue:

    
    public function is_post_editor_page() {
        if ( ! is_admin() ) {
            return false;
        }
    ​
        /**
         * Check whether the get_current_screen function exists
         * because it is loaded only after 'admin_init' hook.
         */
        if ( ! function_exists( 'get_current_screen' ) ) {
            return false;
        }
    ​
        $screen = get_current_screen();
    ​
        /**
         * Since the screen might not have been set, we should check
         * whether it returned NULL, in order to avoid displaying
         * a 'Trying to get property of non-object' notice.
         */
        return $screen !== null && $screen->parent_base === 'edit';
    }
    

    We would appreciate if you could enhance the way you check whether the user is currently located on the post editor page, so that our plugins won’t face that issue anymore.

    • This topic was modified 5 years, 8 months ago by e4jvikwp.
    • This topic was modified 5 years, 8 months ago by e4jvikwp.
Viewing 1 replies (of 1 total)
  • Plugin Support Ethan Choi

    (@ethanchoi)

    Hey @e4jvikwp,

    Thanks for reaching out!

    Our development team has reviewed your suggestion, and this fix will be included in the next plugin release.

    Thank you 🙂

    • This reply was modified 5 years, 8 months ago by Ethan Choi.
Viewing 1 replies (of 1 total)

The topic ‘Call to undefined function called get_current_screen’ is closed to new replies.