Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the generic control to support post fields #5

Open
6 tasks
bobbingwide opened this issue Jul 10, 2021 · 5 comments
Open
6 tasks

Extend the generic control to support post fields #5

bobbingwide opened this issue Jul 10, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Jul 10, 2021

The [bw_field] and [bw_fields] shortcodes support both post meta fields and fields which are properties of the post.
eg post_date, post_modified.

These are used in Fizzie to display a series of inline fields, see block-template-parts/metadates.html

<p>Published: [bw_field post_date] | Last updated: [bw_field post_modified] [post-edit]</p>

I could use the same solution in Written, but think it would be better to have a block based solution.

Options are:

  • use the post-date block for the first field
  • develop a post-modified-date block for the other one
  • develop an extension for the post-date block to display post modified date
  • extend the sb-field-block to support post fields
  • optionally, develop a post-modified-date variation.
  • develop a styling solution that will support inlining the blocks in a group using grid / flex ... as used in FAQs in This Is... See also Implement post-meta-inline template part to display post meta fields in an inline block thisis#27
@bobbingwide bobbingwide self-assigned this Jul 10, 2021
@bobbingwide
Copy link
Owner Author

bobbingwide commented Jul 10, 2021

Which fields are needed?

See also the Gutenberg issue WordPress/gutenberg#22724, which has been Closed even though the work is not complete. Note that the_modified_date was originally going to implemented as part of the Post Date block.

Field Example value Needed?
ID 1332 Nice to have for debugging ( NTHFD )
post_author 1 Yes - converted to the author name
post_date 2020-11-21 20:55:22 Yes. post-date block
post_date_gmt 0000-00-00 00:00:00 Probably not
post_content post content post-content
post_title archive-block post-title block
post_excerpt post excerpt post-excerpt block
post_status auto-draft NTHFD
comment_status closed See Comments blocks?
ping_status closed ?
post_password No
post_name archive-block NTHFD
to_ping ?
pinged ?
post_modified 2020-11-21 20:55:22 Yes. Display as for post-date
post_modified_gmt 0000-00-00 00:00:00 Probably not
post_content_filtered Probably not
post_parent 0 See sb-parent-block
guid https://s.b/wp56/?post_type=wp_template&p=1332 NTHFD
menu_order 0 NTHFD
post_type wp_template See oik-bob-bing-wide oik-fields block
post_mime_type See oik-bob=bing-wide oik-fields block
comment_count 0 See Comments blocks
filter raw Probably not

@bobbingwide
Copy link
Owner Author

Develop a styling solution that will support inlining the blocks in a group using grid / flex

The metadates.html block template part in Written is currently coded as:

<!-- wp:paragraph -->
<p>Published:</p>
<!-- /wp:paragraph -->

<!-- wp:post-date /-->

<!-- wp:paragraph -->
<p>Last updated:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>[bw_field post_modified]</p>
<!-- /wp:paragraph -->

Here's the output from the metadates.html block template part

<div class="wp-block-template-part">
<p>Published:</p>
<div class="wp-block-post-date"><time datetime="2021-07-06T16:23:21+00:00">July 6, 2021</time></div>
<p>Last updated:</p>
<span class="post_modified">July 6, 2021</span>
</div>

@bobbingwide
Copy link
Owner Author

bobbingwide commented Jul 10, 2021

Need to explain why the paragraph tag surrounding the output of the [bw_field post_modified] shortcode has been stripped.

Explanation

It's the shortcode_unautop() function call in gutenberg_render_block_core_template_part() that strips the <p> tag.

I believe this is undesirable processing... a feechur.

I don't imagine I'll experience the problem when the shortcode has been converted to a block. But what about other people expecting to see the paragraph if they use this construct?

@bobbingwide
Copy link
Owner Author

It's the shortcode_unautop() function call in gutenberg_render_block_core_template_part() that strips the <p> tag.
I believe this is undesirable processing... a feechur.

I raised an issue WordPress/gutenberg#33345

@bobbingwide
Copy link
Owner Author

Options are:
develop a post-modified-date block for the other one
extend the sb-field-block to support post fields

I found it easier to extend the Fields block in oik-blocks.

C:\apache\htdocs\wordpress\wp-content\plugins\oik-blocks>git diff blocks\oik-fields
diff --git a/blocks/oik-fields/index.js b/blocks/oik-fields/index.js
index a7a2437..2aada86 100644
--- a/blocks/oik-fields/index.js
+++ b/blocks/oik-fields/index.js
@@ -8,7 +8,7 @@
  * - Not yet aware of the Fields associated with a CPT
  * - Does not require fields to be exposed in the REST API
  *
- * @copyright (C) Copyright Bobbing Wide 2018-2020
+ * @copyright (C) Copyright Bobbing Wide 2018-2021
  * @author Herb Miller @bobbingwide
  */
 //import './style.scss';
@@ -51,6 +51,10 @@ const fieldsOptions =
         "thumbnail": "Thumbnail",
         "googlemap": "Google Maps Map",
         "template": "Page template name",
+        "post_date": "Post date",
+        "post_modified": "Post modified date",
+        //"author": "Author",
+        "author_name": "Author name"
     };

For post_date and post_modified the code change was as simple as adding two new entries in the fieldOptions select list.
The Server Side Rendering logic for the block already used bw_metadata() and there were already implementing functions
bw_theme_field_post_date() and bw_theme_field_post_modified(). Note: oik-blocks is dependent upon oik-fields for this logic.

I needed to write new logic to register the author_name virtual field.
Its callback function bw_fields_get_author_name() is a wrapper to get_the_author().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant