You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simpler request data validation for REST endpoints
The Restful class has a new get_params() method that makes it easier to parse and validate request data parameters while also improving the conciseness and readability of your code.
Previously, you might write code like this in order to parse and validate request data:
$data = $this->get_put_data (true);
if (! isset ($data->id)) {
return$this->error ('Missing parameters: id', 400);
}
if (! isset ($data->name)) {
return$this->error ('Missing parameters: name', 400);
}
// etc.
If $data is false, Restful will automatically send an appropriate error response, so you can simply return without having to write any additional error handling logic.
When you pass it an ordinary array, get_params() considers all fields specified to be required, and omits all others. Note that you can still get the full, unvalidated list like this:
$data = $this->get_params ();
However, you can do much more with get_params(), including using booleans to specify required versus optional fields:
This also makes it easier to see the expected parameters and their validation rules all in one place at the top of your endpoint methods, using the same validation rules that forms and models also use.
Custom CSS class selector for content blocks
The blocks editor now provides a way to select and set custom CSS classes on individual blocks via a dropdown menu.
The editor looks for a layouts/your-theme/blocks.css file in your layouts and reads that for custom CSS classes. If not found, it reads all layouts/your-theme/*.css files and parses them for custom CSS classes.
It looks for any CSS class of the form .block-outer.custom-class-name, for example:
It then turns all unique classes found into selectable options in a dropdown list (the above would appear as "Dark Background") so you can offer your site editors more customization options without sacrificing control over the look and feel of your sites.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Elefant 2.2.3 has been released with a number of bug fixes and improvements.
Click here to download or update.
Simpler request data validation for REST endpoints
The Restful class has a new
get_params()
method that makes it easier to parse and validate request data parameters while also improving the conciseness and readability of your code.Previously, you might write code like this in order to parse and validate request data:
Now you can write this to do the same thing:
If
$data
is false, Restful will automatically send an appropriate error response, so you can simply return without having to write any additional error handling logic.When you pass it an ordinary array,
get_params()
considers all fields specified to be required, and omits all others. Note that you can still get the full, unvalidated list like this:However, you can do much more with
get_params()
, including using booleans to specify required versus optional fields:And you can take it one step further by specifying an array of input validations that will be sent to the Validator class like this:
This also makes it easier to see the expected parameters and their validation rules all in one place at the top of your endpoint methods, using the same validation rules that forms and models also use.
Custom CSS class selector for content blocks
The blocks editor now provides a way to select and set custom CSS classes on individual blocks via a dropdown menu.
The editor looks for a
layouts/your-theme/blocks.css
file in your layouts and reads that for custom CSS classes. If not found, it reads alllayouts/your-theme/*.css
files and parses them for custom CSS classes.It looks for any CSS class of the form
.block-outer.custom-class-name
, for example:It then turns all unique classes found into selectable options in a dropdown list (the above would appear as "Dark Background") so you can offer your site editors more customization options without sacrificing control over the look and feel of your sites.
This is especially powerful coupled with other recent improvements to the blocks/group helper.
Other bug fixes and improvements
SameSite=Lax
unlink()
for asynchronous deletions on newer versions of phpredisClick here for the full list of changes.
Beta Was this translation helpful? Give feedback.
All reactions