mirror of
https://github.com/Automattic/wordpress-activitypub
synced 2024-10-18 14:23:31 +00:00
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:
parent
5b9131fded
commit
dd5aa9ba5f
1 changed files with 19 additions and 0 deletions
|
@ -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>';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue