WordPress multisite user permissions are much more restrictive than on WordPress single site. One such change is that on multisite only super-admin users have the ‘unfiltered_html’ capability. It is possible however to restore our desired user permissions on multisite using a filter on the ‘map_meta_cap’hook. map_meta_cap The map_meta_cap hook can be used to provide additional …
Blog
WordPress add_filter and apply_filters
I used to find the difference between add_filter and apply_filters in WordPress quite confusing. While these two functions are related they are also entirely different. I’ll explain below how their purpose and usage differs. apply_filters The apply_filters function “calls the callback functions that have been added to a filter hook”. If that explanation seems clear …
WordPress Media Iframe With Custom Attributes
I recently worked on a case in the WordPress block editor in which I needed to add support for clipboard events in a media iframe. In this case, the iframe was being used inside a custom version of wp.media.view.MediaFrame. While wp.media.view does not natively support custom attributes on iframes, we can create our own custom …
Continue reading “WordPress Media Iframe With Custom Attributes”
Create WordPress Post Meta When a Post is Created
When working with WordPress post meta data, we may want to create our own custom post meta fields. To create WordPress post meta fields when a post is created, we can do so with a PHP function like this: We can then attach our function to the ‘wp_insert_post’ action hook: So our complete code looks …
Continue reading “Create WordPress Post Meta When a Post is Created”
Only Commit Changes to Tracked Files in Git
I recently started using the command git add -u when preparing my code for commit via the command line. This helps me to only commit changes to tracked files. Not long ago I would occasionally make accidental commits of untracked file changes when using the command git add . If you’re new to git, the …
Continue reading “Only Commit Changes to Tracked Files in Git”
WordPress User Notices
When working in WordPress’ Gutenberg editor, there may be times when we wish to notify the admin user of a change or response to an action. For example, if we have a custom block that makes a remote API request, we might want to notify the user about the result of that request. Luckily, WordPress …
How To Write A Good Pull Request
I’ve found that the more informative I make my pull request descriptions, the more quickly they get reviewed and the less bugs they generate in the future. To this end and to avoid annoying my colleagues, I follow a few guidelines on how to write a good pull request. Provide Context What is the nature …
Remove Whitespace From Code Changes
I can’t tell you how many times I’ve committed and pushed some code changes only to realize or have a colleague point out that my changes introduced trailing whitespace. This happened all too frequently until I recently adopted some tools and practices to keep my whitespace in check. Turns out it’s pretty easy to remove …
PHP Null Coalescing Operator
Until recently, I often found myself using conditional logic with isset() in cases like the following: or perhaps using a ternary: The above examples work just fine, and if you’re using an older version of PHP, these might be some of your best options. However, users of PHP 7.0 and newer can take advantage of …