PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-api-handler.php +158 -138 5.0.3.2 → 6.2.1 View file →
@@ -6,159 +6,179 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_API_Handler()
12 17 *
13 18 * MainWP API settings page
14 19 */
15 -class MainWP_API_Handler {
20 +class MainWP_API_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16 21
17 - /**
18 - * Get Class name.
19 - *
20 - * @return string __CLASS__.
21 - */
22 - public static function get_class_name() {
23 - return __CLASS__;
24 - }
22 + /**
23 + * Get Class name.
24 + *
25 + * @return string __CLASS__.
26 + */
27 + public static function get_class_name() {
28 + return __CLASS__;
29 + }
25 30
26 - /**
27 - * Check if extension has an update.
28 - *
29 - * @return array $output List of results.
30 - *
31 - * @uses MainWP_Api_Manager_Plugin_Update::bulk_update_check()
32 - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
33 - */
34 - public static function check_exts_upgrade() {
31 + /**
32 + * Check if extension has an update.
33 + *
34 + * @return mixed $output List of results.
35 + *
36 + * @uses MainWP_Api_Manager_Plugin_Update::bulk_update_check()
37 + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
38 + */
39 + public static function check_exts_upgrade() { // phpcs:ignore -- NOSONAR - complex.
35 40
36 - $extensions = MainWP_Extensions_Handler::get_extensions();
37 - $output = array();
38 - $check_exts = array();
39 - foreach ( $extensions as $ext ) {
40 - if ( isset( $ext['activated_key'] ) && 'Activated' === $ext['activated_key'] ) {
41 - $args = array();
42 - $args['plugin_name'] = $ext['api'];
43 - $args['version'] = $ext['version'];
44 - $args['product_id'] = $ext['product_id'];
45 - $args['api_key'] = $ext['api_key'];
46 - $args['instance'] = $ext['instance_id'];
47 - $args['software_version'] = $ext['software_version'];
48 - $check_exts[ $args['plugin_name'] ] = $args;
49 - }
50 - }
41 + $extensions = MainWP_Extensions_Handler::get_extensions();
42 + $output = array();
43 + $check_exts = array();
44 + foreach ( $extensions as $ext ) {
45 + if ( isset( $ext['activated_key'] ) && 'Activated' === $ext['activated_key'] ) {
46 + // MWP-1546: $ext['api_key'] no longer exists in the aggregated
47 + // mainwp_extensions option (the plaintext was removed from
48 + // there). Fetch the per-slug activation info, which decrypts
49 + // the api_key on read and returns plaintext only for this
50 + // request scope.
51 + $args = array();
52 + $api_slug = isset( $ext['slug'] ) ? dirname( $ext['slug'] ) : '';
53 + $activation = MainWP_Api_Manager::instance()->get_activation_info( $api_slug );
54 + $args['plugin_name'] = $ext['api'];
55 + $args['version'] = $ext['version'];
56 + $args['product_id'] = $ext['product_id'];
57 + $args['api_key'] = is_array( $activation ) && isset( $activation['api_key'] ) ? $activation['api_key'] : '';
58 + $args['instance'] = $ext['instance_id'];
59 + $args['software_version'] = $ext['software_version'];
60 + $check_exts[ $args['plugin_name'] ] = $args;
61 + }
62 + }
51 63
52 - if ( empty( $check_exts ) ) {
53 - return false;
54 - }
64 + if ( empty( $check_exts ) ) {
65 + return false;
66 + }
55 67
56 - $i = 0;
57 - $count = 0;
58 - $max_check = 6;
59 - $total_check = count( $check_exts );
60 - $bulk_checks = array();
68 + $i = 0;
69 + $count = 0;
70 + $max_check = 6;
71 + $total_check = count( $check_exts );
72 + $bulk_checks = array();
61 73
62 - foreach ( $check_exts as $ext_name => $ext ) {
63 - $bulk_checks[ $ext_name ] = $ext;
64 - ++$i;
65 - ++$count;
66 - if ( $count === $max_check || $i === $total_check ) {
67 - $results = MainWP_Api_Manager_Plugin_Update::instance()->bulk_update_check( $bulk_checks ); // bulk check response array of info.
68 - if ( is_array( $results ) && 0 < count( $results ) ) {
69 - foreach ( $results as $slug => $response ) {
70 - if ( ! is_array( $response ) || ! isset( $response['new_version'] ) ) {
71 - continue;
72 - }
73 - $rslt = new \stdClass();
74 - $rslt->slug = $slug;
75 - $rslt->new_version = $response['new_version'];
76 - $rslt->package = $response['package'];
77 - $rslt->key_status = '';
78 - $rslt->apiManager = 1;
74 + foreach ( $check_exts as $ext_name => $ext ) {
75 + $bulk_checks[ $ext_name ] = $ext;
76 + ++$i;
77 + ++$count;
78 + if ( $count === $max_check || $i === $total_check ) {
79 + $results = MainWP_Api_Manager_Plugin_Update::instance()->bulk_update_check( $bulk_checks ); // bulk check response array of info.
80 + if ( is_array( $results ) && ! empty( $results ) ) {
81 + foreach ( $results as $slug => $response ) {
82 + if ( ! is_array( $response ) || ! isset( $response['new_version'] ) ) {
83 + continue;
84 + }
85 + $rslt = new \stdClass();
86 + $rslt->slug = $slug;
87 + $rslt->new_version = $response['new_version'];
88 + $rslt->package = array_key_exists( 'package', $response ) ? $response['package'] : null;
89 + $rslt->key_status = '';
90 + $rslt->apiManager = 1;
79 91
80 - if ( isset( $response['errors'] ) ) {
81 - $rslt->error = $response['errors'];
82 - }
83 - $output[ $slug ] = $rslt;
84 - }
85 - }
86 - $count = 0;
87 - $bulk_checks = array();
88 - sleep( 3 );
89 - }
90 - }
91 - return $output;
92 - }
92 + if ( isset( $response['errors'] ) ) {
93 + $rslt->error = $response['errors'];
94 + }
95 + $output[ $slug ] = $rslt;
96 + }
97 + }
98 + $count = 0;
99 + $bulk_checks = array();
100 + sleep( 3 );
101 + }
102 + }
103 + return $output;
104 + }
93 105
94 - /**
95 - * Check extension information for an update.
96 - *
97 - * @param string $pSlug Extension slug.
98 - *
99 - * @return array $rslt An array containing update information.
100 - *
101 - * @uses \MainWP\Dashboard\MainWP_Api_Manager::update_check()
102 - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
103 - */
104 - public static function get_upgrade_information( $pSlug ) {
106 + /**
107 + * Check extension information for an update.
108 + *
109 + * @param string $pSlug Extension slug.
110 + *
111 + * @return array $rslt An array containing update information.
112 + *
113 + * @uses \MainWP\Dashboard\MainWP_Api_Manager::update_check()
114 + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
115 + */
116 + public static function get_upgrade_information( $pSlug ) {
105 117
106 - $extensions = MainWP_Extensions_Handler::get_extensions();
107 - $rslt = null;
108 - foreach ( $extensions as $ext ) {
109 - if ( isset( $ext['api'] ) && ( $pSlug === $ext['api'] ) && isset( $ext['apiManager'] ) && ! empty( $ext['apiManager'] ) ) {
110 - $args = array();
111 - $args['plugin_name'] = $ext['api'];
112 - $args['version'] = $ext['version'];
113 - $args['product_id'] = $ext['product_id'];
114 - $args['api_key'] = $ext['api_key'];
115 - $args['instance'] = $ext['instance_id'];
116 - $args['software_version'] = $ext['software_version'];
117 - $response = MainWP_Api_Manager_Plugin_Update::instance()->update_check( $args );
118 + $extensions = MainWP_Extensions_Handler::get_extensions();
119 + $rslt = null;
120 + foreach ( $extensions as $ext ) {
121 + if ( isset( $ext['api'] ) && ( $pSlug === $ext['api'] ) && isset( $ext['apiManager'] ) && ! empty( $ext['apiManager'] ) ) {
122 + // MWP-1546: same migration as check_exts_upgrade above --
123 + // pull the api_key from per-slug get_activation_info() instead
124 + // of the (now-stripped) aggregated mainwp_extensions option.
125 + $api_slug = isset( $ext['slug'] ) ? dirname( $ext['slug'] ) : '';
126 + $activation = MainWP_Api_Manager::instance()->get_activation_info( $api_slug );
127 + $args = array();
128 + $args['plugin_name'] = $ext['api'];
129 + $args['version'] = $ext['version'];
130 + $args['product_id'] = $ext['product_id'];
131 + $args['api_key'] = is_array( $activation ) && isset( $activation['api_key'] ) ? $activation['api_key'] : '';
132 + $args['instance'] = $ext['instance_id'];
133 + $args['software_version'] = $ext['software_version'];
134 + $response = MainWP_Api_Manager_Plugin_Update::instance()->update_check( $args );
118 135
119 - if ( ! empty( $response ) ) {
120 - $rslt = new \stdClass();
121 - $rslt->slug = $ext['api'];
122 - $rslt->new_version = $response->new_version;
123 - $rslt->package = $response->package;
124 - $rslt->key_status = '';
125 - $rslt->apiManager = 1;
126 - if ( isset( $response->errors ) ) {
127 - $rslt->error = $response->errors;
128 - }
129 - }
130 - break;
131 - }
132 - }
133 - return $rslt;
134 - }
136 + if ( ! empty( $response ) ) {
137 + $rslt = new \stdClass();
138 + $rslt->slug = $ext['api'];
139 + $rslt->new_version = $response->new_version;
140 + $rslt->package = $response->package;
141 + $rslt->key_status = '';
142 + $rslt->apiManager = 1;
143 + if ( isset( $response->errors ) ) {
144 + $rslt->error = $response->errors;
145 + }
146 + }
147 + break;
148 + }
149 + }
150 + return $rslt;
151 + }
135 152
136 - /**
137 - * Get extension information.
138 - *
139 - * @param string $pSlug Extension slug.
140 - *
141 - * @return array $rslt An array containing extension information.
142 - *
143 - * @uses \MainWP\Dashboard\MainWP_Api_Manager::request_extension_information()
144 - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
145 - */
146 - public static function get_update_information( $pSlug ) {
147 - $extensions = MainWP_Extensions_Handler::get_extensions();
148 - $rslt = null;
149 - foreach ( $extensions as $ext ) {
150 - if ( isset( $ext['api'] ) && $pSlug === $ext['api'] && isset( $ext['apiManager'] ) && ! empty( $ext['apiManager'] ) ) {
151 - $args = array();
152 - $args['plugin_name'] = $ext['api'];
153 - $args['version'] = $ext['version'];
154 - $args['product_id'] = $ext['product_id'];
155 - $args['api_key'] = $ext['api_key'];
156 - $args['instance'] = $ext['instance_id'];
157 - $args['software_version'] = $ext['software_version'];
158 - $rslt = MainWP_Api_Manager::instance()->request_extension_information( $args );
159 - break;
160 - }
161 - }
162 - return $rslt;
163 - }
153 + /**
154 + * Get extension information.
155 + *
156 + * @param string $pSlug Extension slug.
157 + *
158 + * @return array $rslt An array containing extension information.
159 + *
160 + * @uses \MainWP\Dashboard\MainWP_Api_Manager::request_extension_information()
161 + * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions()
162 + */
163 + public static function get_update_information( $pSlug ) {
164 + $extensions = MainWP_Extensions_Handler::get_extensions();
165 + $rslt = null;
166 + foreach ( $extensions as $ext ) {
167 + if ( isset( $ext['api'] ) && $pSlug === $ext['api'] && isset( $ext['apiManager'] ) && ! empty( $ext['apiManager'] ) ) {
168 + // MWP-1546: same migration as the two functions above.
169 + $api_slug = isset( $ext['slug'] ) ? dirname( $ext['slug'] ) : '';
170 + $activation = MainWP_Api_Manager::instance()->get_activation_info( $api_slug );
171 + $args = array();
172 + $args['plugin_name'] = $ext['api'];
173 + $args['version'] = $ext['version'];
174 + $args['product_id'] = $ext['product_id'];
175 + $args['api_key'] = is_array( $activation ) && isset( $activation['api_key'] ) ? $activation['api_key'] : '';
176 + $args['instance'] = $ext['instance_id'];
177 + $args['software_version'] = $ext['software_version'];
178 + $rslt = MainWP_Api_Manager::instance()->request_extension_information( $args );
179 + break;
180 + }
181 + }
182 + return $rslt;
183 + }
164 184 }