Fatal error when kit doesn't exist or needs to be recreated.
patrick-leb opened this issue · 1 comments
patrick-leb commented
Consider the following function:
/**
* Helper function to return a setting.
*
* Saves 2 lines to get kit, then get setting. Also caches the kit and setting.
*
* @param string $setting_id
* @return string|array same as the Elementor internal function does.
*/
function hello_elementor_get_setting( $setting_id ) {
global $hello_elementor_settings;
$return = '';
if ( ! isset( $hello_elementor_settings['kit_settings'] ) ) {
$kit = \Elementor\Plugin::$instance->documents->get( \Elementor\Plugin::$instance->kits_manager->get_active_id(), false );
if($kit){
$hello_elementor_settings['kit_settings'] = $kit->get_settings();
}
}
if ( isset( $hello_elementor_settings['kit_settings'][ $setting_id ] ) ) {
$return = $hello_elementor_settings['kit_settings'][ $setting_id ];
}
return apply_filters( 'hello_elementor_' . $setting_id, $return );
}
As per the definition of \Elementor\Plugin::$instance->documents->get()
it could return false
which then crashes $kit->get_settings()
.
Suggested fix:
if ( ! isset( $hello_elementor_settings['kit_settings'] ) ) {
$kit = \Elementor\Plugin::$instance->documents->get( \Elementor\Plugin::$instance->kits_manager->get_active_id(), false );
if($kit){
$hello_elementor_settings['kit_settings'] = $kit->get_settings();
}
}