| 开发者 | jhorowitz |
|---|---|
| 更新时间 | 2026年5月23日 04:03 |
| 捐献地址: | 去捐款 |
| PHP版本: | 7.0 及以上 |
| WordPress版本: | 7.0 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
/wp-content/plugins/content-visibility-for-divi-builder directory, or install the plugin through the WordPress plugins screen directly.Yes! In Divi 4 and below: This plugin detects and modifies Modules and Sections by class inheritance. As long as Elegant Themes continues to have a single root class for everything, this plugin should detect all of them, including third party ones! In Divi 5: This plugin detects and modifies Modules and Sections by instrumenting all Gutenberg block render callbacks. As long as Elegant Themes continues to utilize Gutenberg blocks with render callbacks for everything, this plugin should detect all of them, including third party ones!
Yes. If you decide to deactivate or uninstall this plugin, the "Content Visibility" configuration option will disappear from the Divi Builder, and will not have any effect on the frontend output. Of course, the "Content Visibility" settings that were defined for a particular Section or Module will continue to persist in the database, until that post/page is updated. This can be a good thing, however, as you may want to reinstall/reactivate in the future and not have to re-enter all of your "Content Visibility" expressions!
Once the plugin is installed and activated, a "Content Visibility" option will appear in each Section or Module's settings on either the Advanced tab under Visibility (for Divi 4.x or higher) or the General Settings / Content tab (for Divi 3.x or lower.) You may enter any PHP boolean expression you would like, (e.g. is_user_logged_in()), and the Section or Module will only display if the expression evaluates to true. NOTE: Complex expressions are usually best entered as a custom function call defined in a child theme or plugin! So, for example, you could enter my_custom_function() in the Content Visibility option, and then define that function (returning true or false) in your child theme's functions.php. If there are several common boolean expressions you use, this also has the added benefit of allowing you to change the behavior of your content by simply modifying the function body once instead of re-entering Content Visibility options all over the place.
Starting in version 5.00, the plugin includes expression validation that checks visibility expressions before they are evaluated. This prevents potentially dangerous PHP code (such as system commands, file operations, or network calls) from being executed via visibility expressions. Expression validation works by:
functions.php, re-scan to verify zero remaining errors, then click "Enable Validation".
Validation can be disabled later (a "Disable Validation" form appears once it is enabled, requiring you to type DISABLE to confirm). Use this if validation causes unexpected behavior on your site while you investigate.
When validation is enabled and an expression is blocked, the content will be shown (not hidden) and an email notification is sent to the site admin with details about the blocked expression. Publishing posts whose content contains expressions that fail validation is blocked at the editor — Gutenberg / the Divi 5 Visual Builder surface a clear error, and the classic editor and the Divi 3 & 4 builders abort the save before any database write so the existing post is left exactly as it was (a published page stays published with its previous content; in-progress edits remain in the editor for you to fix and re-save).
Validation uses a curated allowlist of safe callables (WordPress conditional tags) plus an extension filter for adding your own. Out of the box the following work:
is_user_logged_in()current_user_can('editor')is_admin() && is_singular()is_page() || is_archive()==, !=, ===, !==, <, >, &&, ||, !, ?:, ??true / false / nullmy_custom_helper() or MyTheme::shouldBeVisible()) are NOT allowlisted by default — admins explicitly add them via the content_visibility_for_divi_builder_allowed_callables filter (a ready-to-paste snippet is generated by the content scanner on the Expression Validation tab).
The following types of expressions are blocked:
wtf (without parens) — must be a function call, static method, class constant access, or a true/false/null literalsystem('ls'), update_option(...), wp_mail(...), etc. — built-in denylist (filterable)$_GET['cmd'] — $ and T_VARIABLE are not allowed'system'('ls') — string literal followed by (new ReflectionFunction(...) — new keyword blocked (write a static helper that does the new internally instead)Foo::bar()->baz() — cannot be reliably analyzed; rewrite as a static helpereval(...), include(...) — blocked token types`ls` — backtick character blocked$x = 1 — both $ and = are blocked charactersYes! Three filters are available for developers to customize validation behavior. See the "Developer Filters" section below for details.
new, instance method chains (Foo::bar()->baz()), variable functions, string-as-callable, and bare identifiers are hard errors and cannot be allowlisted — rewrite as a static helper. New installs have validation enabled by default; existing installs ship with validation off and a persistent admin notice prompting the migration workflow.add_filter('content_visibility_for_divi_builder_allowed_callables', ...) snippet pre-populated with every custom callable found in current content (with first-sighting context: post id, module name, admin label, file:line via Reflection when available). Non-allowlistable patterns (instance methods, etc.) are listed separately as "must be rewritten."WP_Error with a structured error message; the classic editor and the Divi 3 & 4 builders abort the save before any database write so an already-published page stays published with its previous content, and the in-progress edits remain in the editor for you to fix and re-save.cvdb/v1/: security/scan, security/validate-expression (server-truth validator for the inline UI), notices/rating/dismiss (replaces an AJAX action).eval() is unavailable on the host (e.g. Suhosin's executor.disable_eval, custom hardening). Detected via runtime smoke probe.content_visibility_for_divi_builder_allowed_callables. Extension point for admins to allowlist custom callables. Accepts function names and Class::method static-method entries; namespace-qualified names are normalized (leading \, namespace\ prefix stripped, lowercased).blocked_functions, allowed_tokens, allowed_chars, allowed_callables) with paste-ready examples.