Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Last active April 25, 2021 20:28
Show Gist options
  • Save 2ndkauboy/f9b357002202c06aeeca9431f6772dc4 to your computer and use it in GitHub Desktop.
Save 2ndkauboy/f9b357002202c06aeeca9431f6772dc4 to your computer and use it in GitHub Desktop.
Hide the download buttons in browers supporting the controlList attribute.
<?php
/**
* Hide Download Buttons for Embeds
*
* @package hdboe
* @author Bernhard Kau
* @license GPLv3
*
* @wordpress-plugin
* Plugin Name: Hide Download Buttons for Embeds
* Plugin URI: https://gist.github.com/2ndkauboy/f9b357002202c06aeeca9431f6772dc4
* Description: Hide the download buttons in browers supporting the controlList attribute.
* Version: 1.0.0
* Author: Bernhard Kau
* Author URI: https://kau-boys.de
* Text Domain: hide-download-button-on-embeds
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
*/
/**
* Add the controlsList attribute to audio blocks to hide the download button
*
* @param string $block_content The block content about to be appended.
* @param array $block The full block, including name and attributes.
*
* @return string
*/
function hide_download_buttons_on_embeds_render_block( $block_content, $block ) {
if ( 'core/audio' === $block['blockName'] ) {
$block_content = str_replace( '<audio ', '<audio controlsList="nodownload" ', $block_content );
}
if ( 'core/video' === $block['blockName'] ) {
$block_content = str_replace( '<video ', '<video controlsList="nodownload" ', $block_content );
}
return $block_content;
}
add_filter( 'render_block', 'hide_download_buttons_on_embeds_render_block', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment