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
- Enable the REST API in Ultimate Multisite settings
- Call
GET /wp-json/wu/v2/site/{id} with valid API credentials
- Observe that
customer_id, membership_id, type, active, etc. are all null
- 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.
Bug Description
The REST API returns
nullfor all meta-stored properties across 7 models. This makes the API unusable for retrieving critical data likecustomer_id,membership_id,line_items, etc.Root Cause
Base_Model::to_array()(line 840) usesget_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 remainnullin the serialized JSON response.Affected Models and Fields
customer_id,membership_id,featured_image_id,categories+idreturns0instead ofblog_idfeatured_image_id,tax_category,contact_us_label,contact_us_link,feature_list,available_addons,legacy_options,pwyw_minimum_amount,pwyw_suggested_amount,pwyw_recurring_modehas_trialed,extra_informationline_items,invoice_numberthank_you_page_id,conversion_snippetsevent,schedulemigrated_from_id,notice_typeNote:
Discount_CodeandEventalready overrideto_array()and are not affected.Steps to Reproduce
GET /wp-json/wu/v2/site/{id}with valid API credentialscustomer_id,membership_id,type,active, etc. are allnullGET /wp-json/wu/v2/site?domain=example.comExample 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 callingparent::to_array(). This follows the existing pattern used byDiscount_CodeandEventmodels.I'll submit a PR with the fix shortly.