bobbingwide / oik-blocks

WordPress 5.0 blocks for oik shortcodes
https://oik-plugins.com/oik-plugins/oik-blocks
GNU General Public License v3.0
1 stars 0 forks source link

Add new Fields to the Fields block: post_date, post_modified and author_name #45

Open bobbingwide opened 3 years ago

bobbingwide commented 3 years ago

In order to support the metadates.html template in FSE themes such as Written I want to replace existing shortcodes with blocks. I found that the quickest way to implement the solution was to extend the Fields block with a co-requisite improvement to the oik-fields plugin upon which the block is dependent.

See https://github.com/bobbingwide/sb-field-block/issues/5

Requirement

Solution

bobbingwide commented 2 years ago

In the Site editor (beta) the post_id attribute is not passed to the server so the post date, post modified date and post author field values can't be populated.

For the Author block the prefix is displayed, but for post date and post modified we get block rendered as empty. image

This is styled with min-height: 200px , so looks wrong.

In the block editor the post_id query parameter is passed. eg. Block editor for post 1269

context=edit&attributes%5Bfields%5D=post_date&attributes%5Blabels%5D=&post_id=1269&_locale=user

What should we do about this? Simplest thing is to detect a null string being returned in oik_blocks_fields_results() and replace it with the selected field name.

    if( $html === null ) {
        $html = $fields;
    }