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

Conditions Not Working Starting With 3.4.0 #16003

Closed
meceware opened this issue Aug 17, 2021 · 9 comments
Closed

Conditions Not Working Starting With 3.4.0 #16003

meceware opened this issue Aug 17, 2021 · 9 comments
Labels
bug Indicates a bug with one or multiple components.

Comments

@meceware
Copy link

Hey guys,

I'm an Elementor plugin developer, and I've been facing an issue with Elementor 3.4. The conditions are not working anymore. I've searched the issues but couldn't find an answer. Please find a simple test plugin code below:

You can install the file as a new plugin on a test site. This code works with previous versions of Elementor but not with Elementor 3.4.0. Can you help and see what's happening?

Thank you,

<?php
/**
 * Plugin Name: My Plugin
 * Author: meceware
 * Version: 1.0.0
 * Description: My Plugin
 * Text Domain: my-test-plugin
**/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

use Elementor\Controls_Manager as ControlsManager;

add_action('plugins_loaded', 'myOnPluginsLoaded', 100);
function myOnPluginsLoaded() {
  add_action('elementor/init', 'myOnElementorInit');
}

function myOnElementorInit() {
  add_action('elementor/element/wp-page/document_settings/after_section_end', 'myAddTab', 10, 2);
}

function myAddTab($page){
  $page->start_controls_section(
    'tab-my-experiment',
    array(
      'label' => 'Experiment',
      'tab' => ControlsManager::TAB_SETTINGS,
    )
  );

  $page->add_control(
    'my-exp-enabled',
    array(
      'label' => 'Experiment Label',
      'type' => ControlsManager::SWITCHER,
      'default' => 'no',
      'label_on' => 'Yes',
      'label_off' => 'No',
      'return_value' => 'yes',
    )
  );

  // *********************************************************************
  // Here the conditional switcher should be visible when the other one is enabled, but not working anymore
  // *********************************************************************
  $page->add_control(
    'my-exp-condition',
    array(
      'label' => 'Experiment Condition',
      'type' => ControlsManager::SWITCHER,
      'default' => 'no',
      'description' => 'Check Label and see',
      'condition' => array(
        'my-exp-enabled' => 'yes', // The condition is given here
      ),
    )
  );

  $page->end_controls_section();
}
@udidol udidol added the bug Indicates a bug with one or multiple components. label Aug 17, 2021
@udidol
Copy link
Contributor

udidol commented Aug 17, 2021

Hey @meceware,
Thank you for your detailed report and example!
Thanks to your report, we have discovered a bug with our conditions system in the Editor environment in 3.4.0.
Your plugin example was also very helpful, it allowed us to isolate the issue within minutes and find the problem.
Kudos!

We will be releasing a version with bugfixes very soon, and a fix to this issue will be included.

@meceware
Copy link
Author

Awesome :)

Cheers,

@shilo-ey
Copy link
Contributor

This issue has been resolved in Elementor v3.4.1

Feel free to update

Thanks!

@posimyth
Copy link

posimyth commented Aug 19, 2021

@shilo-ey It's resolved for Dash(-) but still issue with Capitals in conditions. It was working fine till 3.4.0 but in 3.4.1 it started creating issue.

$repeater = new \Elementor\Repeater();
$repeater->add_control(
	'selectFeed',[
		'label' => esc_html__( 'Source','plugin-name' ),
		'type' => Controls_Manager::SELECT,
		'default' => 'Facebook',
		'options' => [
			'Facebook' => esc_html__( 'Facebook','plugin-name' ),
			'Instagram' => esc_html__( 'Instagram','plugin-name' ),
			'Twitter' => esc_html__( 'Twitter','plugin-name' ),
			'Youtube' => esc_html__( 'Youtube','plugin-name' ),
			'Vimeo' => esc_html__( 'Vimeo','plugin-name' ),					
		],
	]
);
$repeater->add_control(
	'SFFacebookButton',
	[
		'type' => Controls_Manager::RAW_HTML,
		'raw' => '<a class="tp-feed-fb-button" id="tp-feed-fb-button" ><i class="fa fa-facebook-official" aria-hidden="true"></i>Generate Access Token</a>',
		'content_classes' => 'tp-feed-fb-btn',
		'label_block' => true,
		'condition' => [
			'selectFeed' => 'Facebook',
		],
	]
);
$repeater->add_control(
	'ProfileType',[
		'label' => esc_html__( 'Select Option','plugin-name' ),
		'type' => Controls_Manager::SELECT,
		'default' => 'post',
		'options' => [
			'post' => esc_html__( 'Individual','plugin-name' ),
			'page' => esc_html__( 'Page','plugin-name' ),					
		],
		'condition' => [
			'selectFeed' => 'Facebook',
		],
	]
);	

Check Video, Where we have shown a comparison of 3.4.0 to 3.4.1. https://app.vmaker.com/record/KcfR8nUXWB5AN5n9

It required action soon on this as many of our users will have issue due to this.

Thanks from The Plus Addons for Elementor Team

@udidol
Copy link
Contributor

udidol commented Aug 19, 2021

@posimyth
Hi, I see the problem with capital letters. It will be resolved in the upcoming patch version.

@udidol udidol reopened this Aug 19, 2021
@posimyth
Copy link

@udidol @shilo-ey Let us know, If you want us to test when you release it's beta. I think, You need to release patch soon as many other developers might have such issue as well.

@udidol
Copy link
Contributor

udidol commented Aug 19, 2021

@posimyth
There's no beta, it's a patch version that will likely be released today, which will include several fixes.

@VadymPogorelov
Copy link

VadymPogorelov commented Aug 19, 2021

Why I can't use, for example, a '.' (dot) in the option name? Or uppercase letters? Why are these restrictions in the names of options, moreover, used only when processing visibility conditions, but not when creating options?

Please note that in addition to editor.js (which causes the js-error in the console - see #16065 ), there is a similar check in controls-stack.php:
preg_match( '/([a-z_\-0-9]+)(?:\[([a-z_]+)])?(!?)$/i', $condition_key, $condition_key_parts );

I think that such "cutting" of only suitable characters when getting the option name is meaningless - as a result, the check will still not work, because the name of the option to be checked will differ from its real name specified when creating the element (if the option name contains characters that are unacceptable in your opinion): http://joxi.ru/l2ZGE58cRQxW4A
It turns out that I can create a parameter named 'title.next', but I cannot use it in conditions for other fields! Why such a "selective" cleanup of names?

@shilo-ey
Copy link
Contributor

This issue has been resolved in Elementor v3.4.2

Feel free to update

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates a bug with one or multiple components.
Projects
None yet
Development

No branches or pull requests

5 participants