Skip to content

Instantly share code, notes, and snippets.

@webdevs-pro
Created January 22, 2022 19:15
Show Gist options
  • Save webdevs-pro/f72af6630dd41b357306d04dc32989d4 to your computer and use it in GitHub Desktop.
Save webdevs-pro/f72af6630dd41b357306d04dc32989d4 to your computer and use it in GitHub Desktop.
<?php
class AIGetElementSettings {
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 get_settings () {
$widget = $this->elementor()->elements_manager->create_element_instance( $this->widget );
return $widget->get_settings_for_display();
}
public function elementor(){
return Elementor\Plugin::$instance;
}
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;
}
}
}
add_action( 'elementor/init', function() {
$widget = new AIGetElementSettings( 21361, '7g12w74', 'frymo-contact-form' );
$settings = $widget->get_settings();
error_log( "settings\n" . print_r( $settings, true ) . "\n" );
}, 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment