Skip to content

REST API returns null for all meta-stored fields on Site and 6 other models #469

Description

@vuckro

Bug Description

The REST API returns null for all meta-stored properties across 7 models. This makes the API unusable for retrieving critical data like customer_id, membership_id, line_items, etc.

Root Cause

Base_Model::to_array() (line 840) uses get_object_vars($this) to serialize models. However, several models use lazy-loaded properties that are fetched from metadata tables only when their getter is called (e.g., get_customer_id() calls $this->get_meta('wu_customer_id')).

Since to_array() never calls these getters, the properties remain null in the serialized JSON response.

Affected Models and Fields

Model Null Fields in API Response
Site customer_id, membership_id, featured_image_id, categories + id returns 0 instead of blog_id
Product featured_image_id, tax_category, contact_us_label, contact_us_link, feature_list, available_addons, legacy_options, pwyw_minimum_amount, pwyw_suggested_amount, pwyw_recurring_mode
Customer has_trialed, extra_information
Payment line_items, invoice_number
Checkout_Form thank_you_page_id, conversion_snippets
Email event, schedule
Broadcast migrated_from_id, notice_type

Note: Discount_Code and Event already override to_array() and are not affected.

Steps to Reproduce

  1. Enable the REST API in Ultimate Multisite settings
  2. Call GET /wp-json/wu/v2/site/{id} with valid API credentials
  3. Observe that customer_id, membership_id, type, active, etc. are all null
  4. Same issue on GET /wp-json/wu/v2/site?domain=example.com

Example API Response (Site)

{
  "id": 0,
  "blog_id": "7",
  "domain": "www.example.com",
  "customer_id": null,
  "membership_id": null,
  "type": null,
  "active": null,
  "template_id": null,
  "featured_image_id": null,
  "categories": null
}

Proposed Fix

Override to_array() in each affected model to call the lazy-loaded getters before calling parent::to_array(). This follows the existing pattern used by Discount_Code and Event models.

I'll submit a PR with the fix shortly.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions