assets
3 weeks ago
init.php
3 weeks ago
layout-import-api.php
2 years ago
layout-list-api.php
3 weeks ago
library-source.php
2 years ago
layout-import-api.php
49 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Modules\Layout_Manager; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 7 | |
| 8 | class Layout_Import_Api { |
| 9 | public function __construct() { |
| 10 | add_action( 'elementor/ajax/register_actions', array( $this, 'register_ajax_actions' ) ); |
| 11 | } |
| 12 | |
| 13 | public function register_ajax_actions( Ajax $ajax ) { |
| 14 | $ajax->register_ajax_action( |
| 15 | 'get_elementskit_template_data', |
| 16 | function( $data ) { |
| 17 | if ( ! current_user_can( 'edit_posts' ) ) { |
| 18 | throw new \Exception( 'Access Denied' ); |
| 19 | } |
| 20 | |
| 21 | if ( ! empty( $data['editor_post_id'] ) ) { |
| 22 | $editor_post_id = absint( $data['editor_post_id'] ); |
| 23 | |
| 24 | if ( ! get_post( $editor_post_id ) ) { |
| 25 | throw new \Exception( esc_html__( 'Post not found', 'elementskit-lite' ) ); |
| 26 | } |
| 27 | |
| 28 | \Elementor\Plugin::instance()->db->switch_to_post( $editor_post_id ); |
| 29 | } |
| 30 | |
| 31 | if ( empty( $data['template_id'] ) ) { |
| 32 | throw new \Exception( esc_html__( 'Template id missing', 'elementskit-lite' ) ); |
| 33 | } |
| 34 | |
| 35 | $result = $this->get_template_data( $data ); |
| 36 | |
| 37 | return $result; |
| 38 | } |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | private function get_template_data( array $args ) { |
| 43 | $source = new Library_Source(); |
| 44 | $data = $source->get_data( $args ); |
| 45 | return $data; |
| 46 | } |
| 47 | |
| 48 | } |
| 49 |