Skip to content

filters_index

Polmonite edited this page Sep 21, 2019 · 1 revision

Filters

A Filter actually can be any function globally accessible. It doesn't need to be registered or hooked. Also as a lot of php functions have fucked-up names, this collection of filters is useful to try and standardize their names and arguments.

Filters are attached to a Malini\Post through the addFilter or addFilters methods. They are defined through simple strings, like:

$a_malini_post->addFilters([
    'id'        => 'string',
    'title'     => 'trim'
]);

More filters can be defined, dividing them through a pipe, like:

$a_malini_post->addFilters([
    'id'        => 'string|hash',
    'title'     => 'string|trim|slug'
]);

Filters may also have arguments; they are defined by adding a colon after the filter name and dividing them by commas, like:

$a_malini_post->addFilters([
    'created_at'    => 'format_date:Y-m-d',
    'excerpt'       => 'string|trim|truncate:300'
]);

If a list of filters needs more complex arguments, you can pass them as an array of array; just remember that the array elements will be used in the order they are passed respectively as the filter name and arguments, like:

$a_malini_post->addFilters([
    'content'    => [
        [ 'replace', '<!-- wp:paragraph -->', '' ]
    ]
]);

Other

Extend Malini

  • Create your own Accessor
  • Create your own Decorator
  • Available Extensions
    • Malini\Aeria
    • Malini\YOAST
    • Malini\ACF
Clone this wiki locally