[BUG] Missing constant in Controls_Manager class from last versions
teolaz opened this issue · 9 comments
Hey,
i developed some widgets to integrate with Elementor existent ones...
When i updated Elementor, the error below appeared
Fatal error: Uncaught Error: Undefined class constant 'CHECKBOX' in /var/www/sites/vivatek/wp-content/themes/websolution-complete-theme/inc/classes/Elementor/Widgets/LightboxGallery.php:68 Stack trace: #0 /var/www/sites/vivatek/wp-content/plugins/elementor/includes/base/controls-stack.php(471): WebSolution\CompleteTheme\Elementor\Widgets\LightboxGallery->_register_controls() #1 /var/www/sites/vivatek/wp-content/plugins/elementor/includes/base/controls-stack.php(60): Elementor\Controls_Stack->_init_controls() #2 /var/www/sites/vivatek/wp-content/plugins/elementor/includes/base/controls-stack.php(130): Elementor\Controls_Stack->get_controls() #3 /var/www/sites/vivatek/wp-content/plugins/elementor/includes/css-file/global-css-file.php(75): Elementor\Controls_Stack->get_scheme_controls() #4 /var/www/sites/vivatek/wp-content/plugins/elementor/includes/css-file/global-css-file.php(34): Elementor\Global_CSS_File->render_schemes_css() #5 /var/www/sites/vivatek/wp-content/plugins/elementor/includes/css-file/css-file.php(310): Elem in /var/www/sites/vivatek/wp-content/themes/websolution-complete-theme/inc/classes/Elementor/Widgets/LightboxGallery.php on line 68
I checked the old plugin version, file controls.php
Who should i blame for this? :D @KingYes @kobizz @matipojo
Please pay attention to not remove main functionalities instead of enhancing them.
@teolaz These controls were never officially a part of our API.
The official "Checkbox" control is Switcher.
The official method for dividers between controls is separator.
Sorry for the inconvenience, it is in order to have a more consistent and homogeneous methodology across the board. Thanks for the understanding.
@joshmarom do you agree with me when something is written it needs to be maintained or at limit deprecated in favour of something else? I don't think this is a good programming methodology... You cannot delete pieces of code without repercussions... luckily i didn't updated all my elementor sites!
@teolaz Ok, you are right, we should not have removed it without allowing time for developers to fix their code. We just never really saw these controls as an official part of the system.
Here's what we're going to do:
In the next version, we will temporarily put those controls back, but they are deprecated and should not be used anymore.
In the future, they will be completely removed again.
@joshmarom what i intend is to deprecate the method, not removing it.
Rewriting the add_control method should work, like this:
public function add_control( $id, array $args, $overwrite = false ) {
// deprecated CHECKBOX and DIVIDER controls type are shaped into SWITCHER and SEPARATOR
if(
!empty($args['type']) &&
in_array($args['type'], [Controls_Manager::CHECKBOX, Controls_Manager::DIVIDER])
){
/*
* Here the code to deprecate all unused fields
* the best thing is transforming CHECKBOX args into SWITCHER ones
* and same thing for DIVIDER
* .........
*/
}
if ( empty( $args['type'] ) || ! in_array( $args['type'], [ Controls_Manager::SECTION, Controls_Manager::WP_WIDGET ] ) ) {
if ( null !== $this->_current_section ) {
if ( ! empty( $args['section'] ) || ! empty( $args['tab'] ) ) {
_doing_it_wrong( __CLASS__ . '::' . __FUNCTION__, 'Cannot redeclare control with `tab` or `section` args inside section. - ' . $id, '1.0.0' );
}
$args = array_merge( $args, $this->_current_section );
if ( null !== $this->_current_tab ) {
$args = array_merge( $args, $this->_current_tab );
}
} elseif ( empty( $args['section'] ) ) {
wp_die( __CLASS__ . '::' . __FUNCTION__ . ': Cannot add a control outside a section (use `start_controls_section`).' );
}
}
return Plugin::$instance->controls_manager->add_control_to_stack( $this, $id, $args, $overwrite );
}
so, if i registered this control
$this->add_control(
'add_caption',
[
'label' => __( 'Add caption to images (from images description)', 'websolution-complete-theme' ),
'type' => Controls_Manager::CHECKBOX,
'default' => '',
]
);
you can rewrite its args and build a new registered control like you've registered this
$this->add_control(
'add_caption',
[
'label' => __( 'Add caption to images (from images description)', 'websolution-complete-theme' ),
'type' => Controls_Manager::SWITCHER,
'default' => '',
'label_on' => 'on',
'label_off' => 'off',
'return_value' => 'on', //that was the default value for CHECKBOX control
]
);
Thanks for posting the issue and linking to fixes. I ran into these issues as well. Good thing you have future release branches to test against before updating to production.
I love what you guys are doing. Keep up the great work. :)
@KingYes why you closed this without a word on what i wrote on correctly deprecating?
@joshmarom seen what i wrote?
Yes @teolaz , we saw your suggestion.
Checkbox and Switcher are not 100% compatible and we are not interested in gracefully converting checkbox controls into switcher controls.
Even more so, there simply is no practical way to convert divider control into separator since separator isn't even a standalone control, but an attribute.