PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.0
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / ajax / dashboard.php

dashboard.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.0, at includes/ajax/dashboard.php

211 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Ajax;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use ABlocks\Classes\AbstractAjaxHandler;
10 use ABlocks\Classes\FileUpload;
11 use ABlocks\Classes\FontLoadLocally;
12 use ABlocks\Helper;
13
14 class Dashboard extends AbstractAjaxHandler {
15 public function __construct() {
16 $this->actions = array(
17 'get_admin_menu_items' => array(
18 'callback' => array( $this, 'get_admin_menu_items' ),
19 'capability' => 'manage_options',
20 ),
21 'regenerate_assets' => array(
22 'callback' => array( $this, 'regenerate_assets' ),
23 'capability' => 'manage_options',
24 ),
25 'clear_demo_transients' => array(
26 'callback' => array( $this, 'clear_demo_transients' ),
27 'capability' => 'manage_options',
28 ),
29 'install_academy_lms' => array(
30 'callback' => array( $this, 'install_academy_lms' ),
31 'capability' => 'manage_options',
32 ),
33 'install_storeengine' => array(
34 'callback' => array( $this, 'install_storeengine' ),
35 'capability' => 'manage_options',
36 ),
37 'install_ecm' => array(
38 'callback' => array( $this, 'install_ecm' ),
39 ),
40 'download_google_fonts' => array(
41 'callback' => array( $this, 'download_google_fonts' ),
42 'capability' => 'manage_options',
43 ),
44 );
45 }
46
47 public function get_admin_menu_items() {
48 $menu_items = wp_json_encode( Helper::get_admin_menu_list() );
49 wp_send_json_success( $menu_items );
50 }
51 public function regenerate_assets() {
52 $FileUpload = new FileUpload();
53 $has_delete = $FileUpload->delete_files();
54 Helper::clear_third_party_plugin_cache();
55 update_option( ABLOCKS_FONTS_SETTINGS_NAME, '{}' );
56 wp_send_json_success( $has_delete );
57 }
58
59 public function clear_demo_transients() {
60 global $wpdb;
61
62 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
63 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_ablocks_demo_%' OR option_name LIKE '_transient_timeout_ablocks_demo_%'" );
64
65 if ( ! empty( $wpdb->last_error ) ) {
66 wp_send_json_error( $wpdb->last_error );
67 }
68
69 wp_send_json_success();
70 }
71 public function install_academy_lms() {
72 // Check user permissions
73 if ( ! current_user_can( 'install_plugins' ) ) {
74 wp_send_json_error( __( 'You do not have sufficient permissions to install plugins.', 'ablocks' ) );
75 }
76
77 // Check if the plugin is already installed
78 if ( ! Helper::is_plugin_installed( 'academy/academy.php' ) ) {
79
80 $plugin_status = $this->install_plugin( 'academy', true );
81 if ( $plugin_status ) {
82 wp_send_json_success( __( 'Plugin installed and activated successfully!', 'ablocks' ) );
83 }
84 wp_send_json_error( __( 'Sorry, failed to download.', 'ablocks' ) );
85 }
86
87 // Activate the plugin
88 $activate_status = activate_plugin( 'academy/academy.php' );
89 if ( is_wp_error( $activate_status ) ) {
90 wp_send_json_error( 'Plugin activation failed: ' . $activate_status->get_error_message() );
91 }
92 wp_send_json_success( __( 'Plugin installed and activated successfully!', 'ablocks' ) );
93 }
94 public function install_storeengine() {
95 // Check user permissions
96 if ( ! current_user_can( 'install_plugins' ) ) {
97 wp_send_json_error( __( 'You do not have sufficient permissions to install plugins.', 'ablocks' ) );
98 }
99
100 // Check if the plugin is already installed
101 if ( ! Helper::is_plugin_installed( 'storeengine/storeengine.php' ) ) {
102
103 $plugin_status = $this->install_plugin( 'storeengine', true );
104 if ( $plugin_status ) {
105 wp_send_json_success( __( 'Plugin installed and activated successfully!', 'ablocks' ) );
106 }
107 wp_send_json_error( __( 'Sorry, failed to download.', 'ablocks' ) );
108 }
109
110 // Activate the plugin
111 $activate_status = activate_plugin( 'storeengine/storeengine.php' );
112 if ( is_wp_error( $activate_status ) ) {
113 wp_send_json_error( 'Plugin activation failed: ' . $activate_status->get_error_message() );
114 }
115 wp_send_json_success( __( 'Plugin installed and activated successfully!', 'ablocks' ) );
116 }
117 public function install_ecm() {
118 // Check user permissions
119 if ( ! current_user_can( 'install_plugins' ) ) {
120 wp_send_json_error( __( 'You do not have sufficient permissions to install plugins.', 'ablocks' ) );
121 }
122
123 // Check if the plugin is already installed
124 if ( ! Helper::is_plugin_installed( 'easy-content-manager/easy-content-manager.php' ) ) {
125
126 $plugin_status = $this->install_plugin( 'easy-content-manager', true );
127 if ( $plugin_status ) {
128 wp_send_json_success( __( 'Plugin installed and activated successfully!', 'ablocks' ) );
129 }
130 wp_send_json_error( __( 'Sorry, failed to download.', 'ablocks' ) );
131 }
132
133 // Activate the plugin
134 $activate_status = activate_plugin( 'easy-content-manager/easy-content-manager.php' );
135 if ( is_wp_error( $activate_status ) ) {
136 wp_send_json_error( 'Plugin activation failed: ' . $activate_status->get_error_message() );
137 }
138 wp_send_json_success( __( 'Plugin installed and activated successfully!', 'ablocks' ) );
139 }
140 public function install_plugin( $slug = '', $active = true ) {
141 if ( empty( $slug ) ) {
142 return new \WP_Error( 'empty_arg', __( 'Argument should not be empty.', 'ablocks' ) );
143 }
144
145 include_once ABSPATH . 'wp-admin/includes/file.php';
146 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
147 include_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php';
148
149 $plugin_data = $this->get_remote_plugin_data( $slug );
150
151 if ( is_wp_error( $plugin_data ) ) {
152 return $plugin_data;
153 }
154
155 $upgrader = new \Plugin_Upgrader( new \Automatic_Upgrader_Skin() );
156
157 // install plugin
158 $install = $upgrader->install( $plugin_data->download_link );
159
160 if ( is_wp_error( $install ) ) {
161 return $install;
162 }
163
164 // activate plugin
165 if ( $install === true && $active ) {
166 $active = activate_plugin( $upgrader->plugin_info(), '', false, true );
167
168 if ( is_wp_error( $active ) ) {
169 return $active;
170 }
171
172 return $active === null;
173 }
174
175 return $install;
176 }
177
178 public function get_remote_plugin_data( $slug = '' ) {
179 if ( empty( $slug ) ) {
180 return new \WP_Error( 'empty_arg', __( 'Argument should not be empty.', 'ablocks' ) );
181 }
182
183 $response = wp_remote_post(
184 'http://api.wordpress.org/plugins/info/1.0/',
185 array(
186 'body' => array(
187 'action' => 'plugin_information',
188 'request' => maybe_serialize( (object) array(
189 'slug' => $slug,
190 'fields' => array(
191 'version' => false,
192 ),
193 )),
194 ),
195 )
196 );
197
198 if ( is_wp_error( $response ) ) {
199 return $response;
200 }
201
202 return maybe_unserialize( wp_remote_retrieve_body( $response ) );
203 }
204
205 public function download_google_fonts() {
206 global $ablocks_fonts;
207 $fontDownloader = new FontLoadLocally();
208 $fontDownloader->process_font_queue( $ablocks_fonts );
209 }
210 }
211