| @@ -10,9 +10,9 @@ | ||
| 10 | 10 | namespace MainWP\Dashboard; |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; | |
| 14 | + exit; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Class MainWP_Api_Manager_Key |
| @@ -25,316 +25,301 @@ | ||
| 25 | 25 | * @author Todd Lahman LLC |
| 26 | 26 | * @copyright Copyright (c) Todd Lahman LLC |
| 27 | 27 | * @since 1.3.0 |
| 28 | 28 | */ |
| 29 | -class MainWP_Api_Manager_Key { | |
| 29 | +class MainWP_Api_Manager_Key { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 30 | 30 | |
| 31 | - /** | |
| 32 | - * Set initial $instance value. | |
| 33 | - * | |
| 34 | - * @var null | |
| 35 | - */ | |
| 36 | - protected static $instance = null; | |
| 31 | + /** | |
| 32 | + * Set initial $instance value. | |
| 33 | + * | |
| 34 | + * @var null | |
| 35 | + */ | |
| 36 | + protected static $instance = null; | |
| 37 | 37 | |
| 38 | - /** | |
| 39 | - * Set initial $apisslverify value. | |
| 40 | - * | |
| 41 | - * @var int | |
| 42 | - */ | |
| 43 | - protected static $apisslverify = 1; | |
| 38 | + /** | |
| 39 | + * Set initial $apisslverify value. | |
| 40 | + * | |
| 41 | + * @var int | |
| 42 | + */ | |
| 43 | + protected static $apisslverify = 1; | |
| 44 | 44 | |
| 45 | - /** | |
| 46 | - * Create a new Self Instance. | |
| 47 | - * | |
| 48 | - * @return mixed self::$instance | |
| 49 | - */ | |
| 50 | - public static function instance() { | |
| 45 | + /** | |
| 46 | + * Create a new Self Instance. | |
| 47 | + * | |
| 48 | + * @return mixed static::$instance | |
| 49 | + */ | |
| 50 | + public static function instance() { | |
| 51 | 51 | |
| 52 | - if ( is_null( self::$instance ) ) { | |
| 53 | - self::$instance = new self(); | |
| 54 | - } | |
| 52 | + if ( is_null( static::$instance ) ) { | |
| 53 | + static::$instance = new self(); | |
| 54 | + } | |
| 55 | 55 | |
| 56 | - return self::$instance; | |
| 57 | - } | |
| 56 | + return static::$instance; | |
| 57 | + } | |
| 58 | 58 | |
| 59 | - /** | |
| 60 | - * MainWP_Api_Manager_Key constructor. | |
| 61 | - * | |
| 62 | - * Run any time class is called. | |
| 63 | - * Validate SSL certificate. | |
| 64 | - */ | |
| 65 | - public function __construct() { | |
| 66 | - self::$apisslverify = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( 1 === (int) get_option( 'mainwp_api_sslVerifyCertificate' ) ) ) ? 1 : 0; | |
| 67 | - } | |
| 59 | + /** | |
| 60 | + * MainWP_Api_Manager_Key constructor. | |
| 61 | + * | |
| 62 | + * Run any time class is called. | |
| 63 | + * Validate SSL certificate. | |
| 64 | + */ | |
| 65 | + public function __construct() { | |
| 66 | + static::$apisslverify = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( 1 === (int) get_option( 'mainwp_api_sslVerifyCertificate' ) ) ) ? 1 : 0; | |
| 67 | + } | |
| 68 | 68 | |
| 69 | - /** | |
| 70 | - * Activate extension. | |
| 71 | - * | |
| 72 | - * This function checks the users login information & grabs the update URL for the specific extension & activates it. | |
| 73 | - * | |
| 74 | - * @param array $args Extension arguments. | |
| 75 | - * | |
| 76 | - * @return array Request response. | |
| 77 | - * | |
| 78 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 79 | - */ | |
| 80 | - public function activate( $args ) { | |
| 69 | + /** | |
| 70 | + * Activate extension. | |
| 71 | + * | |
| 72 | + * This function checks the users login information & grabs the update URL for the specific extension & activates it. | |
| 73 | + * | |
| 74 | + * @param array $args Extension arguments. | |
| 75 | + * | |
| 76 | + * @return array Request response. | |
| 77 | + * | |
| 78 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 79 | + */ | |
| 80 | + public function activate( $args ) { | |
| 81 | 81 | |
| 82 | - $defaults = array( | |
| 83 | - 'request' => 'softwareactivation', | |
| 84 | - ); | |
| 82 | + $defaults = array( | |
| 83 | + 'request' => 'softwareactivation', | |
| 84 | + 'dashboard_version' => MainWP_System::instance()->get_dashboard_version(), | |
| 85 | + ); | |
| 85 | 86 | |
| 86 | - $args = wp_parse_args( $defaults, $args ); | |
| 87 | + $args = wp_parse_args( $defaults, $args ); | |
| 87 | 88 | |
| 88 | - $request = wp_remote_post( | |
| 89 | - MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 90 | - array( | |
| 91 | - 'body' => $args, | |
| 92 | - 'timeout' => 50, | |
| 93 | - 'sslverify' => self::$apisslverify, | |
| 94 | - ) | |
| 95 | - ); | |
| 89 | + $request = wp_remote_post( | |
| 90 | + MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 91 | + array( | |
| 92 | + 'body' => $args, | |
| 93 | + 'timeout' => 50, | |
| 94 | + 'sslverify' => static::$apisslverify, | |
| 95 | + ) | |
| 96 | + ); | |
| 96 | 97 | |
| 97 | - if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 98 | + if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 98 | 99 | |
| 99 | - return false; | |
| 100 | - } | |
| 100 | + return false; | |
| 101 | + } | |
| 101 | 102 | |
| 102 | - $response = wp_remote_retrieve_body( $request ); | |
| 103 | + return wp_remote_retrieve_body( $request ); | |
| 104 | + } | |
| 103 | 105 | |
| 104 | - return $response; | |
| 105 | - } | |
| 106 | + /** | |
| 107 | + * Deactivate extension . | |
| 108 | + * | |
| 109 | + * This function checks the users login information & grabs the update URL for the specific extension & deactivates it. | |
| 110 | + * | |
| 111 | + * @param array $args Extension arguments. | |
| 112 | + * | |
| 113 | + * @return array Request response. | |
| 114 | + * | |
| 115 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 116 | + */ | |
| 117 | + public function deactivate( $args ) { | |
| 106 | 118 | |
| 107 | - /** | |
| 108 | - * Deactivate extension . | |
| 109 | - * | |
| 110 | - * This function checks the users login information & grabs the update URL for the specific extension & deactivates it. | |
| 111 | - * | |
| 112 | - * @param array $args Extension arguments. | |
| 113 | - * | |
| 114 | - * @return array Request response. | |
| 115 | - * | |
| 116 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 117 | - */ | |
| 118 | - public function deactivate( $args ) { | |
| 119 | + $defaults = array( | |
| 120 | + 'request' => 'deactivate', // old: wc-api/deactivation. | |
| 121 | + 'dashboard_version' => MainWP_System::instance()->get_dashboard_version(), | |
| 122 | + ); | |
| 119 | 123 | |
| 120 | - $defaults = array( | |
| 121 | - 'request' => 'deactivate', // old: wc-api/deactivation. | |
| 122 | - ); | |
| 124 | + $args = wp_parse_args( $defaults, $args ); | |
| 123 | 125 | |
| 124 | - $args = wp_parse_args( $defaults, $args ); | |
| 126 | + $request = wp_remote_post( | |
| 127 | + MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', // old: wc-api/deactivate. | |
| 128 | + array( | |
| 129 | + 'body' => $args, | |
| 130 | + 'timeout' => 50, | |
| 131 | + 'sslverify' => static::$apisslverify, | |
| 132 | + ) | |
| 133 | + ); | |
| 125 | 134 | |
| 126 | - $request = wp_remote_post( | |
| 127 | - MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', // old: wc-api/deactivate. | |
| 128 | - array( | |
| 129 | - 'body' => $args, | |
| 130 | - 'timeout' => 50, | |
| 131 | - 'sslverify' => self::$apisslverify, | |
| 132 | - ) | |
| 133 | - ); | |
| 135 | + if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 136 | + // Request failed. | |
| 137 | + return false; | |
| 138 | + } | |
| 134 | 139 | |
| 135 | - if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 136 | - // Request failed. | |
| 137 | - return false; | |
| 138 | - } | |
| 140 | + return wp_remote_retrieve_body( $request ); | |
| 141 | + } | |
| 139 | 142 | |
| 140 | - $response = wp_remote_retrieve_body( $request ); | |
| 143 | + /** | |
| 144 | + * Grab extension API Key. | |
| 145 | + * | |
| 146 | + * This function checks the users login information & grabs the update URL for the specific extension & returns the API Key. | |
| 147 | + * | |
| 148 | + * @param array $args Extension arguments. | |
| 149 | + * | |
| 150 | + * @return array Request response. | |
| 151 | + * | |
| 152 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 153 | + */ | |
| 154 | + public function grab_api_key( $args ) { | |
| 141 | 155 | |
| 142 | - return $response; | |
| 143 | - } | |
| 156 | + $defaults = array( | |
| 157 | + 'request' => 'grabapikey', | |
| 158 | + 'dashboard_version' => MainWP_System::instance()->get_dashboard_version(), | |
| 159 | + ); | |
| 144 | 160 | |
| 145 | - /** | |
| 146 | - * Grab extension API Key. | |
| 147 | - * | |
| 148 | - * This function checks the users login information & grabs the update URL for the specific extension & returns the API Key. | |
| 149 | - * | |
| 150 | - * @param array $args Extension arguments. | |
| 151 | - * | |
| 152 | - * @return array Request response. | |
| 153 | - * | |
| 154 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 155 | - */ | |
| 156 | - public function grab_api_key( $args ) { | |
| 161 | + $args = wp_parse_args( $defaults, $args ); | |
| 157 | 162 | |
| 158 | - $defaults = array( | |
| 159 | - 'request' => 'grabapikey', | |
| 160 | - ); | |
| 163 | + $request = wp_remote_post( | |
| 164 | + MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 165 | + array( | |
| 166 | + 'body' => $args, | |
| 167 | + 'timeout' => 50, | |
| 168 | + 'sslverify' => static::$apisslverify, | |
| 169 | + ) | |
| 170 | + ); | |
| 161 | 171 | |
| 162 | - $args = wp_parse_args( $defaults, $args ); | |
| 172 | + if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 173 | + // Request failed. | |
| 174 | + return false; | |
| 175 | + } | |
| 163 | 176 | |
| 164 | - $request = wp_remote_post( | |
| 165 | - MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 166 | - array( | |
| 167 | - 'body' => $args, | |
| 168 | - 'timeout' => 50, | |
| 169 | - 'sslverify' => self::$apisslverify, | |
| 170 | - ) | |
| 171 | - ); | |
| 177 | + return wp_remote_retrieve_body( $request ); | |
| 178 | + } | |
| 172 | 179 | |
| 173 | - if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 174 | - // Request failed. | |
| 175 | - return false; | |
| 176 | - } | |
| 180 | + /** | |
| 181 | + * Test login API. | |
| 182 | + * | |
| 183 | + * This function checks the users login information & Tests it against the MainWP.com Login Credentials stored on the license server. | |
| 184 | + * | |
| 185 | + * @param aray $args Login arguments. | |
| 186 | + * | |
| 187 | + * @return array Request response. | |
| 188 | + * | |
| 189 | + * @throws \MainWP_Exception Request error codes. | |
| 190 | + * | |
| 191 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 192 | + * @uses \MainWP\Dashboard\MainWP_Logger::debug() | |
| 193 | + * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string() | |
| 194 | + * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 195 | + */ | |
| 196 | + public function verify_api_key( $args ) { | |
| 177 | 197 | |
| 178 | - $response = wp_remote_retrieve_body( $request ); | |
| 198 | + $defaults = array( | |
| 199 | + 'request' => 'testloginapi', | |
| 200 | + ); | |
| 179 | 201 | |
| 180 | - return $response; | |
| 181 | - } | |
| 202 | + $args = wp_parse_args( $defaults, $args ); | |
| 182 | 203 | |
| 183 | - /** | |
| 184 | - * Test login API. | |
| 185 | - * | |
| 186 | - * This function checks the users login information & Tests it against the MainWP.com Login Credentials stored on the license server. | |
| 187 | - * | |
| 188 | - * @param aray $args Login arguments. | |
| 189 | - * | |
| 190 | - * @return array Request response. | |
| 191 | - * | |
| 192 | - * @throws \Exception Request error codes. | |
| 193 | - * | |
| 194 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 195 | - * @uses \MainWP\Dashboard\MainWP_Logger::debug() | |
| 196 | - * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string() | |
| 197 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 198 | - */ | |
| 199 | - public function verify_api_key( $args ) { | |
| 204 | + $request = wp_remote_post( | |
| 205 | + MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 206 | + array( | |
| 207 | + 'body' => $args, | |
| 208 | + 'timeout' => 50, | |
| 209 | + 'sslverify' => static::$apisslverify, | |
| 210 | + ) | |
| 211 | + ); | |
| 200 | 212 | |
| 201 | - $defaults = array( | |
| 202 | - 'request' => 'testloginapi', | |
| 203 | - ); | |
| 213 | + if ( is_wp_error( $request ) ) { | |
| 214 | + if ( 1 === (int) static::$apisslverify ) { | |
| 215 | + MainWP_Utility::update_option( 'mainwp_api_sslVerifyCertificate', 0 ); | |
| 204 | 216 | |
| 205 | - $args = wp_parse_args( $defaults, $args ); | |
| 217 | + return array( 'retry_action' => 1 ); | |
| 218 | + } | |
| 206 | 219 | |
| 207 | - $request = wp_remote_post( | |
| 208 | - MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 209 | - array( | |
| 210 | - 'body' => $args, | |
| 211 | - 'timeout' => 50, | |
| 212 | - 'sslverify' => self::$apisslverify, | |
| 213 | - ) | |
| 214 | - ); | |
| 220 | + throw new MainWP_Exception( $request->get_error_message() ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 221 | + } | |
| 215 | 222 | |
| 216 | - $log = $request; | |
| 217 | - if ( is_array( $log ) && isset( $log['http_response'] ) ) { | |
| 218 | - unset( $log['http_response'] ); | |
| 219 | - } | |
| 223 | + $code = wp_remote_retrieve_response_code( $request ); | |
| 224 | + if ( 200 !== $code ) { | |
| 225 | + /* translators: 1: Opening anchor tag, 2: Closing anchor tag */ | |
| 226 | + $error = sprintf( esc_html__( 'Login verification could not be completed. Please contact %1$sMainWP Support%2$s so we can assist.', 'mainwp' ), '<a href="https://community.mainwp.com/" target="_blank">', '</a>' ); | |
| 227 | + throw new MainWP_Exception( $error ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Escaped. | |
| 228 | + } | |
| 220 | 229 | |
| 221 | - MainWP_Logger::instance()->debug( 'verify_api_key:: RESULT :: ' . MainWP_Utility::value_to_string( $log, true ) ); | |
| 230 | + return wp_remote_retrieve_body( $request ); | |
| 231 | + } | |
| 222 | 232 | |
| 223 | - if ( is_wp_error( $request ) ) { | |
| 224 | - if ( 1 === (int) self::$apisslverify ) { | |
| 225 | - MainWP_Utility::update_option( 'mainwp_api_sslVerifyCertificate', 0 ); | |
| 233 | + /** | |
| 234 | + * Get purchased software. | |
| 235 | + * | |
| 236 | + * This function grabs a list of purchased MainWP Extensions that are available for download. | |
| 237 | + * | |
| 238 | + * @param array $args Software Arguments. | |
| 239 | + * | |
| 240 | + * @return array Request response. | |
| 241 | + * | |
| 242 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 243 | + */ | |
| 244 | + public function get_purchased_software( $args ) { | |
| 226 | 245 | |
| 227 | - return array( 'retry_action' => 1 ); | |
| 228 | - } | |
| 246 | + $defaults = array( | |
| 247 | + 'request' => 'getpurchasedsoftware', | |
| 248 | + ); | |
| 229 | 249 | |
| 230 | - throw new \Exception( $request->get_error_message() ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 231 | - } | |
| 250 | + $args = wp_parse_args( $defaults, $args ); | |
| 232 | 251 | |
| 233 | - $code = wp_remote_retrieve_response_code( $request ); | |
| 234 | - if ( 200 !== $code ) { | |
| 235 | - $error = sprintf( esc_html__( 'Login verification could not be completed. Please contact %1$sMainWP Support%2$s so we can assist.', 'mainwp' ), '<a href="https://managers.mainwp.com/" target="_blank">', '</a>' ); | |
| 236 | - throw new \Exception( $error ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Escaped. | |
| 237 | - } | |
| 252 | + $request = wp_remote_post( | |
| 253 | + MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 254 | + array( | |
| 255 | + 'body' => $args, | |
| 256 | + 'timeout' => 200, | |
| 257 | + 'sslverify' => static::$apisslverify, | |
| 258 | + ) | |
| 259 | + ); | |
| 238 | 260 | |
| 239 | - $response = wp_remote_retrieve_body( $request ); | |
| 261 | + MainWP_Logger::instance()->debug( 'Get purchased softwares: ' . MainWP_Utility::value_to_string( $request ) ); | |
| 240 | 262 | |
| 241 | - return $response; | |
| 242 | - } | |
| 263 | + if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 264 | + // Request failed. | |
| 265 | + return false; | |
| 266 | + } | |
| 243 | 267 | |
| 244 | - /** | |
| 245 | - * Get purchased software. | |
| 246 | - * | |
| 247 | - * This function grabs a list of purchased MainWP Extensions that are available for download. | |
| 248 | - * | |
| 249 | - * @param array $args Software Arguments. | |
| 250 | - * | |
| 251 | - * @return array Request response. | |
| 252 | - * | |
| 253 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 254 | - */ | |
| 255 | - public function get_purchased_software( $args ) { | |
| 268 | + return wp_remote_retrieve_body( $request ); | |
| 269 | + } | |
| 256 | 270 | |
| 257 | - $defaults = array( | |
| 258 | - 'request' => 'getpurchasedsoftware', | |
| 259 | - ); | |
| 271 | + /** | |
| 272 | + * Purchase software. | |
| 273 | + * | |
| 274 | + * @param array $args Software arguments. | |
| 275 | + * | |
| 276 | + * @return array Request response. | |
| 277 | + * | |
| 278 | + * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 279 | + */ | |
| 280 | + public function purchase_software( $args ) { | |
| 281 | + $defaults = array( | |
| 282 | + 'request' => 'purchasesoftware', | |
| 283 | + ); | |
| 284 | + $args = wp_parse_args( $defaults, $args ); | |
| 260 | 285 | |
| 261 | - $args = wp_parse_args( $defaults, $args ); | |
| 286 | + $request = wp_remote_post( | |
| 287 | + MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 288 | + array( | |
| 289 | + 'body' => $args, | |
| 290 | + 'timeout' => 50, | |
| 291 | + 'sslverify' => static::$apisslverify, | |
| 292 | + ) | |
| 293 | + ); | |
| 262 | 294 | |
| 263 | - $request = wp_remote_post( | |
| 264 | - MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 265 | - array( | |
| 266 | - 'body' => $args, | |
| 267 | - 'timeout' => 200, | |
| 268 | - 'sslverify' => self::$apisslverify, | |
| 269 | - ) | |
| 270 | - ); | |
| 295 | + if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 296 | + // Request failed. | |
| 297 | + return false; | |
| 298 | + } | |
| 271 | 299 | |
| 272 | - MainWP_Logger::instance()->debug( 'Get purchased softwares: ' . MainWP_Utility::value_to_string( $request ) ); | |
| 300 | + return wp_remote_retrieve_body( $request ); | |
| 301 | + } | |
| 273 | 302 | |
| 274 | - if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 275 | - // Request failed. | |
| 276 | - return false; | |
| 277 | - } | |
| 303 | + /** | |
| 304 | + * Get decrypt master api key. | |
| 305 | + * | |
| 306 | + * @return array Request response. | |
| 307 | + */ | |
| 308 | + public function get_decrypt_master_api_key() { | |
| 309 | + $decryp_api_key = ''; | |
| 278 | 310 | |
| 279 | - $response = wp_remote_retrieve_body( $request ); | |
| 280 | - | |
| 281 | - return $response; | |
| 282 | - } | |
| 283 | - | |
| 284 | - /** | |
| 285 | - * Purchase software. | |
| 286 | - * | |
| 287 | - * @param array $args Software arguments. | |
| 288 | - * | |
| 289 | - * @return array Request response. | |
| 290 | - * | |
| 291 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 292 | - */ | |
| 293 | - public function purchase_software( $args ) { | |
| 294 | - $defaults = array( | |
| 295 | - 'request' => 'purchasesoftware', | |
| 296 | - ); | |
| 297 | - $args = wp_parse_args( $defaults, $args ); | |
| 298 | - | |
| 299 | - $request = wp_remote_post( | |
| 300 | - MainWP_Api_Manager::instance()->get_upgrade_url() . '?mainwp-api=am-software-api', | |
| 301 | - array( | |
| 302 | - 'body' => $args, | |
| 303 | - 'timeout' => 50, | |
| 304 | - 'sslverify' => self::$apisslverify, | |
| 305 | - ) | |
| 306 | - ); | |
| 307 | - | |
| 308 | - if ( is_wp_error( $request ) || 200 !== wp_remote_retrieve_response_code( $request ) ) { | |
| 309 | - // Request failed. | |
| 310 | - return false; | |
| 311 | - } | |
| 312 | - | |
| 313 | - $response = wp_remote_retrieve_body( $request ); | |
| 314 | - return $response; | |
| 315 | - } | |
| 316 | - | |
| 317 | - /** | |
| 318 | - * Get decrypt master api key. | |
| 319 | - * | |
| 320 | - * @return array Request response. | |
| 321 | - */ | |
| 322 | - public function get_decrypt_master_api_key() { | |
| 323 | - $decryp_api_key = ''; | |
| 324 | - | |
| 325 | - // to check old value. | |
| 326 | - $old_enscrypt = get_option( 'mainwp_extensions_master_api_key', false ); | |
| 327 | - if ( false !== $old_enscrypt && is_string( $old_enscrypt ) && ! empty( $old_enscrypt ) ) { // to compatible. | |
| 328 | - // old encrypt. | |
| 329 | - $decryp_api_key = ! empty( $old_enscrypt ) ? MainWP_Api_Manager_Password_Management::decrypt_string( $old_enscrypt ) : ''; | |
| 330 | - // convert to new encrypt: to compatible. | |
| 331 | - if ( ! empty( $decryp_api_key ) && is_string( $decryp_api_key ) ) { | |
| 332 | - MainWP_Keys_Manager::instance()->update_key_value( 'mainwp_extensions_master_api_key', $decryp_api_key ); | |
| 333 | - } | |
| 334 | - } | |
| 335 | - $decryp_api_key = MainWP_Keys_Manager::instance()->get_keys_value( 'mainwp_extensions_master_api_key' ); | |
| 336 | - return $decryp_api_key; | |
| 337 | - } | |
| 311 | + // to check old value. | |
| 312 | + $old_enscrypt = get_option( 'mainwp_extensions_master_api_key', false ); | |
| 313 | + if ( false !== $old_enscrypt && is_string( $old_enscrypt ) && ! empty( $old_enscrypt ) ) { // to compatible. | |
| 314 | + // old encrypt. | |
| 315 | + $decryp_api_key = ! empty( $old_enscrypt ) ? MainWP_Api_Manager_Password_Management::decrypt_string( $old_enscrypt ) : ''; | |
| 316 | + // convert to new encrypt: to compatible. | |
| 317 | + if ( ! empty( $decryp_api_key ) && is_string( $decryp_api_key ) ) { | |
| 318 | + MainWP_Keys_Manager::instance()->update_key_value( 'mainwp_extensions_master_api_key', $decryp_api_key ); | |
| 319 | + } | |
| 320 | + } | |
| 321 | + return MainWP_Keys_Manager::instance()->get_keys_value( 'mainwp_extensions_master_api_key' ); | |
| 322 | + } | |
| 338 | 323 | } |
| 339 | 324 | |
| 340 | 325 | // Class is instantiated as an object by other classes on-demand. |