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

Add batch routine to create a block post given block_type_name, title and component #64

Closed
bobbingwide opened this issue Feb 19, 2019 · 6 comments
Assignees

Comments

@bobbingwide
Copy link
Owner

There are over 140 blocks in the first 9 plugins that I want to catalogue. See #61.
Manually creating them takes too long, even with the template for new posts.

Proposed solution

Create a batch routine to generate the posts, setting post_meta, Yoast SEO stuff and so on.
Each block will need editing... but it'll be a kick start.

run from oik-shortcodes/admin

oikwp oik-create-blocks.php oik-block/uk-tides "UK Tides" oik-blocks
@bobbingwide
Copy link
Owner Author

bobbingwide commented Feb 22, 2019

Since there are so many blocks delivered by multiple plugins we need to make it easier to list them.

Requirements

  • There should be a 'Block keywords' taxonomy storing the 3 keywords allowed for each block.
  • The block_keyword taxonomy should also be a field.
  • There should be a Block categories taxonomy to store the Block's Category. Note: Currently only one value is supported by the editor.
  • The block_categories taxonomy should also be a field.
  • These fields can be used to display related blocks.

Proposed solution

Auto population

  • Add another batch routine to set Keywords for each block.

  • Stored in taxonomy called block_keyword.

  • It should also set the block Category, in block_category.

  • The routine can also attempt to update the Yoast SEO stuff

  • Use the first paragraph block for the Yoast SEO Description (yoast_wpseo_metadesc).

  • Set the Yoast Focus Keyphrase ( yoast_wpseo_focuskw) with the Block name followed by ' block'.

  • Change the Blocklist block to create the commands for both create and update.

  • The block create routine could be updated later to do all of these.

  • And/or a filter on the post save could be used to set any missing SEO data.

example.

oikwp oik-create-blocks.php advgb/accordion "Accordion"  url=blocks.wp-a2z.org
oikwp oik-update-blocks.php advgb/accordion "accordion,list,faq" agb url=blocks.wp-a2z.org

@bobbingwide
Copy link
Owner Author

The keyword category is no longer limited to 3 keywords.

@bobbingwide
Copy link
Owner Author

For improved display of the excerpt the more tag should be after the block info tag.

@bobbingwide
Copy link
Owner Author

bobbingwide commented May 31, 2019

The batch routines served their purpose when creating new blocks but were only able to go so far.

  • It was not possible to automatically generate the HTML for the block's icon.
  • It was not possible to automatically generate the block example, notes or screenshot.

I now want to add some PHP server logic that will generate / update the block definition given the block's registration information, including the icon.

Proposed solution

Implement an AJAX request oiksc_create_or_update_block that will be invoked from the Block List block. The PHP logic will combine the functions developed for the batch routine to create or update the definition for a block. When a new block CPT is being created it will create the correct oik-blocks/blockinfo block using the icon which is passed as a serialised string.

Most of the block CPT's fields should be correctly populated. It should then be a case of editing the generated content to create the example(s) and screenshot and adding a link to documentation, if known.

Stage 1 - Prototype

In this first version the AJAX request will be run directly by the user, by right clicking on the link in the block list block and choosing Open link in new window. The output from the AJAX request will be displayed here. This will include a link to edit the post after the create or update has been run.

See bobbingwide/oik-blocks#27 for the changes to the Block list block.

Stage 2 - Reconciliation

The Block List block will assist in the process, providing buttons to perform the required actions, retrieving the results and displaying them accordingly.

@bobbingwide
Copy link
Owner Author

The json_encode() call used to encode attrs needs to include the additional option required in the oik-clone logic. JSON_UNESCAPED_UNICODE... to not encode Unicode characters.
Example being the ellipsis ... which would be converted to /u2026.

How do I get a backslash on this iPad keyboard? Ah. Use the fn key: fn+x

@bobbingwide
Copy link
Owner Author

The original batch routine have been superceded by the AJAX method. This method sometimes fails when the block icon's SVG is enormous. The workaround is to edit the request to remove the icon and run it again. The issue was released in v1.35.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant