Repository navigation
Add settings export and import in a new Backup tab - #350
Conversation
- Move the list of boolean settings into Settings::get_boolean_option_keys() so the form sanitizer and the importer share one list of toggles. - Let the form sanitizer hand back a value untouched while a settings import is writing the option. It requires the settings form nonce, which an import does not have, so the saved option would otherwise be replaced by the previous one. - Make ImageManagement::downgrade_target_to_supported_formats() public and static, so an import can reuse the same server support check. - Hide the main save bar on the Backup tab, which has its own forms.
The Backup tab downloads the FrontBlocks settings as a JSON file and imports one on another site, to clone a configuration between sites. - The file declares a format and a format version, and holds only settings that are safe to move: module toggles, simple options and the image format options that do not depend on the site. Credentials, license keys, the maintenance image and the image size configuration are never written. - The import merges: only the keys in the file change. Every value is validated against a schema, and unknown or invalid values are skipped and listed afterwards. An image format the server cannot produce is downgraded, and the two short description options stay exclusive. - Files must be valid JSON, declare the format, stay under 256 KB and have the .json extension. A rejected file changes nothing. - Export and import need the edit_theme_options capability and a nonce. - The frontblocks_import_settings_schema and frontblocks_export_settings filters let add-ons contribute their own settings.
Cover the schema and value validation, the exported document, file validation, merging, the short description exclusion, the image format downgrade, the sanitizer bypass during an import, the Backup tab and its export and import requests (capability, nonce, bad uploads).
Add docs/SETTINGS-EXPORT-IMPORT.md with the file format, what is and is not exported, how the import behaves and how add-ons extend it, and link it from the readme. Add the changelog entry.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Add an optional `content` section to the settings file, filled by add-ons through two filters, so things that are not settings, such as the popups of FrontBlocks PRO, can travel with the rest. - frontblocks_export_content collects the content of each add-on under a section id. Invalid ids and empty or non-array sections are dropped. - frontblocks_import_content hands each section to the add-on that knows it, after the settings are applied, and collects a report. The report is normalized, and a section nothing can import is listed as skipped. - The summary shows, for each section, what was created and updated, what was skipped and what needs a review, all escaped. - A content section that is not an object rejects the file. - Raise the file size limit from 256 KB to 2 MB, since content such as popups can be long.
Cover the export filter and its cleanup, the content check of the file, the import filter and its report normalization, sections without a handler, the order against the settings, and how the summary shows and escapes a section.
Describe the content section of the file, the two filters add-ons use, what an import handler must check, and the new 2 MB limit.
ReviewNo blocking security issues. Capability and nonce checks on both actions, Suggested changes
Minor
|
- Resolve the conflicts with Staging Mode: enable_staging joins get_boolean_option_keys() and both changelog entries stay. - Do not export or import site state: enable_maintenance, enable_staging and scroll_top_icon_url. A file that has them gets them skipped with a reason. - Export image_max_upload_dimension_enabled as true when it was never saved, so an import can turn it back on. - Cap the skipped list of the import summary at 50 entries (keys cut to 60 characters) and show how many more. - Die with an error instead of downloading an empty file when the JSON cannot be encoded. - Tests for all of the above and for the short description options when the file touches neither.
|
Conflicts with trunk are resolved (Staging Mode:
Not changed on purpose: the Staging measure checkboxes (block emails, etc.) are not exported; they only matter while staging is on, and staging itself is site state. |
Staging Mode was merged with one optional measure, staging_restrict_access. It joins get_boolean_option_keys() for the settings form and, like the other staging state, is not exported or imported.
- Build the Backup URL with Settings::get_settings_url() when FrontBlocks has its own menu, and fall back to the Appearance screen otherwise. - Cap the content sections of an import at 20 and the skipped and notes lists that add-ons report, so a crafted file cannot fill the result. - Export the effective image values (size limit, WebP and AVIF quality, target format) when Image Management was never saved, using new default constants in ImageManagement. - Count the length of text values in characters with mb_strlen(). - Fire frontblocks_sanitize_settings on import, as a normal save does. - List maintenance, staging and the scroll-to-top icon in the "What is not included" box, and use Staging::RESTRICT_ACCESS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ort-import # Conflicts: # readme.txt
…ort-import # Conflicts: # readme.txt
- Link to the Backup tab with Settings::get_settings_url() only: the Appearance fallback and its PAGE_SLUG constant are gone now that the FrontBlocks menu is in trunk. - Move the Backup entry after the post types of the FrontBlocks menu, right before License, so the sidebar matches the tab bar. The License mover becomes Settings::move_tab_entry_last(). - Refuse an export the import would reject (over 2 MB or nested too deeply), and report a file nested too deeply with its own message. - Let only the value the import writes skip the form sanitizer; any other write during the import still needs the settings nonce. - Show a warning, not a success, when nothing was imported, and do not count a setting the exclusive rule turned off as applied. - Fix the translators comment of the exclusive-rule note and use the image defaults constants in Frontend\ImageManagement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A toggle of a module the site does not have (FrontBlocks PRO without a valid license, or WooCommerce not active) is off only because the module is missing. Exporting it as off turned that module off on a destination that uses it, for example popups or the WooCommerce features. The export now skips those toggles, so an import leaves them as they are on the destination. The PRO and WooCommerce toggle lists move to Settings::get_pro_option_keys() and get_woocommerce_option_keys(), which the PRO cards of the settings screen also use, and add-ons can adjust the skipped keys with the frontblocks_export_unavailable_keys filter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes #351
Summary
Adds a Backup tab to Appearance > FrontBlocks that downloads the FrontBlocks settings as a JSON file and imports one on another site, so a configuration can be cloned between client sites instead of switching modules on by hand.
How it works
Export. Downloads
frontblocks-settings-<host>-<date>.jsonwith the module toggles, the simple options and the image format options that do not depend on the site. A toggle that was never saved is exported asfalse, so the file always describes the effective state.Import. Merges the file over the current settings. Only the keys in the file change, and everything else stays as it was.
"format": "frontblocks-settings", have a supportedformat_version, be at most 2 MB and end in.json. A rejected file changes nothing.Content from add-ons. The file has an optional
contentsection that add-ons fill through two filters,frontblocks_export_contentandfrontblocks_import_content, so things that are not settings can travel too. FrontBlocks PRO uses it for popups (see the PRO pull request). The import hands each section to the add-on that knows it after the settings are applied, and the summary shows what was created, updated and skipped and what needs a review. A section no add-on can import is listed as skipped, and each add-on checks what the current user may create, because the import only requiresedit_theme_options.Never exported: Google Sign-In credentials, license keys, the maintenance image (an attachment ID), the image size configuration and per-site state. See
docs/SETTINGS-EXPORT-IMPORT.md.Security
edit_theme_options(the capability of the settings screen) and a nonce, for both export and import. A nonce for the other action is not accepted.is_uploaded_file(), and only decoded as JSON. It is never included or executed.Design notes
update_option( 'frontblocks_settings' )goes throughSettings::sanitize_settings(), which requires the settings form nonce and otherwise returns the previous value, so an import would be lost silently.SettingsTransfer::is_importing()is true only while the import writes the option, and the sanitizer returns the already validated value in that case. A test checks that a normal save without the nonce is still refused.Settings::get_boolean_option_keys(), used by both the form sanitizer and the importer, so they cannot drift apart.frontblocks_settings_tabsandfrontblocks_settings_tab_panels) in its own class, soSettings.phpdoes not grow. The main save bar is hidden on this tab because it has its own forms.frontblocks_import_settings_schemaandfrontblocks_export_settingsfilters let add-ons such as FrontBlocks PRO contribute their own keys, and the two content filters let them move content. A key that is not in the schema is skipped on import.@since 1.6.0. Adjust it if this ships in another version.Testing
tests/Unit/SettingsTransferTest.php): schema and value validation, the exported document, file validation, merging, the image format downgrade, the sanitizer bypass, the tab and the export and import requests (capability, nonce, bad uploads), and the content sections (export cleanup, import order, report normalization, escaping).is_uploaded_file()check, the unknown key filter, the merge or the sanitizer bypass makes tests fail.trunkplus the new ones).composer lintandcomposer phpstanare clean. The files were also checked for syntax on PHP 7.4..txtfile, a newer format, another plugin's format, a file over the size limit and a file with only invalid values were rejected with a message and changed nothing. An editor gets a 403.Notes for reviewers
Settings::get_boolean_option_keys()(or declared through the schema filter) to travel with the rest. Nothing breaks if they are not: they are skipped on import.trunk:Settings.phpcallsclosest('.tw:flex'), which is not a valid selector and needs the colon escaped. It is outside this change.