AyeCode / geodirectory

GeoDirectory is the leading Directory Plugin for WordPress. Compatible with Gutenberg and the most popular page builders such as Elementor, Oxygen, Beaver Builder and Divi. GeoDirectory is the only solution for WordPress that can scale to millions of listings and high traffic.
https://wpgeodirectory.com/
Other
40 stars 21 forks source link

Fix for Fatal Error When Elementor is Not Installed in GeoDirectory v2.3.19+ #2499

Closed 0x4d4n closed 8 months ago

0x4d4n commented 9 months ago

Description of the Change This pull request addresses the issue where a PHP fatal error occurs in GeoDirectory version 2.3.19 or higher when Elementor is not installed. The error is triggered in the class-geodir-elementor.php file.

Approach The proposed change involves adding a conditional check to ensure the Elementor class exists before attempting to use it. This prevents the fatal error and allows GeoDirectory to function normally even when Elementor is not present.

Code Changes Modified get_elementor_document function in class-geodir-elementor.php:

public static function get_elementor_document( $page_id ) {
    // Check if Elementor Plugin class exists to ensure compatibility
    if ( class_exists( '\Elementor\Plugin' ) ) {
        // If Elementor is available, get the document
        $document = \Elementor\Plugin::$instance->documents->get( (int) $page_id );
        return $document;
    } else {
        // Return null if Elementor is not active or installed
        // This prevents errors and ensures graceful degradation
        return null;
    }
}

Related Issue https://github.com/AyeCode/geodirectory/issues/2498

kprajapatii commented 8 months ago

Merged manually https://github.com/AyeCode/geodirectory/pull/2500