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

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