/**
  * Generates a certificate with Let's Encrypt.
  *
  * This method is called through one of the action callbacks.
  *
  * In a Multinetwork setup, a certificate can either be generated for only the current
  * network or for all networks.
  *
  * @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 generate_certificate($data = array(), $network_wide = false)
 {
     if (!Util::can_generate_certificate()) {
         return new WP_Error('domain_cannot_sign', __('Domain cannot be signed. Either the account is not registered yet or the settings are not valid.', 'wp-encrypt'));
     }
     $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');
     }
     $domain = $network_wide ? Util::get_network_domain() : Util::get_site_domain();
     $addon_domains = $network_wide ? Util::get_network_addon_domains(null, Util::get_option('include_all_networks')) : array();
     /**
      * Filters the addon domains to create the certificate for.
      *
      * Using this filter basically allows to generate the certificate for any URLs,
      * even those outside of the WordPress installation.
      *
      * @since 1.0.0
      *
      * @param array  $addon_domains The addon domains.
      * @param string $domain        The root domain for the certificate.
      * @param bool   $network_wide  Whether this certificate is created for an entire network.
      */
     $addon_domains = apply_filters('wpenc_addon_domains', $addon_domains, $domain, $network_wide);
     $manager = CertificateManager::get();
     $response = $manager->generate_certificate($domain, $addon_domains, array('ST' => Util::get_option('country_name'), 'C' => Util::get_option('country_code'), 'O' => Util::get_option('organization')));
     if (is_wp_error($response)) {
         return $response;
     }
     Util::set_registration_info('certificate', $response);
     if (Util::get_option('autogenerate_certificate')) {
         Util::schedule_autogenerate_event(current_time('timestamp'), true);
     }
     /**
      * Fires after the SSL certificate has been generated.
      *
      * The hook is invoked after both initial and subsequent certificate generation processes.
      *
      * @since 1.0.0
      *
      * @param array  $response      Response from the certificate generation call.
      * @param string $domain        Primary domain of the generated certificate.
      * @param array  $addon_domains Additional domains of the generated certificate.
      */
     do_action('wpenc_certificate_generated', $response, $domain, $addon_domains);
     return sprintf(__('Certificate generated for %s.', 'wp-encrypt'), implode(', ', $response['domains']));
 }
Beispiel #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;
 }