<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Code Amp</title><description>Code Amp builds high-performance search and filtering software, and tools for AI operators and agents.</description><link>https://codeamp.com/</link><item><title>Introducing Operator Kit</title><link>https://codeamp.com/blog/introducing-operator-kit/</link><guid isPermaLink="true">https://codeamp.com/blog/introducing-operator-kit/</guid><description>Operator Kit is our new home for tools that help people and teams work with AI agents. The first two, Help Scout CLI and Dash CLI, are available now.</description><pubDate>Fri, 07 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We’ve launched &lt;a href=&quot;https://operatorkit.ai&quot;&gt;Operator Kit&lt;/a&gt;, a new site for the AI tools we’re building at Code Amp.&lt;/p&gt;
&lt;p&gt;Most of our work so far has been in WordPress, through &lt;a href=&quot;https://searchandfilter.com/&quot;&gt;Search &amp;amp; Filter&lt;/a&gt;, and that carries on as before. But more of our own day is now spent working alongside AI agents, and we’ve been building tools to make that work easier. Operator Kit gives those tools a home of their own, separate from our WordPress products.&lt;/p&gt;
&lt;p&gt;It’s aimed at operators: the people and teams who hand real work to AI agents such as Claude, and stay responsible for the result. Our motto for the site is “Handcrafted, with AI”. AI helps us build these tools, and each one gets the same care we’d give anything we made by hand.&lt;/p&gt;
&lt;h2 id=&quot;available-now&quot;&gt;Available now&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://operatorkit.ai/tools/helpscout-cli&quot;&gt;Help Scout CLI&lt;/a&gt;&lt;/strong&gt; lets your AI agent work in Help Scout. It can read conversations, write replies, manage tags, and do most of what you’d do in Help Scout yourself. It also redacts personal information, such as customer names and email addresses, before the data reaches your agent.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://operatorkit.ai/tools/dash-cli&quot;&gt;Dash CLI&lt;/a&gt;&lt;/strong&gt; gives you shortcuts for the terminal. If you spend your day on the command line, you can run long or fiddly commands in a couple of keystrokes, and stop mistyping them.&lt;/p&gt;
&lt;p&gt;Both are open source.&lt;/p&gt;
&lt;h2 id=&quot;whats-next&quot;&gt;What’s next&lt;/h2&gt;
&lt;p&gt;There are bigger projects on the way, and we’ll write about them properly soon. If you work with AI agents, &lt;a href=&quot;https://operatorkit.ai&quot;&gt;sign up on the site&lt;/a&gt; to hear when new tools are released.&lt;/p&gt;
&lt;p&gt;Operator Kit is still a work in progress, so we’d like to know what you think. &lt;a href=&quot;https://codeamp.com/contact/&quot;&gt;Get in touch&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>AI</category></item><item><title>Using PHP namespaces in WordPress plugins + creating an autoloader</title><link>https://codeamp.com/blog/using-php-namespaces-in-wordpress-plugins-creating-an-autoloader/</link><guid isPermaLink="true">https://codeamp.com/blog/using-php-namespaces-in-wordpress-plugins-creating-an-autoloader/</guid><description>I&apos;ve been working on upgrading one of my WordPress plugins – Search &amp; Filter for some time now, quite the overhaul you might say… When planning this update…</description><pubDate>Thu, 19 Aug 2021 10:27:48 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://codeamp.com/_astro/wp-autoload-namespace-1.WZDb_FvR_rn4Qo.webp&quot; alt=&quot;&quot; width=&quot;899&quot; height=&quot;495&quot;&gt;&lt;/p&gt;&lt;p&gt;I’ve been working on upgrading one of my WordPress plugins – Search &amp;amp; Filter for some time now, quite the overhaul you might say…&lt;/p&gt;
&lt;p&gt;When planning this update there were a bunch of things &lt;em&gt;I knew&lt;/em&gt; I needed to implement. I won’t bore you with all the details, but two tasks I wanted to tick off were:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use PHP namespaces&lt;/li&gt;
&lt;li&gt;Setup an autoloader&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;php-namespaces&quot;&gt;PHP namespaces&lt;/h2&gt;
&lt;p&gt;The plugin is getting quite big, and having everything as a class with a unique name was getting a bit messy.&lt;/p&gt;
&lt;p&gt;PHP namespaces solve this issue perfectly as you can scope your classes and then you only need to worry about the uniqueness of your top-level namespace (uniqueness is important in WP plugins in order to avoid conflicts with other plugins).&lt;/p&gt;
&lt;p&gt;This also lends itself very nicely to consistent project structure because you will likely nest your files in directories matching your namespaces – everything becomes more predictable and uniform.&lt;/p&gt;
&lt;h2 id=&quot;php-autoloader&quot;&gt;PHP autoloader&lt;/h2&gt;
&lt;p&gt;When PHP applications grow in size, rather than having to &lt;code&gt;require&lt;/code&gt; every other &lt;code&gt;.php&lt;/code&gt; file in a long list (or by some other method) it’s good practice to automatically load them.&lt;/p&gt;
&lt;p&gt;As long as your application has a predictable structure (namespace and class names), you don’t need to specify which files to load because we can predict where the relevant file is for a particular class (more on that later).&lt;/p&gt;
&lt;p&gt;What’s also great about autoloaders is they only load files at the last minute – when a class is used – giving your application a lighter memory footprint.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;These two concepts absolutely go hand in hand.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;wordpress-enters-the-room&quot;&gt;WordPress enters the room…&lt;/h2&gt;
&lt;p&gt;Ok, so we know from the above that if our plugin is going to grow that we’re going to want to use both namespaces and an autoloader.&lt;/p&gt;
&lt;p&gt;And if we’re good developers, we also want to follow the &lt;a href=&quot;https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/&quot;&gt;WordPress coding standards&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Coding standards are a good thing and often in the life of a developer, we’ll find conflicting scenarios where we might want to use one set of standards or the other.&lt;/p&gt;
&lt;p&gt;The problem here is, while &lt;a href=&quot;https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/&quot;&gt;WordPress coding standards&lt;/a&gt; cover a lot they don’t mention anything about namespaces.&lt;/p&gt;
&lt;p&gt;I’ve read a few articles similar to this on ways to use autoloading with WordPress like &lt;a href=&quot;https://www.smashingmagazine.com/2015/05/how-to-use-autoloading-and-a-plugin-container-in-wordpress-plugins/&quot;&gt;this one&lt;/a&gt; and &lt;a href=&quot;https://awhitepixel.com/blog/autoloader-namespaces-theme-plugin/&quot;&gt;this one&lt;/a&gt; – and I’m going to share my take on a possible setup.&lt;/p&gt;
&lt;p&gt;There is no mention of namespaces in the docs which leaves this wide open to interpretation and using our best guess – this post is my best guess as to what I think the WordPress way could be.&lt;/p&gt;
&lt;h2 id=&quot;wordpress-php-coding-standards&quot;&gt;WordPress PHP Coding Standards&lt;/h2&gt;
&lt;p&gt;In the &lt;a href=&quot;https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions&quot;&gt;naming conventions&lt;/a&gt;, it’s stated that class names should be cased like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;My_Class&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that they should have a corresponding filename something like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;class-my-class.php&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The class name is lowercased, underscores are hyphenated and the filename is prepended with &lt;code&gt;class-&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;So far so good.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;plugin-development-best-practises&quot;&gt;Plugin Development Best Practises&lt;/h3&gt;
&lt;p&gt;There is a &lt;a href=&quot;https://developer.wordpress.org/plugins/plugin-basics/best-practices/&quot;&gt;section in the best practises&lt;/a&gt; which is hugely important:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Prefix everything!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When a site can have hundreds of plugins, the only way our code won’t be messed with is if we prefix everything (including class names).&lt;/p&gt;
&lt;p&gt;You might want to go with a simple abbreviation prefix, eg, if your plugin was called &lt;code&gt;Speed Up&lt;/code&gt;, you could use &lt;code&gt;SU_My_Class&lt;/code&gt; but in my opinion (and in the examples) the full name is better, so in theory, the ideal class name would be:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speed_Up_My_Class&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;It’s already getting ugly, but it is necessary.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This would ideally be in a file:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;class-speed-up-my-class.php&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;switching-to-namespaces&quot;&gt;Switching to namespaces&lt;/h2&gt;
&lt;p&gt;When structuring a plugin like this it is common to find yourself with tons of files starting with &lt;code&gt;class-speed-up-... .php&lt;/code&gt; – to me it’s ugly, but it’s necessary because it accurately represents the class name, which has been prefixed too &lt;code&gt;Speed_Up_...&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If we switch to namespaces we can alleviate some of this pain and repetition:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;namespace&lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt; Speed_Up&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt; My_Class&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The great thing here is, now &lt;code&gt;My_Class&lt;/code&gt; lives inside the &lt;code&gt;Speed_Up&lt;/code&gt; namespace, we don’t need to worry about prefixing it with &lt;code&gt;Speed_Up&lt;/code&gt; again. By using a namespace, we’ve kind of prefixed everything inside of it automatically and it won’t conflict with other plugins.&lt;/p&gt;
&lt;p&gt;This is how we would use the class now:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;$my_class &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; \Speed_Up\My_Class&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So I think there is not much complexity in this process – just start using them and drop the plugin prefix from all your class names (and filenames) – to be honest I think it’s keeping in line with the spirit of &lt;strong&gt;prefix everything&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;*Also – I haven’t mentioned it explicitly – in my opinion, the naming convention of the namespace should match that of a class, with underscores separating words with initial capital letters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A quick note about namespaces&lt;/strong&gt; – they support nesting! So you can keep adding names spaces and sub-levels to improve your code organisation – eg:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speed_Up&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frontend&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scripts&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Register&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;setting-up-the-autoloader&quot;&gt;Setting up the autoloader&lt;/h2&gt;
&lt;p&gt;Now we’ve got the namespace out of the way let’s head back to the autoloader.&lt;/p&gt;
&lt;p&gt;There are a few ways to setup autoloaders (each with its own unique benefits) &lt;em&gt;which I’m not going to get into right now&lt;/em&gt; – I’m going to go for the easiest and most straightforward method while also keeping things in the spirit of the WordPress coding standards.&lt;/p&gt;
&lt;p&gt;Setting one up requires using &lt;a href=&quot;https://www.php.net/manual/en/language.oop5.autoload.php&quot;&gt;built-in PHP features&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To implement this in a plugin would require adding some code at the top of your plugins main &lt;code&gt;php&lt;/code&gt; file – if we’re sticking with the name &lt;code&gt;speed-up&lt;/code&gt; then it would be located:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;wp-content/plugins/speed-up/speed-up.php&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;We could also create a new file &lt;code&gt;autoload.php&lt;/code&gt; in the root directory to store our autoloader – which is something you’ll probably see quite often when reading up on the subject. *&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If we add the first example from the PHP docs:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ($class_name) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    include&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $class_name &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;.php&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we’ll be all set to go! Well, kind of.&lt;/p&gt;
&lt;p&gt;What this code does is register a callback to be used, to specify which filename/path we should look in order to find a class.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Roughly how it works:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When a class is first used, eg: &lt;code&gt;$my_class = new My_Class()&lt;/code&gt; and it is not yet loaded, the function we passed to &lt;code&gt;spl_autoload_register&lt;/code&gt; will be run to try to resolve the filename for the class.&lt;/p&gt;
&lt;p&gt;It is passed in the &lt;code&gt;$class_name&lt;/code&gt;, and then you can see the file is loaded via &lt;code&gt;include&lt;/code&gt;. In the example above, based on the class name the file&lt;/p&gt;
&lt;p&gt;&lt;code&gt;My_Class.php&lt;/code&gt; would attempt to be loaded.&lt;/p&gt;
&lt;p&gt;Also, something worth observing, when a class is used in a namespace, the full namespace + class name is passed through &lt;code&gt;$class_name&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;writing-an-autoloader-for-a-wordpress-plugin&quot;&gt;Writing an autoloader for a WordPress plugin&lt;/h3&gt;
&lt;p&gt;So let’s apply the coding standards to the autoloader and calculate the correct file path based on namespace and class name.&lt;/p&gt;
&lt;p&gt;What we want to achieve:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Class filenames must be prefixed with &lt;code&gt;class-&lt;/code&gt;…&lt;/li&gt;
&lt;li&gt;Class filenames should be lowercase&lt;/li&gt;
&lt;li&gt;Underscores should be replaced with dashes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And we’re going to convert namespaces. Classes belonging to a namespace should live in a folder (namespace name) that follows the conversion process of a class. So we need to add:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Namespace names will be converted to lowercase&lt;/li&gt;
&lt;li&gt;Namespace names will have underscores replaced with dashes&lt;/li&gt;
&lt;li&gt;Namespaces will be folders so convert &lt;code&gt;\&lt;/code&gt; to a directory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In addition – because the root plugin folder “is the plugin” and already has a directory name relevant to the plugin name, eg – &lt;code&gt;speed-up&lt;/code&gt; we shouldn’t create another folder called &lt;code&gt;speed-up&lt;/code&gt; just to match our &lt;code&gt;Speed_Up&lt;/code&gt; plugin namespace, it’s unnecessarily repetitive and we’ll actually remove that, and instead, we’ll create a folder called &lt;code&gt;includes&lt;/code&gt; for our classes instead.&lt;/p&gt;
&lt;p&gt;So our plugin structure would look like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;speed-up // top-level plugin folder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-- speed-up.php // main plugin file&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-- readme.txt // required with every plugin&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;-- includes // this folder is where we store all our classes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;---- database // folder for the sub namespace Database&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;------ class-connect.php // class Connect&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;       class-worker.php // class Worker&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The class &lt;code&gt;Worker&lt;/code&gt; in &lt;code&gt;includes\database\class-worker.php&lt;/code&gt; above would be accessed like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speed_Up&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Database&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Worker&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For me, this is the perfect balance of adding namespaces to WordPress plugins while keeping in the spirit of the coding standards.&lt;/p&gt;
&lt;h3 id=&quot;the-code&quot;&gt;The code&lt;/h3&gt;
&lt;p&gt;To parse the name space and class names, and follow those above conversion rules (class name -&amp;gt; path + filename) would result in some PHP code like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;// Define the main autoloader&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;speed_up_autoloader&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; speed_up_autoloader&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $class_name ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    // These should be changed for your particular plugin requirements&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    $parent_namespace &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Speed_Up&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    $classes_subfolder &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;includes&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; !==&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; strpos&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $class_name, $parent_namespace ) ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $classes_dir &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; realpath&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;plugin_dir_path&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ) ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DIRECTORY_SEPARATOR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $classes_subfolder &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DIRECTORY_SEPARATOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        // Project namespace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $project_namespace &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $parent_namespace &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $length &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; strlen&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $project_namespace );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        // Remove top-level namespace (that is the current dir)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $class_file &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; substr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $class_name, $length );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        // Swap underscores for dashes and lowercase&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $class_file &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; str_replace&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;_&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;-&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;strtolower&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $class_file ) );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        // Prepend `class-` to the filename (last class part)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $class_parts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; explode&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, $class_file );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $last_index &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $class_parts ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $class_parts[ $last_index ] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;class-&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $class_parts[ $last_index ];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        // Join everything back together and add the file extension&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $class_file &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; implode&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DIRECTORY_SEPARATOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, $class_parts ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;.php&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        $location &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $classes_dir &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $class_file;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; is_file&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $location ) ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        require_once&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $location;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I’ve also setup a tiny demo plugin using the above for you to play with over on GitHub:&lt;br&gt;
&lt;a href=&quot;https://github.com/rmorse/speed-up&quot;&gt;Github Repo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you want to read more articles like this you can &lt;a href=&quot;https://x.com/rossmorsali&quot;&gt;follow me on X&lt;/a&gt; to keep up to date.&lt;/p&gt;
</content:encoded><category>PHP</category><category>Plugins</category><category>WordPress</category></item><item><title>Update: Custom Layouts 1.3.0</title><link>https://codeamp.com/blog/update-custom-layouts-1-3-0/</link><guid isPermaLink="true">https://codeamp.com/blog/update-custom-layouts-1-3-0/</guid><description>This one is a bit of a special release. While previous versions have mostly revolved around improving the admin UI and workflow, this release aims to add…</description><pubDate>Tue, 16 Mar 2021 09:37:42 GMT</pubDate><content:encoded>&lt;p&gt;This one is a bit of a special release.&lt;/p&gt;
&lt;p&gt;While previous versions have mostly revolved around improving the admin UI and workflow, this release aims to add features that open up a ton of options for creating dynamic templates.&lt;/p&gt;
&lt;p&gt;The driving force behind all this you &lt;em&gt;(didn’t)&lt;/em&gt; ask?&lt;/p&gt;
&lt;h2 id=&quot;new-template-elements&quot;&gt;New template elements&lt;/h2&gt;
&lt;h3 id=&quot;1-custom-field&quot;&gt;1. Custom Field&lt;/h3&gt;
&lt;p&gt;&lt;img alt=&quot;Custom Field Element Insepctor&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;263&quot; height=&quot;371&quot; src=&quot;https://codeamp.com/_astro/image-1.DUl62B5F_Z1lBqKD.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;This supports native WordPress Custom Fields and has 3 formatting options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Text&lt;/strong&gt; – display the Custom Field as is, or restrict its length by number of words / characters, add a custom ellipsis.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Number&lt;/strong&gt; – format to number of decimal places (up to 4), choose custom comma and period characters for i18n&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Date&lt;/strong&gt; – Dates can be formatted according to a few preset options as well as allowing custom formatting&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We also wanted to put a bit of extra effort into making this control easy to use – so we’ve opted to use a customised autocomplete control for choosing your custom field key – that means you can copy and paste your custom field names (for power users), but you’ll also get a suggestion box to help you choose your custom field more easily.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Advanced Custom Fields&lt;/strong&gt; + &lt;strong&gt;Pods&lt;/strong&gt; users – custom fields for both plugins are supported, but currently these are only single value custom fields (ie, where a custom field has a string, date or numeric value). We will be improving integration with this (I’m looking at you relationship + repeater fields 👀) – &lt;em&gt;for now, you can always use their respective shortcodes in our new text element.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;2-taxonomy&quot;&gt;2. Taxonomy&lt;/h3&gt;
&lt;p&gt;This one we wanted to ship with release, but it proved to be a bit more tricky to implement.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;263&quot; height=&quot;346&quot; src=&quot;https://codeamp.com/_astro/image-2.BobkrVQG_Z2n7QdA.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can now select any taxonomy, or combination of taxonomies and then merge the terms together as one list – you can use multiple taxonomy elements in a template and seperate them out. There are also design controls for the individual taxonomy terms – so you can completely customise the look and feel of this element.&lt;/p&gt;
&lt;h3 id=&quot;3-text&quot;&gt;3. Text&lt;/h3&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;263&quot; height=&quot;240&quot; src=&quot;https://codeamp.com/_astro/image-3.CQKZ3arp_2mlPU5.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;Well this is a simple one, its a plain text box to enter text… ahem… and it’s not even Rich Text (that’s coming)… But what makes this powerful is it also supports shortcodes.&lt;/p&gt;
&lt;p&gt;This means you can hook in &lt;strong&gt;any shortcode&lt;/strong&gt; here and start extending.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;275&quot; height=&quot;472&quot; src=&quot;https://codeamp.com/_astro/image-4.VASDkSfV_ZnW0Om.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;An example using Custom Field, Taxonomy + Text Elements&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-css-units--better-at-responsive&quot;&gt;More CSS units / better at responsive&lt;/h2&gt;
&lt;p&gt;We’ve upgraded some admin controls to use the &lt;a href=&quot;https://developer.wordpress.org/block-editor/reference-guides/components/box-control/&quot;&gt;Gutenberg BoxControl Component&lt;/a&gt;. This means, for &lt;strong&gt;margin&lt;/strong&gt;, &lt;strong&gt;padding&lt;/strong&gt; and &lt;strong&gt;border radius&lt;/strong&gt;, across all elements, you can now use additional CSS unit types, independently for each value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;px&lt;/li&gt;
&lt;li&gt;%&lt;/li&gt;
&lt;li&gt;rem&lt;/li&gt;
&lt;li&gt;vh&lt;/li&gt;
&lt;li&gt;vw&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This opens up a ton of design possibilities and allows for better responsive designs – we finally have scalable units.&lt;/p&gt;
&lt;h2 id=&quot;toolbar-button--full-width--auto-width&quot;&gt;Toolbar Button – Full width / auto width&lt;/h2&gt;
&lt;p&gt;We’ve added a new toolbar button for most element types. This sets the container width to wrap around the content, or to fill the available width of the template – you will see the effect on any elements that have a background color applied.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;550&quot; height=&quot;337&quot; src=&quot;https://codeamp.com/_astro/cl-width-mode.CmvShyR9_Z2x5CTp.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;That’s it for now – I think we’ve covered the main changes in version 1.3.0.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://wordpress.org/plugins/custom-layouts/#developers&quot;&gt;View the full Changelog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://wordpress.org/plugins/custom-layouts/&quot;&gt;Get the Custom Layouts plugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://codeamp.com/blog/creating-the-custom-layouts-plugin/&quot;&gt;Article: Creating the Custom Layouts Plugin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-would-you-like-to-see-next&quot;&gt;What would you like to see next?&lt;/h2&gt;
&lt;p&gt;Some ideas floating around at the moment:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Website, demos, docs (these are coming very soon)&lt;/li&gt;
&lt;li&gt;Modernise the admin UI (don’t use classic post meta boxes when editing templates)&lt;/li&gt;
&lt;li&gt;Onboarding – make it easier to understand how everything works together (welcome screen?)&lt;/li&gt;
&lt;li&gt;Make our Template Elements available as blocks for FSE&lt;/li&gt;
&lt;li&gt;Make Blocks available in our Template Editor&lt;/li&gt;
&lt;li&gt;Elements for rows + columns&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All the things on the roadmap:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Improve performance and load speed by providing an option to use CSS Grid for layouts + masonry&lt;/li&gt;
&lt;li&gt;Support additional CSS unit types in more places&lt;/li&gt;
&lt;li&gt;Elements for WooCommerce&lt;/li&gt;
&lt;li&gt;Elements for ACF&lt;/li&gt;
&lt;li&gt;More layout elements (possibly use the block library)&lt;/li&gt;
&lt;li&gt;Additional hover options&lt;/li&gt;
&lt;li&gt;Additional font options – either Google fonts or the Gutenberg api which looks like it’s coming soon&lt;/li&gt;
&lt;li&gt;Social/sharing elements&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Gutenberg</category><category>Plugins</category><category>WordPress</category></item><item><title>A Gutenberg MultiSelect component</title><link>https://codeamp.com/blog/a-gutenberg-multiselect-component/</link><guid isPermaLink="true">https://codeamp.com/blog/a-gutenberg-multiselect-component/</guid><description>This is a little adaptation of the FormTokenField found in Gutenberg core. Working on the Custom Layouts plugin, I needed a multiselect for it&apos;s layout block…</description><pubDate>Wed, 27 Jan 2021 11:50:29 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;277&quot; height=&quot;161&quot; src=&quot;https://codeamp.com/_astro/token-multi-select-control.CBGUrPFz_ZxlXeF.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is a little adaptation of the &lt;code&gt;FormTokenField&lt;/code&gt; found in Gutenberg core.&lt;/p&gt;
&lt;p&gt;Working on the &lt;a href=&quot;https://wordpress.org/plugins/custom-layouts/&quot;&gt;Custom Layouts&lt;/a&gt; plugin, I needed a multiselect for it’s layout block and editor options.&lt;/p&gt;
&lt;p&gt;There are some cool controls already in Gutenberg for selecting a page, or choosing tags, but they are not actual multiselect – that is, a set of options presented to the user to choose from, and the ability to select multiple (this is just my opinion, not definition…).&lt;/p&gt;
&lt;p&gt;The existing compontents require search/input before displaying options, whereas I wanted to show all options on interaction. While I can see &lt;a href=&quot;https://github.com/WordPress/gutenberg/issues/1044&quot;&gt;it is not planned&lt;/a&gt; to add this into the current components system, I think it will be covered by &lt;a href=&quot;https://g2-components.com/&quot;&gt;G2 Components&lt;/a&gt; – so consider this a filler, until that time.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/rmorse/wp-token-multiselect-control&quot;&gt;You can get the source code here.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I hope you will find it handy – happy coding &lt;em&gt;(and hurry up G2, thanks…)&lt;/em&gt;&lt;/p&gt;
</content:encoded><category>Gutenberg</category><category>Plugins</category><category>WordPress</category></item><item><title>Creating the Custom Layouts plugin</title><link>https://codeamp.com/blog/creating-the-custom-layouts-plugin/</link><guid isPermaLink="true">https://codeamp.com/blog/creating-the-custom-layouts-plugin/</guid><description>So I thought I’d write a post about a project I’ve been working on, a new plugin – Custom Layouts.</description><pubDate>Sun, 03 Jan 2021 18:57:47 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://codeamp.com/_astro/custom-layouts-demo-website-sml.BP8K6NU4_Z27779v.webp&quot; alt=&quot;&quot; width=&quot;730&quot; height=&quot;414&quot;&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;For those interested – this is how and why this plugin came to be. If you’re looking for the docs – they’re being written – link coming soon.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So I thought I’d write a post about a project I’ve been working on, a new plugin – &lt;a href=&quot;https://wordpress.org/plugins/custom-layouts&quot;&gt;Custom Layouts&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The plugin offers some familiar features that you’ve seen before, packaged in themes or available in a myriad of plugins free and paid for.. that is:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The ability to display posts or products, in a list or grid&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So why did I decide to create the same thing that’s been done many times over before? Let’s cover a bit of background.&lt;/p&gt;
&lt;h2 id=&quot;the-background&quot;&gt;The Background&lt;/h2&gt;
&lt;p&gt;This plugin started as a feature idea for another plugin I develop (&lt;a href=&quot;https://searchandfilter.com/&quot;&gt;Search &amp;amp; Filter&lt;/a&gt;). That plugin allows you to create filters on the frontend of your site, so your users can find the content they are looking for.&lt;/p&gt;
&lt;p&gt;Since the early days of developing Search &amp;amp; Filter, our users have been asking us how to customize the results/layouts. Our approach has been to integrate with some of the excellent themes and plugins out there (and for developers, there are plenty of options built-in)…&lt;/p&gt;
&lt;p&gt;But we always found scenarios where our users couldn’t use a provided integration, or didn’t want to buy into a whole ecosystem to customize a layout, &lt;em&gt;or&lt;/em&gt;, wanted to use a plugin that we didn’t yet provide an integration for.&lt;/p&gt;
&lt;p&gt;So it seems the best way to serve our users is to offer these features in some shape or form as a “catch-all”. An option for our users who couldn’t use the other offerings – or even eventually as a preferred option.&lt;/p&gt;
&lt;h2 id=&quot;to-create-a-feature-or-a-new-plugin&quot;&gt;To create a feature or a new plugin?&lt;/h2&gt;
&lt;h3 id=&quot;as-a-set-of-features&quot;&gt;As a set of features&lt;/h3&gt;
&lt;p&gt;Although this where the idea/requirement came from, this option I preferred less.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Having this hidden as a sub-feature of another product is not doing all that functionality and time invested, justice.&lt;/li&gt;
&lt;li&gt;It will add bloat (many people will not need it) to the Search &amp;amp; Filter plugin&lt;/li&gt;
&lt;li&gt;Limited exposure to the existing user base of the filter plugin&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;as-a-plugin&quot;&gt;As a plugin&lt;/h3&gt;
&lt;p&gt;This seemed to be the right direction. If we’re going to build something well, with a decent set of features, then it makes sense to manage it on its own.&lt;/p&gt;
&lt;p&gt;Not only that, but it’s clear there is a huge market for these kinds of plugins. It can stand on its own and there would be plenty of people (I hope) wanting to use this standalone.&lt;/p&gt;
&lt;p&gt;We would then benefit from added traffic/sales to Search &amp;amp; Filter via users of this new plugin – bonus 🙂&lt;/p&gt;
&lt;p&gt;And what about a premium version? For now, this doesn’t interest me. The idea is not to be the most comprehensive offering on the market – or to cater to a niche (good reasons to put a price tag on).&lt;/p&gt;
&lt;p&gt;I like the idea of creating something and giving it away (and let’s be honest, this option still has it’s benefits) – I’ve personally gained so much from the WordPress ecosystem and I’ve given back here and there, but I think this could be a more substantial contribution.&lt;/p&gt;
&lt;h2 id=&quot;requirements&quot;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;So what started out as a feature idea for a premium plugin, turned out to be a fully-fledged project of its own. With this came a new set of requirements and considerations:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Allow users to build highly customized layouts for lists/grids of posts&lt;/li&gt;
&lt;li&gt;Integrate seamlessly with our existing plugin Search &amp;amp; Filter Pro&lt;/li&gt;
&lt;li&gt;Be incredibly easy to use&lt;/li&gt;
&lt;li&gt;Improve on the existing offerings (if we’re going to build something that’s been built many times before, we really should have some good reasons to do so – such as improving features/ease of use is a good enough excuse for me)&lt;/li&gt;
&lt;li&gt;Work well in as many installs/environments as possible (as is the nature of building a plugin for the plugins repo)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;improving-on-existing-solutions&quot;&gt;Improving on existing solutions&lt;/h2&gt;
&lt;p&gt;To be honest there are so many great options and there’s really nothing obvious that stands out. However, I have identified one area I think is a common pain point for most existing solutions – &lt;strong&gt;a cluttered UI&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;problems-with-a-cluttered-ui&quot;&gt;Problems with a cluttered UI&lt;/h3&gt;
&lt;p&gt;In order to offer more features to the user, all solutions must provide more options (generally speaking)… In the era of page builders and WYSIWYG editors, current solutions are in general, fantastic. But many suffer from the same thing – adding hundreds (well maybe not that many) of customization options, in 1 sidebar/panel (ala Gutenberg + Elementor plugins) or adding too many options to the block toolbar.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1298&quot; height=&quot;778&quot; src=&quot;https://codeamp.com/_astro/image.W_FnnP8a_Z1LbFxk.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Posts Block from the WP.com Editing ToolkitSorry Automattic – there’s actually nothing wrong with this… (yet?)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So there are two ways I think most offerings are going: add more features and clutter the UI, or limit features and improve the editing experience (by the way I’m not advocating that more options are always better, but in some use cases you really do want to offer more features but can’t).&lt;/p&gt;
&lt;p&gt;In the example above, I think we’re already reaching a critical point in terms of offering options to the user – there are certainly enough toolbar options, and while the sidebar has been carefully managed to not be too overwhelming, you can easily see that if we want to start adding individual options for things like the post title, author section – then it’s going to start affecting the user experience.&lt;/p&gt;
&lt;p&gt;Anyway, for this particular plugin, I’d rather not choose – I want to offer more options and I want it to be easy to use (I’m demanding)… The good thing is, I think this problem has already been solved for us – in the page builders themselves!&lt;/p&gt;
&lt;p&gt;They are the best examples of increasing complexity + features whilst also improving the user experience.&lt;/p&gt;
&lt;p&gt;So why not bring the “page builder” paradigm one level deeper into this plugin?&lt;/p&gt;
&lt;h3 id=&quot;another-layer-of-abstraction&quot;&gt;Another layer of abstraction&lt;/h3&gt;
&lt;p&gt;In my opinion, there is a clear separation between the list/grid layout and the design of each individual item/result.&lt;/p&gt;
&lt;p&gt;* There has always been a clear separation of these two areas in WordPress itself and may be better known as “the loop” and “template part”.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1641&quot; height=&quot;937&quot; src=&quot;https://codeamp.com/_astro/image-1.BXyGshmG_Zswj7N.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Grid/Layout Vs Post Template&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If we separate the two, we achieve 2 things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A higher degree of customizability with the individual item/template&lt;/li&gt;
&lt;li&gt;Simplify the process of adding a layout/grid/list and declutter this experience&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-solution-separate-the-layout-from-the-post-template&quot;&gt;The solution: separate the layout from the post template&lt;/h3&gt;
&lt;p&gt;That’s it – we should provide a visual page builder type solution to building layouts and templates, but, not together in the same widget/block…&lt;/p&gt;
&lt;p&gt;Cue the Custom Layouts plugin 🙂&lt;/p&gt;
&lt;h2 id=&quot;implemenation--gutenberg&quot;&gt;Implemenation (+ Gutenberg)&lt;/h2&gt;
&lt;p&gt;So there could be a few approaches to create something like this while ticking off the requirements:&lt;/p&gt;
&lt;h3 id=&quot;using-the-block-editor-as-the-foundation&quot;&gt;Using the Block Editor as the foundation&lt;/h3&gt;
&lt;p&gt;I thought about the potential to use Blocks for the layout, and InnerBlocks for the post templates – I’m not 100% that this is the easiest way to do this for user experience – nor is the implementation (as far as I can tell) of InnerBlocks mature enough to build upon – I’d rather wait a little while (and learn a bit more)…&lt;/p&gt;
&lt;p&gt;This option also has the huge caveat of forcing the plugin to be available to Block Editor users only.&lt;/p&gt;
&lt;h3 id=&quot;building-a-custom-solution&quot;&gt;Building a custom solution&lt;/h3&gt;
&lt;p&gt;The way forward I felt is to create something that works well on its own (so it works for everyone) and then from there consider how to integrate that with the block editor for a better user experience/workflow (it’s the future, by the way 😉 ).&lt;/p&gt;
&lt;h3 id=&quot;the-solution&quot;&gt;The solution:&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Regular WordPress CPT’s are registered for layouts + templates&lt;/li&gt;
&lt;li&gt;These CPTs will have custom React Apps for building layouts + templates using a drag and drop interface – we use 90% Gutenberg components for building the UI, so everything looks and feels like WordPress (and so it also works incredibly well)&lt;/li&gt;
&lt;li&gt;Layouts are made available via shortcodes for any WP install so can be placed anywhere&lt;/li&gt;
&lt;li&gt;After this, we tightly integrated our layouts + template editor with the Block Editor by adding a layout block, and linking that with the template editor via a modal, so you never have to leave the editing experience&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;* Block Editor users – one thing I would say, that while offering a modal for the template editor is a pretty cool experience (stops you from navigating away from the editor) – I’m not 100% sold on if that is the best way to achieve this – it’s a work in progress.&lt;/p&gt;
&lt;p&gt;** Also, all modals in the Block Editor are subject to some buggy behaviour – &lt;a href=&quot;https://github.com/WordPress/gutenberg/issues/18755&quot;&gt;the editor captures keyboard shortcuts&lt;/a&gt; and makes changes to the document underneath.&lt;/p&gt;
&lt;h3 id=&quot;benefits&quot;&gt;Benefits&lt;/h3&gt;
&lt;p&gt;So, using this approach now means several things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The layout + template editors are available to all WordPress users no matter your choice of editing experience.&lt;/li&gt;
&lt;li&gt;It’s much easier to change what you want – clicking on the post title to bring up the post title options seems much more natural in the template editor rather than burying the options in a panel in a sidebar of a layout.&lt;/li&gt;
&lt;li&gt;We get to (once again) overload the user with options ^^ – well, hopefully not, but we can offer more “sub-options” (ie options for the post title, featured image, etc) more easily now, and they are less confusing + easier to locate.&lt;/li&gt;
&lt;li&gt;Layouts also become simpler to use – they consist of only a few settings, query-related, layout related, and choosing a post template – gone is the overhead of all those options cluttering the sidebar unless you choose to drill down into it.&lt;/li&gt;
&lt;li&gt;Templates and layouts are re-usable – so you can update the template once and see changes reflected across the site. If you are using the Block Editor, you can create a re-usable block for much the same effect. I do see some cross over functionality here which I’m sure will be refined over time.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So there you have it, the making of, so to speak…&lt;/p&gt;
&lt;h2 id=&quot;after-thoughts&quot;&gt;After thoughts&lt;/h2&gt;
&lt;p&gt;This plugin has essentially been the product of 1.5 years of learning React + Gutenberg – and 4 months building this plugin.&lt;/p&gt;
&lt;p&gt;I have to say, working with Gutenberg and the Block Editor as a developer is a far superior experience to the old paradigm (the classic editor) – the learning curve is definitely greater, but once you get over the hump it seems the future is bright.&lt;/p&gt;
&lt;p&gt;I also love the fact that we don’t actually need to be using the Block Editor to use Gutenberg components – that means we can still build what we want and how we want it (providing we’re using React), whilst keeping the UI in tune with the rest of WordPress.&lt;/p&gt;
&lt;p&gt;Saying that, I have experienced some friction with using Gutenberg components in custom React apps – but I’m assuming that will reduce over time.&lt;/p&gt;
&lt;p&gt;And it look’s like there are already some developments coming with the &lt;a href=&quot;https://g2-components.com/components/&quot;&gt;g2 components&lt;/a&gt; which may resolve some of these pain points – due to better standardization across components.&lt;/p&gt;
&lt;p&gt;Anyway, that’s it for this post – if you’ve made it down here, thanks for reading, and let me know your thoughts 🙂&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://wordpress.org/plugins/custom-layouts&quot;&gt;Get the Custom Layouts plugin from the plugins repo&lt;/a&gt;&lt;/p&gt;
</content:encoded><category>Gutenberg</category><category>Plugins</category><category>WordPress</category></item><item><title>Interacting with Gutenberg&apos;s RichText Component</title><link>https://codeamp.com/blog/interacting-with-gutenbergs-richtext-component-using-a-button/</link><guid isPermaLink="true">https://codeamp.com/blog/interacting-with-gutenbergs-richtext-component-using-a-button/</guid><description>…by inserting a shortcode (using a button). As of the latest WordPress update we all now know about the Gutenberg editor, and whether you love or hate it, it’s…</description><pubDate>Thu, 23 Aug 2018 13:16:44 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://codeamp.com/_astro/gutenberg-insert-shortcode.Jupy-AI2_22TjDs.webp&quot; alt=&quot;&quot; width=&quot;730&quot; height=&quot;237&quot;&gt;&lt;/p&gt;&lt;h2 id=&quot;by-inserting-a-shortcode-using-a-button&quot;&gt;…by inserting a shortcode (using a button).&lt;/h2&gt;
&lt;p&gt;As of the latest WordPress update we all now know about the Gutenberg editor, and whether you love or hate it, it’s here to stay.&lt;/p&gt;
&lt;p&gt;But, as it’s &lt;em&gt;so&lt;/em&gt; new, it means the APIs are still being worked on – which (naturally) means some things are just not possible or documented yet.&lt;/p&gt;
&lt;p&gt;That being said, there are plenty of great resources out there at the moment for creating Gutenberg Blocks.  This post assumes you know how to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a Gutenberg Block Plugin&lt;br&gt;
&lt;em&gt;~ check out &lt;a href=&quot;https://github.com/ahmadawais/create-guten-block&quot;&gt;create-guten-block&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Add Toolbars to Blocks&lt;br&gt;
&lt;em&gt;~ &lt;a href=&quot;https://wordpress.org/gutenberg/handbook/blocks/block-controls-toolbars-and-inspector/&quot;&gt;official docs&lt;/a&gt; have got you covered&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Add the RichText component to a Block&lt;br&gt;
&lt;em&gt;~ check out the &lt;a href=&quot;https://www.youtube.com/watch?v=K3uQa035HTk&quot;&gt;excellent video&lt;/a&gt; by Zac Gordon&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The Problem&lt;/h2&gt;
&lt;p&gt;What if we want to make a word red, or add a shortcode into our RichText Component with a single click? …and how about from a button on the toolbar?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Sure, we can roll our own and create any kind of editor in our block (we have total flexibility to integrate TinyMCE however we want), but surely there’s a way to do it with the built in RichText component… After all its what the core blocks use, and we like doing things the WP way right?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is something that all my googling couldn’t unearth…&lt;/p&gt;
&lt;p&gt;After some days digging around and a lot of hacking at code I’ve found there is indeed a way.&lt;/p&gt;
&lt;h2 id=&quot;the-solution&quot;&gt;The Solution&lt;/h2&gt;
&lt;p&gt;Before we get to that, lets get up and running with some familiar Gutenberg Block code.&lt;/p&gt;
&lt;h3 id=&quot;1--create-a-block-with-richtext-and-blockcontrols-toolbar-components&quot;&gt;1.  Create a Block with RichText and BlockControls (Toolbar) Components&lt;/h3&gt;
&lt;p&gt;This post assumes you already know how to create a Gutenberg Block with a &lt;code&gt;RichText&lt;/code&gt; component. If not, you should familiarise yourself with the resources above.  Your code should look something like this:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://gist.github.com/rmorse/1300421889ec7fbb9217899e61ab703d&quot;&gt;View the Code&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Nothing out of the ordinary – we’re using &lt;code&gt;registerBlockType&lt;/code&gt; to setup our block, adding &lt;code&gt;RichText&lt;/code&gt; and  &lt;code&gt;BlockControls&lt;/code&gt; components to our &lt;code&gt;edit&lt;/code&gt; function, with a couple of functions handling the changes and setting the content.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If you’re using create-guten-block, then replace &lt;code&gt;src/block/block.js&lt;/code&gt; with the above Gist.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;2-accessing-the-editor&quot;&gt;2. Accessing the editor&lt;/h3&gt;
&lt;h4 id=&quot;using-onsetup&quot;&gt;Using `onSetup`&lt;/h4&gt;
&lt;p&gt;Although it’s &lt;a href=&quot;https://github.com/WordPress/gutenberg/tree/master/packages/editor/src/components/rich-text&quot;&gt;not documented&lt;/a&gt; yet we can see &lt;code&gt;onSetup&lt;/code&gt; is a &lt;a href=&quot;https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/rich-text/index.js#L150&quot;&gt;callback we can utilise&lt;/a&gt; which will return a copy of the TinyMCE editor (&lt;code&gt;RichText&lt;/code&gt; components use TinyMCE).  However for me at least this was not the tricky part.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; I’m pretty new to React + ES6 and still getting my head around some of their concepts – which is probably why I found this more difficult to understand than some might.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;My first idea was to setup a callback which receives the TinyMCE editor, and then stores a reference to that in the current object:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; onEditorSetup&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.editor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; editor;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Fail… What’s wrong with this?  …Scope.&lt;/p&gt;
&lt;p&gt;One thing I’ve learnt is, the &lt;code&gt;edit&lt;/code&gt; function is returned for each instance of our block in the post editor view, but the parent object with the &lt;code&gt;edit&lt;/code&gt; function is invoked only once when setting up the block as a block type (should be pretty obvious really, took me a minute).&lt;/p&gt;
&lt;p&gt;This means that anything we want to use in our &lt;code&gt;edit&lt;/code&gt; function, must live only inside the &lt;code&gt;edit&lt;/code&gt; function (pretty much) so that each instance is self contained, and interacts with its own objects…&lt;/p&gt;
&lt;p&gt;Hmm… Where to go from here… where do we store the reference to editor?&lt;/p&gt;
&lt;h4 id=&quot;extending-the-edit-function&quot;&gt;Extending the `edit` function&lt;/h4&gt;
&lt;p&gt;If &lt;code&gt;edit&lt;/code&gt; is a function, then I could see no reliable way to keep track of each instance of our editor and controls. I did think about wrapping RichText in a React Component so I could keep a reference to the editor, within a certain scope, but then realised that I’d run in to the same problem when trying to get the toolbar button to interact with it. It was a bit beyond me.&lt;/p&gt;
&lt;p&gt;Cue examining the Gutenberg source code (again). Sure enough, &lt;a href=&quot;https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/list/index.js&quot;&gt;there is a Gutenberg component that utilises the &lt;code&gt;onSetup&lt;/code&gt; callback&lt;/a&gt; and provides a great example of how to handle this scenario correctly.&lt;/p&gt;
&lt;p&gt;Turns out my thinking was a bit limited, what I needed to understand was that &lt;code&gt;edit&lt;/code&gt; just needs to return a React Component.&lt;/p&gt;
&lt;p&gt;So what they’ve done with the List Component is &lt;a href=&quot;https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/list/index.js#L210&quot;&gt;create a React Component&lt;/a&gt; on &lt;code&gt;edit&lt;/code&gt;, and return the &lt;code&gt;RichText&lt;/code&gt; and all the trimmings together &lt;em&gt;within&lt;/em&gt; the Component, so they can access shared local variables, functions etc.&lt;/p&gt;
&lt;p&gt;Great stuff, this means we can get our button talking to the editor within the same scope.&lt;/p&gt;
&lt;p&gt;Lets see what &lt;code&gt;edit&lt;/code&gt; might look like, using inspiration from the Gutenberg source (check the inline comments):&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;edit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; Component&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    //standard constructor for a component&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    constructor&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        super&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;arguments&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        //make sure we bind `this` to the current component within our callbacks&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.setupEditor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.setupEditor.&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.onChangeContent &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.onChangeContent.&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.state &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;            //we don&apos;t need our component to manage a state in this instance&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    //same as before, except `this` actually references this component&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;    setupEditor&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;editor&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.editor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; editor;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    //no change here again, except the binding of `this`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;    onChangeContent&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;newContent&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.props.&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;setAttributes&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( { content: newContent } );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    //slightly different pattern of syntax here, we&apos;re returning a function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;    onClickShortcodeButton&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;            //the content we want to insert&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            var&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; myContent &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;[myshortcode][/myshortcode]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.editor ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                //execCommand is a TinyMCE function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.editor.&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;execCommand&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;mceInsertContent&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, myContent );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    //all react components require render - this is what will be returned by our component&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;    render&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        const&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            attributes&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            setAttributes&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            className&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.props;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;Fragment&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;BlockControls&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                    controls&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                            icon: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;edit&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                            title: &lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;__&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Insert Shortcode&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                            onClick: &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;onClickShortcodeButton&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    ] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                /&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;RichText&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                    //getSettings={ this.getEditorSettings } //a useful callback for adding params to TinyMCE on setup&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                    onSetup&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.setupEditor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                    key&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;editable&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                    tagName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;p&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                    className&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; className &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                    onChange&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  {&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.onChangeContent &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                    value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; attributes.content&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                /&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;Fragment&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;},&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Remember&lt;/em&gt; &lt;code&gt;edit&lt;/code&gt; &lt;em&gt;is now a React + ES6 Component, so the syntax is fairly standard, but not what you might be used to seeing in a Block.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;What we’ve done here is port everything (our click handlers, return elements) over so that it uses the correct syntax/structure for a React Component.  One thing to note is, if we’re using a React Component it must properly return the Component in the &lt;code&gt;render&lt;/code&gt; method, which looks a lot like the return of our old &lt;code&gt;edit&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;There is one addition though, now that we have &lt;code&gt;this.editor&lt;/code&gt; working within the scope of the Component, I’ve added the final functionality allowing the button to interact with it:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;onClickShortcodeButton&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;	return&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;		&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;		//the content we want to insert&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;		var&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; myContent &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;[myshortcode][/myshortcode]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;		&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;		if&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.editor ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;			//execCommand is a TinyMCE function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;			this&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.editor.&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;execCommand&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;mceInsertContent&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, myContent );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This just updates the click callback to interact with &lt;code&gt;this.editor&lt;/code&gt;, and in this case we wanted to insert a shortcode using &lt;code&gt;execCommand&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And that’s it! Everything should be working together nicely now.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;From here, the world is your oyster – you have access to the TinyMCE editor which means you can now develop the same functionality into your Gutenberg Blocks as we can with the Classic editor.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;NB&lt;/strong&gt; – you’ll notice in the source a commented &lt;code&gt;getSettings&lt;/code&gt; callback, this allows you to modify the settings object that gets passed into TinyMCE when being initialised – might be useful!&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&quot;files&quot;&gt;Files&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/rmorse/insert-shortcode-button-guten-block/blob/master/src/block/block.js&quot;&gt;View the Final Code&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/rmorse/insert-shortcode-button-guten-block&quot;&gt;Code as a CGB (create-guten-block) Plugin&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;There are plenty of possibilities now that we’re able to access TinyMCE in our custom blocks and indeed this will be useful for many right away…&lt;/p&gt;
&lt;p&gt;But I’m sure there are a few others thinking, why do all this now? – what we really want to do is add this kind of functionality to the core blocks…! –  and that’s also my thought process…&lt;/p&gt;
&lt;p&gt;I think in all likelihood when Gutenberg allows us to extend core blocks, they’re going to have to add a way to access the TinyMCE editors within them, much like when we use &lt;code&gt;onSetup&lt;/code&gt; now within our own blocks.&lt;/p&gt;
&lt;p&gt;Hopefully, when the time comes and the APIs get updated, we’ll have code that’s pretty much ready to go and had some testing in the Gutenberg  environment at least.&lt;/p&gt;
&lt;p&gt;That’s all for now – I would love to hear about things that you’ve made as well as any thoughts on the article.&lt;/p&gt;
</content:encoded><category>Gutenberg</category><category>WordPress</category></item><item><title>Designs &amp; Code will be no more… Long live Code Amp</title><link>https://codeamp.com/blog/what-happened-to-designs-code/</link><guid isPermaLink="true">https://codeamp.com/blog/what-happened-to-designs-code/</guid><description>I thought I&apos;d kick off the site with this quick post. A bit of info on what is going on around Designs &amp; Code and Code Amp (short version: we&apos;ve changed name).</description><pubDate>Wed, 22 Aug 2018 15:43:58 GMT</pubDate><content:encoded>&lt;p&gt;I thought I’d kick off the site with this quick post.&lt;/p&gt;
&lt;p&gt;A bit of info on what is going on around &lt;strong&gt;Designs &amp;amp; Code&lt;/strong&gt; and &lt;strong&gt;Code Amp&lt;/strong&gt; (short version: we’ve changed name).&lt;/p&gt;
&lt;p&gt;Essentially, Designs &amp;amp; Code was supposed to be the digital home of the 2 WordPress Plugins I develop.&lt;/p&gt;
&lt;p&gt;Over time things have changed, one of the plugins has it’s own website now – &lt;a href=&quot;https://searchandfilter.com&quot;&gt;searchandfilter.com&lt;/a&gt;, and the other will shortly follow.&lt;/p&gt;
&lt;p&gt;In tandem, while we’ve grown and given our plugins their own homes, I’ve also formed a UK Limited company to handle the business end of our Pro plugins – Code Amp.&lt;/p&gt;
&lt;p&gt;In lieu of the above, Designs &amp;amp; Code will be retired, and rather than have a boring company profile / website here I thought I’d do what I’ve wanted to do for some time – start a tech blog based around coding and WordPress.&lt;/p&gt;
&lt;p&gt;…and there you have it, straight forward really – and just to clarify, nothing else has changed behind the scenes – its still me, Ross, running the shop.&lt;/p&gt;
&lt;p&gt;That’s all for now, my next post on Gutenberg and Blocks is following shortly.&lt;/p&gt;
&lt;p&gt;Over and out.&lt;/p&gt;
</content:encoded><category>General</category></item></channel></rss>