documenting wordpress plugin creation
even since the days of impossible creatures i like to combine two things and see what will happen, now i am combining two things that i like – creating wordpress plugins and documenting by free writing. lets see what will happen.
the plugin
so, i am gonna build a simple plugin, it will be mostly used in the block editor and its functionality will be as followes:
turn heading blocks into a HTTP URI fragment. with the option to toggle it on or off for each block, and maybe later a global toggle.
the environment
i realy wanted to use wp-env for this, but i ran into problems and didnt want to handle node issues, so i am just using good old localwp.
the scaffold
i realy want to make this plugin in wordpress coding standards, and make it the vanilla way of creating a wp plugin, so i used the trusted wp-cli tool.
wp scaffold plugin head-to-head --prompt
was the line i entered into my terminal and after some prompting from the wp-cli side, i was up-and-running with a new plugin starter kit.
out of the box i got some stuff i dont know or do know but havent used.
- .editorconfig – i know what it is, but didnt got a chance to use yet
- .gitignore – know and using
- gruntfile.js – heard about grunt, i understand what it is but didnt used it. ill probably delete it
- package.json – related to grunt i guess
- .distignore – dont know what this is
- readme.txt – a readme, a long one, i will not use it one
- and ofcourse head-to-head.php which is the main file of the plugin, the only one needed actually
i dont know if using wp scaffold was a good choice, i could have used my AI coder to spit up some wp plugin data and start, but i want to do it "the wordpress way", whatever it is…
the plan
- add filter to the
render_block
hook – to render the <a> tag to wrap the heading - add filter to
registerBlockType
hook – to add attribute to hold the value of the id of the heading
i got stuck
ok great i got stuck, this means i can explore the block editor and dig through the system.
i am trying to get the id attribute in the render_block
php hook. this hook has 3 parameters: the block content, the parsed block, and the block object. in the parsed block i get no attributes at all, in the block object i get only 1 paramter which is "level".
i need to find a way to get the id from the block attributes to the render_block
php hook