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

Backward Compatibility Issue : shortcode_atts renamed to props. shortcode_atts function equivalent absent #37

Open
ketanshah79 opened this issue Apr 27, 2018 · 20 comments · May be fixed by #515
Assignees

Comments

@ketanshah79
Copy link

ketanshah79 commented Apr 27, 2018

Public property $shortcode_atts renamed to $props

ET_Builder_Element class has renamed shortcode_atts public property to props.

image

This is a breaking change. It broke one of my modules which extends Divi's Image module. Another module which extends Divi's Button module is broken too.

Ideally, the module should have supported shortcode_atts and should have been phased out in a timeframe.

Assuming I fix this and release this, how am I am supposed to maintain backward compatibility with users who are using divi versions lessor than 3.1.

There are quite a few third party divi modules. I am surprised how little thought has gone into this. This is a very high-handed approach. There is no mention of this in the changelog too?

Below is a screenshot or the same.

  • Ditto issue for shortcode_atts() function
  • Am sure there will be other things I'll discover as I move ahead.

Please bring back the deprecating code. Its hurting my business!

Regards
Ketan

@xxtesaxx
Copy link

xxtesaxx commented Apr 27, 2018

My modules are still compatible with the shortcode_callback functions but I'm not extending original Divi modules. Maybe you can just check if this or that exists in the parent class and make a call depending on that. Or you check the Divi Builder version to make that decission.

In this thread the following is suggested: https://stackoverflow.com/questions/3046654/checking-if-an-overridden-parent-method-exists-before-calling-it

public function func() 
{
    if (is_callable('parent::func')) {
        parent::func();
    }
}

Maybe that helps you.

Another suggestion would be to create two modules. One which is compatible with the old 3.0.x and one which is compatible with the new 3.1. In each modules class file, first add a check for the builder version and return early before actually creating the instance of the class to register it.

Keep in mind that 3.0.x won't get any more updates so you can keep your existing function and just don't add new stuff. If ppl want new stuff, they can update to 3.1

@ketanshah79
Copy link
Author

ketanshah79 commented Apr 27, 2018

Thanks @xxtesaxx .

Yes it could very likely be the extension of the existing divi modules and/or the use of properties/functions which has no backward compatibility. shortcode_callback function could be backward as I haven't dug very deep into their code.

Maybe you can just check if this or that exists in the parent class and make a call depending on that

I like the idea of doing checks this way. I'll have total control over my code. It would be great if elegant theme comes out with a detailed list of things which can cause breaking changes so that we can factor those in our code.

Another suggestion would be to create two modules

This will only cause confusion as 2 modules will show up in the module list. Will lead to abandonment.

Currently I feel like a one-legged man in an ass-kicking contest 😁

Regards,
Ketan

@xxtesaxx
Copy link

The default implementation or render() is backwards compatible. Thats why my modules still work right out of the box:

public function render( $attrs, $content = null, $render_slug ) {
	if ( method_exists( $this, 'shortcode_callback' ) ) {
		// Backwards compatibility
		return $this->__call( 'shortcode_callback', array( $attrs, $content, $render_slug ) );
	}

	return '';
}

Only if you extend the core module, there is already a render function overwritten and therefore your shortcode_callback() won't reg called. You could overwrite render() and call the greatparents render method using reflection: https://stackoverflow.com/questions/12850802/how-to-call-grandparent-method-without-getting-e-strict-error

@ketanshah79
Copy link
Author

@xxtesaxx Thats correct. shortcode_callback does have backword compatibility

So I'll take my words back on that particular one !!!

I'll conditionally check on shortcode_atts propery and shortcode_atts function (in the before_render function) and refactor my code accordingly.

Thanks for your quick replies. Much appreciated. Have a great weekend!

@ketanshah79 ketanshah79 changed the title Backward Compatibility Issue : shortcode_atts renamed to props. Render method instead of shortcode_atts() method. Backward Compatibility Issue : shortcode_atts renamed to props. shortcode_atts function equivalent absent Apr 27, 2018
@ketanshah79
Copy link
Author

ketanshah79 commented Apr 27, 2018

I managed to solve the backward compatibility issue.

Step 1: Identify if the code is before/after version 3.1

I used the following function below to do the identification. function shortcode_atts is no longer used in version 3.1+. If function shortcode_atts is not present, then its version 3.1 and above.

public function get_module_props_name() { return method_exists('\\ET_Builder_Module_Image', 'shortcode_atts') ? 'shortcode_atts' : 'props'; }

Quick tip: I indentify this in my module constructor and store it in a variable df_props, for example.

Step 2: Replace the $shortcode_atts variable.

With the new version, property $shortcode_atts has become $props. This name is stored in $df_props variable.

So I will simply replace the $this->shortcode_atts property references with $this->{$this->df_props}

Step 3: If your code uses parent::shortcode_atts() function, use the following below.

if ($this->df_props == 'shortcode_atts') { $html = parent::shortcode_callback($atts, $content, $function_name); } else { $html = parent::render($atts, $content, $function_name); }

Tip: Since you are call parent::shortcode_callback in your code, for some strange reason, I will also have to define the render method as well.

function render($atts, $content = null, $function_name) { return $this->shortcode_callback($atts, $content, $function_name); }

@elegantthemes elegantthemes deleted a comment from etstaging Apr 27, 2018
@lots0logs
Copy link
Member

You shouldn't have had to do anything special for backwards compatibility. All of the properties and methods that were renamed have backwards compatibility code in-place. Could you provide us with a copy of one of the modules that appears to be broken due to renamed methods and/or fields? Thanks.

@ketanshah79
Copy link
Author

Thanks @lots0logs

I've sent you an email with the copy of broken and fixed plugin along with a brief description via email found on your github profile

@ketanshah79
Copy link
Author

@lots0logs

  1. Were you able to replicate the issue with the plugins I sent?
  2. Any ETA on when a fix will be applied to the divi theme?

Thanks

@lots0logs
Copy link
Member

No, I'm afraid I haven't had a chance to look at it yet. I'm bogged down with GDPR stuff right now. As soon as that's done I'll be able to come back to this. Thanks for your patience.

@ketanshah79
Copy link
Author

Hi @lots0logs,

Any updates on this one?

Thanks

@lots0logs
Copy link
Member

Unfortunately no, but the good news is that we've set aside time to address 3rd-party api bugs for the new backend builder release (which is in like ~3 weeks). This one is near the top of the list.

@ketanshah79
Copy link
Author

Greetings @lots0logs . Any updates on this one? thanks

@ketanshah79
Copy link
Author

Greetings @lots0logs . Hope you are doing well. Any update on this one?

thanks

@fikrirasyid
Copy link
Contributor

Hi @ketanshah79, we're really sorry that it took us quite some time to address this. I'm Fikri from ET team; As @lots0logs mentioned at #37 (comment), we're currently addressing significant amout of issues for the upcoming release. Can you give me the access to your plugin? @lots0logs has forwarded the email you sent to him so i can take a look at the issue but once i tried to download the plugin i have no permission to do so. My email is my github username + @gmail.com.

Thanks.

@ketanshah79
Copy link
Author

thanks @fikrirasyid .

I did receive an access request from you few days ago but rejected it :)

I'll set up something by Monday.

Thanks

@fikrirasyid
Copy link
Contributor

@ketanshah79 my pleasure. Yeah, sorry i was requesting it but forgot to follow it up here. There were couple of things happening 🤦‍♂️

Thanks, just let me know 👍

@fikrirasyid
Copy link
Contributor

fikrirasyid commented Nov 6, 2018

Hi @ketanshah79, is there any update regarding the access request? Thanks

@ketanshah79
Copy link
Author

ketanshah79 commented Nov 6, 2018 via email

@ketanshah79
Copy link
Author

@fikrirasyid sent :)

@ketanshah79
Copy link
Author

@fikrirasyid

Any updates on this one?

Thanks

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

Successfully merging a pull request may close this issue.

4 participants