Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/presente.../open-gra...
File: image-presenter.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Presenters\Open_Graph;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
[4] Fix | Delete
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Presenter class for the Open Graph image.
[8] Fix | Delete
*/
[9] Fix | Delete
class Image_Presenter extends Abstract_Indexable_Presenter {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* The tag key name.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string
[15] Fix | Delete
*/
[16] Fix | Delete
protected $key = 'og:image';
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Image tags that we output for each image.
[20] Fix | Delete
*
[21] Fix | Delete
* @var array<string>
[22] Fix | Delete
*/
[23] Fix | Delete
protected static $image_tags = [
[24] Fix | Delete
'width' => 'width',
[25] Fix | Delete
'height' => 'height',
[26] Fix | Delete
'type' => 'type',
[27] Fix | Delete
];
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Returns the image for a post.
[31] Fix | Delete
*
[32] Fix | Delete
* @return string The image tag.
[33] Fix | Delete
*/
[34] Fix | Delete
public function present() {
[35] Fix | Delete
$images = $this->get();
[36] Fix | Delete
[37] Fix | Delete
if ( empty( $images ) ) {
[38] Fix | Delete
return '';
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
$return = '';
[42] Fix | Delete
foreach ( $images as $image_meta ) {
[43] Fix | Delete
$image_url = $image_meta['url'];
[44] Fix | Delete
[45] Fix | Delete
if ( \is_attachment() ) {
[46] Fix | Delete
global $wp;
[47] Fix | Delete
$image_url = \home_url( $wp->request );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$class = \is_admin_bar_showing() ? ' class="yoast-seo-meta-tag"' : '';
[51] Fix | Delete
[52] Fix | Delete
$return .= '<meta property="og:image" content="' . \esc_url( $image_url, null, 'attribute' ) . '"' . $class . ' />';
[53] Fix | Delete
[54] Fix | Delete
foreach ( static::$image_tags as $key => $value ) {
[55] Fix | Delete
if ( empty( $image_meta[ $key ] ) ) {
[56] Fix | Delete
continue;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
$return .= \PHP_EOL . "\t" . '<meta property="og:image:' . \esc_attr( $key ) . '" content="' . \esc_attr( $image_meta[ $key ] ) . '"' . $class . ' />';
[60] Fix | Delete
}
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
return $return;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Gets the raw value of a presentation.
[68] Fix | Delete
*
[69] Fix | Delete
* @return array<string,int> The raw value.
[70] Fix | Delete
*/
[71] Fix | Delete
public function get() {
[72] Fix | Delete
$images = [];
[73] Fix | Delete
[74] Fix | Delete
foreach ( $this->presentation->open_graph_images as $open_graph_image ) {
[75] Fix | Delete
$images[] = \array_intersect_key(
[76] Fix | Delete
// First filter the object.
[77] Fix | Delete
$this->filter( $open_graph_image ),
[78] Fix | Delete
// Then strip all keys that aren't in the image tags or the url.
[79] Fix | Delete
\array_flip( \array_merge( static::$image_tags, [ 'url' ] ) )
[80] Fix | Delete
);
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return \array_filter( $images );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Run the image content through the `wpseo_opengraph_image` filter.
[88] Fix | Delete
*
[89] Fix | Delete
* @param array<string,int> $image The image.
[90] Fix | Delete
*
[91] Fix | Delete
* @return array<string,int> The filtered image.
[92] Fix | Delete
*/
[93] Fix | Delete
protected function filter( $image ) {
[94] Fix | Delete
/**
[95] Fix | Delete
* Filter: 'wpseo_opengraph_image' - Allow changing the Open Graph image url.
[96] Fix | Delete
*
[97] Fix | Delete
* @param string $image_url The URL of the Open Graph image.
[98] Fix | Delete
* @param Indexable_Presentation $presentation The presentation of an indexable.
[99] Fix | Delete
*/
[100] Fix | Delete
$image_url = \apply_filters( 'wpseo_opengraph_image', $image['url'], $this->presentation );
[101] Fix | Delete
if ( ! empty( $image_url ) && \is_string( $image_url ) ) {
[102] Fix | Delete
$image['url'] = \trim( $image_url );
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
$image_type = ( $image['type'] ?? '' );
[106] Fix | Delete
/**
[107] Fix | Delete
* Filter: 'wpseo_opengraph_image_type' - Allow changing the Open Graph image type.
[108] Fix | Delete
*
[109] Fix | Delete
* @param string $image_type The type of the Open Graph image.
[110] Fix | Delete
* @param Indexable_Presentation $presentation The presentation of an indexable.
[111] Fix | Delete
*/
[112] Fix | Delete
$image_type = \apply_filters( 'wpseo_opengraph_image_type', $image_type, $this->presentation );
[113] Fix | Delete
if ( ! empty( $image_type ) && \is_string( $image_type ) ) {
[114] Fix | Delete
$image['type'] = \trim( $image_type );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
$image_width = ( $image['width'] ?? '' );
[118] Fix | Delete
/**
[119] Fix | Delete
* Filter: 'wpseo_opengraph_image_width' - Allow changing the Open Graph image width.
[120] Fix | Delete
*
[121] Fix | Delete
* @param int $image_width The width of the Open Graph image.
[122] Fix | Delete
* @param Indexable_Presentation $presentation The presentation of an indexable.
[123] Fix | Delete
*/
[124] Fix | Delete
$image_width = (int) \apply_filters( 'wpseo_opengraph_image_width', $image_width, $this->presentation );
[125] Fix | Delete
if ( ! empty( $image_width ) && $image_width > 0 ) {
[126] Fix | Delete
$image['width'] = $image_width;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
$image_height = ( $image['height'] ?? '' );
[130] Fix | Delete
/**
[131] Fix | Delete
* Filter: 'wpseo_opengraph_image_height' - Allow changing the Open Graph image height.
[132] Fix | Delete
*
[133] Fix | Delete
* @param int $image_height The height of the Open Graph image.
[134] Fix | Delete
* @param Indexable_Presentation $presentation The presentation of an indexable.
[135] Fix | Delete
*/
[136] Fix | Delete
$image_height = (int) \apply_filters( 'wpseo_opengraph_image_height', $image_height, $this->presentation );
[137] Fix | Delete
if ( ! empty( $image_height ) && $image_height > 0 ) {
[138] Fix | Delete
$image['height'] = $image_height;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
return $image;
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function