Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/admin/dashboard/plugins/plugins-api.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + class Blocksy_Admin_Dashboard_API_Premium_Plugins extends Blocksy_Admin_Dashboard_API {
4 + protected $ajax_actions = array(
5 + 'get_premium_plugins_status',
6 +
7 + 'premium_plugin_download',
8 + 'premium_plugin_activate',
9 + 'premium_plugin_deactivate',
10 + 'premium_plugin_delete',
11 + );
12 +
13 + public function get_premium_plugins_status() {
14 + $this->check_capability('edit_plugins');
15 + $this->check_nonce();
16 +
17 + $result = [];
18 + // Is not installed.
19 + $status = 'uninstalled';
20 +
21 + $manager = new Blocksy_Plugin_Manager();
22 + $plugin_manager_config = $manager->get_config();
23 + $plugins = $plugin_manager_config;
24 + $installed_plugins = $manager->get_installed_plugins();
25 +
26 + foreach (array_keys($plugins) as $plugin) {
27 + $installed_path = $manager->is_plugin_installed($plugin);
28 +
29 + if (! $installed_path) {
30 + $status = 'uninstalled'; // Plugin is not installed.
31 + } else {
32 + if ( is_plugin_active( $installed_path ) ) {
33 + $status = 'activated'; // Plugin is active.
34 + } else {
35 + $status = 'deactivated'; // Plugin is installed but inactive.
36 + }
37 + }
38 +
39 + $result[] = array(
40 + 'name' => $plugin,
41 + 'status' => $status,
42 + );
43 + }
44 +
45 + wp_send_json_success($result);
46 + }
47 +
48 + public function premium_plugin_download() {
49 + $this->check_capability('install_plugins');
50 + $this->check_nonce();
51 +
52 + $plugin = $this->get_plugin_from_request();
53 +
54 + $manager = new Blocksy_Plugin_Manager();
55 + $install = $manager->prepare_install($plugin);
56 +
57 + if ($install) {
58 + wp_send_json_success();
59 + }
60 +
61 + wp_send_json_error();
62 + }
63 +
64 + public function premium_plugin_activate() {
65 + $this->check_capability('edit_plugins');
66 + $this->check_nonce();
67 +
68 + $plugin = $this->get_plugin_from_request();
69 +
70 + $manager = new Blocksy_Plugin_Manager();
71 + $result = $manager->plugin_activation($plugin);
72 +
73 + if (is_wp_error($result)) {
74 + wp_send_json_error($result);
75 + }
76 +
77 + wp_send_json_success();
78 + }
79 +
80 + public function premium_plugin_deactivate() {
81 + $this->check_capability('edit_plugins');
82 + $this->check_nonce();
83 +
84 + $plugin = $this->get_plugin_from_request();
85 +
86 + $manager = new Blocksy_Plugin_Manager();
87 + $result = $manager->plugin_deactivation($plugin);
88 +
89 + if (is_wp_error($result)) {
90 + wp_send_json_error($result);
91 + }
92 +
93 + wp_send_json_success();
94 + }
95 +
96 + public function premium_plugin_delete() {
97 + $this->check_capability('delete_plugins');
98 + $this->check_nonce();
99 +
100 + $plugin = $this->get_plugin_from_request();
101 +
102 + $manager = new Blocksy_Plugin_Manager();
103 + $result = $manager->uninstall_plugin($plugin);
104 +
105 + if (is_wp_error($result)) {
106 + wp_send_json_error($result);
107 + }
108 +
109 + wp_send_json_success();
110 + }
111 +
112 + public function check_capability($cap = 'install_plugins') {
113 + $manager = new Blocksy_Plugin_Manager();
114 +
115 + if (! $manager->can($cap)) {
116 + wp_send_json_error();
117 + }
118 +
119 + return true;
120 + }
121 +
122 + public function check_nonce() {
123 + if (! check_ajax_referer('ct-dashboard', 'nonce', false)) {
124 + wp_send_json_error('nonce');
125 + }
126 + }
127 +
128 + public function get_plugin_from_request() {
129 + if (! isset($_POST['plugin'])) {
130 + wp_send_json_error();
131 + }
132 +
133 + return sanitize_text_field(wp_unslash($_POST['plugin']));
134 + }
135 + }
136 +
137 +