close
Skip to content

fix: restore date-type meta generation (missing Chronos import)#209

Merged
bordoni merged 1 commit into
mainfrom
fix/meta-type-date-chronos-fatal
May 22, 2026
Merged

fix: restore date-type meta generation (missing Chronos import)#209
bordoni merged 1 commit into
mainfrom
fix/meta-type-date-chronos-fatal

Conversation

@bordoni
Copy link
Copy Markdown
Owner

@bordoni bordoni commented May 22, 2026

Summary

  • Adds the missing use FakerPress\ThirdParty\Cake\Chronos\Chronos; to WP_Meta.php, fixing a fatal that hit anyone using a date-type meta rule.
  • Normalises \$settings->taxonomies / \$settings->terms to arrays inside WP_Post::tax_input so the array→stdClass cast does not emit "Undefined property" warnings on sparse configs (visible in the same stack trace under PHP 8.x).
  • Adds focused regression tests (WP_MetaTest, WP_PostTest) and an end-to-end repro in PostsEndpointTest so the next refactor catches this immediately.

Refs wp.org support thread: https://wordpress.org/support/topic/fatal-error-when-using-date-option-in-meta-field-rules/

Why this slipped through

Chronos was added to WP_Post, WP_User, and WP_Comment but the use line was forgotten in WP_Meta. PHP resolved the unqualified Chronos against the file's namespace, fataling with Class "FakerPress\Provider\Chronos" not found. The tax_input warning never crashed locally on older PHP but trips error displays under PHP 8.x with display_errors on.

There was no test that called meta_type_date, which is why the regression shipped.

Test plan

  • slic run wpunit — 69 tests, 228 assertions, all green.
  • Manual: in wp-admin/admin.php?page=fakerpress-posts, add a Meta rule with type "Date", min/max set, click Generate; confirm a post is created and the meta value is a valid datetime string. Confirm debug.log shows no warnings or fatals.
  • composer lint:php against the touched source files — no new violations introduced.

The `meta_type_date` provider referenced `Chronos` without importing it, so
PHP resolved the unqualified name against the current namespace and fataled
with "Class FakerPress\Provider\Chronos not found" the moment any post was
generated with a date-type meta rule.

A secondary "Undefined property: stdClass::$terms" warning surfaced in
WP_Post::tax_input when the config row had no `terms` or `taxonomies` key,
because the array-to-stdClass cast does not synthesize missing properties
under PHP 8.x.

Both defects landed when the providers were ported to Chronos and only
hit users who supplied date meta rules — the rest of the meta types kept
working because they never touch Chronos.

Tests:
- WP_MetaTest covers `meta_type_date` directly and via Faker::format,
  catching the missing import the next time the file is refactored.
- WP_PostTest converts PHP warnings to exceptions while exercising
  `tax_input` with sparse configs, locking in the property normalization.
- PostsEndpointTest gains an end-to-end repro of the user's stack trace.

Refs: https://wordpress.org/support/topic/fatal-error-when-using-date-option-in-meta-field-rules/
@bordoni bordoni added this to the 0.9.1 milestone May 22, 2026
@bordoni bordoni merged commit f2b7c66 into main May 22, 2026
5 of 10 checks passed
bordoni added a commit that referenced this pull request May 22, 2026
Two wp.org regressions land in this patch release:

- #209 — `WP_Meta::meta_type_date` fataled with "Class 'Chronos' not
  found" because the provider file never imported Chronos. Restores
  date-type meta generation and adds a regression test path
  (WP_MetaTest plus an end-to-end REST repro).
- #210 — The Posts generator silently created Posts instead of the
  user-selected type because the admin form's plural `post_types` value
  was overwritten by the singular alias's default of `post`. The schema
  now documents `post_types` as the canonical parameter (array or CSV)
  with `post_type` kept as a deprecated alias.

Plus a PHP 8.x undefined-property warning in `WP_Post::tax_input` and
fresh wpunit coverage that pins both regressions in place.
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