PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.3
Elementor Website Builder – more than just a page builder v3.35.3
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 / modules / apps / admin-apps-page.php

admin-apps-page.php in Elementor Website Builder – more than just a page builder 3.35.3, at modules/apps/admin-apps-page.php

190 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\Apps;
3
4 use Elementor\Core\Isolation\Wordpress_Adapter;
5 use Elementor\Core\Isolation\Plugin_Status_Adapter;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Admin_Apps_Page {
12
13 const APPS_URL = 'https://assets.elementor.com/apps/v1/apps.json';
14
15 private static ?Wordpress_Adapter $wordpress_adapter = null;
16
17 private static ?Plugin_Status_Adapter $plugin_status_adapter = null;
18
19 public static function render() {
20 ?>
21 <div class="wrap e-a-apps">
22
23 <div class="e-a-page-title">
24 <h2><?php echo esc_html__( 'Popular Add-ons, New Possibilities.', 'elementor' ); ?></h2>
25 <p><?php echo esc_html__( 'Boost your web-creation process with add-ons, plugins, and more tools specially selected to unleash your creativity, increase productivity, and enhance your Elementor-powered website.', 'elementor' ); ?>*<br>
26 <a href="https://go.elementor.com/wp-dash-apps-about-apps-page/" target="_blank"><?php echo esc_html__( 'Learn more about this page.', 'elementor' ); ?></a>
27 </p>
28 </div>
29
30 <div class="e-a-list">
31 <?php self::render_plugins_list(); ?>
32 </div>
33 <div class="e-a-page-footer">
34 <p>*<?php echo esc_html__( 'Please note that certain tools and services on this page are developed by third-party companies and are not part of Elementor\'s suite of products or support. Before using them, we recommend independently evaluating them. Additionally, when clicking on their action buttons, you may be redirected to an external website.', 'elementor' ); ?></p>
35 </div>
36 </div>
37 <?php
38 }
39
40 private static function render_plugins_list() {
41 $plugins = self::get_plugins();
42
43 foreach ( $plugins as $plugin ) {
44 self::render_plugin_item( $plugin );
45 }
46 }
47
48 private static function get_plugins(): array {
49 if ( ! self::$wordpress_adapter ) {
50 self::$wordpress_adapter = new Wordpress_Adapter();
51 }
52
53 if ( ! self::$plugin_status_adapter ) {
54 self::$plugin_status_adapter = new Plugin_Status_Adapter( self::$wordpress_adapter );
55 }
56
57 $apps = static::get_remote_apps();
58
59 return static::filter_apps( $apps );
60 }
61
62 private static function get_remote_apps() {
63 $apps = wp_remote_get( static::APPS_URL );
64
65 if ( is_wp_error( $apps ) ) {
66 return [];
67 }
68
69 $apps = json_decode( wp_remote_retrieve_body( $apps ), true );
70
71 if ( empty( $apps['apps'] ) || ! is_array( $apps['apps'] ) ) {
72 return [];
73 }
74
75 return $apps['apps'];
76 }
77
78 private static function filter_apps( $apps ) {
79 $filtered_apps = [];
80
81 foreach ( $apps as $app ) {
82 if ( static::is_wporg_app( $app ) ) {
83 $app = static::filter_wporg_app( $app );
84 }
85
86 if ( static::is_ecom_app( $app ) ) {
87 $app = static::filter_ecom_app( $app );
88 }
89
90 if ( empty( $app ) ) {
91 continue;
92 }
93
94 $filtered_apps[] = $app;
95 }
96
97 return $filtered_apps;
98 }
99
100 private static function is_wporg_app( $app ) {
101 return isset( $app['type'] ) && 'wporg' === $app['type'];
102 }
103
104 private static function filter_wporg_app( $app ) {
105 if ( self::$wordpress_adapter->is_plugin_active( $app['file_path'] ) ) {
106 return null;
107 }
108
109 if ( self::$plugin_status_adapter->is_plugin_installed( $app['file_path'] ) ) {
110 if ( current_user_can( 'activate_plugins' ) ) {
111 $app['action_label'] = esc_html__( 'Activate', 'elementor' );
112 $app['action_url'] = self::$plugin_status_adapter->get_activate_plugin_url( $app['file_path'] );
113 } else {
114 $app['action_label'] = esc_html__( 'Cannot Activate', 'elementor' );
115 $app['action_url'] = '#';
116 }
117 } elseif ( current_user_can( 'install_plugins' ) ) {
118 $app['action_label'] = esc_html__( 'Install', 'elementor' );
119 $app['action_url'] = self::$plugin_status_adapter->get_install_plugin_url( $app['file_path'] );
120 } else {
121 $app['action_label'] = esc_html__( 'Cannot Install', 'elementor' );
122 $app['action_url'] = '#';
123 }
124
125 return $app;
126 }
127
128 private static function is_ecom_app( $app ) {
129 return isset( $app['type'] ) && 'ecom' === $app['type'];
130 }
131
132 private static function filter_ecom_app( $app ) {
133 if ( self::$wordpress_adapter->is_plugin_active( $app['file_path'] ) ) {
134 return null;
135 }
136
137 if ( ! self::$plugin_status_adapter->is_plugin_installed( $app['file_path'] ) ) {
138 return $app;
139 }
140
141 if ( current_user_can( 'activate_plugins' ) ) {
142 $app['action_label'] = esc_html__( 'Activate', 'elementor' );
143 $app['action_url'] = self::$plugin_status_adapter->get_activate_plugin_url( $app['file_path'] );
144 } else {
145 $app['action_label'] = esc_html__( 'Cannot Activate', 'elementor' );
146 $app['action_url'] = '#';
147 }
148
149 $app['target'] = '_self';
150
151 return $app;
152 }
153
154 private static function get_images_url() {
155 return ELEMENTOR_URL . 'modules/apps/images/';
156 }
157
158 private static function is_elementor_pro_installed() {
159 return defined( 'ELEMENTOR_PRO_VERSION' );
160 }
161
162 private static function render_plugin_item( $plugin ) {
163 ?>
164 <div class="e-a-item"<?php echo ! empty( $plugin['file_path'] ) ? ' data-plugin="' . esc_attr( $plugin['file_path'] ) . '"' : ''; ?>>
165 <div class="e-a-heading">
166 <img class="e-a-img" src="<?php echo esc_url( $plugin['image'] ); ?>" alt="<?php echo esc_attr( $plugin['name'] ); ?>">
167 <?php if ( ! empty( $plugin['badge'] ) ) : ?>
168 <span class="e-a-badge"><?php echo esc_html( $plugin['badge'] ); ?></span>
169 <?php endif; ?>
170 </div>
171 <h3 class="e-a-title"><?php echo esc_html( $plugin['name'] ); ?></h3>
172 <p class="e-a-author"><?php esc_html_e( 'By', 'elementor' ); ?> <a href="<?php echo esc_url( $plugin['author_url'] ); ?>" target="_blank"><?php echo esc_html( $plugin['author'] ); ?></a></p>
173 <div class="e-a-desc">
174 <p><?php echo esc_html( $plugin['description'] ); ?></p>
175 <?php if ( ! empty( $plugin['offering'] ) ) : ?>
176 <p class="e-a-offering"><?php echo esc_html( $plugin['offering'] ); ?></p>
177 <?php endif; ?>
178 </div>
179
180 <p class="e-a-actions">
181 <?php if ( ! empty( $plugin['learn_more_url'] ) ) : ?>
182 <a class="e-a-learn-more" href="<?php echo esc_url( $plugin['learn_more_url'] ); ?>" target="_blank"><?php echo esc_html__( 'Learn More', 'elementor' ); ?></a>
183 <?php endif; ?>
184 <a href="<?php echo esc_url( $plugin['action_url'] ); ?>" class="e-btn e-accent" target="<?php echo isset( $plugin['target'] ) ? esc_attr( $plugin['target'] ) : '_blank'; ?>"><?php echo esc_html( $plugin['action_label'] ); ?></a>
185 </p>
186 </div>
187 <?php
188 }
189 }
190