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

192 lines 6.1 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 } else {
118 if ( current_user_can( 'install_plugins' ) ) {
119 $app['action_label'] = esc_html__( 'Install', 'elementor' );
120 $app['action_url'] = self::$plugin_status_adapter->get_install_plugin_url( $app['file_path'] );
121 } else {
122 $app['action_label'] = esc_html__( 'Cannot Install', 'elementor' );
123 $app['action_url'] = '#';
124 }
125 }
126
127 return $app;
128 }
129
130 private static function is_ecom_app( $app ) {
131 return isset( $app['type'] ) && 'ecom' === $app['type'];
132 }
133
134 private static function filter_ecom_app( $app ) {
135 if ( self::$wordpress_adapter->is_plugin_active( $app['file_path'] ) ) {
136 return null;
137 }
138
139 if ( ! self::$plugin_status_adapter->is_plugin_installed( $app['file_path'] ) ) {
140 return $app;
141 }
142
143 if ( current_user_can( 'activate_plugins' ) ) {
144 $app['action_label'] = esc_html__( 'Activate', 'elementor' );
145 $app['action_url'] = self::$plugin_status_adapter->get_activate_plugin_url( $app['file_path'] );
146 } else {
147 $app['action_label'] = esc_html__( 'Cannot Activate', 'elementor' );
148 $app['action_url'] = '#';
149 }
150
151 $app['target'] = '_self';
152
153 return $app;
154 }
155
156 private static function get_images_url() {
157 return ELEMENTOR_URL . 'modules/apps/images/';
158 }
159
160 private static function is_elementor_pro_installed() {
161 return defined( 'ELEMENTOR_PRO_VERSION' );
162 }
163
164 private static function render_plugin_item( $plugin ) {
165 ?>
166 <div class="e-a-item">
167 <div class="e-a-heading">
168 <img class="e-a-img" src="<?php echo esc_url( $plugin['image'] ); ?>" alt="<?php echo esc_attr( $plugin['name'] ); ?>">
169 <?php if ( ! empty( $plugin['badge'] ) ) : ?>
170 <span class="e-a-badge"><?php echo esc_html( $plugin['badge'] ); ?></span>
171 <?php endif; ?>
172 </div>
173 <h3 class="e-a-title"><?php echo esc_html( $plugin['name'] ); ?></h3>
174 <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>
175 <div class="e-a-desc">
176 <p><?php echo esc_html( $plugin['description'] ); ?></p>
177 <?php if ( ! empty( $plugin['offering'] ) ) : ?>
178 <p class="e-a-offering"><?php echo esc_html( $plugin['offering'] ); ?></p>
179 <?php endif; ?>
180 </div>
181
182 <p class="e-a-actions">
183 <?php if ( ! empty( $plugin['learn_more_url'] ) ) : ?>
184 <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>
185 <?php endif; ?>
186 <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>
187 </p>
188 </div>
189 <?php
190 }
191 }
192