Fix Gravity Forms & Magento 2 WordPress Integration confliction
Fatal error: Uncaught Error: Call to a member function get() on null in /magento/dir/vendor/magento/framework/Code/Generator.php:242 Stack trace: #0 /magento/dir/vendor/magento/framework/Code/Generator.php(120): Magento\Framework\Code\Generator->shouldSkipGeneration('logger', 'K', 'KLogger') #1 /wordpress/dir/wp-content/plugins/m2wp/include/classes/M2I_Mage_Autoloader.php(27): Magento\Framework\Code\Generator->generateClass('KLogger') #2 [internal function]: M2I_Mage_Autoloader->load('KLogger') #3 [internal function]: spl_autoload_call('KLogger') #4 /wordpress/dir/wp-content/plugins/gravityforms/includes/logging/logging.php(653): class_exists('KLogger') #5 /wordpress/dir/wp-content/plugins/gravityforms/common.php(4513): GFLogging::include_logger() #6 /wordpress/dir/wp-content/plugins/gravityforms/includes/class-gf-upgrade.php(230): GFCommon::log_debug('GF_Upgrade::set...') #7 /wordpress/dir/wp-content/plugins/gravityforms/includes/cl in /magento/dir/vendor/magento/framework/Code/Generator.php on line 242
This is a very uncommon issue, the WordPress site has the plugin Magento 2 WordPress Integration. It checks the class name exists or not in Magento 2 Autoloader. But the code seems doesn’t work very well. Also, the logging code of Gravity Forms plugin is very bad, there is no way to totally disable its logging function and force it to stop to load KLogger
class.
So there is only a temporary fix before they do refactor their logging code or someone finds out a better way. Just need to modify the file wp-content/plugins/gravityforms/common.php
and add return
to the head of 3 functions:
- log_error
- log_debug
- log_remote_response
Example:
// Other code public static function log_error( $message ) { return; if ( class_exists( 'GFLogging' ) ) { GFLogging::include_logger(); GFLogging::log_message( 'gravityforms', $message, KLogger::ERROR ); } } public static function log_debug( $message ) { return; if ( class_exists( 'GFLogging' ) ) { GFLogging::include_logger(); GFLogging::log_message( 'gravityforms', $message, KLogger::DEBUG ); } } /** * Log the remote request response. * * @since 2.2.2.1 * * @param WP_Error|array $response The remote request response or WP_Error on failure. */ public static function log_remote_response( $response ) { return; if ( is_wp_error( $response ) || isset( $_GET['gform_debug'] ) ) { self::log_error( __METHOD__ . '(): ' . print_r( $response, 1 ) ); } else { self::log_debug( sprintf( '%s(): code: %s; body: %s', __METHOD__, wp_remote_retrieve_response_code( $response ), wp_remote_retrieve_body( $response ) ) ); } } // Other code