PluginProbe
Elementor Website Builder – more than just a page builder / 3.11.5
Elementor Website Builder – more than just a page builder v3.11.5
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / common / modules / connect / apps / library.php

library.php in Elementor Website Builder – more than just a page builder 3.11.5, at core/common/modules/connect/apps/library.php

131 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Common\Modules\Connect\Apps;
3
4 use Elementor\Api;
5 use Elementor\User;
6 use Elementor\Plugin;
7 use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 class Library extends Common_App {
14
15 public function get_title() {
16 return esc_html__( 'Library', 'elementor' );
17 }
18
19 /**
20 * @since 2.3.0
21 * @access protected
22 */
23 protected function get_slug() {
24 return 'library';
25 }
26
27 public function get_template_content( $id ) {
28 if ( ! $this->is_connected() ) {
29 return new \WP_Error( '401', esc_html__( 'Connecting to the Library failed. Please try reloading the page and try again', 'elementor' ) );
30 }
31
32 $body_args = [
33 'id' => $id,
34
35 // Which API version is used.
36 'api_version' => ELEMENTOR_VERSION,
37 // Which language to return.
38 'site_lang' => get_bloginfo( 'language' ),
39 ];
40
41 /**
42 * API: Template body args.
43 *
44 * Filters the body arguments send with the GET request when fetching the content.
45 *
46 * @since 1.0.0
47 *
48 * @param array $body_args Body arguments.
49 */
50 $body_args = apply_filters( 'elementor/api/get_templates/body_args', $body_args );
51
52 $template_content = $this->request( 'get_template_content', $body_args, true );
53
54 if ( is_wp_error( $template_content ) && 401 === $template_content->get_error_code() ) {
55 // Normalize 401 message
56 return new \WP_Error( 401, esc_html__( 'Connecting to the Library failed. Please try reloading the page and try again', 'elementor' ) );
57 }
58
59 return $template_content;
60 }
61
62 public function localize_settings( $settings ) {
63 $is_connected = $this->is_connected();
64
65 /** @var ConnectModule $connect */
66 $connect = Plugin::$instance->common->get_component( 'connect' );
67
68 return array_replace_recursive( $settings, [
69 'library_connect' => [
70 'is_connected' => $is_connected,
71 'subscription_plans' => $connect->get_subscription_plans( 'template-library' ),
72 'base_access_level' => ConnectModule::ACCESS_LEVEL_CORE,
73 'current_access_level' => ConnectModule::ACCESS_LEVEL_CORE,
74 ],
75 ] );
76 }
77
78 public function library_connect_popup_seen() {
79 User::set_introduction_viewed( [
80 'introductionKey' => 'library_connect',
81 ] );
82 }
83
84 /**
85 * @param \Elementor\Core\Common\Modules\Ajax\Module $ajax_manager
86 */
87 public function register_ajax_actions( $ajax_manager ) {
88 $ajax_manager->register_ajax_action( 'library_connect_popup_seen', [ $this, 'library_connect_popup_seen' ] );
89 }
90
91 /**
92 * After Connect
93 *
94 * After Connecting to the library, re-fetch the library data to get it up to date.
95 *
96 * @since 3.7.0
97 */
98 protected function after_connect() {
99 Api::get_library_data( true );
100 }
101
102 protected function get_app_info() {
103 return [
104 'user_common_data' => [
105 'label' => 'User Common Data',
106 'value' => get_user_option( $this->get_option_name(), get_current_user_id() ),
107 ],
108 'connect_site_key' => [
109 'label' => 'Site Key',
110 'value' => get_option( self::OPTION_CONNECT_SITE_KEY ),
111 ],
112 'remote_info_library' => [
113 'label' => 'Remote Library Info',
114 'value' => get_option( 'elementor_remote_info_library' ),
115 ],
116 ];
117 }
118
119 protected function get_popup_success_event_data() {
120 return [
121 'access_level' => ConnectModule::ACCESS_LEVEL_CORE,
122 ];
123 }
124
125 protected function init() {
126 add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );
127 add_filter( 'elementor/common/localize_settings', [ $this, 'localize_settings' ] );
128 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
129 }
130 }
131