示例#1
0
 /**
  * Install an extension
  * 
  * @param string $storedLicense
  * 
  * @return string
  * 
  * @access public
  */
 public function install($storedLicense = null)
 {
     $repo = AAM_Core_Repository::getInstance();
     $license = AAM_Core_Request::post('license', $storedLicense);
     //download the extension from the server first
     $package = AAM_Core_Server::download($license);
     if (is_wp_error($package)) {
         $response = array('status' => 'failure', 'error' => $package->get_error_message());
     } elseif ($error = $repo->checkDirectory()) {
         $response = $this->installFailureResponse($error, $package);
         $this->storeLicense($package->title, $license);
     } else {
         //otherwise install the extension
         $result = $repo->addExtension(base64_decode($package->content));
         if (is_wp_error($result)) {
             $response = $this->installFailureResponse($result->get_error_message(), $package);
         } else {
             $response = array('status' => 'success');
         }
         $this->storeLicense($package->title, $license);
     }
     return json_encode($response);
 }