Skip to content

Instantly share code, notes, and snippets.

@danyj
Created May 17, 2019 11:41
Show Gist options
  • Save danyj/317e0fdc9e18d2857f331245f2cedd1d to your computer and use it in GitHub Desktop.
Save danyj/317e0fdc9e18d2857f331245f2cedd1d to your computer and use it in GitHub Desktop.
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
Copy link
Author

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();

@webdevs-pro
Copy link

Thanks!

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