PluginProbe ʕ •ᴥ•ʔ
Spider Elements – Premium Elementor Widgets & Addons Library / 1.5.0
Spider Elements – Premium Elementor Widgets & Addons Library v1.5.0
trunk 1.0.0 1.1.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.7.0 1.8.0 1.9.0
spider-elements / includes / template_library / templates / Load.php
spider-elements / includes / template_library / templates Last commit date
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
Load.php
68 lines
1 <?php
2 namespace SPEL\includes\template_library;
3
4 use SPEL\includes\template_library\Init as Init;
5 use SPEL\includes\template_library\Api as Api;
6
7 use Elementor\Plugin;
8 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
9
10 if ( ! defined( 'ABSPATH' ) ) {exit;}
11
12 class Load {
13
14 private static $instance = null;
15
16 protected static $library_data = null;
17
18 public function load(){
19 add_action( 'elementor/editor/footer', [ $this, 'load_template_views' ], 999);
20 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
21 }
22
23 public function load_template_views() {
24 include Init::dir() . 'views/templates.php';
25 }
26
27 public static function get_library() {
28 if ( is_null( self::$library_data ) ) {
29 self::$library_data = new Api();
30 }
31 return self::$library_data;
32 }
33
34 public function register_ajax_actions( Ajax $ajax ) {
35 $ajax->register_ajax_action( 'get_docy_library_data', function( $data ) {
36 if ( ! current_user_can( 'edit_posts' ) ) {
37 throw new \Exception( 'Access Denied' );
38 }
39 if ( ! empty( $data['editor_post_id'] ) ) {
40 $editor_post_id = absint( $data['editor_post_id'] );
41 if ( ! get_post( $editor_post_id ) ) {
42 throw new \Exception( __( 'Post not found.', 'spider-elements' ) );
43 }
44 Plugin::$instance->db->switch_to_post( $editor_post_id );
45 }
46 return self::get_library_data( $data );
47 } );
48 }
49
50 public static function get_library_data( array $args ) {
51 $library_data = self::get_library();
52 if ( ! empty( $args['sync'] ) ) {
53 $library_data::get_library_data( true );
54 }
55 return [
56 'templates' => $library_data->get_items(),
57 'tags' => $library_data->get_tags(),
58 'type_tags' => $library_data->get_type_tags(),
59 ];
60 }
61
62 public static function instance(){
63 if( is_null(self::$instance) ){
64 self::$instance = new self();
65 }
66 return self::$instance;
67 }
68 }