<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>rm.codes</title><description>Software development, music and animation</description><link>https://rm.codes/</link><item><title>Data loading in React based WordPress admin pages</title><link>https://rm.codes/blog/data-loading-in-react-based-wordpress-admin-pages/</link><guid isPermaLink="true">https://rm.codes/blog/data-loading-in-react-based-wordpress-admin-pages/</guid><description>I saw a twitter discussion recently that got me thinking. When building plugins with custom admin pages, one of the more modern approaches is to build them in React, and re-use the Gutenberg component library for building out the UI so we get a nice native-feeling experience. I’m all for this and doing it in…</description><pubDate>Wed, 31 Jul 2024 10:19:53 GMT</pubDate><content:encoded>&lt;p&gt;I saw a twitter discussion recently that got me thinking.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is really helpful, thanks! I’ve been using wp_localize_script() to pass the data from PHP to React. Is this bad?&lt;/p&gt;
&lt;p&gt;— James Koussertari (@jkoussertari) &lt;a href=&quot;https://x.com/jkoussertari/status/1818316943981691071?ref_src=twsrc%5Etfw&quot;&gt;July 30, 2024&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When building plugins with custom admin pages, one of the more modern approaches is to build them in React, and re-use the &lt;a href=&quot;https://developer.wordpress.org/block-editor/reference-guides/components/&quot;&gt;Gutenberg component library&lt;/a&gt; for building out the UI so we get a nice native-feeling experience.&lt;/p&gt;
&lt;p&gt;I’m all for this and doing it in all the plugins I’m working on at the moment, the upcoming version of &lt;a href=&quot;https://searchandfilter.com/&quot;&gt;Search &amp;amp; Filter&lt;/a&gt; heavily leverages this.&lt;/p&gt;
&lt;p&gt;The discussion then turned to, “how to pass data from PHP to React” – I’ll be sharing my approach and answer to that question below.&lt;/p&gt;
&lt;h2 id=&quot;whats-wrong-with-wp_localize_script-&quot;&gt;Whats wrong with &lt;code&gt;wp_localize_script()&lt;/code&gt; ?&lt;/h2&gt;
&lt;p&gt;Well, nothing at all. It’s a great way to attach JavaScript variables to your script or application and it’s been used forever across WordPress, and it’s &lt;a href=&quot;https://developer.wordpress.org/reference/functions/wp_localize_script/#comment-1301&quot;&gt;relatively straight forward to use&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;90% of the tutorials out there will show you this technique and I have nothing against it.&lt;/p&gt;
&lt;p&gt;The only limitation is that it is loaded on page load, before your JavaScript is run, so the data is not interactive in anyway.&lt;/p&gt;
&lt;p&gt;This leads me on to what I think is a better approach when building admin pages using React.&lt;/p&gt;
&lt;h2 id=&quot;react-and-the-wordpressdata-package&quot;&gt;React and the &lt;code&gt;@wordpress/data&lt;/code&gt; package&lt;/h2&gt;
&lt;p&gt;I’m assuming in this post you are already using React for your custom admin pages (or have started to), and you’re familiar with the &lt;a href=&quot;https://developer.wordpress.org/rest-api/&quot;&gt;REST API&lt;/a&gt; as a way to fetch data.&lt;/p&gt;
&lt;p&gt;Now that’s out of the way, its worth mentioning (quite briefly) that one of the best ways to interact with the REST API in a WordPress based React application is via the &lt;code&gt;@wordpress/data&lt;/code&gt; package.&lt;/p&gt;
&lt;p&gt;Working with custom stores for your own REST API endpoints is complex in its own right and I’m not going to be able to explain it here quickly or succinctly, I’ll leave that to people before me who have already done it well.&lt;/p&gt;
&lt;p&gt;One of my favorite and more technical introductions on the &lt;code&gt;@wordpress/data&lt;/code&gt; package is &lt;a href=&quot;https://unfoldingneurons.com/2020/wordpress-data-series-overview-and-introduction&quot;&gt;this series from Darren Ethier&lt;/a&gt; (a la WooCommerce) – it’s a little out dated but it does go in quite deep and most of it still works correctly – it has certainly helped me out!&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.wordpress.org/block-editor/reference-guides/packages/packages-data/&quot;&gt;The official documentation&lt;/a&gt; has also improved and gives a good working example via their shop example at the above link.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If anyone has any better resources I’d be happy to include them here, just let me know.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To summarise my thoughts on this: the WordPress &lt;code&gt;@wordpress/data&lt;/code&gt; package is the official WordPress supported way of interacting with data and the REST API in your React applications, and while it’s quite complex and has a learning curve, the rewards are well worth it in my opinion.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;But there is one caveat when using this on custom admin pages&lt;/strong&gt;, but first I’ll get to why we shouldn’t use it…&lt;/p&gt;
&lt;h2 id=&quot;when-shouldnt-we-use-wordpressdata&quot;&gt;When shouldn’t we use &lt;code&gt;@wordpress/data&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;I think the data package and it’s learning curve can be complete overkill for some use cases.&lt;/p&gt;
&lt;p&gt;If your admin screens are not very interactive, or don’t need to use Ajax or the REST API, then I would recommend preloading your data and pass it into your app as a JavaScript object via &lt;code&gt;wp_localize_script()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;However, if you need interactivity, are using data that needs to be saved and updated, or doing anything with the classic &lt;a href=&quot;https://developer.wordpress.org/plugins/javascript/ajax/&quot;&gt;WordPress Ajax&lt;/a&gt; hooks (&lt;code&gt;wp_ajax_...&lt;/code&gt;) then I would recommend to start using the newer data package.&lt;/p&gt;
&lt;h2 id=&quot;back-to-the-caveat-what-if-we-want-data-on-page-load&quot;&gt;Back to the caveat: what if we want data on page load&lt;/h2&gt;
&lt;p&gt;Unlike &lt;code&gt;wp_localize_script()&lt;/code&gt; , using the data package doesn’t inject data into your application on page load.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First your JavaScript application needs to initialize&lt;/li&gt;
&lt;li&gt;Then a request is made the a REST API endpoint&lt;/li&gt;
&lt;li&gt;Then we need to wait for the response to get our data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;No one likes looking at loading icons after loading a page, its frustrating for everyone.&lt;/p&gt;
&lt;p&gt;A possible solution could be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;wp_localize_script()&lt;/code&gt; for the initial data&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;@wordpress/data&lt;/code&gt; for the rest&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I’m not a fan of this approach, I’ve tried it and have some thoughts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What happens if the data you fetch via the REST API collides with the data you preloaded? Work arounds could be made but things can get messy quickly.&lt;/li&gt;
&lt;li&gt;Why does an application need multiple methods of handling data? One streamlined API for everything would be ideal.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Surely there has got to be a better approach?!&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;preloading-our-rest-api-endpoints&quot;&gt;Preloading our REST API endpoints&lt;/h3&gt;
&lt;p&gt;If we could preload specific REST API endpoints on page load, then we wouldn’t need to have multiple methods of injecting data in our application.&lt;/p&gt;
&lt;p&gt;Fortunately, taking a browse through WordPress core gives us all the information we need to achieve this today.&lt;/p&gt;
&lt;p&gt;The block editor is already using the preloading REST API endpoints technique extensively, I first discovered this via the hook &lt;code&gt;block_editor_rest_api_preload&lt;/code&gt; which allows you to add your own endpoints for preloading requests in the block editor.&lt;/p&gt;
&lt;p&gt;Without this we’d be staring at loading icons forever whenever we want to edit a post or page.&lt;/p&gt;
&lt;p&gt;The secret sauce for how this all works is in the WordPress core function &lt;code&gt;block_editor_rest_api_preload()&lt;/code&gt; found in &lt;code&gt;wp-includes\block-editor.php&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;While it’s probably entirely possible to re-use this function “as is” on your own admin screen there are a couple of issues I have with it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you use this function on your admin screens, other plugins hooking into &lt;code&gt;block_editor_rest_api_preload&lt;/code&gt; will load their assets and endpoints, probably not what you need or expected.&lt;/li&gt;
&lt;li&gt;The second argument to the function is &lt;code&gt;$block_editor_context&lt;/code&gt;, and while I don’t understand it fully, it references things like &lt;code&gt;$block_editor_context-&amp;gt;post&lt;/code&gt; , and I’m not dealing with posts on my admin screens, so I think this is just not meant for use in custom admin screens.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;creating-a-new-preload-function-for-custom-admin-screens&quot;&gt;Creating a new preload function for custom admin screens&lt;/h3&gt;
&lt;p&gt;Taking the above code from core, and stripping out everything that does not seem relevant for my use case, I’ve come up with this function:&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;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; * Preload the API requests.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; $preload_paths The paths to preload.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&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; rmcodes_preload_api_requests&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $preload_paths ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	/* Copied from core and modified - wp-includes/block-editor.php */&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;	// Restore the global $post as it was before API preloading.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	// Preload common data.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;	global&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $post, $wp_scripts, $wp_styles, $post_id;&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;	/*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	* Ensure the global $post, $wp_scripts, and $wp_styles remain the same after&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	* API data is preloaded.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	* Because API preloading can call the_content and other filters, plugins&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	* can unexpectedly modify the global $post or enqueue assets which are not&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	* intended for the block editor.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$backup_global_post &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; empty&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $post ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; clone&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $post &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $post;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$backup_wp_scripts  &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; empty&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $wp_scripts ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; clone&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $wp_scripts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $wp_scripts;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$backup_wp_styles   &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; empty&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $wp_styles ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; clone&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $wp_styles &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $wp_styles;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$backup_post_id     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $post_id;&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;	$preload_data &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; array_reduce&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;		$preload_paths,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;		&apos;rest_preload_api_request&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:#6CB6FF&quot;&gt;		array&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;	//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$post &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $backup_global_post;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$wp_scripts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $backup_wp_scripts;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$wp_styles &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $backup_wp_styles;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$post_id &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $backup_post_id;&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:#DCBDFB&quot;&gt;	wp_add_inline_script&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:#96D0FF&quot;&gt;		&apos;wp-api-fetch&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:#6CB6FF&quot;&gt;		sprintf&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:#96D0FF&quot;&gt;			&apos;wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );&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:#DCBDFB&quot;&gt;			wp_json_encode&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $preload_data )&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:#96D0FF&quot;&gt;		&apos;after&apos;&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:#DCBDFB&quot;&gt;	wp_add_inline_script&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:#96D0FF&quot;&gt;		&apos;wp-api-fetch&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:#96D0FF&quot;&gt;		&apos;window.apiResult =  &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; wp_json_encode&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $preload_data ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;		&apos;after&apos;&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;And I use this in the &lt;code&gt;admin_enqueue_scripts&lt;/code&gt; hook:&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;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; * Preload REST API endpoint.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; $hook Hook suffix for the current admin page.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&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; rmcodes_enqueue_admin_script&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;	// Don&apos;t load it on every admin screen (!), check and return early...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	// The REST API paths to preload.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;	$preload_paths &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; array&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:#96D0FF&quot;&gt;		&apos;/rm-codes/v1/admin/data&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:#96D0FF&quot;&gt;		&apos;/rm-codes/v1/admin/pages&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:#96D0FF&quot;&gt;		&apos;/rm-codes/v1/another-endpoint&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:#ADBAC7&quot;&gt;	&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;	rmcodes_preload_api_requests&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $preload_paths );&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:#DCBDFB&quot;&gt;add_action&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;admin_enqueue_scripts&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rmcodes_enqueue_admin_script&apos;&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;And that’s it! Now you can preload your own REST API endpoints on your admin screens, streamlining the flow of your data when using the &lt;code&gt;@wordpress/data&lt;/code&gt; package.&lt;/p&gt;
&lt;h3 id=&quot;you-can-use-apifetch-without-the-data-package&quot;&gt;You can use &lt;code&gt;apiFetch&lt;/code&gt; without the data package&lt;/h3&gt;
&lt;p&gt;That’s right, you don’t actually need to use &lt;code&gt;@wordpress/data&lt;/code&gt; at all…&lt;/p&gt;
&lt;p&gt;This approach short circuits the WordPress &lt;code&gt;apiFetch()&lt;/code&gt; javascript function, which means any type of data fetching via the REST API with WordPress’ &lt;code&gt;apiFetch&lt;/code&gt; should be compatible.&lt;/p&gt;
&lt;p&gt;It is still recommened to use a store of some kind rather than running &lt;code&gt;apiFetch&lt;/code&gt; in your components, data fetching and management shouldn’t really be done in a components &lt;code&gt;useEffect&lt;/code&gt; hook.&lt;/p&gt;
&lt;h2 id=&quot;further-thoughts&quot;&gt;Further thoughts&lt;/h2&gt;
&lt;p&gt;It would be great if WordPress could provide a base function like this, a possible name could be &lt;code&gt;wp_rest_api_preload()&lt;/code&gt; which passes in the current admin screen as an argument, for developers to tap into. This function could then be reused for things like the block editor and the &lt;code&gt;block_editor_rest_api_preload()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;It’s clearly becoming more and more common for developers to use React for custom admin screens and giving a nice integrated way to do this would be a big help.&lt;/p&gt;
&lt;p&gt;If you have any alternative approaches or thoughts I’m keen to hear them!&lt;/p&gt;
</content:encoded><category>Block Editor</category><category>Plugin development</category><category>WordPress</category></item><item><title>WCEU Torino – a first timers experience</title><link>https://rm.codes/blog/wceu-torino-a-first-timers-experience/</link><guid isPermaLink="true">https://rm.codes/blog/wceu-torino-a-first-timers-experience/</guid><description>So it seems to be the thing to do a write up after a WordCamp experience. I hope I’m not adding noise to the already great articles I’ve read out there, I thought it would be a good idea to do a small write up from a first timers perspective. While I’ve been “in” the…</description><pubDate>Tue, 25 Jun 2024 10:26:49 GMT</pubDate><content:encoded>&lt;p&gt;So it seems to be the thing to do a write up after a WordCamp experience. I hope I’m not adding noise to the already great articles I’ve read out there, I thought it would be a good idea to do a small write up from a first timers perspective.&lt;/p&gt;
&lt;p&gt;While I’ve been “in” the WordPress community for over a decade, I’ve really not been very active, or visible (classic developer mindset?).&lt;/p&gt;
&lt;p&gt;So this all changed when I decided to attend WCEU, as a necessary part of growth on a personal level, but also on a business level – I wanted to get my name and face out there as well as my brand and while this kind of thing has traditionally been out of my comfort zone it was time to change things up a bit. I also had a great support network from my mastermind group which made things 10x easier.&lt;/p&gt;
&lt;h2 id=&quot;travelling-to-torino&quot;&gt;Travelling to Torino&lt;/h2&gt;
&lt;p&gt;My journey started in the north of Spain, a region called Asturias. There are not too many international flights from here so I needed to catch two flights to make it to Torino with a change over at Frankfurt.&lt;/p&gt;
&lt;p&gt;All was going well until I was about to board the connecting flight in Frankfurt. Patrick, a friend from my mastermind group had just messaged me, telling me how lucky I was that I didn’t have any issues as a lot of flights from Frankfurt had been cancelled recently.&lt;/p&gt;
&lt;p&gt;And guess what, within 60 seconds of his message (and 5 minutes until boarding) my flight got cancelled. I know exactly who I blame for this catastrophy… 🤨&lt;/p&gt;
&lt;p&gt;Fortunately a replacement flight was arranged and I managed to make it to Torino only 2 hours late, not too bad. I took a couple of pictures as we were landing at night only to discover that the one of them captured the Lingotto center perfectly – the venue hosting WCEU.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Flight was cancelled but only delayed 2 hours in the end…&lt;/p&gt;
&lt;p&gt;But did I get lucky and take a photo of the Lingotto center?&lt;a href=&quot;https://x.com/hashtag/wceu?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#wceu&lt;/a&gt; &lt;a href=&quot;https://t.co/uGAzi4m2md&quot;&gt;pic.twitter.com/uGAzi4m2md&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;— Ross Morsali (@rossmorsali) &lt;a href=&quot;https://x.com/rossmorsali/status/1801015150633173341?ref_src=twsrc%5Etfw&quot;&gt;June 12, 2024&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;day-one--contributor-day&quot;&gt;Day one / contributor day&lt;/h2&gt;
&lt;p&gt;My first full day was Thursday, aka contributor day. I had always looked forward to joining a contributor day as I’ve seen countless people talking about the positive atmosphere of them over the years, it sure sounded like a lot of fun!&lt;/p&gt;
&lt;p&gt;Unfortunately I didn’t realise that it was a requirement to register to participate in contributor day – I had assumed that anyone who got there a day early could join in… how wrong I was!&lt;/p&gt;
&lt;p&gt;So instead of joining the masses for what sounded like a fantastic contributor day, me and a few friends from my mastermind group decided to do a city escape tour – we downloaded an app which took us on a kind of role playing journey around the city – while I wasn’t too into the game I did enjoy going around the city and visiting some of its landmarks – my best photos were from this part of the trip.&lt;/p&gt;
&lt;p&gt;This was also my first taste of real Italian pizza 😋&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_111454058-EDIT.B5-ih_DQ_1gsNXv.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_120234163.HpD2sLmJ_1eKQkj.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_125951991.rL-C-j8x_Z11sg2r.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_135451961.CeP8p-Qp_Z6J8W0.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Dinner in a pizza restaurant with the Mastermind gang.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/Photo-13-06-2024-14-26-12.CqYZ53NR_1mcvji.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;The chef that cooked our pizza (also the owner, I think)&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;2133&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_122550351.Cz9BN8Ij_190dHL.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1203&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_125814961-EDIT.Bp8Z_x3x_XjWQx.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;2133&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_130558241-EDIT.Cmx9Vloe_Z1R0w4I.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;2334&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_133739657-EDIT.Ps4lenDS_Z2ofTD3.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;2133&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_101719514.C2JRwt6Q_Z1TfX9F.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_113331615.pxsocoMF_Z15CxNF.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_113832374-1.rqLnrPGu_1INGa.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;2133&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_115255901.D8MOSNF-_jgcG8.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240613_115213568-1.CXHeZVJv_13SzYX.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;It was really great getting to know &lt;a href=&quot;https://x.com/PoeHaH&quot;&gt;Maarten&lt;/a&gt; + &lt;a href=&quot;https://x.com/miene&quot;&gt;Ine&lt;/a&gt; (from &lt;a href=&quot;https://www.studiowombat.com/&quot;&gt;Studio Wombat&lt;/a&gt;) and &lt;a href=&quot;https://x.com/patrickposner_&quot;&gt;Patrick Posner&lt;/a&gt; (from &lt;a href=&quot;https://simplystatic.com/&quot;&gt;Simply Static&lt;/a&gt; and &lt;a href=&quot;https://olliewp.com/&quot;&gt;Ollie WP&lt;/a&gt;) in real life!&lt;/p&gt;
&lt;p&gt;Later that evening we headed over to the &lt;a href=&quot;https://x.com/freemius&quot;&gt;Freemius Makers Meet&lt;/a&gt; event. This was my first experience being surrounded by so many people from the industry and so many familiar faces I’d seen on Twitter over the years – it was a bit overhelming at times and I mostly opted to stay quiet rather going around making big introductions to people I’d recognised – I think I just needed to get warmed up!&lt;/p&gt;
&lt;p&gt;After the Freemius party we headed over to the Elementor Party and managed to snap my first #MichelleAndMe! I just know there will be many more of these to come! (Please ignore the typo, it was the beer I promise).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A verrry late night &lt;a href=&quot;https://x.com/hashtag/MichelleAndMe?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#MichelleAndMe&lt;/a&gt; 🙃&lt;/p&gt;
&lt;p&gt;It was a please meeting you &lt;a href=&quot;https://x.com/michelleames?ref_src=twsrc%5Etfw&quot;&gt;@michelleames&lt;/a&gt; (with &lt;a href=&quot;https://x.com/patrickposner_?ref_src=twsrc%5Etfw&quot;&gt;@patrickposner_&lt;/a&gt; ) &lt;a href=&quot;https://t.co/D7hySCytCC&quot;&gt;pic.twitter.com/D7hySCytCC&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;— Ross Morsali (@rossmorsali) &lt;a href=&quot;https://x.com/rossmorsali/status/1801383873978273825?ref_src=twsrc%5Etfw&quot;&gt;June 13, 2024&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I also managed to meet the people behind &lt;a href=&quot;https://www.dynamic.ooo/&quot;&gt;Dynamic.ooo&lt;/a&gt; – Giovanni and his awesome team. I’ve collaborated with them for several years now bringing Search &amp;amp; Filter to some of their Elementor widgets so it was good to chat about whats coming next in Search &amp;amp; Filter version 3 and what they’ve got coming up (🔥).&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Piero and I at the Dynamic.ooo booth.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/image.Bwb4L9B2_PuwwM.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;It really is great to get to meet the people you’ve been talking and working with virtually for years!&lt;/p&gt;
&lt;h2 id=&quot;day-two&quot;&gt;Day two&lt;/h2&gt;
&lt;p&gt;So this was the first proper day of the conference. I didn’t really know what to expect, for the most part my plan was to go around and check out the various sponsor booths and dip into a few talks or workshops.&lt;/p&gt;
&lt;p&gt;With my &lt;a href=&quot;https://searchandfilter.com/&quot;&gt;Search &amp;amp; Filter&lt;/a&gt; plugin, we have a lot of integrations with other plugins which made it easy to go upto many booths and start chatting – it was really cool to meet the people behind the plugins and get some useful contacts in those businesses.&lt;/p&gt;
&lt;p&gt;I’ve tried reaching out to some of our integration partners in the past, and often you might not get introduced to the right people at the right time. The sponsorship booths helped me cut the line and make direct connections with the people I need to be in contact with – this really was one of the biggest benefits of the whole experience for me.&lt;/p&gt;
&lt;p&gt;Again I have to tip my hat to my friends from the mastermind group, whenever I got tired or a little bored, I could always return the to the Studio Wombat booth to find familiar (and friendly) faces. We spent so much time there I was made an honarary member.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Patrick and I at the Studio Wombat booth, wearing honarary Studio Wombat shirts.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;2133&quot; src=&quot;https://rm.codes/_astro/Photo-15-06-2024-12-52-36.BHva2TrI_IuBpm.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;Later that evening I went for a meal where I sampled some more amazing fresh pasta, followed by the WooCommerce event just around the corner. This was probably one of my favourite, larger, events – the music wasn’t too loud so you could chat and everyone was having a great time.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Pasta in Italy - Alla Norma&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/PXL_20240614_180407546.BkznNs97_Z1KNva3.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;I also managed to finally meet one of my oldest customers – Brian and his amazing team from &lt;a href=&quot;https://digicube.ch/&quot;&gt;digicube&lt;/a&gt;. They’re not only one of my longest customers, I actually hired them to build the new Search &amp;amp; Filter website (yet to be released). It was so nice to meet them in person, all round good vibes.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;The team from Digicube - Brian, Makedonka, Artan, Bone and Alessa&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1067&quot; src=&quot;https://rm.codes/_astro/Bild-1.DPdFhxIR_ZRItvq.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;I finished the night over in the next building for the Yoast PRIDE party – I didn’t stay too long as I was very aware of my need wake up early the next day and be in good form.&lt;/p&gt;
&lt;h2 id=&quot;day-three&quot;&gt;Day three&lt;/h2&gt;
&lt;p&gt;The final day of the conference – that was quick! For the most part it was much the same as the day before, walking around meeting and greeting people, suprisingly there were still plenty of people I hadn’t yet connected with.&lt;/p&gt;
&lt;p&gt;I also managed to catch the talk from &lt;a href=&quot;https://x.com/KatieKeithBarn2&quot;&gt;Katie Keith&lt;/a&gt; + &lt;a href=&quot;https://x.com/learnwithmattc&quot;&gt;Matt Cromwell&lt;/a&gt; (who co-host &lt;a href=&quot;https://wpproducttalk.com/&quot;&gt;WP Product Talk&lt;/a&gt;) which was great despite a fair few technical issues!&lt;/p&gt;
&lt;p&gt;In the evening I had the privilege of being invited to a small WooCommerce dinner. This was one of the highlights of the trip for me, we got speak to some of the team directly who were very candid and open to all kinds of conversations and questions.&lt;/p&gt;
&lt;p&gt;A large part of the userbase of Search &amp;amp; Filter are of course WooCommerce users, so it was super insightful to hear about what’s coming next and to be honest, to see the team so open to receiving feedback and being willing to engage with the community was a real confidence booster.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;What a lovely dinner and deep conversations. I’m excited about the future of WooCommerce. &lt;a href=&quot;https://t.co/RHxiQ02v51&quot;&gt;https://t.co/RHxiQ02v51&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;— Ross Morsali (@rossmorsali) &lt;a href=&quot;https://x.com/rossmorsali/status/1802158104257179808?ref_src=twsrc%5Etfw&quot;&gt;June 16, 2024&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Thanks to &lt;a href=&quot;https://x.com/jamesckemp&quot;&gt;James Kemp&lt;/a&gt; and &lt;a href=&quot;https://x.com/nerrad&quot;&gt;Darren Ethier&lt;/a&gt; for inviting me and setting this up!&lt;/p&gt;
&lt;p&gt;Following the dinner we headed straight to the official party back in the Lingotto Center. It was a nice space where people could let their hair down and unwind.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;WCEU after party with Patrick, Maarten and myself&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;2133&quot; src=&quot;https://rm.codes/_astro/Photo-15-06-2024-23-22-15.BZYR33cG_Z1HKFnp.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;But I’m very picky about music, so I mostly enjoyed the conversations outside!&lt;/p&gt;
&lt;h2 id=&quot;notable-introductions&quot;&gt;Notable introductions&lt;/h2&gt;
&lt;p&gt;There are some people in the WordPress space we all know and love, and while I may not have spent much time with them it was really great to meet them in person, finally. In no particular order:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://x.com/courtneyr_dev&quot;&gt;Courtney Robertson&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://x.com/michelleames&quot;&gt;Michelle Frechette&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://x.com/BobWP&quot;&gt;BobWP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://x.com/wpbuilds&quot;&gt;Nathan Wrigley&lt;/a&gt; aka WP Builds&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://x.com/westguard&quot;&gt;Mark Westguard&lt;/a&gt; from WS Form&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://x.com/heyamberhinds&quot;&gt;Amber&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://x.com/mr_chrishinds&quot;&gt;Chris&lt;/a&gt; Hinds&lt;/li&gt;
&lt;li&gt;And I’m sure many more, if you’re not on this list it’s probably a mistake on my part!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;mastermind&quot;&gt;Mastermind&lt;/h2&gt;
&lt;p&gt;As I mentioned a few times already, the experience wouldn’t have been the same without the support from my mastermind group – Maarten, Ine and Patrick! I particularly like this photo of us all (and the clear shot of the Search &amp;amp; Filter logo is just a bonus!):&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Selfie while out on the streets of Torino - left to right is myself, Maarten, Ine and Patrick&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;1200&quot; src=&quot;https://rm.codes/_astro/IMG_1588.zaR-6JkX_mgiSx.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you’re a product maker and not part of a mastermind, I encourage to start your own or find one! The advice and moral support I’ve been getting from them has been invaluable – I guess I hope I’m returning some of that back to them too.&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;All in all it has been an incredible experience, I loved the city of Torino and the events in and around the conference have been fantastic.&lt;/p&gt;
&lt;p&gt;I really couldn’t have had a better experience from my first attendance at a WordCamp, I’m grateful to everyone who welcomed me and made the experience what it was.&lt;/p&gt;
&lt;p&gt;Some tips from a first timer:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It really helps if you already know &lt;em&gt;some&lt;/em&gt; people who are going, for me this was my mastermind group – its always nice to know you have somewhere to return after you run out of steam from so many conversations.&lt;/li&gt;
&lt;li&gt;Be open to talking to anyone and everyone, without an agenda.&lt;/li&gt;
&lt;li&gt;Extend your trip by a day or two on either side – I learnt my lesson this time, I wish I could have experienced a little more of Torino.&lt;/li&gt;
&lt;li&gt;Make sure you follow the lists of events (wherever they’re posted) and sign up to them EARLY, especially contributor day (!).&lt;/li&gt;
&lt;li&gt;Try not to eat more than one pizza per day 😅&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you’ve also written a summary post, I’d like to read it, so send it my way!&lt;/p&gt;
</content:encoded><category>WordCamp</category><category>WordPress</category></item><item><title>SlotFills and fillProps in the block editor</title><link>https://rm.codes/blog/slotfills-and-fillprops-in-the-block-editor/</link><guid isPermaLink="true">https://rm.codes/blog/slotfills-and-fillprops-in-the-block-editor/</guid><description>When building blocks or working with the Gutenberg APIs you might have come across SlotFills. They’re really useful and allow you to insert components in different locations from seemingly disconnected parts of your application. A quick explanation The way it works is, a &lt;Slot /&gt; component will be added somewhere in an application – and…</description><pubDate>Fri, 26 May 2023 11:27:29 GMT</pubDate><content:encoded>&lt;p&gt;When building blocks or working with the Gutenberg APIs you might have come across &lt;a href=&quot;https://developer.wordpress.org/block-editor/reference-guides/slotfills/&quot;&gt;SlotFills&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;They’re really useful and allow you to insert components in different locations from seemingly disconnected parts of your application.&lt;/p&gt;
&lt;h2 id=&quot;a-quick-explanation&quot;&gt;A quick explanation&lt;/h2&gt;
&lt;p&gt;The way it works is, a &lt;code&gt;&amp;lt;Slot /&amp;gt;&lt;/code&gt; component will be added somewhere in an application – and then in other parts of the application you can use a &lt;code&gt;&amp;lt;Fill /&amp;gt;&lt;/code&gt; to “send” content to the slot.&lt;/p&gt;
&lt;p&gt;Under the hood they use React Portals so often appear somewhere else completely in the DOM.&lt;/p&gt;
&lt;p&gt;Gutenberg uses these under the hood for things like sidebars and block controls, if you’ve built blocks before then you’ve likely used &lt;a href=&quot;https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/block-controls-toolbar-and-sidebar/&quot;&gt;&lt;strong&gt;BlockControls&lt;/strong&gt; and the &lt;strong&gt;InspectorControls&lt;/strong&gt;&lt;/a&gt; for building out your block admin UI.&lt;/p&gt;
&lt;p&gt;The great thing is we can also use our own SlotsFills for things like custom admin screens, making them extensible – &lt;a href=&quot;https://nickdiego.com/a-primer-on-wordpress-slotfill-technology/&quot;&gt;Nick Diego has a great article&lt;/a&gt; explaining how he’s used them on his custom admin screens and then extended those screens via another plugin.&lt;/p&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;/h2&gt;
&lt;p&gt;Here’s a quick example showing how to use Slots and Fills – &lt;a href=&quot;https://developer.wordpress.org/block-editor/reference-guides/components/slot-fill/&quot;&gt;checkout the Gutenberg docs&lt;/a&gt; for a more detailed example.&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;jsx&quot;&gt;&lt;code&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;import&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; { createSlotFill } &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;@wordpress/components&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;const&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Fill&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Slot&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:#DCBDFB&quot;&gt; createSlotFill&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;MyList&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:#768390&quot;&gt;// The main component.&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:#DCBDFB&quot;&gt; MyComponent&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 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:#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;&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;ListComponent&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;ListExtensionComponent&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;/&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&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;// A list component, that we want to be extensible.&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:#DCBDFB&quot;&gt; ListComponent&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 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:#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;ul&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;li&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;A list item&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;li&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;Slot&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;ul&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&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;// A seperate component, which uses the Fill to extend the list.&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:#DCBDFB&quot;&gt; ListExtensionComponent&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 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:#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;Fill&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;li&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;Another list item&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;li&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;Fill&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;/code&gt;&lt;/pre&gt;
&lt;p&gt;The rendered HTML will look something like:&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;html&quot;&gt;&lt;code&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;ul&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;li&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;A list item&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;li&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;li&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;Another list item&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;li&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;ul&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;passing-props-fillprops&quot;&gt;Passing props (fillProps)&lt;/h2&gt;
&lt;p&gt;The reason I wanted to write this article was because I came upon an issue that took me a little while to figure out.&lt;/p&gt;
&lt;p&gt;I have a &lt;code&gt;Slot&lt;/code&gt; in a dropdown menu so that it can be extended from different parts of my application – so far so good. But for a specific button (one that opens a modal) I wanted to close the dropdown menu on interaction.&lt;/p&gt;
&lt;p&gt;This meant that the button needs access to the &lt;code&gt;onClose()&lt;/code&gt; function from the parent dropdown component – so I needed to find a way to pass props to the &lt;strong&gt;Fill&lt;/strong&gt;. Que &lt;code&gt;fillProps&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After a too much trial and error I started combing the Gutenberg source code and found that there was an easy way to do this all along, &lt;a href=&quot;https://github.com/WordPress/gutenberg/blob/bc7030daa86543d6d9301bb9844caa09de36c4b8/packages/components/src/slot-fill/slot.js#L63&quot;&gt;it’s just not documented very well&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If we pass &lt;code&gt;fillProps&lt;/code&gt; to our &lt;code&gt;Slot&lt;/code&gt;, then we can access that in the &lt;code&gt;Fill&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Lets say we have a &lt;code&gt;closePopup()&lt;/code&gt; function:&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; closePopup&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;	console.&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Close the popup!&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;Here’s what the &lt;code&gt;Slot&lt;/code&gt; would look like when we use &lt;code&gt;fillProps&lt;/code&gt;:&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;jsx&quot;&gt;&lt;code&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;Slot&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; fillProps&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; { closePopup } &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then the &lt;code&gt;Fill&lt;/code&gt; can consume those props if we pass a function as the &lt;code&gt;Fill&lt;/code&gt; content:&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;jsx&quot;&gt;&lt;code&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;Fill&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:#F47067&quot;&gt;	{&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( { &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;closePopup&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;		&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;Button&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; onClick&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; closePopup &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;Close&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;Button&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 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;lt;/&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;Fill&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s similar to how we can pass functions as &lt;code&gt;children&lt;/code&gt; in React.&lt;/p&gt;
&lt;p&gt;Here I’m using the SlotFill to add the &lt;strong&gt;Export All&lt;/strong&gt; button to the dropdown, and then I’m using the &lt;code&gt;fillProps&lt;/code&gt; to pass the &lt;code&gt;closePopup&lt;/code&gt; function so that the popup menu is closed when clicked, which is then followed by opening the modal.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1057&quot; height=&quot;712&quot; src=&quot;https://rm.codes/_astro/chrome_8MPsVv6iLP.DzjXOn0I_Zm4qCE.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the end all it took was some digging in the Gutenberg source code to find a prop, and the rest is already done!&lt;/p&gt;
&lt;p&gt;I’m sure there are plenty of use cases for this, I’d be interested to hear yours.&lt;/p&gt;
</content:encoded></item><item><title>Installing WordPress Coding Standards</title><link>https://rm.codes/blog/installing-wordpress-coding-standards/</link><guid isPermaLink="true">https://rm.codes/blog/installing-wordpress-coding-standards/</guid><description>… as a project dependency. A problem I came across recently when working on a project with a colleague was setting up WordPress Coding Standards (WPCS) with PHP Code Sniffer (PHPCS). I already had it setup on my development machine, with PHPCS installed globally as well as the WP Coding Standards. But lets say we…</description><pubDate>Tue, 28 Feb 2023 15:41:46 GMT</pubDate><content:encoded>&lt;p&gt;… as a project dependency.&lt;/p&gt;
&lt;p&gt;A problem I came across recently when working on a project with a colleague was setting up WordPress Coding Standards (WPCS) with PHP Code Sniffer (PHPCS).&lt;/p&gt;
&lt;p&gt;I already had it setup on my development machine, with PHPCS installed globally as well as the WP Coding Standards. But lets say we want to encourage use of WPCS in a project where we might have different team members involved, then I think its a good idea to install it as a dependency.&lt;/p&gt;
&lt;h3 id=&quot;what-are-the-wp-coding-standards-and-what-is-phpcs&quot;&gt;What are the WP Coding Standards, and what is PHPCS&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/&quot;&gt;The WP Coding Standards&lt;/a&gt; are a set of guidlines to follow when building a plugin or theme on top of WordPress. In this post I’m referring to the PHP Coding standards.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/squizlabs/PHP_CodeSniffer&quot;&gt;PHPCS&lt;/a&gt; – is a command line tool to detect issues in your PHP code by comparing it against a set of rules that you can define. In this case the WordPress coding standards rules. You can also configure it to format your PHP files for you.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get PHPCS to understand and apply the WPCS rules to your code, there is the &lt;a href=&quot;https://github.com/WordPress/WordPress-Coding-Standards&quot;&gt;WordPress Coding Standards PHPCS&lt;/a&gt; repository which we’ll be installing via Composer into your project, it comes with a copy of PHPCS.&lt;/p&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;
&lt;p&gt;This post assumes you already have &lt;strong&gt;&lt;a href=&quot;https://getcomposer.org/&quot;&gt;Composer&lt;/a&gt;&lt;/strong&gt; setup on your machine and that you’re familiar with creating repositories and adding composer to your project via the command line.&lt;/p&gt;
&lt;p&gt;I’m also writing this from a Windows machine, so you might need to fiddle with paths etc if you’re using something else – &lt;em&gt;double check the installation paths of your packages when using Composer&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&quot;setup&quot;&gt;Setup&lt;/h2&gt;
&lt;h3 id=&quot;add-the-package-to-your-project&quot;&gt;Add the package to your project&lt;/h3&gt;
&lt;p&gt;If you haven’t setup composer in your project yet, at the command line run:&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;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;composer&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; init&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And follow the usual prompts to configure your project.&lt;/p&gt;
&lt;p&gt;Then require WordPress Coding Standards which will also give you a local copy of PHPCS, run:&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;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;composer&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; require&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; wp-coding-standards/wpcs&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;add-wpcs-rules-location-to-phpcs&quot;&gt;Add WPCS rules location to PHPCS&lt;/h3&gt;
&lt;p&gt;Once that is installed we need to tell PHPCS the location of our WordPress rules, we can run:&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;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;vendor/bin/phpcs&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; --config-set&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; installed_paths&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; ../../wp-coding-standards/wpcs&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: I’m using a relative path of the rules to the PHPCS installation &lt;code&gt;**../../wp-coding-standards/wpcs**&lt;/code&gt;. You can use an absolute path too.&lt;/p&gt;
&lt;h3 id=&quot;automating-this-for-developers&quot;&gt;Automating this for developers&lt;/h3&gt;
&lt;p&gt;When developers setup your repository and install the projects dependencies via &lt;code&gt;**composer install**&lt;/code&gt; it might be nice to simplify the above step by running it automatically after we run the install – via a post install script.&lt;/p&gt;
&lt;p&gt;This requires adding a “scripts” section after your “require” section in &lt;code&gt;**composer.json**&lt;/code&gt;, so 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;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;require&quot;&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:#8DDB8C&quot;&gt;	&quot;wp-coding-standards/wpcs&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;^2.3&quot;&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;Would become 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;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;require&quot;&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:#8DDB8C&quot;&gt;	&quot;wp-coding-standards/wpcs&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;^2.3&quot;&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:#96D0FF&quot;&gt;&quot;scripts&quot;&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:#8DDB8C&quot;&gt;    &quot;post-update-cmd&quot;&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:#96D0FF&quot;&gt;        &quot;vendor/bin/phpcs --config-set installed_paths ../../wp-coding-standards/wpcs&quot;&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;Once you’ve added that, you can be sure the next team members on your project will automatically get PHPCS configured with WPCS out of the box.&lt;/p&gt;
&lt;h3 id=&quot;configure-your-ide-vs-code&quot;&gt;Configure your IDE (VS Code)&lt;/h3&gt;
&lt;p&gt;If you’re using VS Code, I would recommend the &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=wongjn.php-sniffer&quot;&gt;PHP Sniffer extension by wongjn&lt;/a&gt; which allows us to format the code on save too.&lt;/p&gt;
&lt;p&gt;Once installed, open the extensions settings and take note to switch the &lt;strong&gt;workspace&lt;/strong&gt; tab.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;A cropped screenshot showing the option in PHP Sniffer to specify the location of phpcs.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1163&quot; height=&quot;621&quot; src=&quot;https://rm.codes/_astro/image-2.XoIfvTFa_tay7b.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;I was happy with the defaults, the only thing we need to do is add our &lt;strong&gt;executable folder&lt;/strong&gt; as &lt;code&gt;**vendor\bin**&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you check your workspace settings, it should look like:&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;json&quot;&gt;&lt;code&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:#8DDB8C&quot;&gt;	&quot;phpSniffer.executablesFolder&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;vendor&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;bin&quot;&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;&lt;strong&gt;Note:&lt;/strong&gt; instead of setting a path, you could let PHP Sniffer try to autodetect this for you:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;A cropped screenshot showing the option in PHP Sniffer to enable the “auto detect” feature&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;844&quot; height=&quot;108&quot; src=&quot;https://rm.codes/_astro/image-1.CQnYj_am_ZrLOqh.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Personally, I like the re-assurance of specifying the location.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;auto-formatting-on-save-phpcbf&quot;&gt;Auto formatting on save (phpcbf)&lt;/h3&gt;
&lt;p&gt;To tell VS Code we want to format on save, we just need to include the &lt;code&gt;editor.formatOnSave&lt;/code&gt; directive in our workspace settings:&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;json&quot;&gt;&lt;code&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:#8DDB8C&quot;&gt;	&quot;phpSniffer.executablesFolder&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;vendor&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;bin&quot;&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:#8DDB8C&quot;&gt;	&quot;editor.formatOnSave&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;true&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:#8DDB8C&quot;&gt;	&quot;[php]&quot;&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:#8DDB8C&quot;&gt;		&quot;editor.defaultFormatter&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;wongjn.php-sniffer&quot;&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;Depending on your setup, you might also want to tell VSCode to use the extension specifically for formatting php files using the &lt;code&gt;**[php]**&lt;/code&gt; property and then defining &lt;code&gt;**editor.defaultFormatter**&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;configure-the-wordpress-coding-standards&quot;&gt;Configure the WordPress Coding Standards&lt;/h3&gt;
&lt;p&gt;We can configure the extension to use the WordPress rules directly or (which I prefer), we can instead create custom rules based on the WPCS rules which will allow us to customise them at a later date – we’ll call our custom ruleset &lt;code&gt;**RmCodesRuleSet**&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To do this we can create a &lt;code&gt;**.phpcs.xml**&lt;/code&gt; file in the root of our project with the contents:&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;xml&quot;&gt;&lt;code&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;xml&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; version&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;1.0&quot;&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;ruleset&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;RmCodesRuleSet&quot;&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;rule&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ref&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;WordPress&quot;&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;ruleset&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The phpcs extension will automatically read this file and the &lt;code&gt;**&amp;lt;rule ref=&quot;WordPress&quot;&amp;gt;**&lt;/code&gt; so it knows to inherit the WordPress Coding Standard Rules.&lt;/p&gt;
&lt;p&gt;The VS Code PHP Sniffer extension (as well as many others) will usually load a &lt;code&gt;.phpcs.xml&lt;/code&gt; file automatically.&lt;/p&gt;
&lt;h3 id=&quot;excluding-some-rules&quot;&gt;Excluding some rules&lt;/h3&gt;
&lt;p&gt;Finally, if you want to exclude specific rules we can do that by using the exclude &lt;code&gt;&amp;lt;exclude&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;
&lt;p&gt;I often exclude the filename restrictions as I’m usually using namespaces these days (with a different file structure) and the yoda conditions I’ve heard will be removed from the coding standards at some point anyway.&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;xml&quot;&gt;&lt;code&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;xml&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; version&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;1.0&quot;&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;ruleset&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;RmCodesRuleSet&quot;&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;rule&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ref&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;WordPress&quot;&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:#768390&quot;&gt;        &amp;lt;!-- Exclude the filename restrictions assocatied with class name --&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;exclude&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;WordPress.Files.FileName&quot;&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:#768390&quot;&gt;        &amp;lt;!-- Exclude the requirement to use Yoda conditions --&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;exclude&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;WordPress.PHP.YodaConditions.NotYoda&quot;&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;rule&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;ruleset&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;taking-it-further&quot;&gt;Taking it further&lt;/h3&gt;
&lt;p&gt;Aside from setting up PHPCS + WPCS in your repository and IDE, we could also configure it to run on push via Github actions.&lt;/p&gt;
&lt;p&gt;But that’ll probably be another article…&lt;/p&gt;
</content:encoded></item><item><title>Creating sidebars for the post and site editors</title><link>https://rm.codes/blog/creating-sidebars-for-the-post-and-site-editors/</link><guid isPermaLink="true">https://rm.codes/blog/creating-sidebars-for-the-post-and-site-editors/</guid><description>There are multiple articles on how to create a sidebar in the block editor but something you might not have seen is how to do that for the site editor (aka Full Site Editing, aka FSE). It’s a nearly identical setup to create a sidebar for the site editor but it is not yet documented,…</description><pubDate>Mon, 30 Jan 2023 11:22:15 GMT</pubDate><content:encoded>&lt;p&gt;There are multiple articles on how to create a sidebar in the block editor but something you might not have seen is how to do that for the site editor (aka Full Site Editing, aka FSE).&lt;/p&gt;
&lt;p&gt;It’s a nearly identical setup to create a sidebar for the site editor but it is &lt;a href=&quot;https://developer.wordpress.org/block-editor/reference-guides/packages/packages-edit-site/&quot;&gt;not yet documented&lt;/a&gt;, I recently discovered the code &lt;a href=&quot;https://github.com/WordPress/gutenberg/issues/38673#issuecomment-1245530826&quot;&gt;burried in a github reply&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To clarify the terms site editor and post editor:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The post editor is used on any screen where we can edit a post, page or CPT.&lt;/li&gt;
&lt;li&gt;The site editor is available only in the latest themes that support full site editing and allows you to edit parts of your site that are not related to post content.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both of these use the block editor by default.&lt;/p&gt;
&lt;p&gt;Lets start with adding a sidebar to the &lt;strong&gt;post editor&lt;/strong&gt;:&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;jsx&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; { registerPlugin } &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;@wordpress/plugins&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:#768390&quot;&gt;// The edit post PluginSidebar.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; { PluginSidebar } &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;@wordpress/edit-post&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;import&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; icon &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;./icons/rm-codes&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;// Link your own icon.&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;const&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; RmCodesSidebars&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 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;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;PluginSidebar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;		name&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;a-sidebar&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;		title&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;A sidebar&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;		icon&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; icon &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:#96D0FF&quot;&gt; &apos;rm-codes-sidebar&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:#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;		Sidebar Content goes here.&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;PluginSidebar&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&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;// Register `rm-codes` plugin.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;registerPlugin&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm-codes&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;	render: RmCodesSidebars,&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;And now the code for registering a sidebar in the &lt;strong&gt;site editor&lt;/strong&gt;:&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;jsx&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; { registerPlugin } &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;@wordpress/plugins&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:#768390&quot;&gt;// The *edit site* PluginSidebar.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; { PluginSidebar } &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;@wordpress/edit-site&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;import&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; icon &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;./icons/rm-codes&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;// Link your own icon.&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;const&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; RmCodesSidebars&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 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;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;PluginSidebar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;		name&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;a-sidebar&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;		title&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;A sidebar&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;		icon&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; icon &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:#96D0FF&quot;&gt; &apos;rm-codes-sidebar&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:#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;		Sidebar Content goes here.&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;PluginSidebar&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&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;// Register `rm-codes` plugi.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;registerPlugin&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm-codes&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;	render: RmCodesSidebars,&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;The only difference here is that &lt;strong&gt;&lt;code&gt;PluginSidebar&lt;/code&gt;&lt;/strong&gt; is loaded from &lt;code&gt;**@wordpress/edit-site**&lt;/code&gt; rather than &lt;code&gt;**@wordpress/edit-post**&lt;/code&gt;, presumably the main difference is the slotfill that is used to get the sidebar to show up in the right place.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note to self: maybe we can create a single &lt;code&gt;PluginSidebar&lt;/code&gt; that works across all editing contexts.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;further-thoughts&quot;&gt;Further thoughts&lt;/h3&gt;
&lt;p&gt;It should be possible to add a sidebar wherever we have a full block editor experience, while this covers off the two most common use cases there is still one area where adding sidebars is not possible: &lt;strong&gt;the classic widgets screen&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Since WordPress 5.8 hybrid themes or classic themes have access to a new block editor powered widgets screen:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;A screenshot of the widgets screen in WordPress, which uses the block editor since version 5.8.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;1600&quot; height=&quot;781&quot; src=&quot;https://rm.codes/_astro/image-3.D9ieCDFP_1dblwd.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The block editor powered classic widgets screen.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately there is &lt;a href=&quot;https://github.com/WordPress/gutenberg/issues/47029&quot;&gt;no mechanism to add a sidebar here&lt;/a&gt; at the moment.&lt;/p&gt;
&lt;p&gt;For consistency across all block editor implementations I would hope to see this added at some point, presumably under the package &lt;code&gt;**@wordpress/edit-widgets**&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;There is &lt;a href=&quot;https://github.com/WordPress/gutenberg/issues/47029&quot;&gt;an issue open for this&lt;/a&gt; but as of yet it has not gained much traction.&lt;/p&gt;
</content:encoded><category>Block Editor</category><category>Plugin development</category><category>WordPress</category></item><item><title>Creating Cron jobs in WordPress plugins</title><link>https://rm.codes/blog/creating-cron-jobs-in-wordpress-plugins/</link><guid isPermaLink="true">https://rm.codes/blog/creating-cron-jobs-in-wordpress-plugins/</guid><description>This topic has been covered plenty already but I always find myself googling this or looking at an old codebase when I need to create cron jobs in WordPress. So this is more of a note to self (as I imagine many future posts will be) of how to do this as a self contained…</description><pubDate>Tue, 03 Jan 2023 15:30:03 GMT</pubDate><content:encoded>&lt;p&gt;This topic has been covered plenty already but I always find myself googling this or looking at an old codebase when I need to create cron jobs in WordPress.&lt;/p&gt;
&lt;p&gt;So this is more of a note to self (as I imagine many future posts will be) of how to do this as a self contained example, in a WordPress plugin.&lt;/p&gt;
&lt;p&gt;Here’s the code, with 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;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;// Setup the interval/frequency for the cron job.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;add_filter&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;cron_schedules&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm_codes_cron_schedules&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; rm_codes_cron_schedules&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $schedules ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	// Create a 12hrs interval.&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:#F47067&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; isset&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $schedules[&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;12hrs&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;		$schedules[&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;12hrs&apos;&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; array&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:#96D0FF&quot;&gt;			&apos;interval&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DAY_IN_SECONDS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&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:#96D0FF&quot;&gt;			&apos;display&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  =&amp;gt;&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;Once every 12 hours&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm-codes&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:#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; $schedules;&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:#768390&quot;&gt;// Attach the cron job setup to plugin activation&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;register_activation_hook&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:#96D0FF&quot;&gt;&apos;rm_codes_cron_activate&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:#768390&quot;&gt;// Setup the cron job to run at the specified interval.&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; rm_codes_cron_activate&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;	// If the cron job is not scheduled, schedule it.&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:#F47067&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; wp_next_scheduled&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm_codes_cron&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:#DCBDFB&quot;&gt;		wp_schedule_event&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;12hrs&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm_codes_cron&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:#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;// Remove the cron job when the plugin deactivates.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;register_deactivation_hook&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:#96D0FF&quot;&gt;&apos;rm_codes_cron_deactivate&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:#768390&quot;&gt;// Deactivate the cron job.&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; rm_codes_cron_deactivate&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:#DCBDFB&quot;&gt;	wp_clear_scheduled_hook&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm_codes_cron&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&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;// Add the cron job task action.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;add_action&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm_codes_cron&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;rm_codes_cron_run_task&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:#768390&quot;&gt;// The task to run.&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; rm_codes_cron_run_task&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;	// Run the task...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	// ** error_log() won&apos;t usually work in cron for debugging,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;	// better use file_put_contents.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;	file_put_contents&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;WP_CONTENT_DIR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;/debug.log&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cron job ran at &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; .&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; gmdate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;M d Y H:i:s&apos;&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; PHP_EOL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FILE_APPEND&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;&lt;em&gt;Remember, don’t do anything time critical with WP Cron as it will only be run when a visitor hits your site and the interval has passed.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For further reading checkout &lt;a href=&quot;https://developer.wordpress.org/plugins/cron/&quot;&gt;the docs on WP Cron&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>WordPress</category></item><item><title>How to add a Mastodon verified link without a plugin</title><link>https://rm.codes/blog/how-to-add-a-mastodon-verified-link-without-a-plugin/</link><guid isPermaLink="true">https://rm.codes/blog/how-to-add-a-mastodon-verified-link-without-a-plugin/</guid><description>You can add Mastodon verified links to your WordPress site without using a plugin by adding a code snippet (below). If you’re not sure what a verified link is, they look like this, with the check: First make sure to use the core Mastodon social link block and add a link to your Mastodon profile:…</description><pubDate>Mon, 02 Jan 2023 11:02:43 GMT</pubDate><content:encoded>&lt;p&gt;You can add Mastodon verified links to your WordPress site without using a plugin by adding a code snippet (below).&lt;/p&gt;
&lt;p&gt;If you’re not sure what a verified link is, they look like this, with the check:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;A screenshot of the list of links on my Mastodon profile, showing one of the links as verified with a checkmark.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;567&quot; height=&quot;206&quot; src=&quot;https://rm.codes/_astro/image.DR9uWxef_2d4Nj0.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;First make sure to use the core Mastodon social link block and add a link to your Mastodon profile:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Screenshot of the WodrPress block editor UI, showing a Mastodon social link added to the page, with the URL editor opened.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; width=&quot;531&quot; height=&quot;195&quot; src=&quot;https://rm.codes/_astro/image-1.C5M5cAH0_Z2kIYI9.webp&quot;&gt;&lt;/p&gt;
&lt;p&gt;Then add the following code snippet to your child theme’s &lt;code&gt;functions.php&lt;/code&gt;:&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;// Filter the Mastadon social link and add rel=me&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; add_mastodon_rel_me&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( $block_content, $block ) {&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; ( $block[&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;attrs&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;service&apos;&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:#96D0FF&quot;&gt; &apos;mastodon&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;		return&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $block_content;&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:#ADBAC7&quot;&gt;	$block_content &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; preg_replace&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;@&amp;lt;a(.*)&amp;gt;@U&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;&amp;lt;a$1 rel=&quot;me&quot;&amp;gt;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, $block_content );&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; $block_content;&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:#DCBDFB&quot;&gt;add_filter&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;render_block_core/social-link&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;add_mastodon_rel_me&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&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;I’m using this for the link at the bottom of this site ⬇&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer: all Mastodon links (via the social link block) will be updated with the rel=”me” attribute – probably fine for personal sites but maybe not if you are using multiple Mastodon profile links.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Update: &lt;a href=&quot;https://x.com/Mamaduka/status/1609904364088352776&quot;&gt;I’ve been kindly informed&lt;/a&gt; that with Gutenberg 14.5 the link block comes with a &lt;code&gt;rel&lt;/code&gt; attribute option in the UI, this is not yet released in core (my guess would be WP 6.2) but you can get it today by installing the &lt;a href=&quot;https://wordpress.org/plugins/gutenberg/&quot;&gt;Gutenberg feature plugin&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>Block Editor</category><category>WordPress</category></item><item><title>Hello world 2023 edition</title><link>https://rm.codes/blog/hello-world/</link><guid isPermaLink="true">https://rm.codes/blog/hello-world/</guid><description>If you’re seeing this message then its likely you’ve found this site while it’s still in development. This is currently a playground for testing out some new WordPress features (such as FSE) and occasionally blogging about WordPress and web development in general. So 👋 happy new year and bye for now.</description><pubDate>Mon, 02 Jan 2023 10:52:34 GMT</pubDate><content:encoded>&lt;p&gt;If you’re seeing this message then its likely you’ve found this site while it’s still in development.&lt;/p&gt;
&lt;p&gt;This is currently a playground for testing out some new WordPress features (such as FSE) and occasionally blogging about WordPress and web development in general.&lt;/p&gt;
&lt;p&gt;So 👋 happy new year and bye for now.&lt;/p&gt;
</content:encoded></item></channel></rss>