← All changes
|
_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php
+27
-7
16.3-a.1
→
16.3-a.7
View file →
| @@ -91,8 +91,16 @@ | ||
| 91 | 91 | ); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | if ( Jetpack::activate_module( $module_slug, false, false ) ) { |
| 95 | + if ( ! Jetpack::is_module_active( $module_slug ) ) { | |
| 96 | + return new WP_Error( | |
| 97 | + 'module_forced', | |
| 98 | + esc_html__( 'The requested Jetpack module is disabled by your host or site administrator, so it stays off.', 'jetpack' ), | |
| 99 | + array( 'status' => 409 ) | |
| 100 | + ); | |
| 101 | + } | |
| 102 | + | |
| 95 | 103 | return rest_ensure_response( |
| 96 | 104 | array( |
| 97 | 105 | 'code' => 'success', |
| 98 | 106 | 'message' => esc_html__( 'The requested Jetpack module was activated.', 'jetpack' ), |
| @@ -152,9 +160,20 @@ | ||
| 152 | 160 | array( 'status' => 409 ) |
| 153 | 161 | ); |
| 154 | 162 | } |
| 155 | 163 | |
| 156 | - if ( Jetpack::deactivate_module( $module_slug ) ) { | |
| 164 | + $deactivated = Jetpack::deactivate_module( $module_slug ); | |
| 165 | + | |
| 166 | + // A module that was never saved as active leaves nothing to change, so check the outcome. | |
| 167 | + if ( Jetpack::is_module_active( $module_slug ) ) { | |
| 168 | + return new WP_Error( | |
| 169 | + 'module_forced', | |
| 170 | + esc_html__( 'The requested Jetpack module is enabled by your host or site administrator, so it stays on.', 'jetpack' ), | |
| 171 | + array( 'status' => 409 ) | |
| 172 | + ); | |
| 173 | + } | |
| 174 | + | |
| 175 | + if ( $deactivated ) { | |
| 157 | 176 | return rest_ensure_response( |
| 158 | 177 | array( |
| 159 | 178 | 'code' => 'success', |
| 160 | 179 | 'message' => esc_html__( 'The requested Jetpack module was deactivated.', 'jetpack' ), |
| @@ -262,9 +281,9 @@ | ||
| 262 | 281 | $activated = array(); |
| 263 | 282 | $failed = array(); |
| 264 | 283 | |
| 265 | 284 | foreach ( $request['modules'] as $module ) { |
| 266 | - if ( Jetpack::activate_module( $module, false, false ) ) { | |
| 285 | + if ( Jetpack::activate_module( $module, false, false ) && Jetpack::is_module_active( $module ) ) { | |
| 267 | 286 | $activated[] = $module; |
| 268 | 287 | } else { |
| 269 | 288 | $failed[] = $module; |
| 270 | 289 | } |
| @@ -815,14 +834,15 @@ | ||
| 815 | 834 | case 'facebook': |
| 816 | 835 | $grouped_options_current = (array) get_option( 'verification_services_codes' ); |
| 817 | 836 | $grouped_options = $grouped_options_current; |
| 818 | 837 | |
| 819 | - // Extracts the content attribute from the HTML meta tag if needed. | |
| 820 | - if ( preg_match( '#.*<meta name="(?:[^"]+)" content="([^"]+)" />.*#i', $value, $matches ) ) { | |
| 821 | - $grouped_options[ $option ] = $matches[1]; | |
| 822 | - } else { | |
| 823 | - $grouped_options[ $option ] = $value; | |
| 838 | + $validated_code = jetpack_verification_validate_code( $value ); | |
| 839 | + if ( false === $validated_code ) { | |
| 840 | + $error = esc_html__( 'The site verification code is invalid.', 'jetpack' ); | |
| 841 | + break; | |
| 824 | 842 | } |
| 843 | + | |
| 844 | + $grouped_options[ $option ] = $validated_code; | |
| 825 | 845 | |
| 826 | 846 | // If option value was the same, consider it done. |
| 827 | 847 | $updated = $grouped_options_current !== $grouped_options |
| 828 | 848 | ? update_option( 'verification_services_codes', $grouped_options ) |