| @@ -6,8 +6,13 @@ | ||
| 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 |
| @@ -25,9 +30,9 @@ | ||
| 25 | 30 | |
| 26 | 31 | /** |
| 27 | 32 | * Check if extension has an update. |
| 28 | 33 | * |
| 29 | - * @return array $output List of results. | |
| 34 | + * @return mixed $output List of results. | |
| 30 | 35 | * |
| 31 | 36 | * @uses MainWP_Api_Manager_Plugin_Update::bulk_update_check() |
| 32 | 37 | * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extensions() |
| 33 | 38 | */ |
| @@ -37,13 +42,20 @@ | ||
| 37 | 42 | $output = array(); |
| 38 | 43 | $check_exts = array(); |
| 39 | 44 | foreach ( $extensions as $ext ) { |
| 40 | 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. | |
| 41 | 51 | $args = array(); |
| 52 | + $api_slug = isset( $ext['slug'] ) ? dirname( $ext['slug'] ) : ''; | |
| 53 | + $activation = MainWP_Api_Manager::instance()->get_activation_info( $api_slug ); | |
| 42 | 54 | $args['plugin_name'] = $ext['api']; |
| 43 | 55 | $args['version'] = $ext['version']; |
| 44 | 56 | $args['product_id'] = $ext['product_id']; |
| 45 | - $args['api_key'] = $ext['api_key']; | |
| 57 | + $args['api_key'] = is_array( $activation ) && isset( $activation['api_key'] ) ? $activation['api_key'] : ''; | |
| 46 | 58 | $args['instance'] = $ext['instance_id']; |
| 47 | 59 | $args['software_version'] = $ext['software_version']; |
| 48 | 60 | $check_exts[ $args['plugin_name'] ] = $args; |
| 49 | 61 | } |
| @@ -72,9 +84,9 @@ | ||
| 72 | 84 | } |
| 73 | 85 | $rslt = new \stdClass(); |
| 74 | 86 | $rslt->slug = $slug; |
| 75 | 87 | $rslt->new_version = $response['new_version']; |
| 76 | - $rslt->package = $response['package']; | |
| 88 | + $rslt->package = array_key_exists( 'package', $response ) ? $response['package'] : null; | |
| 77 | 89 | $rslt->key_status = ''; |
| 78 | 90 | $rslt->apiManager = 1; |
| 79 | 91 | |
| 80 | 92 | if ( isset( $response['errors'] ) ) { |
| @@ -106,13 +118,18 @@ | ||
| 106 | 118 | $extensions = MainWP_Extensions_Handler::get_extensions(); |
| 107 | 119 | $rslt = null; |
| 108 | 120 | foreach ( $extensions as $ext ) { |
| 109 | 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 ); | |
| 110 | 127 | $args = array(); |
| 111 | 128 | $args['plugin_name'] = $ext['api']; |
| 112 | 129 | $args['version'] = $ext['version']; |
| 113 | 130 | $args['product_id'] = $ext['product_id']; |
| 114 | - $args['api_key'] = $ext['api_key']; | |
| 131 | + $args['api_key'] = is_array( $activation ) && isset( $activation['api_key'] ) ? $activation['api_key'] : ''; | |
| 115 | 132 | $args['instance'] = $ext['instance_id']; |
| 116 | 133 | $args['software_version'] = $ext['software_version']; |
| 117 | 134 | $response = MainWP_Api_Manager_Plugin_Update::instance()->update_check( $args ); |
| 118 | 135 | |
| @@ -147,13 +164,16 @@ | ||
| 147 | 164 | $extensions = MainWP_Extensions_Handler::get_extensions(); |
| 148 | 165 | $rslt = null; |
| 149 | 166 | foreach ( $extensions as $ext ) { |
| 150 | 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 ); | |
| 151 | 171 | $args = array(); |
| 152 | 172 | $args['plugin_name'] = $ext['api']; |
| 153 | 173 | $args['version'] = $ext['version']; |
| 154 | 174 | $args['product_id'] = $ext['product_id']; |
| 155 | - $args['api_key'] = $ext['api_key']; | |
| 175 | + $args['api_key'] = is_array( $activation ) && isset( $activation['api_key'] ) ? $activation['api_key'] : ''; | |
| 156 | 176 | $args['instance'] = $ext['instance_id']; |
| 157 | 177 | $args['software_version'] = $ext['software_version']; |
| 158 | 178 | $rslt = MainWP_Api_Manager::instance()->request_extension_information( $args ); |
| 159 | 179 | break; |