Unified Snippets: implement Tier 3 scanner - Divi#393
Open
louiswol94 wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the Tier 3 Divi Theme Options scanner to the Unified Snippets feature. Surfaces the five code-input fields that Divi exposes under Theme Options — Custom CSS and the four "Integration" textareas (head, body, single top, single bottom) — as read-only
Discovered_Snippets so they show up alongside the rest of a site's custom code in the Unified view.This is Phase 1 (discovery only): each snippet carries the metadata a later Phase 3 importer needs (accurate
type, scanner-specificimport_notes, and a deterministicsource_path), but no code generation happens inside the scanner.What's in the box
Divi_Theme_Options_Scanner— extendsScanner_Base,id = 'divi-theme-options',risk = medium,supports_import = true,supports_editing = false(Phase 4)Plugin::init_unified_snippets()alongside the existing Tier 1/2 scannersExtrasibling theme, and hash/checksum stabilityKey design decisions
Storage read path mirrors Divi's
et_get_option(). Divi stores theme options either as a single serialised array underet_<shortname>(one-row mode) or as per-key options named after the full field id e.g.divi_integration_head(per-row mode), decided per-install byet_options_stored_in_one_row(). Rather than depend on Divi's globals, the scanner checks both layouts and returns whichever yields a value. Both modes have dedicated tests.is_activehonours Divi's enable toggles, strictly. The four Integration fields each have a companion_integrate_*_enablecheckbox that Divi checks at runtime before emitting the code. Divi's runtime test iset_get_option(...) === 'on', which means a missing toggle (booleanfalsefromet_get_option()) does NOT emit — the checkboxstd => 'on'inoptions_divi.phponly controls the admin UI default-checked state, not the runtime default. The scanner mirrors that strict check, so the Unified view reflects what Divi is actually emitting. Tests cover the three real states:'on', missing, and the literal string'false'that Divi writes on save-with-unchecked.Availability is gated on the active template (
DiviorExtra). We deliberately do not scan when Divi is merely installed-but-inactive — its hooks are not running, so the code is dormant."Body code" maps to
footer-content, notwp_body_open. Despite the Divi UI labelling it "body", Divi actually emits this field onwp_footerat priority 12 (seeDivi/epanel/custom_functions.php). Importing into Code Snippets'footer-contentscope reproduces the runtime behaviour. The priority delta (Divi: 12 vsfooter-content: default 10 perEvaluate_Content::init()) is surfaced inimport_notes— the imported snippet executes slightly earlier than Divi did, which is usually harmless but may matter for order-sensitive scripts. The head field has the same delta (Divi: 12 vshead-content: 10) and the same note.Single top / single bottom flag the Divi dependency. These fields fire on Divi's own
et_before_post/et_after_posthooks.import_notesmakes it explicit that the imported snippet will only run while Divi is the active theme — we don't block the import, but the user knows what they're signing up for.Per-field metadata only; no wrapping in the scanner. Code generation lives in the (separate) Phase 3 importer, which will switch on
scanner_id === 'divi-theme-options'+type. Keeps the scanner small and read-only, per the architecture doc.Field mapping (for Phase 3)
custom_csscsssite-cssintegration_headhtmlhead-contentintegration_bodyhtmlfooter-contentintegration_single_tophtmlglobal(PHP wrap)add_action( 'et_before_post', ... )integration_single_bottomhtmlglobal(PHP wrap)add_action( 'et_after_post', ... )Testability
The production class has no test-only seams — no override arrays, no injected collaborators, no protected hooks. Tests drive it through the same WordPress surface production uses:
wp_optionsfixtures are written via realupdate_option()calls (both one-rowet_divibundles and per-rowdivi_*options).is_available()is exercised by short-circuitingget_template()through the documentedpre_option_template/pre_option_stylesheetfilters — no theme activation required.tear_down();WP_UnitTestCase's transactional isolation backs that up.This means the tests double as integration coverage for the
read_option()two-storage-mode logic, rather than bypassing it.Out of scope
et_before_post/et_after_postwrap generator)_et_pb_custom_csspostmeta (the Elementor-equivalent "per-element CSS" problem — warrants its own scanner withis_importable = false)Test plan
npm run test:php— 12 cases pass under theunified-snippetsgroupnpm run lint:php)type,is_active, andimport_notes_integrate_*_enabletoggles, rescan, verify the corresponding snippet returns withis_active = falseis_available()returns false and the scanner is skipped