'deadbolt', 'export_version' => self::EXPORT_VERSION, 'plugin_version' => Bootstrap::version(), 'exported_at' => gmdate( 'c' ), 'settings' => $settings, ] ) ); } // End ajax_export() /** * AJAX: import settings from an uploaded export. * * @return void */ public function ajax_import() : void { Helpers::verify_ajax( Settings::NONCE ); $raw = isset( $_POST[ 'payload' ] ) ? wp_unslash( $_POST[ 'payload' ] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- the nonce is verified by Helpers::verify_ajax() above, JSON is decoded and every setting is sanitized by Settings::save(). $payload = is_string( $raw ) ? json_decode( $raw, true ) : null; if ( ! is_array( $payload ) || ! in_array( $payload[ 'plugin' ] ?? '', self::IMPORT_SOURCES, true ) || ! is_array( $payload[ 'settings' ] ?? null ) ) { wp_send_json_error( __( 'That file is not a valid settings export.', 'deadbolt' ) ); } Settings::save( array_intersect_key( $payload[ 'settings' ], Settings::fields() ) ); do_action( 'deadbolt_settings_imported', $payload ); wp_send_json_success(); } // End ajax_import() /** * AJAX: reset every setting to its default. * * @return void */ public function ajax_reset() : void { Helpers::verify_ajax( Settings::NONCE ); Settings::reset(); wp_send_json_success(); } // End ajax_reset() /** * AJAX: run the import from earlier names of this plugin again. * * @return void */ public function ajax_migrate() : void { Helpers::verify_ajax( Settings::NONCE ); $summary = Migrate::execute( true ); if ( ! empty( $summary[ 'error' ] ) ) { wp_send_json_error( sprintf( /* translators: %s: Error message. */ __( 'The import failed: %s', 'deadbolt' ), $summary[ 'error' ] ) ); } if ( ! empty( $summary[ 'skipped' ] ) ) { wp_send_json_error( __( 'The import is already running. Try again in a moment.', 'deadbolt' ) ); } wp_send_json_success( sprintf( /* translators: 1: Number of posts with access rules, 2: Number of templates carried over or created. */ __( 'Import finished. Kept the access rules on %1$d posts and carried over or created %2$d templates. Reloading…', 'deadbolt' ), (int) ( $summary[ 'rules' ] ?? 0 ) + (int) ( $summary[ 'posts' ] ?? 0 ), (int) ( $summary[ 'moved' ] ?? 0 ) + (int) ( $summary[ 'templates' ] ?? 0 ) ) ); } // End ajax_migrate() } // End class Advanced Advanced::instance();