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

197 lines 6.4 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 use Elementor\Plugin;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Admin_Apps_Page {
13
14 const APPS_URL = 'https://assets.elementor.com/apps/v1/apps.json';
15
16 private static ?Wordpress_Adapter $wordpress_adapter = null;
17
18 private static ?Plugin_Status_Adapter $plugin_status_adapter = null;
19
20 public static function render() {
21 ?>
22 <div class="wrap e-a-apps">
23
24 <div class="e-a-page-title">
25 <h2><?php echo esc_html__( 'Popular Add-ons, New Possibilities.', 'elementor' ); ?></h2>
26 <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>
27 <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>
28 </p>
29 </div>
30
31 <div class="e-a-list">
32 <?php self::render_plugins_list(); ?>
33 </div>
34 <div class="e-a-page-footer">
35 <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>
36 </div>
37 </div>
38 <?php
39 }
40
41 private static function render_plugins_list() {
42 $plugins = self::get_plugins();
43
44 foreach ( $plugins as $plugin ) {
45 self::render_plugin_item( $plugin );
46 }
47 }
48
49 private static function get_plugins() : array {
50 $container = Plugin::$instance->elementor_container();
51
52 if ( $container->has( Wordpress_Adapter::class ) ) {
53 self::$wordpress_adapter = $container->get( Wordpress_Adapter::class );
54 } else if ( ! self::$wordpress_adapter ) {
55 self::$wordpress_adapter = new Wordpress_Adapter();
56 }
57
58 if ( ! self::$plugin_status_adapter ) {
59 self::$plugin_status_adapter = new Plugin_Status_Adapter( self::$wordpress_adapter );
60 }
61
62 $apps = static::get_remote_apps();
63
64 return static::filter_apps( $apps );
65 }
66
67 private static function get_remote_apps() {
68 $apps = wp_remote_get( static::APPS_URL );
69
70 if ( is_wp_error( $apps ) ) {
71 return [];
72 }
73
74 $apps = json_decode( wp_remote_retrieve_body( $apps ), true );
75
76 if ( empty( $apps['apps'] ) || ! is_array( $apps['apps'] ) ) {
77 return [];
78 }
79
80 return $apps['apps'];
81 }
82
83 private static function filter_apps( $apps ) {
84 $filtered_apps = [];
85
86 foreach ( $apps as $app ) {
87 if ( static::is_wporg_app( $app ) ) {
88 $app = static::filter_wporg_app( $app );
89 }
90
91 if ( static::is_ecom_app( $app ) ) {
92 $app = static::filter_ecom_app( $app );
93 }
94
95 if ( empty( $app ) ) {
96 continue;
97 }
98
99 $filtered_apps[] = $app;
100 }
101
102 return $filtered_apps;
103 }
104
105 private static function is_wporg_app( $app ) {
106 return isset( $app['type'] ) && 'wporg' === $app['type'];
107 }
108
109 private static function filter_wporg_app( $app ) {
110 if ( self::$wordpress_adapter->is_plugin_active( $app['file_path'] ) ) {
111 return null;
112 }
113
114 if ( self::$plugin_status_adapter->is_plugin_installed( $app['file_path'] ) ) {
115 if ( current_user_can( 'activate_plugins' ) ) {
116 $app['action_label'] = esc_html__( 'Activate', 'elementor' );
117 $app['action_url'] = self::$plugin_status_adapter->get_activate_plugin_url( $app['file_path'] );
118 } else {
119 $app['action_label'] = esc_html__( 'Cannot Activate', 'elementor' );
120 $app['action_url'] = '#';
121 }
122 } else {
123 if ( current_user_can( 'install_plugins' ) ) {
124 $app['action_label'] = esc_html__( 'Install', 'elementor' );
125 $app['action_url'] = self::$plugin_status_adapter->get_install_plugin_url( $app['file_path'] );
126 } else {
127 $app['action_label'] = esc_html__( 'Cannot Install', 'elementor' );
128 $app['action_url'] = '#';
129 }
130 }
131
132 return $app;
133 }
134
135 private static function is_ecom_app( $app ) {
136 return isset( $app['type'] ) && 'ecom' === $app['type'];
137 }
138
139 private static function filter_ecom_app( $app ) {
140 if ( self::$wordpress_adapter->is_plugin_active( $app['file_path'] ) ) {
141 return null;
142 }
143
144 if ( ! self::$plugin_status_adapter->is_plugin_installed( $app['file_path'] ) ) {
145 return $app;
146 }
147
148 if ( current_user_can( 'activate_plugins' ) ) {
149 $app['action_label'] = esc_html__( 'Activate', 'elementor' );
150 $app['action_url'] = self::$plugin_status_adapter->get_activate_plugin_url( $app['file_path'] );
151 } else {
152 $app['action_label'] = esc_html__( 'Cannot Activate', 'elementor' );
153 $app['action_url'] = '#';
154 }
155
156 $app['target'] = '_self';
157
158 return $app;
159 }
160
161 private static function get_images_url() {
162 return ELEMENTOR_URL . 'modules/apps/images/';
163 }
164
165 private static function is_elementor_pro_installed() {
166 return defined( 'ELEMENTOR_PRO_VERSION' );
167 }
168
169 private static function render_plugin_item( $plugin ) {
170 ?>
171 <div class="e-a-item"<?php echo ! empty( $plugin['file_path'] ) ? ' data-plugin="' . esc_attr( $plugin['file_path'] ) . '"' : ''; ?>>
172 <div class="e-a-heading">
173 <img class="e-a-img" src="<?php echo esc_url( $plugin['image'] ); ?>" alt="<?php echo esc_attr( $plugin['name'] ); ?>">
174 <?php if ( ! empty( $plugin['badge'] ) ) : ?>
175 <span class="e-a-badge"><?php echo esc_html( $plugin['badge'] ); ?></span>
176 <?php endif; ?>
177 </div>
178 <h3 class="e-a-title"><?php echo esc_html( $plugin['name'] ); ?></h3>
179 <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>
180 <div class="e-a-desc">
181 <p><?php echo esc_html( $plugin['description'] ); ?></p>
182 <?php if ( ! empty( $plugin['offering'] ) ) : ?>
183 <p class="e-a-offering"><?php echo esc_html( $plugin['offering'] ); ?></p>
184 <?php endif; ?>
185 </div>
186
187 <p class="e-a-actions">
188 <?php if ( ! empty( $plugin['learn_more_url'] ) ) : ?>
189 <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>
190 <?php endif; ?>
191 <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>
192 </p>
193 </div>
194 <?php
195 }
196 }
197