| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins/wordpress-seo/frontend/ |
Upload File : |
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Frontend
*/
/**
* Class WPSEO_OpenGraph_OEmbed.
*/
class WPSEO_OpenGraph_OEmbed implements WPSEO_WordPress_Integration {
/**
* Registers the hooks.
*/
public function register_hooks() {
// Check to make sure opengraph is enabled before adding filter.
if ( WPSEO_Options::get( 'opengraph' ) ) {
add_filter( 'oembed_response_data', array( $this, 'set_oembed_data' ), 10, 2 );
}
}
/**
* Callback function to pass to the oEmbed's response data that will enable
* support for using the image and title set by the WordPress SEO plugin's fields. This
* address the concern where some social channels/subscribed use oEmebed data over OpenGraph data
* if both are present.
*
* @param array $data The oEmbed data.
* @param WP_Post $post The current Post object.
*
* @link https://developer.wordpress.org/reference/hooks/oembed_response_data/ for hook info.
*
* @return array $filter_data - An array of oEmbed data with modified values where appropriate.
*/
public function set_oembed_data( $data, $post ) {
// Data to be returned.
$filter_data = $data;
// Look for the Yoast meta values (image and title)...
$opengraph_title = WPSEO_Meta::get_value( 'opengraph-title', $post->ID );
$opengraph_image = WPSEO_Meta::get_value( 'opengraph-image', $post->ID );
// If yoast has a title set, update oEmbed with Yoast's title.
if ( ! empty( $opengraph_title ) ) {
$filter_data['title'] = $opengraph_title;
}
// If WPSEO Image was _not_ set, return the `$filter_data` as it currently is.
if ( empty( $opengraph_image ) ) {
return $filter_data;
}
// Since the a WPSEO Image was set, update the oEmbed data with the Yoast Image's info.
// Get the image's ID from a URL.
$image_id = WPSEO_Image_Utils::get_attachment_by_url( $opengraph_image );
// Get the image's info from it's ID.
$image_info = wp_get_attachment_metadata( $image_id );
// Update the oEmbed data.
$filter_data['thumbnail_url'] = $opengraph_image;
if ( ! empty( $image_info['height'] ) ) {
$filter_data['thumbnail_height'] = $image_info['height'];
}
if ( ! empty( $image_info['width'] ) ) {
$filter_data['thumbnail_width'] = $image_info['width'];
}
return $filter_data;
}
}