I have an object of random structure and a schedule. The schedule defines standard values and – of course – the structure of the objects.
What I want to do is validate the object and recursively process the nodes by calling a function for each node that should get the node (for example, an array in an object) and the node schedule (standard values, etc. After checking for validity)
WordPress uses schedules: https://developer.wordpress.org/news/2024/07/json-schema-in-wordpress/
But do I have to reinvent the wheel for that or is what I am trying to do with WPS -INBUUWED Functionality?
I have seen some JSON scheme -implementations as these: https://github.com/opis/json-schema
But they don’t have a callback methods to process the junction. So, if you have an object and a schedule in WordPress, how would you process it to get standard values of the schedule?
To make this a little clearer:
If my object has a ‘test’ feature with an array with a key ‘key’ with a value-zero, my invoice with that array must be called if Null is a valid value and the array and the schedule node must be given.
An example RDF/A, this is the actual output of what I have coded so far:
<div vocab="https://schema.org/" typeof="Organization">
<h1 property="name ">Hoffmann Dental Manufaktur GmbH</h1>
<address property="address" typeof="PostalAddress">
<span property="streetAddress ">Komturstraße 58-62</span>,
<span property="postalCode ">12099</span>
<span property="addressLocality ">Berlin</span>,
<span property="addressCountry ">Germany</span>
</address>
<div property="contactPoint" typeof="ContactPoint">
<span property="telephone ">☏: +49 30 820099-0</span>
<span property="faxNumber ">?: +49 30 820099-29</span>
<a property="email href="mailto:info@hoffmann-dental.com"">info@hoffmann-dental.com</a>
</div>
<div property="contactPoint" typeof="ContactPoint">
<h2 property="contactType ">Werksverkauf / Factory sales</h2>
<span property="telephone ">☏: +49 30 820099-15</span>
<span property="hoursAvailable" typeof="OpeningHoursSpecification">
<span property="dayOfWeek ">Mo-Fr</span>
<time property="opens" content="00:08:00">08:00</time>
<time property="closes" content="00:16:00">16:00</time>
</span>
</div>
</div>
This is the schedule that I use for this:
$schema = [
'type'=> 'object',
'typeof'=> 'Organization',
'vocab'=> 'https://schema.org/',
'properties'=> [
'title'=> [
'type'=> 'string',
'default'=> 'Acme GmbH',
'description'=> 'Title',
'alias'=> 'name'
],
'address'=> [
'$ref'=> '#/$defs/address'
],
'contacts'=> [
'type'=> 'array',
'items' => [
'$ref'=> '#/$defs/contactPoint'
]
],
],
'$defs'=> [
'address'=> [
'type'=> 'object',
'typeof'=> 'PostalAddress',
'tag'=> 'address',
'properties'=> [
'streetAddress'=> [
'type'=> 'string',
'default'=> 'Am Acker 1-15',
'description'=> 'Street address'
],
'postalCode'=> [
'type'=> 'string',
'default'=> '12345',
'description'=> 'Postal code'
],
'addressLocality'=> [
'type'=> 'string',
'default'=> 'Berlin',
'description'=> 'City / Village'
],
'addressCountry'=> [
'type'=> 'string',
'default'=> 'Germany',
'description'=> 'Country'
]
]
],
'contactPoint' => [
'type'=> 'object',
'typeof'=> 'ContactPoint',
'properties'=> [
'contactType'=> [
'type'=> 'string',
'default'=> 'General Manager',
'description'=> 'Contact Type'
],
'telephone'=> [
'type'=> 'string',
'default'=> '+49 30 1234567-0',
'description'=> 'Telephone'
],
'faxNumber'=> [
'type'=> 'string',
'default'=> '+49 30 1234567-9',
'description'=> 'Fax Number'
],
'email'=> [
'type'=> 'string',
'default'=> 'a@bc.org',
'description'=> 'Email',
'tag'=> 'a'
],
]
]
]
];
The copy has everything, of the object, the schedule offers the data structure and all VOCAB, Typeof- and Property characteristics. I already have this active with a basic set of JSON scheme without advanced functions.
I just don’t want to do the wheel again.
#WordPress #follow #object #recursively #schedule

