Adds a core/embed block filter to transform iframes to links (#750)

* Add function to transform outgoing embed/iframe to simple url

* Fix descriptions and code style

* filter content for core/embed blocks

* some re-arranges

---------

Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
This commit is contained in:
Django 2024-05-02 01:39:25 -06:00 committed by GitHub
parent 5b9131fded
commit dd5aa9ba5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -702,6 +702,8 @@ class Post extends Base {
*/
do_action( 'activitypub_before_get_content', $post );
add_filter( 'render_block_core/embed', array( self::class, 'revert_embed_links' ), 10, 2 );
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$post = $this->wp_object;
$content = $this->get_post_content_template();
@ -786,4 +788,21 @@ class Post extends Base {
*/
return apply_filters( 'activitypub_post_locale', $lang, $post_id, $this->wp_object );
}
/**
* Transform Embed blocks to block level link.
*
* Remote servers will simply drop iframe elements, rendering incomplete content.
*
* @see https://www.w3.org/TR/activitypub/#security-sanitizing-content
* @see https://www.w3.org/wiki/ActivityPub/Primer/HTML
*
* @param string $block_content The block content (html)
* @param object $block The block object
*
* @return string A block level link
*/
public static function revert_embed_links( $block_content, $block ) {
return '<p><a href="' . esc_url( $block['attrs']['url'] ) . '">' . $block['attrs']['url'] . '</a></p>';
}
}