Add new action to register custom Elementor endpoints #26534
gerardreches
started this conversation in
Feature Request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Prerequisites
What problem is your feature request going to solve? Please describe..
Elementor's regex for their global colors and typography endpoints don't allow hyphens or underscores in the global property ID, as they are currently randomly generated strings (check #12571 ). This makes difficult for advanced users with CSS knowledge to reuse the global color variables.
I am developing a solution to use user-defined IDs instead of random strings, which is already working and doesn't cause any issues with Elementor.
However, the implementation could be much better if I could make use of Elementor's existing classes. The requested action hook is necessary in order to extend the existing endpoint classes and correctly register them in the Controller. This would reduce the amount of code required to implement the feature, as most of it is copied from the existing class contained in the Elementor plugin, as well as improving compatibility and avoiding breaking changes.
Describe the solution you'd like.
I need to register a new custom endpoint in the method
register_endpoints()from classElementor\Core\Editor\Data\Globals\Controller.Could you please add a new action hook inside this method? The variable
$thismust be passed as a parameter for the action hook.This would be the updated class method:
The only change is that the line
do_action( 'elementor/controller/register_endpoints', $this )has been added.Of course you could change the action name to whichever you find more appropiate.
Describe alternatives you've considered.
It can also be solved by adding a new filter in Elementor\Core\Editor\Data\Globals\Endpoints\Base by updating the method
register()for the following:Only one line of code is updated, replacing
'[\w]+'withapply_filters( 'elementor/endpoints/id_arg_type_regex', '[\w]+', $this->get_name() ). The default value if no filter is added remains the same. However it allows for modifying the regex for a specific endpoint. We pass the value of$this->get_name()as a parameter to be able to check which endpoint is triggering the filter (values can currently becolorsortypography).Additional context
While the latter solution would make everything easier, the former may be easier to include without having to think about possible misuse. Both hooks could be implemented as they are compatible with each other.
Agreement
All reactions