From 926a8b440890fb0feaa863acdedd6d60561e070f Mon Sep 17 00:00:00 2001 From: ABB65 Date: Wed, 28 Oct 2026 08:12:02 +0300 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20WordPress.org=20review=20=E2=80=94?= =?UTF-8?q?=20widgets=20through=20the=20widget=20registry;=20connected=20s?= =?UTF-8?q?ervices=20by=20setting=20name,=20no=20value=20read=20(0.8.4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Coverage and the text scan listed every widget_* option name from the database and read each one; both now ask $wp_widget_factory, and each registered widget reads its own settings. Text::widget_options() and its SQL query are removed. Integrations no longer reads option values to tell whether a credential is set: the database answers whether a credential-named option is empty. Form links count an existing account entry. secret_keys() and its unserialize are removed; evidence is the option name ("mc4wp"). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0184na12xBsMwvjYqcX5LKJv --- README.md | 5 ++- contentrain-bridge.php | 4 +- .../class-contentrain-bridge-coverage.php | 4 +- .../class-contentrain-bridge-integrations.php | 42 +++---------------- includes/class-contentrain-bridge-text.php | 23 +++++++--- readme.txt | 7 +++- tests/integrations.php | 2 +- 7 files changed, 37 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 73a1009..61a8cbd 100644 --- a/README.md +++ b/README.md @@ -277,8 +277,9 @@ analytics, CRM, newsletter, ads, comments, captcha, CDN — with the evidence fo each: an active plugin, a settings option by name, a script host in the theme or on the rendered home page, a form wired to the service, or embedded content. Each says whether an account must be reconnected and whether a credential is set on -WordPress. No key, token or password is exported: a credential is only checked -for being set, in memory, and the export names the setting, never its value. The +WordPress. No key, token or password is exported or read: a setting whose name +says credential counts as set when it is not empty (the database answers that, +not the value), and the export names the setting, never its value. The list is shown on the Bridge screen and reaches Migrate's intake as an `integration_reconnect_required` issue. diff --git a/contentrain-bridge.php b/contentrain-bridge.php index 2706854..0ea9372 100644 --- a/contentrain-bridge.php +++ b/contentrain-bridge.php @@ -3,7 +3,7 @@ * Plugin Name: Contentrain Bridge * Plugin URI: https://github.com/Contentrain/wordpress-bridge * Description: Model and export WordPress content and interface text as Contentrain JSON/Markdown, with optional GitHub delivery. - * Version: 0.8.3 + * Version: 0.8.4 * Requires at least: 6.2 * Requires PHP: 7.4 * Author: Contentrain @@ -16,7 +16,7 @@ */ defined( 'ABSPATH' ) || exit; -define( 'CONTENTRAIN_BRIDGE_VERSION', '0.8.3' ); +define( 'CONTENTRAIN_BRIDGE_VERSION', '0.8.4' ); define( 'CONTENTRAIN_BRIDGE_FILE', __FILE__ ); foreach ( array( 'policy', 'files', 'exporter', 'menus', 'source', 'languages', 'inventory', 'delta', 'seo-render', 'seo', 'redirects', 'routing', 'scanner', 'text', 'coverage', 'integrations', 'acf', 'models', 'validator', 'rawir', 'jobs', 'github', 'key', 'remote', 'robots', 'admin' ) as $contentrain_bridge_class ) { diff --git a/includes/class-contentrain-bridge-coverage.php b/includes/class-contentrain-bridge-coverage.php index e674dfe..c6c8607 100644 --- a/includes/class-contentrain-bridge-coverage.php +++ b/includes/class-contentrain-bridge-coverage.php @@ -156,8 +156,8 @@ public static function report( $job ) { // ---- Widgets and Customizer: exported as interface text when that scan ran. ---- $text = ! empty( $job['options']['scan_sources'] ) ? 'exported:interface-text' : 'excluded:interface-text-scan-off'; $widgets = 0; - foreach ( $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'widget\\_%'" ) as $name ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Independent enumeration. - $widgets += count( array_filter( (array) get_option( $name ), 'is_array' ) ); + foreach ( Text::widgets() as $widget ) { + $widgets += count( array_filter( (array) $widget->get_settings(), 'is_array' ) ); } $sources[] = self::source( 'widgets', 'site', $widgets, $widgets ? array( $text => $widgets ) : array() ); $mods = array_filter( (array) get_theme_mods(), 'is_string' ); diff --git a/includes/class-contentrain-bridge-integrations.php b/includes/class-contentrain-bridge-integrations.php index 3fd9843..40c76d4 100644 --- a/includes/class-contentrain-bridge-integrations.php +++ b/includes/class-contentrain-bridge-integrations.php @@ -93,13 +93,12 @@ public static function detect( $post_ids = array(), $html = '' ) { } } - // 2. Settings, by option name. The value is inspected for "is a credential set", never kept. + // 2. Settings, by option name. A credential-named setting that is not empty counts as a credential set; no value is read. global $wpdb; - $names = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name NOT LIKE '\\_%transient\\_%'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Enumerates option names only. + $names = $wpdb->get_results( "SELECT option_name, option_value <> '' AS has_value FROM {$wpdb->options} WHERE option_name NOT LIKE '\\_%transient\\_%'", OBJECT_K ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Enumerates option names, and whether each is empty; no value is read. foreach ( $catalog as $id => list( $name, $category, , $pattern ) ) { - foreach ( preg_grep( $pattern, $names ) as $option ) { - $set = self::secret_keys( get_option( $option ), preg_match( self::SECRET_KEY, $option ) ? $option : '' ); - $add( $id, $name, $category, 'option-key', $option . ( $set ? ' (' . implode( ', ', $set ) . ')' : '' ), true, (bool) $set ); + foreach ( preg_grep( $pattern, array_keys( $names ) ) as $option ) { + $add( $id, $name, $category, 'option-key', $option, true, $names[ $option ]->has_value && preg_match( self::SECRET_KEY, $option ) ); } } foreach ( (array) get_option( 'jetpack_active_modules', array() ) as $module ) { @@ -165,35 +164,6 @@ public static function detect( $post_ids = array(), $html = '' ) { ); } - /** - * Names of credential settings that hold a value. The value is looked at to - * tell "set" from "empty" and discarded; only the key name comes back. - */ - private static function secret_keys( $value, $option_name = '' ) { - $set = array(); - if ( '' !== $option_name && is_scalar( $value ) && '' !== trim( (string) $value ) ) { - $set[] = $option_name; - } - $walk = static function ( $node, $path ) use ( &$walk, &$set ) { - if ( is_object( $node ) ) { - $node = get_object_vars( $node ); - } - if ( ! is_array( $node ) ) { - return; - } - foreach ( $node as $key => $child ) { - $name = '' === $path ? (string) $key : $path . '.' . $key; - if ( is_scalar( $child ) && preg_match( self::SECRET_KEY, (string) $key ) && '' !== trim( (string) $child ) ) { - $set[] = $name; - } else { - $walk( $child, $name ); - } - } - }; - $walk( is_string( $value ) && is_serialized( $value ) ? unserialize( $value, array( 'allowed_classes' => false, 'max_depth' => 16 ) ) : $value, '' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Class instantiation is explicitly disabled; nothing is kept but key names. - return array_values( array_unique( $set ) ); - } - /** Forms connected to a service: Contact Form 7 integrations, WPForms providers, Gravity Forms feeds. */ private static function form_links() { global $wpdb; @@ -202,7 +172,7 @@ private static function form_links() { if ( is_array( $cf7 ) ) { foreach ( array( 'recaptcha' => 'recaptcha', 'sendinblue' => 'brevo', 'constant_contact' => 'constant-contact', 'stripe' => 'stripe' ) as $key => $service ) { if ( ! empty( $cf7[ $key ] ) ) { - $out[] = array( $service, 'contact-form-7 integration: ' . $key, (bool) self::secret_keys( $cf7[ $key ] ) || ! empty( $cf7[ $key ] ) ); + $out[] = array( $service, 'contact-form-7 integration: ' . $key, true ); } } } @@ -210,7 +180,7 @@ private static function form_links() { foreach ( is_array( $providers ) ? array_keys( $providers ) : array() as $provider ) { $service = array( 'mailchimpv3' => 'mailchimp', 'hubspot' => 'hubspot', 'convertkit' => 'convertkit', 'sendinblue' => 'brevo', 'zapier' => 'zapier', 'salesforce' => 'salesforce' )[ $provider ] ?? null; if ( $service ) { - $out[] = array( $service, 'wpforms provider: ' . $provider, (bool) self::secret_keys( $providers[ $provider ] ) ); + $out[] = array( $service, 'wpforms provider: ' . $provider, ! empty( $providers[ $provider ] ) ); } } $feeds = $wpdb->prefix . 'gf_addon_feed'; diff --git a/includes/class-contentrain-bridge-text.php b/includes/class-contentrain-bridge-text.php index 12c065e..0e4ecdb 100644 --- a/includes/class-contentrain-bridge-text.php +++ b/includes/class-contentrain-bridge-text.php @@ -43,12 +43,15 @@ public static function settings( $locale ) { $found[] = self::occurrence( (string) get_option( $option ), 'option:' . $option, 'option', $option, $locale, array( 'target' => $target ) ); } // Classic widgets keep a title and sometimes HTML text; block widgets keep block markup. - foreach ( self::widget_options() as $option ) { - foreach ( (array) get_option( $option, array() ) as $number => $instance ) { + foreach ( self::widgets() as $widget ) { + if ( 'recent-comments' === $widget->id_base ) { + continue; + } + foreach ( (array) $widget->get_settings() as $number => $instance ) { if ( ! is_array( $instance ) ) { continue; } - $source = $option . '#' . $number; + $source = $widget->option_name . '#' . $number; if ( isset( $instance['title'] ) ) { $found[] = self::occurrence( (string) $instance['title'], 'widget:title', 'widget', $source, $locale ); } @@ -303,9 +306,17 @@ private static function split( $found ) { return $out; } - private static function widget_options() { - global $wpdb; - return (array) $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'widget\\_%' AND option_name <> 'widget_recent-comments' ORDER BY option_name" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Enumerates widget option names; no API lists them. + /** The widgets WordPress has registered, by option name; each reads only its own settings. */ + public static function widgets() { + global $wp_widget_factory; + $widgets = array(); + foreach ( (array) ( $wp_widget_factory->widgets ?? array() ) as $widget ) { + if ( $widget instanceof \WP_Widget ) { + $widgets[ $widget->option_name ] = $widget; + } + } + ksort( $widgets ); + return array_values( $widgets ); } private static function landmark( $element ) { diff --git a/readme.txt b/readme.txt index 65ab2fc..03853a4 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: export, migration, headless, astro, content Requires at least: 6.2 Tested up to: 7.1 Requires PHP: 7.4 -Stable tag: 0.8.3 +Stable tag: 0.8.4 License: GPL-2.0-or-later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -90,6 +90,11 @@ The plugin stores export ownership and a source revision marker. It sends nothin == Changelog == += 0.8.4 = + +* Widgets are read through WordPress's own widget registry: each registered widget reads only its own settings. The export no longer lists option names from the database to find widgets, so a widget whose plugin is inactive is not counted or scanned, as WordPress does not show it either. +* Connected services are found by setting names only. A setting whose name marks a credential (key, token, secret) counts as set when it is not empty; the database answers that, and the value is never read. Evidence names the setting ("mc4wp"), not the keys inside it. A form wired to a service (Contact Form 7, WPForms) counts as connected when its account entry exists; the keys inside it are not read. + = 0.8.3 = * The content type list on the export screen shows each type's published count as a number ("Pages (7 published)", plus private ones when there are any). It used to join the per-status counts as text ("Pages (07010000000000)"). diff --git a/tests/integrations.php b/tests/integrations.php index 1f39e45..6013a42 100644 --- a/tests/integrations.php +++ b/tests/integrations.php @@ -121,7 +121,7 @@ function check( $value, $message ) { $all = ''; foreach ( array_keys( $job['files'] ) as $path ) { if ( 0 !== strpos( $path, 'media/' ) ) { $all .= Files::read( $dir, $path ); } } check( ! array_filter( $secrets, static function ( $v ) use ( $all ) { return false !== strpos( $all, $v ); } ) && false === strpos( $all, 'never-export-gf-feed-key' ), 'no credential in any of ' . count( $job['files'] ) . ' exported files' ); -check( (bool) preg_grep( '/^mc4wp \(api_key\)$/', array_column( $by['mailchimp']['evidence'], 'detail' ) ), 'evidence names the setting that holds the key ("mc4wp (api_key)"), never its value' ); +check( in_array( 'mc4wp', array_column( $by['mailchimp']['evidence'], 'detail' ), true ), 'evidence names the setting by its name ("mc4wp"), never its value' ); // ---- What the admin screen and Migrate get. ---- $summary = Jobs::summary( $job ); From 06bd4fb04ead19ef93bc78cfbaf9af043a7a895e Mon Sep 17 00:00:00 2001 From: ABB65 Date: Wed, 28 Oct 2026 08:18:41 +0300 Subject: [PATCH 2/2] docs: integrations wording matches the name-only check (0.8.4) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0184na12xBsMwvjYqcX5LKJv --- README.md | 7 ++++--- includes/class-contentrain-bridge-integrations.php | 7 ++++--- readme.txt | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 61a8cbd..c1b5059 100644 --- a/README.md +++ b/README.md @@ -277,9 +277,10 @@ analytics, CRM, newsletter, ads, comments, captcha, CDN — with the evidence fo each: an active plugin, a settings option by name, a script host in the theme or on the rendered home page, a form wired to the service, or embedded content. Each says whether an account must be reconnected and whether a credential is set on -WordPress. No key, token or password is exported or read: a setting whose name -says credential counts as set when it is not empty (the database answers that, -not the value), and the export names the setting, never its value. The +WordPress. No key, token or password is exported, and no setting is opened to look for +one: a setting whose name says credential counts as set when it is not empty +(the database answers that, not the value), and the export names the setting, +never its value. The list is shown on the Bridge screen and reaches Migrate's intake as an `integration_reconnect_required` issue. diff --git a/includes/class-contentrain-bridge-integrations.php b/includes/class-contentrain-bridge-integrations.php index 40c76d4..c9d45a9 100644 --- a/includes/class-contentrain-bridge-integrations.php +++ b/includes/class-contentrain-bridge-integrations.php @@ -10,9 +10,10 @@ * a settings option by name, a script loaded from the service's domain, a form * wired to it, or content embedded from it. * - * Credentials never leave. An option's value is read only to answer "is a key - * set?" as a boolean, in memory; what is written is the option's *name*, the - * setting's *name*, a domain, a plugin slug. A migrated site has to connect + * Credentials never leave, and no setting is opened to look for one: a + * credential-named option that is not empty counts as set (the database + * answers that); what is written is the option's *name*, the setting's + * *name*, a domain, a plugin slug. A migrated site has to connect * again with its own credentials, and this is the list of what to connect. */ final class Integrations { diff --git a/readme.txt b/readme.txt index 03853a4..4b64332 100644 --- a/readme.txt +++ b/readme.txt @@ -93,7 +93,7 @@ The plugin stores export ownership and a source revision marker. It sends nothin = 0.8.4 = * Widgets are read through WordPress's own widget registry: each registered widget reads only its own settings. The export no longer lists option names from the database to find widgets, so a widget whose plugin is inactive is not counted or scanned, as WordPress does not show it either. -* Connected services are found by setting names only. A setting whose name marks a credential (key, token, secret) counts as set when it is not empty; the database answers that, and the value is never read. Evidence names the setting ("mc4wp"), not the keys inside it. A form wired to a service (Contact Form 7, WPForms) counts as connected when its account entry exists; the keys inside it are not read. +* Connected services are found by setting names only. A setting whose name marks a credential (key, token, secret) counts as set when it is not empty; the database answers that, and the value is never read. Evidence names the setting ("mc4wp"), not the keys inside it. A form wired to a service (Contact Form 7, WPForms) counts as connected when its account entry exists; the keys inside it are not inspected. = 0.8.3 =