Created
May 17, 2019 11:41
-
-
Save danyj/317e0fdc9e18d2857f331245f2cedd1d to your computer and use it in GitHub Desktop.
Pull any Elementor options outside of Elementor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated code to include dynamic field data