• Resolved magicoders

    (@patopaiar)


    Hi guys,

    This ticket is a request for you to introduce a change described below, to avoid an PHP Fatal error: Uncaught Error: Call to a member function enqueue() on null that a site with this plugin enabled was experiencing and needed fixing.

    There are a few threads going around reporting the same error, with replies mostly being that you are not able to reproduce.

    With this site, I could reproduce it, and I think I have figured it out.

    FYI, the error happens when trying to Add or Edit Pages from the backend specifically, and results in a WSOD and users completely unable to access their existing Pages or adding New Pages when this plugin is enabled.

    This is what I have tracked it down to:

    In the file sensei-certificates\classes\class-woothemes-sensei-certificates.php, on lines 109 to 111 in you have this code:

    if ( class_exists( 'Sensei_Assets' ) ) {
    	$instance->assets = new \Sensei_Assets( $instance->plugin_url, dirname( __DIR__ ), SENSEI_CERTIFICATES_VERSION );
    }

    This ends up causing the Fatal Error on sites that have older versions of Sensei, where the class Sensei_Assets does not exist, and $instance->assets is left undefined, as there is no else setting it.

    When in the function enqueue_block_editor_assets this code attempts calling it like so

    WooThemes_Sensei_Certificates::instance()->assets->enqueue(
     'sensei-certificates-block',
     'blocks/index.js'
    );

    This results in Fatal Error:

    PHP Fatal error:  Uncaught Error: Call to a member function enqueue() on null in path-to-site\wp-content\plugins\sensei-certificates\classes\class-woothemes-sensei-certificates.php:1472
    Stack trace:
    #0 path-to-site\wp-includes\class-wp-hook.php(307): WooThemes_Sensei_Certificates->enqueue_block_editor_assets('')
    #1 path-to-site\wp-includes\class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
    #2 path-to-site\wp-includes\plugin.php(474): WP_Hook->do_action(Array)
    #3 path-to-site\wp-admin\edit-form-blocks.php(265): do_action('enqueue_block_e...')
    #4 path-to-site\wp-admin\post-new.php(72): require('C:\\wamp74\\www\\s...')
    #5 {main}
      thrown in path-to-site\wp-content\plugins\sensei-certificates\classes\class-woothemes-sensei-certificates.php on line 1472

    A possible fix, which you can apply as is to at least prevent a Fatal Error that brings down sites entirely, is to update the function to check the assets are set and bail early if they are not like so

    **
     * Enqueue block assets for the editing interface.
     *
     * @access private
     */
    public function enqueue_block_editor_assets() {
      $screen = get_current_screen();
    
      if( !WooThemes_Sensei_Certificates::instance()->assets ){
          return;
      }
    
      if ( $screen && 'page' === $screen->post_type ) { 
       WooThemes_Sensei_Certificates::instance()->assets->enqueue(
       'sensei-certificates-block',
       'blocks/index.js'
      );
      }
     }

    Granted, this I imagine from scanning the code quickly would leave the Certificates block unavailable in the Block Editor, but it definitely beats a server error, no?

    If you could please let me know if it will be possible for you to incorporate this change, would greatly appreciate it.

    Any questions, happy to help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    Thanks for reaching out and sharing your findings with us. I have submitted this as a bug report to our developers here

    https://github.com/woocommerce/sensei-certificates/issues/295

    You can check the progress of the report and follow along with the development on the Github Repo.

    Thanks again for the thorough investigation and for sharing your findings, we really appreciate it.

    Please feel free to reach back out if you have any other questions.

    Thread Starter magicoders

    (@patopaiar)

    Awesome! Thank you so much, really appreciate it from this end as well ??

    You are welcome!! Please feel free to contact us if you have any other questions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP Fatal error’ is closed to new replies.