|
8 | 8 | 'ssl' => false,
|
9 | 9 | ];
|
10 | 10 |
|
11 |
| - add_action( 'jurassic_ninja_add_features_before_auto_login', function( &$app, $features, $domain ) use ( $defaults ) { |
| 11 | + add_action( 'jurassic_ninja_add_features_after_create_app', function( &$app, $features, $domain ) use ( $defaults ) { |
12 | 12 | $features = array_merge( $defaults, $features );
|
13 |
| - // Currently not used but the code works. |
14 | 13 | if ( $features['auto_ssl'] ) {
|
15 |
| - enable_sp_auto_ssl( $app->data->id ); |
| 14 | + // Currently not a feature of Jurassic Ninja but the code works. |
| 15 | + provisioner()->enable_auto_ssl( $app->id ); |
| 16 | + } else { |
| 17 | + $response = provisioner()->add_ssl_certificate( $app->id ); |
16 | 18 | }
|
| 19 | + }, 10, 3 ); |
| 20 | + |
| 21 | + add_action( 'jurassic_ninja_add_features_before_auto_login', function( &$app = null, $features, $domain ) use ( $defaults ) { |
17 | 22 | // We can't easily enable SSL for subodmains because
|
18 | 23 | // wildcard certificates don't support multiple levels of subdomains
|
19 | 24 | // and this can result in awful experience.
|
20 |
| - // Need to explorer a little bit better |
21 |
| - if ( $features['ssl'] && ! $features['subdomain_multisite'] ) { |
| 25 | + // Need to explore a little bit better |
| 26 | + |
| 27 | + if ( $features['ssl'] && ! ( isset( $features['subdomain_multisite'] ) && $features['subdomain_multisite'] ) ) { |
| 28 | + $features = array_merge( $defaults, $features ); |
22 | 29 | if ( $features['auto_ssl'] ) {
|
23 |
| - debug( 'Both ssl and auto_ssl features were requested. Ignoring ssl and launching with auto_ssl' ); |
24 |
| - } else { |
25 |
| - debug( '%s: Enabling custom SSL', $domain ); |
26 |
| - $response = enable_sp_ssl( $app->data->id ); |
27 |
| - if ( is_wp_error( $response ) ) { |
28 |
| - debug( 'Error enabling SSL for %s. Check the next log line for a dump of the WP_Error', $domain ); |
29 |
| - // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r |
30 |
| - debug( print_r( $response, true ) ); |
31 |
| - // phpcs:enable |
32 |
| - throw new \Exception( 'Error enabling SSL: ' . $response->get_error_message() ); |
33 |
| - } |
34 |
| - debug( '%s: Setting home and siteurl options', $domain ); |
35 |
| - set_home_and_site_url( $domain ); |
| 30 | + debug( 'Both ssl and auto_ssl features were requested. Ignoring ssl and launching with custom SSL' ); |
| 31 | + } |
| 32 | + debug( '%s: Enabling custom SSL', $domain ); |
| 33 | + |
| 34 | + $response = provisioner()->force_ssl_redirection( $app->id ); |
| 35 | + |
| 36 | + if ( is_wp_error( $response ) ) { |
| 37 | + throw new \Exception( 'Error enabling SSL: ' . $response->get_error_message() ); |
36 | 38 | }
|
| 39 | + |
| 40 | + debug( '%s: Setting home and siteurl options to account for SSL', $domain ); |
| 41 | + set_home_and_site_url( $domain ); |
37 | 42 | }
|
38 | 43 | }, 10, 3 );
|
39 |
| - add_filter( 'jurassic_ninja_rest_feature_defaults', function( $defaults ) { |
40 |
| - return array_merge( $defaults, [ |
| 44 | + |
| 45 | + add_filter( 'jurassic_ninja_rest_feature_defaults', function( $rest_default_features ) use ( $defaults ) { |
| 46 | + return array_merge( $defaults, $rest_default_features, [ |
41 | 47 | 'ssl' => (bool) settings( 'ssl_use_custom_certificate', false ),
|
42 | 48 | ] );
|
43 | 49 | } );
|
44 | 50 |
|
| 51 | + add_filter( 'jurassic_ninja_rest_create_request_features', function( $features, $json_params ) { |
| 52 | + return array_merge( $features, [ |
| 53 | + 'ssl' => $features['ssl'] && ( isset( $json_params['ssl'] ) ? $json_params['ssl'] : true ), |
| 54 | + ] ); |
| 55 | + }, 10, 2 ); |
| 56 | + |
45 | 57 | add_filter( 'jurassic_ninja_created_site_url', function( $domain, $features ) {
|
46 | 58 | // See note in launch_wordpress() about why we can't launch subdomain_multisite with ssl.
|
47 | 59 | $schema = ( $features['ssl'] && ! $features['subdomain_multisite'] ) ? 'https' : 'http';
|
|
0 commit comments