| @@ -74,9 +74,9 @@ | ||
| 74 | 74 | $log = new ConvertKit_Log( CONVERTKIT_PLUGIN_PATH ); |
| 75 | 75 | $log->clear(); |
| 76 | 76 | |
| 77 | 77 | // Redirect to Tools screen. |
| 78 | - $this->redirect(); | |
| 78 | + $this->redirect_to_tools_screen(); | |
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| @@ -159,17 +159,13 @@ | ||
| 159 | 159 | if ( ! array_key_exists( 'convertkit-export', $_REQUEST ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - // Initialize classes that hold settings. | |
| 164 | - $settings = new ConvertKit_Settings(); | |
| 165 | - $restrict_content_settings = new ConvertKit_Settings_Restrict_Content(); | |
| 166 | - | |
| 167 | 163 | // Define configuration data to include in the export file. |
| 168 | - $json = wp_json_encode( | |
| 164 | + $settings = new ConvertKit_Settings(); | |
| 165 | + $json = wp_json_encode( | |
| 169 | 166 | array( |
| 170 | - 'settings' => $settings->get(), | |
| 171 | - 'restrict_content' => $restrict_content_settings->get(), | |
| 167 | + 'settings' => $settings->get(), | |
| 172 | 168 | ) |
| 173 | 169 | ); |
| 174 | 170 | |
| 175 | 171 | // Download. |
| @@ -176,9 +172,9 @@ | ||
| 176 | 172 | header( 'Content-type: application/x-msdownload' ); |
| 177 | 173 | header( 'Content-Disposition: attachment; filename=convertkit-export.json' ); |
| 178 | 174 | header( 'Pragma: no-cache' ); |
| 179 | 175 | header( 'Expires: 0' ); |
| 180 | - echo $json; // phpcs:ignore WordPress.Security.EscapeOutput | |
| 176 | + echo $json; /* phpcs:ignore */ | |
| 181 | 177 | exit(); |
| 182 | 178 | |
| 183 | 179 | } |
| 184 | 180 | |
| @@ -201,17 +197,17 @@ | ||
| 201 | 197 | return; |
| 202 | 198 | } |
| 203 | 199 | |
| 204 | 200 | // Bail if no configuration file was supplied. |
| 205 | - if ( ! is_array( $_FILES ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 206 | - $this->redirect(); | |
| 201 | + if ( ! is_array( $_FILES ) ) { | |
| 202 | + $this->redirect_to_tools_screen(); | |
| 207 | 203 | } |
| 208 | - if ( $_FILES['import']['error'] !== 0 ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 209 | - $this->redirect( 'import_configuration_upload_error' ); | |
| 204 | + if ( $_FILES['import']['error'] !== 0 ) { | |
| 205 | + $this->redirect_to_tools_screen( 'import_configuration_upload_error' ); | |
| 210 | 206 | } |
| 211 | 207 | |
| 212 | 208 | // Read file. |
| 213 | - $json = $wp_filesystem->get_contents( $_FILES['import']['tmp_name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 209 | + $json = $wp_filesystem->get_contents( $_FILES['import']['tmp_name'] ); | |
| 214 | 210 | |
| 215 | 211 | // Decode. |
| 216 | 212 | $import = json_decode( $json, true ); |
| 217 | 213 | |
| @@ -216,30 +212,22 @@ | ||
| 216 | 212 | $import = json_decode( $json, true ); |
| 217 | 213 | |
| 218 | 214 | // Bail if the data isn't JSON. |
| 219 | 215 | if ( is_null( $import ) ) { |
| 220 | - $this->redirect( 'import_configuration_invalid_file_type' ); | |
| 216 | + $this->redirect_to_tools_screen( 'import_configuration_invalid_file_type' ); | |
| 221 | 217 | } |
| 222 | 218 | |
| 223 | 219 | // Bail if no settings exist. |
| 224 | 220 | if ( ! array_key_exists( 'settings', $import ) ) { |
| 225 | - $this->redirect( 'import_configuration_empty' ); | |
| 221 | + $this->redirect_to_tools_screen( 'import_configuration_empty' ); | |
| 226 | 222 | } |
| 227 | 223 | |
| 228 | 224 | // Import: Settings. |
| 229 | - if ( array_key_exists( 'settings', $import ) ) { | |
| 230 | - $settings = new ConvertKit_Settings(); | |
| 231 | - update_option( $settings::SETTINGS_NAME, $import['settings'] ); | |
| 232 | - } | |
| 225 | + $settings = new ConvertKit_Settings(); | |
| 226 | + update_option( $settings::SETTINGS_NAME, $import['settings'] ); | |
| 233 | 227 | |
| 234 | - // Import: Restrict Content Settings. | |
| 235 | - if ( array_key_exists( 'restrict_content', $import ) ) { | |
| 236 | - $restrict_content_settings = new ConvertKit_Settings_Restrict_Content(); | |
| 237 | - update_option( $restrict_content_settings::SETTINGS_NAME, $import['restrict_content'] ); | |
| 238 | - } | |
| 239 | - | |
| 240 | 228 | // Redirect to Tools screen. |
| 241 | - $this->redirect( false, 'import_configuration_success' ); | |
| 229 | + $this->redirect_to_tools_screen( false, 'import_configuration_success' ); | |
| 242 | 230 | |
| 243 | 231 | } |
| 244 | 232 | |
| 245 | 233 | /** |
| @@ -261,8 +249,36 @@ | ||
| 261 | 249 | |
| 262 | 250 | } |
| 263 | 251 | |
| 264 | 252 | /** |
| 253 | + * Redirects to the ConvertKit > Tools screen. | |
| 254 | + * | |
| 255 | + * @since 1.9.7.4 | |
| 256 | + * | |
| 257 | + * @param false|string $error The error message key. | |
| 258 | + * @param false|string $success The success message key. | |
| 259 | + */ | |
| 260 | + private function redirect_to_tools_screen( $error = false, $success = false ) { | |
| 261 | + | |
| 262 | + // Build URL to redirect to, depending on whether a message is included. | |
| 263 | + $args = array( | |
| 264 | + 'page' => '_wp_convertkit_settings', | |
| 265 | + 'tab' => 'tools', | |
| 266 | + ); | |
| 267 | + if ( $error !== false ) { | |
| 268 | + $args['error'] = $error; | |
| 269 | + } | |
| 270 | + if ( $success !== false ) { | |
| 271 | + $args['success'] = $success; | |
| 272 | + } | |
| 273 | + | |
| 274 | + // Redirect to ConvertKit > Tools screen. | |
| 275 | + wp_safe_redirect( add_query_arg( $args, 'options-general.php' ) ); | |
| 276 | + exit(); | |
| 277 | + | |
| 278 | + } | |
| 279 | + | |
| 280 | + /** | |
| 265 | 281 | * Register fields for this section |
| 266 | 282 | */ |
| 267 | 283 | public function register_fields() { |
| 268 | 284 | |
| @@ -334,21 +350,8 @@ | ||
| 334 | 350 | |
| 335 | 351 | ?> |
| 336 | 352 | <p><?php esc_html_e( 'Tools to help you manage ConvertKit on your site.', 'convertkit' ); ?></p> |
| 337 | 353 | <?php |
| 338 | - | |
| 339 | - } | |
| 340 | - | |
| 341 | - /** | |
| 342 | - * Returns the URL for the ConvertKit documentation for this setting section. | |
| 343 | - * | |
| 344 | - * @since 2.0.8 | |
| 345 | - * | |
| 346 | - * @return string Documentation URL. | |
| 347 | - */ | |
| 348 | - public function documentation_url() { | |
| 349 | - | |
| 350 | - return 'https://help.convertkit.com/en/articles/2502591-the-convertkit-wordpress-plugin'; | |
| 351 | 354 | |
| 352 | 355 | } |
| 353 | 356 | |
| 354 | 357 | /** |