Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pull any Elementor options outside of Elementor
/**
* @package Thz Framework
* @author Themezly
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
* @websites http://www.themezly.com | http://www.youjoomla.com | http://www.yjsimplegrid.com
*/
class ThzelGetElementSettings {
public function __construct( $postid, $widget_id, $widget_type ) {
$this->postid = $postid;
$this->widget_id = $widget_id;
$this->widget_type = $widget_type;
$this->widget = null;
$this->parse();
}
public function elementor(){
return \Elementor\Plugin::$instance;
}
public function get_settings () {
$widget = $this->elementor()->elements_manager->create_element_instance( $this->widget );
return $widget->get_settings_for_display();
}
private function parse() {
$data = $this->read_data();
$this->parse_options($data);
}
private function read_data () {
return $this->elementor()->documents->get( $this->postid )->get_elements_data();
}
private function parse_options($data) {
if(!is_array($data) || empty($data)){
return;
}
foreach ( $data as $item ) {
if(empty($item)){
continue;
}
if ( 'section' === $item['elType'] || 'column' === $item['elType']) {
$this->parse_options($item['elements']);
} else {
$this->parse_options_simple($item);
}
}
}
private function parse_options_simple($item) {
if (
$item['id'] === $this->widget_id &&
$item['widgetType'] === $this->widget_type
) {
$this->widget = $item;
}
}
}
@danyj

This comment has been minimized.

Copy link
Owner Author

@danyj danyj commented May 17, 2019

Usage

/*
    \ThzelGetElementSettings(2,123456,'thzel-posts');
*/
$get_settings	= new \ThzelGetElementSettings(PAGE_ID,ELEMENT_ID,ELEMENT_HANDLE); 
$settings	= $get_settings->get_settings();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment