Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Missing constant in Controls_Manager class from last versions #2003

Closed
teolaz opened this issue Jul 13, 2017 · 9 comments
Closed

[BUG] Missing constant in Controls_Manager class from last versions #2003

teolaz opened this issue Jul 13, 2017 · 9 comments

Comments

@teolaz
Copy link

teolaz commented Jul 13, 2017

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
image

Who should i blame for this? :D @KingYes @kobizz @matipojo
Please pay attention to not remove main functionalities instead of enhancing them.

@nextend
Copy link
Contributor

nextend commented Jul 13, 2017

@teolaz
Copy link
Author

teolaz commented Jul 13, 2017

@nextend tnks!
@kobizz why? if you make available something, please leave it available :) could you please bring it back working asap? even the divider?

@joshmarom
Copy link
Contributor

joshmarom commented Jul 13, 2017

@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.

@teolaz
Copy link
Author

teolaz commented Jul 13, 2017

@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!

@joshmarom
Copy link
Contributor

joshmarom commented Jul 13, 2017

@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.

@teolaz
Copy link
Author

teolaz commented Jul 13, 2017

@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
				]
			);

@ryanlabelle
Copy link

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. :)

@teolaz
Copy link
Author

teolaz commented Jul 24, 2017

@KingYes why you closed this without a word on what i wrote on correctly deprecating?
@joshmarom seen what i wrote?

@joshmarom
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants