Plugin Directory

Changeset 3421155


Ignore:
Timestamp:
12/16/2025 02:48:18 PM (4 months ago)
Author:
youbehero
Message:

Moved WPBakery widget registration to a new compatibility method, ensuring the widget is only loaded when WPBakery and the plugin are active and properly configured. Refactored the registration function name for consistency and removed unconditional inclusion of the widget file.

Location:
youbehero
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • youbehero/tags/1.2.0/includes/class-you-be-hero.php

    r3420113 r3421155  
    134134        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-you-be-hero-shortcodes-public.php';
    135135
    136         /**
    137          * The class responsible for YouBeHero WpBakery Widget
    138          */
    139         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wpbakery-donation-widget.php';
    140 
    141136        $this->loader = new You_Be_Hero_Loader();
    142137
     
    163158
    164159        add_action( 'plugins_loaded', array( $this, 'ybhd_elementor_compatibility' ) );
     160        add_action( 'plugins_loaded', array( $this, 'ybhd_wpbakery_compatibility' ) );
    165161       
    166162    }
     
    177173
    178174            // Check if Elementor is installed and active
    179             if (!did_action('elementor/loaded') || ( isset( $youbehero_data['status'] ) && $youbehero_data['status'] != 'active' ) || !is_plugin_active('youbehero/youbehero.php')) {
     175            // Also verify that we have valid data structure (not just cached invalid data)
     176            if (!did_action('elementor/loaded')
     177                || empty($youbehero_data)
     178                || !isset($youbehero_data['status'])
     179                || $youbehero_data['status'] != 'active'
     180                || !is_plugin_active('youbehero/youbehero.php')) {
    180181                return; // Elementor not active, skip loading
    181182            }
     
    189190
    190191            });
     192        }
     193
     194    }
     195
     196    public function ybhd_wpbakery_compatibility() {
     197
     198        $ybhd_token = get_option( 'ybhd_token' );
     199
     200        if ( ! empty( $ybhd_token ) ) {
     201            include_once(ABSPATH . 'wp-admin/includes/plugin.php');
     202
     203            $youbehero_data = json_decode(get_option('ybhd_dashboard_json'), true);
     204            $youbehero_data = $youbehero_data['data'] ?? [];
     205
     206            // Check if WPBakery is installed and active, and plugin status is active
     207            // Also verify that we have valid data structure (not just cached invalid data)
     208            if (!class_exists('WPBakeryShortCode')
     209                || empty($youbehero_data)
     210                || !isset($youbehero_data['status'])
     211                || $youbehero_data['status'] != 'active'
     212                || !is_plugin_active('youbehero/youbehero.php')) {
     213                return; // WPBakery not active or plugin not configured, skip loading
     214            }
     215
     216            // Include and register widget
     217            require_once plugin_dir_path(dirname(__FILE__)) . 'includes/wpbakery-donation-widget.php';
     218            add_action( 'vc_before_init', 'ybhd_register_wpbakery_element' );
    191219        }
    192220
  • youbehero/tags/1.2.0/includes/wpbakery-donation-widget.php

    r3420210 r3421155  
    1414     * Register the WPBakery element
    1515     */
    16     function youbehero_register_wpbakery_element() {
     16    function ybhd_register_wpbakery_element() {
    1717
    1818        vc_map( array(
     
    5858        ));
    5959    }
    60     add_action( 'vc_before_init', 'youbehero_register_wpbakery_element' );
     60    // Registration will be called conditionally from ybhd_wpbakery_compatibility()
    6161
    6262    /**
  • youbehero/trunk/includes/class-you-be-hero.php

    r3420113 r3421155  
    134134        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-you-be-hero-shortcodes-public.php';
    135135
    136         /**
    137          * The class responsible for YouBeHero WpBakery Widget
    138          */
    139         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wpbakery-donation-widget.php';
    140 
    141136        $this->loader = new You_Be_Hero_Loader();
    142137
     
    163158
    164159        add_action( 'plugins_loaded', array( $this, 'ybhd_elementor_compatibility' ) );
     160        add_action( 'plugins_loaded', array( $this, 'ybhd_wpbakery_compatibility' ) );
    165161       
    166162    }
     
    177173
    178174            // Check if Elementor is installed and active
    179             if (!did_action('elementor/loaded') || ( isset( $youbehero_data['status'] ) && $youbehero_data['status'] != 'active' ) || !is_plugin_active('youbehero/youbehero.php')) {
     175            // Also verify that we have valid data structure (not just cached invalid data)
     176            if (!did_action('elementor/loaded')
     177                || empty($youbehero_data)
     178                || !isset($youbehero_data['status'])
     179                || $youbehero_data['status'] != 'active'
     180                || !is_plugin_active('youbehero/youbehero.php')) {
    180181                return; // Elementor not active, skip loading
    181182            }
     
    189190
    190191            });
     192        }
     193
     194    }
     195
     196    public function ybhd_wpbakery_compatibility() {
     197
     198        $ybhd_token = get_option( 'ybhd_token' );
     199
     200        if ( ! empty( $ybhd_token ) ) {
     201            include_once(ABSPATH . 'wp-admin/includes/plugin.php');
     202
     203            $youbehero_data = json_decode(get_option('ybhd_dashboard_json'), true);
     204            $youbehero_data = $youbehero_data['data'] ?? [];
     205
     206            // Check if WPBakery is installed and active, and plugin status is active
     207            // Also verify that we have valid data structure (not just cached invalid data)
     208            if (!class_exists('WPBakeryShortCode')
     209                || empty($youbehero_data)
     210                || !isset($youbehero_data['status'])
     211                || $youbehero_data['status'] != 'active'
     212                || !is_plugin_active('youbehero/youbehero.php')) {
     213                return; // WPBakery not active or plugin not configured, skip loading
     214            }
     215
     216            // Include and register widget
     217            require_once plugin_dir_path(dirname(__FILE__)) . 'includes/wpbakery-donation-widget.php';
     218            add_action( 'vc_before_init', 'ybhd_register_wpbakery_element' );
    191219        }
    192220
  • youbehero/trunk/includes/wpbakery-donation-widget.php

    r3420213 r3421155  
    1414     * Register the WPBakery element
    1515     */
    16     function youbehero_register_wpbakery_element() {
     16    function ybhd_register_wpbakery_element() {
    1717
    1818        vc_map( array(
     
    5858        ));
    5959    }
    60     add_action( 'vc_before_init', 'youbehero_register_wpbakery_element' );
     60    // Registration will be called conditionally from ybhd_wpbakery_compatibility()
    6161
    6262    /**
Note: See TracChangeset for help on using the changeset viewer.