Making WordPress.org

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#3313 closed enhancement (invalid)

Change get_oembed_response_data to apply filters to title

Reported by: mheikkila's profile mheikkila Owned by:
Milestone: Priority: normal
Component: API Keywords:
Cc:

Description

The function get_oembed_response_data in wp-includes/embed.php outputs the title using

$post->post_title

This is a problem when the title includes special tags. For example, the very popular plugin qTranslateX (https://fi.wordpress.org/plugins/qtranslate-x/) does this to manage multilingual content. In this case, the function should use this to output the title:

apply_filters('the_title',$post->post_title)

The oembed content overrides the og tags. This is a problem for example when sharing a link to LinkedIn.

Change History (3)

#1 @mheikkila
7 years ago

So here would be the new get_oembed_response_data function:

function get_oembed_response_data( $post, $width ) {
	$post  = get_post( $post );
	$width = absint( $width );

	if ( ! $post ) {
		return false;
	}

	if ( 'publish' !== get_post_status( $post ) ) {
		return false;
	}

	/**
	 * Filters the allowed minimum and maximum widths for the oEmbed response.
	 *
	 * @since 4.4.0
	 *
	 * @param array $min_max_width {
	 *     Minimum and maximum widths for the oEmbed response.
	 *
	 *     @type int $min Minimum width. Default 200.
	 *     @type int $max Maximum width. Default 600.
	 * }
	 */
	$min_max_width = apply_filters( 'oembed_min_max_width', array(
		'min' => 200,
		'max' => 600
	) );

	$width  = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
	$height = max( ceil( $width / 16 * 9 ), 200 );

	$data = array(
		'version'       => '1.0',
		'provider_name' => get_bloginfo( 'name' ),
		'provider_url'  => get_home_url(),
		'author_name'   => get_bloginfo( 'name' ),
		'author_url'    => get_home_url(),
		'title'         => apply_filters('the_title',$post->post_title),
		'type'          => 'link',
	);

	$author = get_userdata( $post->post_author );

	if ( $author ) {
		$data['author_name'] = $author->display_name;
		$data['author_url']  = get_author_posts_url( $author->ID );
	}

	/**
	 * Filters the oEmbed response data.
	 *
	 * @since 4.4.0
	 *
	 * @param array   $data   The response data.
	 * @param WP_Post $post   The post object.
	 * @param int     $width  The requested width.
	 * @param int     $height The calculated height.
	 */
	return apply_filters( 'oembed_response_data', $data, $post, $width, $height );
}

#2 @Otto42
7 years ago

  • Resolution set to invalid
  • Status changed from new to closed

If you're talking about modifying part of WordPress itself, then you should make a ticket in core.trac.wordpress.org for it.

This is the meta.trac, where we handle issues with the WordPress.org website itself, along with the surrounding properties like wordcamp.org, browsehappy.com, the make.wordpress.org sites, and others.

#3 @Otto42
7 years ago

  • Keywords needs-patch dev-feedback removed
Note: See TracTickets for help on using tickets.