Skip to content

Preserve literal field values and expose saved field data - #3683

Draft
Crabcyborg wants to merge 12 commits into
masterfrom
feat/code-field-storage-hooks
Draft

Crabcyborg wants to merge 12 commits into
masterfrom
feat/code-field-storage-hooks

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Add opt-in filters that preserve literal source bytes during XML import/export and entry metadata retrieval. Pass saved field columns to the field-created and field-updated hooks so add-ons can keep derived data in sync.

  • frm_xml_field_value_is_literal receives a stdClass with string id, field_key and type on both export and import, so a strict check like 'code' === $field->type behaves the same in both directions.
  • Base64 encoded values ignore whitespace and keep the raw text when the value cannot be decoded.
  • frm_should_unslash_entry_meta_value applies to get_entry_meta_by_field(), get_entry_metas_for_field() and getAll(). The field type is only looked up when the filter has a callback.

Companion Pro PR: https://github.com/Strategy11/formidable-pro/pull/6972 (uses field_value_to_xml(), field_value_from_xml() and field_value_xml_attributes() for entry metas).

Testing

  • Literal value tests: 6 tests and 15 assertions passed, including a real SimpleXMLElement field, a forms XML export and import round trip, and the unslash filter on every read path.
  • --filter 'FrmXML|FrmEntryMeta|FrmField|FrmLiteral': 188 tests and 1014 assertions passed.
  • Scoped PHP syntax, PHPCS, Rector, PHP CS Fixer and Mago lint and analysis passed.

Remaining draft validation

Verify the Code Field add-on against the new XML, metadata and field lifecycle hooks.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@deepsource-io

deepsource-io Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in ab4ee48...c3a4045 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Nov 18, 2026 7:50p.m. Review ↗
JavaScript Nov 18, 2026 7:50p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

* @param bool $literal Whether XML must preserve this field's text exactly.
* @param object $field Field configuration, including its type.
*/
return (bool) apply_filters( 'frm_xml_field_value_is_literal', false, $field );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

Comment thread classes/models/FrmEntryMeta.php Outdated
* @param bool $unslash Whether the field value should be unslashed.
* @param string $type Field type.
*/
return apply_filters( 'frm_should_unslash_entry_meta_value', true, $type ) ? wp_unslash( $value ) : $value;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

add_filter( 'frm_xml_field_value_is_literal', '__return_true' );

try {
$this->assertSame( array( 'encoding' => 'base64' ), FrmXMLHelper::field_value_xml_attributes( $field ), 'Literal values declare their encoding.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

try {
$this->assertSame( array( 'encoding' => 'base64' ), FrmXMLHelper::field_value_xml_attributes( $field ), 'Literal values declare their encoding.' );
$xml = simplexml_load_string( '<default_value encoding="base64">' . FrmXMLHelper::field_value_to_xml( $source, $field ) . '</default_value>' );
$this->assertSame( $source, FrmXMLHelper::field_value_from_xml( $xml, $field ), 'Literal source survives an XML round trip.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertSame( array( 'encoding' => 'base64' ), FrmXMLHelper::field_value_xml_attributes( $field ), 'Literal values declare their encoding.' );
$xml = simplexml_load_string( '<default_value encoding="base64">' . FrmXMLHelper::field_value_to_xml( $source, $field ) . '</default_value>' );
$this->assertSame( $source, FrmXMLHelper::field_value_from_xml( $xml, $field ), 'Literal source survives an XML round trip.' );
$this->assertSame( '{"key":1}', FrmXMLHelper::field_value_from_xml( '{"key":1}', $field ), 'Unmarked literal JSON remains text.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


public function test_compound_values_keep_legacy_decoding() {
$field = (object) array( 'type' => 'checkbox' );
$this->assertSame( array(), FrmXMLHelper::field_value_xml_attributes( $field ), 'Existing fields have no encoding marker.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

public function test_compound_values_keep_legacy_decoding() {
$field = (object) array( 'type' => 'checkbox' );
$this->assertSame( array(), FrmXMLHelper::field_value_xml_attributes( $field ), 'Existing fields have no encoding marker.' );
$this->assertSame( array( 'red', 'blue' ), FrmXMLHelper::field_value_from_xml( '["red","blue"]', $field ), 'Existing compound values still decode.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 10, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request Changes on the current head. This is a draft and the PR body says the Code Field add-on validation is still open, so these are early findings. Three need fixing before it is ready; all are inline.

  1. Blocking: on import, frm_xml_field_value_is_literal gets a SimpleXMLElement as $field, but on export it gets a stdClass. Strict checks like 'code' === $field->type match on export and never on import (reproduced).
  2. Blocking: frm_should_unslash_entry_meta_value is only honoured by get_entry_meta_by_field(). get_entry_metas_for_field() still strips backslashes from the same stored value (reproduced).
  3. Should fix: FrmField::get_type() now runs before the entry cache check in get_entry_meta_by_field(), so every cache hit pays for a field lookup that is not always cached.

Also worth a look, non-blocking: invalid base64 on import silently becomes an empty default value, and only default_value is base64-wrapped, so literal text elsewhere on the field (for example description) still goes through cdata().

Tests run: vendor/bin/phpunit tests/phpunit/xml/test_FrmLiteralFieldValues.php at 80de718 → OK (2 tests, 5 assertions). --filter 'FrmXML|FrmEntryMeta|FrmField|FrmLiteral' at 80de718 → OK (184 tests, 1004 assertions). CI did not run PHPUnit, PHPCS or PHPStan here because the PR is a draft, so those local runs are the only execution of the suite. The new tests do not cover the import path with a real SimpleXMLElement field, the forms_xml.php export template, or the entry-meta filter. That is why findings 1 and 2 got through.

}

$value = (string) $value;
return self::field_value_is_literal( $field ) ? $value : FrmAppHelper::maybe_json_decode( $value );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking. field_value_is_literal( $field ) is called with two different types. On export (forms_xml.php) $field is a stdClass with a string type. On import (fill_field() line 618) it is the raw SimpleXMLElement, so $field->type is an object. A listener written the natural way, 'code' === $field->type, returns true on export and false on import.

I reproduced it with a filter that records its argument. Result: [["stdClass", true], ["SimpleXMLElement", false]]. An unmarked <default_value><![CDATA[{"a":1}]]></default_value> on a code field was then JSON-decoded into array('a' => 1) instead of staying a string. The new test hides this because it passes (object) array( 'type' => 'code' ) for both directions.

Fix: normalise before calling the filter so both directions see the same shape, then add a test that feeds field_value_from_xml() a real SimpleXMLElement:

private static function field_value_is_literal( $field ) {
	$field = (object) array(
		'type' => (string) $field->type,
	);
	// Keep any other keys export callers already pass, if needed.
	return (bool) apply_filters( 'frm_xml_field_value_is_literal', false, $field );
}

Separately: when base64_decode( ..., true ) fails (line 2051), the method returns '' with no notice. A truncated or pretty-printed file silently wipes the default value. Strict mode also rejects whitespace inside the CDATA. Strip whitespace first (preg_replace( '/\s+/', '', (string) $value )) and fall back to the raw string rather than '' on failure.

Comment thread classes/models/FrmEntryMeta.php Outdated
* @param bool $unslash Whether the field value should be unslashed.
* @param string $type Field type.
*/
return apply_filters( 'frm_should_unslash_entry_meta_value', true, $type ) ? wp_unslash( $value ) : $value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (scope). Only get_entry_meta_by_field() honours this filter. The other read paths in this class still call wp_unslash unconditionally. I stored C:\temp\new {"a":1} for a field and enabled the filter with __return_false:

  • get_entry_meta_by_field() returned C:\temp\new {"a":1} (correct).
  • get_entry_metas_for_field( $field_id ) returned C:tempnew {"a":1} (backslashes lost, line 440).

So the same literal value reads back differently depending on which API an add-on or Pro view calls. Either apply maybe_unslash_field_value() in get_entry_metas_for_field() and getAll() (both know the field/type or can look it up), or say in the docblock that this opt-out only covers get_entry_meta_by_field() and add a test that pins that scope.

Comment thread classes/models/FrmEntryMeta.php Outdated
*/
public static function get_entry_meta_by_field( $entry_id, $field_id ) {
global $wpdb;
$field_type = FrmField::get_type( $field_id );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix (performance). FrmField::get_type() used to run only on the cache-miss path. Now it runs on every call, including cache hits. get_type() uses the frm_field cache but falls back to a DB query when the field is not cached, and get_entry_meta_by_field() is called per field per entry. The cached-entry fast path now does an extra lookup in cases where it did none before. I traced this from FrmField::get_type(). I did not benchmark it.

Fix: resolve the type lazily, only where it is needed:

if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
	$result = $cached->metas[ $field_id ];
	return self::maybe_unslash_field_value( $result, FrmField::get_type( $field_id ) );
}

and restore $field_type = FrmField::get_type( $field_id ); after the FrmDb::get_var() call, as it was before. Better still, skip the type lookup entirely when nothing is hooked to frm_should_unslash_entry_meta_value (has_filter()), since the default is the old behaviour.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 10, 2026
The frm_xml_field_value_is_literal filter now always receives a stdClass
with string id, field_key and type, so a strict type check matches on
import as it does on export. Base64 values ignore whitespace and keep the
raw text when they cannot be decoded, rather than becoming empty.

frm_should_unslash_entry_meta_value now also applies to
get_entry_metas_for_field() and getAll(). The field type is only looked
up when the filter has a callback, so cached reads do no extra lookup.

Add tests for a real SimpleXMLElement field, the forms XML export and
import round trip, and the unslash filter on every read path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* @param string $type Field type.
* @param int|string $field_id Field ID or key.
*/
return apply_filters( 'frm_should_unslash_entry_meta_value', true, $type, $field_id ) ? wp_unslash( $value ) : $value;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function apply_filters invoked with 4 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

$xml_field = simplexml_load_string(
'<field><id>5</id><field_key>abc</field_key><type><![CDATA[code]]></type><default_value><![CDATA[{"a":1}]]></default_value></field>'
);
$this->assertSame( '{"a":1}', FrmXMLHelper::field_value_from_xml( $xml_field->default_value, $xml_field ), 'A strict type check matches on import.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

remove_filter( 'frm_xml_field_value_is_literal', $filter, 10 );
}

$this->assertSame( array( array( 'stdClass', 'code' ), array( 'stdClass', 'code' ) ), $seen );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$wrapped = chunk_split( base64_encode( $source ), 8, "\n " );
$xml = simplexml_load_string( '<default_value encoding="base64"><![CDATA[' . $wrapped . ']]></default_value>' );
$field = (object) array( 'type' => 'code' );
$this->assertSame( $source, FrmXMLHelper::field_value_from_xml( $xml, $field ), 'Whitespace in the encoded value is ignored.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertSame( $source, FrmXMLHelper::field_value_from_xml( $xml, $field ), 'Whitespace in the encoded value is ignored.' );

$xml = simplexml_load_string( '<default_value encoding="base64"><![CDATA[not base64!]]></default_value>' );
$this->assertSame( 'not base64!', FrmXMLHelper::field_value_from_xml( $xml, $field ), 'Invalid base64 keeps the raw text.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

// FrmField::getOne() unslashes every column, so compare the stored value.
$this->assertSame( $source, FrmDb::get_var( 'frm_fields', array( 'field_key' => $field_key ), 'default_value' ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

add_filter( 'frm_should_unslash_entry_meta_value', '__return_false' );

try {
$this->assertSame( $stored, FrmEntryMeta::get_entry_meta_by_field( $entry_id, $field_id ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


try {
$this->assertSame( $stored, FrmEntryMeta::get_entry_meta_by_field( $entry_id, $field_id ) );
$this->assertSame( array( $stored ), FrmEntryMeta::get_entry_metas_for_field( $field_id ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

'',
true
);
$this->assertSame( $stored, reset( $all )->meta_value );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


FrmEntryMeta::clear_cache();
wp_cache_flush();
$this->assertSame( 'C:tempnew {"a":1}', FrmEntryMeta::get_entry_meta_by_field( $entry_id, $field_id ), 'Without the filter the legacy unslashing is unchanged.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 11, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request Changes on 9fed47ac8. Both blocking findings from the last round are fixed, and the perf finding is fixed too. One new gap in the same area is still open.

Fixed, verified at this head:

  1. Import now hands frm_xml_field_value_is_literal the same stdClass shape as export. The new test covers a real SimpleXMLElement.
  2. frm_should_unslash_entry_meta_value is now honoured by get_entry_meta_by_field(), get_entry_metas_for_field() and getAll().
  3. FrmField::get_type() only runs when something is hooked to that filter, so cache hits are cheap again.
  4. Invalid base64 on import now keeps the raw text instead of wiping the value.

Blocking: FrmEntry::getOne( $id, true ) still strips backslashes when the filter returns false (inline comment on FrmEntryMeta.php). I reproduced this with a throwaway PHPUnit probe that I deleted afterwards: stored C:\temp\new, filter returning false, get_entry_meta_by_field() returned C:\temp\new but getOne( $id, true )->metas[ $field_id ] returned C:tempnew.

Still open, non-blocking: only default_value is base64-wrapped in forms_xml.php, so literal text elsewhere on the field (e.g. description) still goes through cdata(). The @param on the filter docblock in field_value_is_literal() still lists SimpleXMLElement, but the filter now always gets a stdClass.

Not exercised: the Code Field add-on and the companion Pro PR (formidable-pro#6972), which the PR body lists as the remaining draft validation. I did not run an actual XML export and import through the admin UI. The new round-trip test covers that path in PHPUnit. The branch is 14 commits behind master and merges cleanly. CI skipped PHPUnit, PHPCS and PHPStan because the PR is a draft, so the local runs below are the only execution of the suite. The code-review, security-review and simplify skills were not run this round. I re-read the whole diff by hand and found no escaping or security issue (the base64 path adds no new output).

Tests run: vendor/bin/phpunit tests/phpunit/xml/test_FrmLiteralFieldValues.php at 9fed47a → OK (6 tests, 15 assertions). --filter 'FrmXML|FrmEntryMeta|FrmField|FrmLiteral' at 9fed47a → OK (188 tests, 1014 assertions).

* Keep literal source backslashes when a field opts out of legacy unslashing.
*
* Applied by get_entry_meta_by_field(), get_entry_metas_for_field() and getAll()
* so every read path returns the same value for a field. The field type is only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking. The docblock says this filter is applied so "every read path returns the same value for a field", but FrmEntry::getOne( $id, true ) (and FrmEntry::getAll( ..., true ), which uses the same get_meta()) is not covered. FrmEntry::get_meta() collects the values into $entry->metas, and FrmEntry::prepare_entry() (FrmEntry.php:530) then runs wp_unslash( $entry ) over the whole entry object, metas included, without asking this filter. Reproduced at this head with frm_should_unslash_entry_meta_value returning false and a stored value of C:\temp\new:

get_entry_meta_by_field( $entry_id, $field_id )   => 'C:\temp\new'   (literal, as intended)
FrmEntry::getOne( $entry_id, true )->metas[ $f ]  => 'C:tempnew'        (backslashes stripped)

getOne( $id, true ) is the usual way entry values are read for display, editing, emails and exports, so a field that opted out of unslashing still loses its backslashes on the main path. That defeats the point of the filter. Same class of problem as the earlier get_entry_metas_for_field() finding.

Fix: make FrmEntryMeta::maybe_unslash_field_value() callable from FrmEntry (public with an @internal tag, or a small public wrapper), and in FrmEntry::prepare_entry() unslash the entry without its metas, then unslash each meta through it. metas is keyed by field ID (and by field key when frm_include_meta_keys is on), so pass the ID or key as $field_id:

$metas = $entry->metas ?? null;
unset( $entry->metas );
$entry = wp_unslash( $entry );

if ( is_array( $metas ) ) {
	foreach ( $metas as $meta_field_id => $meta_value ) {
		$metas[ $meta_field_id ] = FrmEntryMeta::maybe_unslash_field_value( $meta_value, $meta_field_id );
	}
	$entry->metas = $metas;
}

Note that get_meta() stores the entry in the frm_entry cache before prepare_entry() runs, so cached and uncached reads must go through this same path. Add a test next to test_unslash_filter_applies_to_every_read_path that asserts FrmEntry::getOne( $entry_id, true )->metas[ $field_id ] equals the stored value with the filter returning false, and 'C:tempnew' without it. If you decide getOne() is out of scope instead, correct this docblock and the PR body so they do not say "every read path", and say so in the companion Pro PR.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 11, 2026

try {
$this->assertSame( $stored, FrmEntryMeta::get_entry_meta_by_field( $entry_id, $field_id ) );
$this->assertSame( $stored, FrmEntry::getOne( $entry_id, true )->metas[ $field_id ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

try {
$this->assertSame( $stored, FrmEntryMeta::get_entry_meta_by_field( $entry_id, $field_id ) );
$this->assertSame( $stored, FrmEntry::getOne( $entry_id, true )->metas[ $field_id ] );
$this->assertSame( $stored, FrmEntry::getOne( $entry_id, true )->metas[ $field_id ], 'Cached entries preserve literal values too.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertSame( $stored, FrmEntry::getOne( $entry_id, true )->metas[ $field_id ] );
$this->assertSame( $stored, FrmEntry::getOne( $entry_id, true )->metas[ $field_id ], 'Cached entries preserve literal values too.' );
$entries = FrmEntry::getAll( array( 'it.id' => $entry_id ), '', '', true );
$this->assertSame( $stored, reset( $entries )->metas[ $field_id ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


// FrmField::getOne() unslashes every column, so compare the stored value.
foreach ( array( 'default_value', 'name', 'description' ) as $column ) {
$this->assertSame( $source, FrmDb::get_var( 'frm_fields', array( 'field_key' => $field_key ), $column ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

try {
wp_cache_flush();
$field_key = FrmField::get_key_by_id( $field_id );
$this->assertSame( $stored, FrmEntry::getOne( $entry_id, true )->metas[ $field_key ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


FrmEntryMeta::clear_cache();
wp_cache_flush();
$this->assertSame( 'C:tempnew {"a":1}', FrmEntry::getOne( $entry_id, true )->metas[ $field_id ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

@franky-the-going-merry franky-the-going-merry Bot added franky-working Franky is actively reviewing this and removed franky-working Franky is actively reviewing this labels Nov 11, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 613fc28e1. The blocking finding from my last round is fixed, and the open non-blocking notes are mostly closed. Still a draft; the Code Field add-on side is not exercised here.

Fixed, verified at this head:

  1. FrmEntry::getOne( $id, true ), FrmEntry::getAll( ..., true ) and the cached path now honour frm_should_unslash_entry_meta_value (field id and field key entries both). The new assertions in test_unslash_filter_applies_to_every_read_path cover id, key, cache and the no-filter legacy case. With FrmEntry.php reverted to master that test fails.
  2. description and name on a literal field are now base64-wrapped on export and decoded on import (my earlier non-blocking note). The round-trip test checks all three columns; with the description decode reverted it fails.

Non-blocking:

  • The @param on the filter docblock in FrmXMLHelper::field_value_is_literal() still says object|SimpleXMLElement, but the filter always gets a stdClass now. Change it to stdClass.
  • With a callback hooked to frm_should_unslash_entry_meta_value, FrmEntry::prepare_entry() now calls FrmField::get_type() once per meta per entry. It is cache-backed, so I expect it to be cheap, but I did not measure it on a large entry list.
  • prepare_entry() drops $entry->metas if it is set to something that is not an array. get_meta() and getAll() always set an array, so I could not reach it.

Tests run: vendor/bin/phpunit -c phpunit9.xml tests/phpunit/xml/test_FrmLiteralFieldValues.php at 613fc28 → OK (6 tests, 22 assertions). --filter 'FrmXML|FrmEntry|FrmField|FrmLiteral' at 613fc28 → OK (196 tests, 1085 assertions). Run in the wordpress-develop harness on PHP 8.4. CI skipped PHPUnit, PHPCS and PHPStan because this is a draft, so these local runs are the only execution of the suite.

Not run: PHPCS (the repo's custom sniff package is missing here) and PHPStan. The Code Field add-on and the companion Pro PR (formidable-pro#6972). An actual XML export and import through the admin UI, since the PHPUnit round trip covers that path. The code-review, security-review and simplify skills were not run this round; I re-read the whole delta by hand and the new name/description output goes through array_to_html_params() and base64, so I found no escaping issue.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 11, 2026
@franky-the-going-merry franky-the-going-merry Bot removed the franky-working Franky is actively reviewing this label Nov 12, 2026
);
$args = array( &$entry );
$this->run_private_method( array( 'FrmEntry', 'prepare_entry' ), $args );
$this->assertSame( 'C:temp', $entry->metas, 'Legacy non-array metas should still be unslashed and preserved.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 12, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 94b6cc9a2, with two non-blocking notes. My last Approve was at 26fa59902; I re-read the whole PR (6 files; it merges cleanly into current master, 38 commits behind), not just the new commit. Still a draft; the Code Field add-on side is not exercised here.

What changed since 26fa59902: one commit in FrmEntry::prepare_entry(). If $entry->metas is set but is not an array, it is now kept (and unslashed) instead of being dropped. That closes my earlier note 2.

  • Probed prepare_entry() with metas absent (no property added), null (stays null), a string C:\temp (becomes C:temp, as before), an array (unslashed per field) and an int (kept).
  • The new test test_prepare_entry_preserves_non_array_meta_values fails with Undefined property: stdClass::$metas when I put the previous FrmEntry.php back, so it guards the change.

Notes (non-blocking)

  1. tests/phpunit/xml/test_FrmLiteralFieldValues.php: the new test method has no blank line before it (PHPCS would flag it).
  2. With a callback hooked to frm_should_unslash_entry_meta_value, prepare_entry() calls FrmField::get_type() once per meta per entry. It is cache-backed and only runs when the filter is hooked, but I have not measured it on a large entry list. Unchanged from my last round.

Tests run at 94b6cc9a2 (wordpress-develop harness, PHP 8.4, PR copied in place of the plugin with vendor copied; CI skips PHPUnit on this draft):

  • vendor/bin/phpunit tests/phpunit/xml/test_FrmLiteralFieldValues.php -> OK (7 tests, 23 assertions).
  • --filter 'FrmXML|FrmEntry|FrmField|FrmLiteral' -> OK (197 tests, 1086 assertions).
  • php -l classes/models/FrmEntry.php -> no syntax errors.

Not exercised: the Code Field add-on and the companion Pro PR (formidable-pro#6972), an actual XML export and import through the admin UI (the PHPUnit round trip covers that path), any live site or page, PHPCS and PHPStan, and the code-review/security-review/simplify skills (the delta is one small branch plus a test, read in full; the rest of the diff was re-read by hand and I found no escaping or security issue).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 12, 2026
Crabcyborg and others added 2 commits November 16, 2026 10:42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 16, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 5faa144, with one non-blocking note still open. Re-review of the whole PR; my last Approve was at 94b6cc9a2. Still a draft, and CI skips PHPUnit, so only what I ran is covered.

What changed: the author's one commit (41aa582ec) adds the blank line before the new test, closing my note 1. The rest is two merges of master; the PR's own diff is still 6 files, +366/-15, and it merges cleanly.

Note (non-blocking, unchanged): with a callback hooked to frm_should_unslash_entry_meta_value, prepare_entry() calls FrmField::get_type() once per meta per entry. It is cache-backed and only runs when the filter is hooked; I have not measured it on a large entry list.

Tests run at 5faa144 (wordpress-develop harness, PHP 8.4, PR tree copied in place of the plugin with vendor copied):

  • phpunit -c phpunit9.xml tests/phpunit/xml/test_FrmLiteralFieldValues.php → OK (7 tests, 23 assertions).
  • --filter 'FrmXML|FrmEntry|FrmField|FrmLiteral' → OK (210 tests, 1173 assertions).
  • php -l on the 5 changed PHP files → no syntax errors.

Not run: the probes and old-file mutation checks from my earlier rounds (the PR's code is unchanged apart from a blank line), PHPCS/PHPStan, code-review/security-review/simplify (no code delta), and the Code Field add-on side. Visual check not exercised: no UI change.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 16, 2026
When frm_should_unslash_entry_meta_value is hooked, prepare_entries()
now shares a field type map across entries, so FrmField::get_type()
runs once per field instead of once per meta per entry. Add a test
that getAll() passes the right type for every meta across entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
remove_filter( 'frm_should_unslash_entry_meta_value', $filter );
}

$this->assertCount( 3, $entries );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertCount()


The method you are trying to call is not defined, which can result in a fatal error.

}

$this->assertCount( 3, $entries );
$this->assertCount( 6, $seen, 'The filter runs once per meta per entry.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertCount()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertCount( 6, $seen, 'The filter runs once per meta per entry.' );

foreach ( $seen as $call ) {
$this->assertSame( array_search( $call[0], $field_ids, true ), $call[1], 'Each meta gets its own field type, including from the shared lookup.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

foreach ( $entries as $entry ) {
$this->assertSame( 'C:text', $entry->metas[ $field_ids['text'] ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.


foreach ( $entries as $entry ) {
$this->assertSame( 'C:text', $entry->metas[ $field_ids['text'] ] );
$this->assertSame( 'C:\\textarea', $entry->metas[ $field_ids['textarea'] ] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmLiteralFieldValues::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 17, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 1ca077410. My last Approve was at 5faa144; I re-read the whole PR (6 files, merges cleanly into current master), not just the new commit. Still a draft; the Code Field add-on side is not exercised here.

What changed since 5faa144: one commit, 1ca077410, in FrmEntry::prepare_entry() / prepare_entries(). Field types are now looked up once per entry list in a shared $field_types array and passed to maybe_unslash_field_value( $value, $field_id, $type ), and only when frm_should_unslash_entry_meta_value has a callback. That closes my last open note (a FrmField::get_type() call per meta per entry). The cache is keyed by the meta key as it appears on the entry (ID or field key), so an ID and a key never share a slot.

Verified at this head

  • The new test_get_all_passes_each_field_type_to_unslash_filter runs getAll() over 3 entries and 2 field types: the filter fires 6 times, each call gets its own field's type, textarea keeps C:\textarea and text unslashes to C:text.
  • Mutation: I changed the shared lookup to always return "text" (checked with cmp that it applied). The new test fails on the textarea call (expected textarea, got text). Original restored.

Tests run at 1ca077410 (wordpress-develop harness, PHP 8.4, PR tree copied in place of the plugin with vendor copied; CI skips PHPUnit on this draft):

  • phpunit -c phpunit9.xml tests/phpunit/xml/test_FrmLiteralFieldValues.php → OK (8 tests, 37 assertions).
  • --filter 'FrmXML|FrmEntry|FrmField|FrmLiteral' → OK (211 tests, 1187 assertions).
  • php -l classes/models/FrmEntry.php → no syntax errors.

Not run: the Code Field add-on and the companion Pro PR (formidable-pro#6972), an actual XML export and import through the admin UI (the PHPUnit round trip covers that path), PHPCS/PHPStan, and code-review/security-review/simplify (the delta is a lookup cache plus a test, read in full; the rest of the diff is unchanged from my earlier rounds). I did not measure the filter-hooked path on a large entry list, but it now does one lookup per field per list. DeepSource's PHP check is red; I did not open its findings. No UI change, so no visual check.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 17, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 17, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve on ca5ada3, nothing outstanding. Re-review of the whole PR (6 files, +453/-17). My last Approve was at 1ca077410. The only change since is a merge of master. The merge was clean (git show --remerge-diff is empty), and the PR's added and removed lines against master are identical to the ones at 1ca077410. My earlier reads, probes and mutation checks on the PR's code still stand. Still a draft; the Code Field add-on side is not exercised here.

Tests run at ca5ada3 (wordpress-develop harness, PHP 8.4, PR tree copied in place of the plugin with vendor copied; original restored afterwards; CI skips PHPUnit on this draft, so these runs are the only execution):

  • phpunit -c phpunit9.xml tests/phpunit/xml/test_FrmLiteralFieldValues.php → OK (8 tests, 37 assertions).
  • --filter 'FrmXML|FrmEntry|FrmField|FrmLiteral' → OK (222 tests, 1229 assertions).
  • php -l on the 5 changed PHP files → no syntax errors.

Not run: the mutation check on the field-type lookup from last round (the PR's code is unchanged), the Code Field add-on and the companion Pro PR (formidable-pro#6972, which I re-approved on its own head today and ran against this head), an XML export and import through the admin UI, PHPCS/PHPStan, and code-review/security-review/simplify (merge-only delta). DeepSource's PHP check is red; I did not open its findings. No UI change, so no visual check.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant