assets
1 year ago
views
1 year ago
Api.php
1 year ago
Import.php
1 year ago
Init.php
1 year ago
Load.php
1 year ago
Import.php
63 lines
| 1 | <?php |
| 2 | namespace SPEL\includes\template_library; |
| 3 | |
| 4 | defined('ABSPATH') || die(); |
| 5 | |
| 6 | |
| 7 | use SPEL\includes\template_library\Api as Api; |
| 8 | use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 9 | use Elementor\Plugin; |
| 10 | |
| 11 | class Import { |
| 12 | |
| 13 | private static $instance = null; |
| 14 | |
| 15 | protected static $template = null; |
| 16 | |
| 17 | public function load(): void |
| 18 | { |
| 19 | add_action( 'elementor/ajax/register_actions', array($this, 'ajax_actions' ) ); |
| 20 | } |
| 21 | |
| 22 | public function ajax_actions( Ajax $ajax ): void |
| 23 | { |
| 24 | $ajax->register_ajax_action( 'get_docy_template_data', function( $data ) { |
| 25 | if ( ! current_user_can( 'edit_posts' ) ) { |
| 26 | throw new \Exception( 'Access Denied' ); |
| 27 | } |
| 28 | |
| 29 | if ( ! empty( $data['editor_post_id'] ) ) { |
| 30 | $editor_post_id = absint( $data['editor_post_id'] ); |
| 31 | |
| 32 | if ( ! get_post( $editor_post_id ) ) { |
| 33 | throw new \Exception( __( 'Post not found', 'spider-elements' ) ); |
| 34 | } |
| 35 | Plugin::$instance->db->switch_to_post( $editor_post_id ); |
| 36 | } |
| 37 | |
| 38 | if ( empty( $data['template_id'] ) ) { |
| 39 | throw new \Exception( __( 'Template id missing', 'spider-elements' ) ); |
| 40 | } |
| 41 | return self::get_template_data( $data ); |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | public static function get_template_data( array $args ) { |
| 46 | $template = self::template_library(); |
| 47 | return $template->get_data( $args ); |
| 48 | } |
| 49 | |
| 50 | public static function template_library() { |
| 51 | if ( is_null( self::$template ) ) { |
| 52 | self::$template = new Api(); |
| 53 | } |
| 54 | return self::$template; |
| 55 | } |
| 56 | |
| 57 | public static function instance(){ |
| 58 | if( is_null(self::$instance) ){ |
| 59 | self::$instance = new self(); |
| 60 | } |
| 61 | return self::$instance; |
| 62 | } |
| 63 | } |