Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/wordpres.../src/surfaces/values
File: meta.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Surfaces\Values;
[2] Fix | Delete
[3] Fix | Delete
use Exception;
[4] Fix | Delete
use WPSEO_Replace_Vars;
[5] Fix | Delete
use Yoast\WP\SEO\Context\Meta_Tags_Context;
[6] Fix | Delete
use Yoast\WP\SEO\Integrations\Front_End_Integration;
[7] Fix | Delete
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
[8] Fix | Delete
use Yoast\WP\SEO\Presenters\Rel_Next_Presenter;
[9] Fix | Delete
use Yoast\WP\SEO\Presenters\Rel_Prev_Presenter;
[10] Fix | Delete
use Yoast\WP\SEO\Surfaces\Helpers_Surface;
[11] Fix | Delete
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Meta value object.
[15] Fix | Delete
*
[16] Fix | Delete
* @property array $breadcrumbs The breadcrumbs array for the current page.
[17] Fix | Delete
* @property string $canonical The canonical URL for the current page.
[18] Fix | Delete
* @property string $company_name The company name from the Knowledge graph settings.
[19] Fix | Delete
* @property int $company_logo_id The attachment ID for the company logo.
[20] Fix | Delete
* @property string $description The meta description for the current page, if set.
[21] Fix | Delete
* @property int $estimated_reading_time_minutes The estimated reading time in minutes for posts.
[22] Fix | Delete
* @property string $main_schema_id Schema ID that points to the main Schema thing on the page, usually the webpage or article Schema piece.
[23] Fix | Delete
* @property string $meta_description The meta description for the current page, if set.
[24] Fix | Delete
* @property string $open_graph_article_author The article:author value.
[25] Fix | Delete
* @property string $open_graph_article_modified_time The article:modified_time value.
[26] Fix | Delete
* @property string $open_graph_article_published_time The article:published_time value.
[27] Fix | Delete
* @property string $open_graph_article_publisher The article:publisher value.
[28] Fix | Delete
* @property string $open_graph_description The og:description.
[29] Fix | Delete
* @property bool $open_graph_enabled Whether OpenGraph is enabled on this site.
[30] Fix | Delete
* @property string $open_graph_fb_app_id The Facebook App ID.
[31] Fix | Delete
* @property array $open_graph_images The array of images we have for this page.
[32] Fix | Delete
* @property string $open_graph_locale The og:locale for the current page.
[33] Fix | Delete
* @property string $open_graph_publisher The OpenGraph publisher reference.
[34] Fix | Delete
* @property string $open_graph_site_name The og:site_name.
[35] Fix | Delete
* @property string $open_graph_title The og:title.
[36] Fix | Delete
* @property string $open_graph_type The og:type.
[37] Fix | Delete
* @property string $open_graph_url The og:url.
[38] Fix | Delete
* @property string $page_type The Schema page type.
[39] Fix | Delete
* @property array $robots An array of the robots values set for the current page.
[40] Fix | Delete
* @property string $rel_next The next page in the series, if any.
[41] Fix | Delete
* @property string $rel_prev The previous page in the series, if any.
[42] Fix | Delete
* @property array $schema The entire Schema array for the current page.
[43] Fix | Delete
* @property string $schema_page_type The Schema page type.
[44] Fix | Delete
* @property string $site_name The site name from the Yoast SEO settings.
[45] Fix | Delete
* @property string $site_represents Whether the site represents a 'person' or a 'company'.
[46] Fix | Delete
* @property array|false $site_represents_reference The schema reference ID for what this site represents.
[47] Fix | Delete
* @property string $site_url The site's main URL.
[48] Fix | Delete
* @property int $site_user_id If the site represents a 'person', this is the ID of the accompanying user profile.
[49] Fix | Delete
* @property string $title The SEO title for the current page.
[50] Fix | Delete
* @property string $twitter_card The Twitter card type for the current page.
[51] Fix | Delete
* @property string $twitter_creator The Twitter card author for the current page.
[52] Fix | Delete
* @property string $twitter_description The Twitter card description for the current page.
[53] Fix | Delete
* @property string $twitter_image The Twitter card image for the current page.
[54] Fix | Delete
* @property string $twitter_site The Twitter card site reference for the current page.
[55] Fix | Delete
* @property string $twitter_title The Twitter card title for the current page.
[56] Fix | Delete
* @property string $wordpress_site_name The site name from the WordPress settings.
[57] Fix | Delete
*/
[58] Fix | Delete
class Meta {
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* The container.
[62] Fix | Delete
*
[63] Fix | Delete
* @var ContainerInterface
[64] Fix | Delete
*/
[65] Fix | Delete
protected $container;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* The meta tags context.
[69] Fix | Delete
*
[70] Fix | Delete
* @var Meta_Tags_Context
[71] Fix | Delete
*/
[72] Fix | Delete
protected $context;
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* The front end integration.
[76] Fix | Delete
*
[77] Fix | Delete
* @var Front_End_Integration
[78] Fix | Delete
*/
[79] Fix | Delete
protected $front_end;
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* The helpers surface.
[83] Fix | Delete
*
[84] Fix | Delete
* @var Helpers_Surface
[85] Fix | Delete
*/
[86] Fix | Delete
protected $helpers;
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* The replace vars helper
[90] Fix | Delete
*
[91] Fix | Delete
* @var WPSEO_Replace_Vars
[92] Fix | Delete
*/
[93] Fix | Delete
protected $replace_vars;
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Create a meta value object.
[97] Fix | Delete
*
[98] Fix | Delete
* @param Meta_Tags_Context $context The indexable presentation.
[99] Fix | Delete
* @param ContainerInterface $container The DI container.
[100] Fix | Delete
*/
[101] Fix | Delete
public function __construct(
[102] Fix | Delete
Meta_Tags_Context $context,
[103] Fix | Delete
ContainerInterface $container
[104] Fix | Delete
) {
[105] Fix | Delete
$this->container = $container;
[106] Fix | Delete
$this->context = $context;
[107] Fix | Delete
[108] Fix | Delete
$this->helpers = $this->container->get( Helpers_Surface::class );
[109] Fix | Delete
$this->replace_vars = $this->container->get( WPSEO_Replace_Vars::class );
[110] Fix | Delete
$this->front_end = $this->container->get( Front_End_Integration::class );
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Returns the output as would be presented in the head.
[115] Fix | Delete
*
[116] Fix | Delete
* @return object The HTML and JSON presentation of the head metadata.
[117] Fix | Delete
*/
[118] Fix | Delete
public function get_head() {
[119] Fix | Delete
$presenters = $this->get_presenters();
[120] Fix | Delete
[121] Fix | Delete
/** This filter is documented in src/integrations/front-end-integration.php */
[122] Fix | Delete
$presentation = \apply_filters( 'wpseo_frontend_presentation', $this->context->presentation, $this->context );
[123] Fix | Delete
[124] Fix | Delete
$html_output = '';
[125] Fix | Delete
$json_head_fields = [];
[126] Fix | Delete
[127] Fix | Delete
foreach ( $presenters as $presenter ) {
[128] Fix | Delete
$presenter->presentation = $presentation;
[129] Fix | Delete
$presenter->replace_vars = $this->replace_vars;
[130] Fix | Delete
$presenter->helpers = $this->helpers;
[131] Fix | Delete
[132] Fix | Delete
$html_output .= $this->create_html_presentation( $presenter );
[133] Fix | Delete
$json_field = $this->create_json_field( $presenter );
[134] Fix | Delete
[135] Fix | Delete
// Only use the output of presenters that could successfully present their data.
[136] Fix | Delete
if ( $json_field !== null && ! empty( $json_field->key ) ) {
[137] Fix | Delete
$json_head_fields[ $json_field->key ] = $json_field->value;
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
$html_output = \trim( $html_output );
[141] Fix | Delete
[142] Fix | Delete
return (object) [
[143] Fix | Delete
'html' => $html_output,
[144] Fix | Delete
'json' => $json_head_fields,
[145] Fix | Delete
];
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Magic getter for presenting values through the appropriate presenter, if it exists.
[150] Fix | Delete
*
[151] Fix | Delete
* @param string $name The property to get.
[152] Fix | Delete
*
[153] Fix | Delete
* @return mixed The value, as presented by teh appropriate presenter.
[154] Fix | Delete
*
[155] Fix | Delete
* @throws Exception If an invalid property is accessed.
[156] Fix | Delete
*/
[157] Fix | Delete
public function __get( $name ) {
[158] Fix | Delete
/** This filter is documented in src/integrations/front-end-integration.php */
[159] Fix | Delete
$presentation = \apply_filters( 'wpseo_frontend_presentation', $this->context->presentation, $this->context );
[160] Fix | Delete
[161] Fix | Delete
if ( ! isset( $presentation->{$name} ) ) {
[162] Fix | Delete
if ( isset( $this->context->{$name} ) ) {
[163] Fix | Delete
$this->{$name} = $this->context->{$name};
[164] Fix | Delete
return $this->{$name};
[165] Fix | Delete
}
[166] Fix | Delete
return null;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
$presenter_namespace = 'Yoast\WP\SEO\Presenters\\';
[170] Fix | Delete
$parts = \explode( '_', $name );
[171] Fix | Delete
if ( $parts[0] === 'twitter' ) {
[172] Fix | Delete
$presenter_namespace .= 'Twitter\\';
[173] Fix | Delete
$parts = \array_slice( $parts, 1 );
[174] Fix | Delete
}
[175] Fix | Delete
elseif ( $parts[0] === 'open' && $parts[1] === 'graph' ) {
[176] Fix | Delete
$presenter_namespace .= 'Open_Graph\\';
[177] Fix | Delete
$parts = \array_slice( $parts, 2 );
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
$presenter_class = $presenter_namespace . \implode( '_', \array_map( 'ucfirst', $parts ) ) . '_Presenter';
[181] Fix | Delete
[182] Fix | Delete
if ( \class_exists( $presenter_class ) ) {
[183] Fix | Delete
/**
[184] Fix | Delete
* The indexable presenter.
[185] Fix | Delete
*
[186] Fix | Delete
* @var Abstract_Indexable_Presenter
[187] Fix | Delete
*/
[188] Fix | Delete
$presenter = new $presenter_class();
[189] Fix | Delete
$presenter->presentation = $presentation;
[190] Fix | Delete
$presenter->helpers = $this->helpers;
[191] Fix | Delete
$presenter->replace_vars = $this->replace_vars;
[192] Fix | Delete
$value = $presenter->get();
[193] Fix | Delete
}
[194] Fix | Delete
else {
[195] Fix | Delete
$value = $presentation->{$name};
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
$this->{$name} = $value;
[199] Fix | Delete
return $this->{$name};
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Magic isset for ensuring properties on the presentation are recognised.
[204] Fix | Delete
*
[205] Fix | Delete
* @param string $name The property to get.
[206] Fix | Delete
*
[207] Fix | Delete
* @return bool Whether or not the requested property exists.
[208] Fix | Delete
*/
[209] Fix | Delete
public function __isset( $name ) {
[210] Fix | Delete
return isset( $this->context->presentation->{$name} );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Strips all nested dependencies from the debug info.
[215] Fix | Delete
*
[216] Fix | Delete
* @return array
[217] Fix | Delete
*/
[218] Fix | Delete
public function __debugInfo() {
[219] Fix | Delete
return [ 'context' => $this->context ];
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* Returns all presenters.
[224] Fix | Delete
*
[225] Fix | Delete
* @return Abstract_Indexable_Presenter[]
[226] Fix | Delete
*/
[227] Fix | Delete
protected function get_presenters() {
[228] Fix | Delete
$presenters = $this->front_end->get_presenters( $this->context->page_type, $this->context );
[229] Fix | Delete
[230] Fix | Delete
if ( $this->context->page_type === 'Date_Archive' ) {
[231] Fix | Delete
/**
[232] Fix | Delete
* Define a filter that removes objects of type Rel_Next_Presenter or Rel_Prev_Presenter from a list.
[233] Fix | Delete
*
[234] Fix | Delete
* @param object $presenter The presenter to verify.
[235] Fix | Delete
*
[236] Fix | Delete
* @return bool True if the presenter is not a Rel_Next or Rel_Prev presenter.
[237] Fix | Delete
*/
[238] Fix | Delete
$callback = static function ( $presenter ) {
[239] Fix | Delete
return ! \is_a( $presenter, Rel_Next_Presenter::class )
[240] Fix | Delete
&& ! \is_a( $presenter, Rel_Prev_Presenter::class );
[241] Fix | Delete
};
[242] Fix | Delete
$presenters = \array_filter( $presenters, $callback );
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
return $presenters;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Uses the presenter to create a line of HTML.
[250] Fix | Delete
*
[251] Fix | Delete
* @param Abstract_Indexable_Presenter $presenter The presenter.
[252] Fix | Delete
*
[253] Fix | Delete
* @return string
[254] Fix | Delete
*/
[255] Fix | Delete
protected function create_html_presentation( $presenter ) {
[256] Fix | Delete
$presenter_output = $presenter->present();
[257] Fix | Delete
if ( ! empty( $presenter_output ) ) {
[258] Fix | Delete
return $presenter_output . \PHP_EOL;
[259] Fix | Delete
}
[260] Fix | Delete
return '';
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Converts a presenter's key and value to JSON.
[265] Fix | Delete
*
[266] Fix | Delete
* @param Abstract_Indexable_Presenter $presenter The presenter whose key and value are to be converted to JSON.
[267] Fix | Delete
*
[268] Fix | Delete
* @return object|null
[269] Fix | Delete
*/
[270] Fix | Delete
protected function create_json_field( $presenter ) {
[271] Fix | Delete
if ( $presenter->get_key() === 'NO KEY PROVIDED' ) {
[272] Fix | Delete
return null;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
$value = $presenter->get();
[276] Fix | Delete
if ( empty( $value ) ) {
[277] Fix | Delete
return null;
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
return (object) [
[281] Fix | Delete
'key' => $presenter->escape_key(),
[282] Fix | Delete
'value' => $value,
[283] Fix | Delete
];
[284] Fix | Delete
}
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function