Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
2ndkauboy
/
hide-download-buttons-for-embeds.php
Secret
Last active
Apr 25, 2021
Star
0
Fork
0
Star
Code
Revisions
2
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Hide the download buttons in browers supporting the controlList attribute.
Raw
hide-download-buttons-for-embeds.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
<?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
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.