Exemplo n.º 1
0
 /**
  * Registers the account with Let's Encrypt.
  *
  * This method is called through one of the action callbacks.
  *
  * @since 1.0.0
  * @access protected
  *
  * @param array $data         The request data for the action.
  * @param bool  $network_wide Whether this action should be performed network-wide.
  * @return string|WP_Error The success message or an error object.
  */
 protected function register_account($data = array(), $network_wide = false)
 {
     $filesystem_check = $this->maybe_request_filesystem_credentials($network_wide);
     if (false === $filesystem_check) {
         return new WP_Error('invalid_filesystem_credentials', __('Invalid or missing filesystem credentials.', 'wp-encrypt'), 'error');
     }
     $manager = CertificateManager::get();
     $response = $manager->register_account();
     if (is_wp_error($response)) {
         $data = $response->get_error_data();
         if (is_array($data) && isset($data['location'])) {
             $response = array_merge(Util::get_registration_info('account'), $data);
             Util::set_registration_info('account', $response);
             return __('Account was already registered before.', 'wp-encrypt');
         }
         return $response;
     }
     Util::set_registration_info('account', $response);
     /**
      * Fires after the account with Let's Encrypt has been registered.
      *
      * @since 1.0.0
      *
      * @param array $response Response from the registration call.
      */
     do_action('wpenc_account_registered', $response);
     return __('Account registered.', 'wp-encrypt');
 }
Exemplo n.º 2
0
 /**
  * Validates the plugin settings.
  *
  * Used as a callback for `register_setting()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @param array $options The options prior to being saved.
  * @return array The validated options.
  */
 public function validate_settings($options = array())
 {
     $options = array_map('strip_tags', array_map('trim', $options));
     if (isset($options['country_code'])) {
         $options['country_code'] = strtoupper(substr($options['country_code'], 0, 2));
     }
     if (isset($options['show_warning_days'])) {
         $options['show_warning_days'] = absint($options['show_warning_days']);
     }
     if (isset($options['autogenerate_certificate']) && $options['autogenerate_certificate']) {
         $certificate_registration_info = Util::get_registration_info('certificate');
         if (isset($certificate_registration_info['_wp_time'])) {
             Util::schedule_autogenerate_event(strtotime($certificate_registration_info['_wp_time']));
         }
     } else {
         Util::unschedule_autogenerate_event();
     }
     return $options;
 }