PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.2
Elementor Website Builder – more than just a page builder v3.5.2
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.5.2, at core/common/modules/connect/apps/library.php

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