August 2021

REST API Blocks plugin update

The REST API blocks plugin, has been available to download via github, since June 2019. You can checkout the original blog post where I discuss the use of this plugin here.

But I got a request from a user to add the plugin to the WordPress.org plugin repo. Normally, I don’t submit my plugins to the plugin repo, as they are developer focused, but in this case, it seems to makes sense to submit this one. So if you want to download this plugin, it can be found here. If you are using composer, I have also submitted it to packagist, so it can also be installed via composer.

Along with the plugin now easier to get than ever, I also released version 0.3.0. This update includes.

  • Improved handling of table blocks.
  • Improved translations.
  • Improved error handling, if composer install is not run.

The future of the plugin

I am currently actively maintaining the plugin and adding new features. If you have any feature request, please feel free to add them in as a github issue.

As of WordPress 5.8, there is a new block based widget editor. There is a pull request to a block data to the new widget rest api. I hope this functionality merged and get a version 0.4.0 out very soon.

I want to get to the point, there the unit test coverage is a such that it is a plugin that can be used widely. It is useful for others to use this plugin and help me find bugs and test the code. I hope in the future, that this plugin could be used to create a template for a WordPress core patch, meaning this functionality would be part of WordPress. But while blocks are actively changing and with full site editing around the corner, but feels like this functionality should live as a plugin, for the near future.

I hope you joy the plugin, if you have an feedback, please create a github issue. If you like my work and want to see more of it, I opened sponsorship via my github sponsor page.

Detect if video has audio

While working on the Web Stories for WordPress plugin and working on functionality to mute videos, there was a need to detect if a video already had audio or not. But doing some quick googling, I noticed there none of the answers I found online works well or at all. Worse yet, the answers were not written using modern javascript, either not using promises or using jQuery. So today, I am sharing this gist, in hopes that the next person who comes across this problem, has a workabout solution.

function hasAudio(video) {
return (
video.mozHasAudio ||
Boolean(video.webkitAudioDecodedByteCount) ||
Boolean(video.audioTracks?.length)
);
}
function hasVideoGotAudio(src) {
const video = document.createElement('video');
video.muted = true;
video.crossOrigin = 'anonymous';
video.preload = 'auto';
return new Promise((resolve, reject) => {
video.addEventListener('error', reject);
video.addEventListener(
'canplay',
() => {
video.currentTime = 0.99;
},
{ once: true } // Important because 'canplay' can be fired hundreds of times.
);
video.addEventListener('seeked', () => resolve(hasAudio(video)), {
once: true,
});
video.src = src;
});
}
export default hasVideoGotAudio;
view raw hasVideoGotAudio.js hosted with ❤ by GitHub

Open for sponsorship

I have been contributing to WordPress since 2015. In my 6 years of contributing I have worked on nearly all parts of core, spreading my contribution to the parts of WordPress I felt that needed me the most. In my time I have help land, some features I am really proud of. These include but are not limited too

  • White screen of death protection.
  • Default meta values
  • WP_Site_Query and WP_Network_Query.
  • Block types REST API
  • Lazy loading images.
  • WebP support.
  • And many more.

Today I announce that I’ve started accepting sponsorship via the GitHub Sponsors program. I am asking for sponsorship, so that I can continue to work on open source and dedicate more time to and not be restricted by limited time between client projects. This ensures that going forward, I continue to contribute and keep making the open web better.

I want to make it clear, even without sponsorship, I will continue to work on open source, but support will help me maintain my plugins and tools and keep them free for everyone.