Phase 5: Content and SEO - Yoast SEO, Schema.org markup, Open Graph, favicon support, XML sitemap
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph article author.
|
||||
*/
|
||||
class Article_Author_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'article:author';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Run the article author's Facebook URL through the `wpseo_opengraph_author_facebook` filter.
|
||||
*
|
||||
* @return string The filtered article author's Facebook URL.
|
||||
*/
|
||||
public function get() {
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_author_facebook' - Allow developers to filter the article author's Facebook URL.
|
||||
*
|
||||
* @param bool|string $article_author The article author's Facebook URL, return false to disable.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
return \trim( \apply_filters( 'wpseo_opengraph_author_facebook', $this->presentation->open_graph_article_author, $this->presentation ) );
|
||||
}
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph article modified time.
|
||||
*/
|
||||
class Article_Modified_Time_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'article:modified_time';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Gets the raw value of a presentation.
|
||||
*
|
||||
* @return string The raw value.
|
||||
*/
|
||||
public function get() {
|
||||
return $this->presentation->open_graph_article_modified_time;
|
||||
}
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph article published time.
|
||||
*/
|
||||
class Article_Published_Time_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'article:published_time';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Gets the raw value of a presentation.
|
||||
*
|
||||
* @return string The raw value.
|
||||
*/
|
||||
public function get() {
|
||||
return $this->presentation->open_graph_article_published_time;
|
||||
}
|
||||
}
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph article publisher.
|
||||
*/
|
||||
class Article_Publisher_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'article:publisher';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Run the article publisher's Facebook URL through the `wpseo_og_article_publisher` filter.
|
||||
*
|
||||
* @return string The filtered article publisher's Facebook URL.
|
||||
*/
|
||||
public function get() {
|
||||
/**
|
||||
* Filter: 'wpseo_og_article_publisher' - Allow developers to filter the article publisher's Facebook URL.
|
||||
*
|
||||
* @param bool|string $article_publisher The article publisher's Facebook URL, return false to disable.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
return \trim( \apply_filters( 'wpseo_og_article_publisher', $this->presentation->open_graph_article_publisher, $this->presentation ) );
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph description.
|
||||
*/
|
||||
class Description_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'og:description';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Run the Open Graph description through replace vars and the `wpseo_opengraph_desc` filter and sanitization.
|
||||
*
|
||||
* @return string The filtered description.
|
||||
*/
|
||||
public function get() {
|
||||
$meta_og_description = $this->replace_vars( $this->presentation->open_graph_description );
|
||||
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_desc' - Allow changing the Yoast SEO generated Open Graph description.
|
||||
*
|
||||
* @param string $description The description.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
$meta_og_description = \apply_filters( 'wpseo_opengraph_desc', $meta_og_description, $this->presentation );
|
||||
$meta_og_description = $this->helpers->string->strip_all_tags( \stripslashes( $meta_og_description ) );
|
||||
return \trim( $meta_og_description );
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph image.
|
||||
*/
|
||||
class Image_Presenter extends Abstract_Indexable_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'og:image';
|
||||
|
||||
/**
|
||||
* Image tags that we output for each image.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected static $image_tags = [
|
||||
'width' => 'width',
|
||||
'height' => 'height',
|
||||
'type' => 'type',
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns the image for a post.
|
||||
*
|
||||
* @return string The image tag.
|
||||
*/
|
||||
public function present() {
|
||||
$images = $this->get();
|
||||
|
||||
if ( empty( $images ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$return = '';
|
||||
foreach ( $images as $image_meta ) {
|
||||
$image_url = $image_meta['url'];
|
||||
|
||||
if ( \is_attachment() ) {
|
||||
global $wp;
|
||||
$image_url = \home_url( $wp->request );
|
||||
}
|
||||
|
||||
$class = \is_admin_bar_showing() ? ' class="yoast-seo-meta-tag"' : '';
|
||||
|
||||
$return .= '<meta property="og:image" content="' . \esc_url( $image_url, null, 'attribute' ) . '"' . $class . ' />';
|
||||
|
||||
foreach ( static::$image_tags as $key => $value ) {
|
||||
if ( empty( $image_meta[ $key ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$return .= \PHP_EOL . "\t" . '<meta property="og:image:' . \esc_attr( $key ) . '" content="' . \esc_attr( $image_meta[ $key ] ) . '"' . $class . ' />';
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw value of a presentation.
|
||||
*
|
||||
* @return array<string, int> The raw value.
|
||||
*/
|
||||
public function get() {
|
||||
$images = [];
|
||||
|
||||
foreach ( $this->presentation->open_graph_images as $open_graph_image ) {
|
||||
$images[] = \array_intersect_key(
|
||||
// First filter the object.
|
||||
$this->filter( $open_graph_image ),
|
||||
// Then strip all keys that aren't in the image tags or the url.
|
||||
\array_flip( \array_merge( static::$image_tags, [ 'url' ] ) )
|
||||
);
|
||||
}
|
||||
|
||||
return \array_filter( $images );
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the image content through the `wpseo_opengraph_image` filter.
|
||||
*
|
||||
* @param array<string, string|int> $image The image.
|
||||
*
|
||||
* @return array<string, string|int> The filtered image.
|
||||
*/
|
||||
protected function filter( $image ) {
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_image' - Allow changing the Open Graph image url.
|
||||
*
|
||||
* @param string $image_url The URL of the Open Graph image.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
$image_url = \apply_filters( 'wpseo_opengraph_image', $image['url'], $this->presentation );
|
||||
if ( ! empty( $image_url ) && \is_string( $image_url ) ) {
|
||||
$image['url'] = \trim( $image_url );
|
||||
}
|
||||
|
||||
$image_type = ( $image['type'] ?? '' );
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_image_type' - Allow changing the Open Graph image type.
|
||||
*
|
||||
* @param string $image_type The type of the Open Graph image.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
$image_type = \apply_filters( 'wpseo_opengraph_image_type', $image_type, $this->presentation );
|
||||
if ( ! empty( $image_type ) && \is_string( $image_type ) ) {
|
||||
$image['type'] = \trim( $image_type );
|
||||
}
|
||||
else {
|
||||
$image['type'] = '';
|
||||
}
|
||||
|
||||
$image_width = ( $image['width'] ?? '' );
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_image_width' - Allow changing the Open Graph image width.
|
||||
*
|
||||
* @param int $image_width The width of the Open Graph image.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
$image_width = (int) \apply_filters( 'wpseo_opengraph_image_width', $image_width, $this->presentation );
|
||||
if ( ! empty( $image_width ) && $image_width > 0 ) {
|
||||
$image['width'] = $image_width;
|
||||
}
|
||||
else {
|
||||
$image['width'] = '';
|
||||
}
|
||||
|
||||
$image_height = ( $image['height'] ?? '' );
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_image_height' - Allow changing the Open Graph image height.
|
||||
*
|
||||
* @param int $image_height The height of the Open Graph image.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
$image_height = (int) \apply_filters( 'wpseo_opengraph_image_height', $image_height, $this->presentation );
|
||||
if ( ! empty( $image_height ) && $image_height > 0 ) {
|
||||
$image['height'] = $image_height;
|
||||
}
|
||||
else {
|
||||
$image['height'] = '';
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Final presenter class for the Open Graph locale.
|
||||
*/
|
||||
final class Locale_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'og:locale';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Run the locale through the `wpseo_og_locale` filter.
|
||||
*
|
||||
* @return string The filtered locale.
|
||||
*/
|
||||
public function get() {
|
||||
/**
|
||||
* Filter: 'wpseo_og_locale' - Allow changing the Yoast SEO Open Graph locale.
|
||||
*
|
||||
* @param string $locale The locale string
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
return (string) \trim( \apply_filters( 'wpseo_og_locale', $this->presentation->open_graph_locale, $this->presentation ) );
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph site name.
|
||||
*/
|
||||
class Site_Name_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'og:site_name';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Runs the site name through the `wpseo_opengraph_site_name` filter.
|
||||
*
|
||||
* @return string The filtered site_name.
|
||||
*/
|
||||
public function get() {
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_site_name' - Allow changing the Yoast SEO generated Open Graph site name.
|
||||
*
|
||||
* @param string $site_name The site_name.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
return (string) \trim( \apply_filters( 'wpseo_opengraph_site_name', $this->presentation->open_graph_site_name, $this->presentation ) );
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph title.
|
||||
*/
|
||||
class Title_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'og:title';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Run the title content through replace vars, the `wpseo_opengraph_title` filter and sanitization.
|
||||
*
|
||||
* @return string The filtered title.
|
||||
*/
|
||||
public function get() {
|
||||
$title = $this->replace_vars( $this->presentation->open_graph_title );
|
||||
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_title' - Allow changing the Yoast SEO generated title.
|
||||
*
|
||||
* @param string $title The title.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
$title = \trim( (string) \apply_filters( 'wpseo_opengraph_title', $title, $this->presentation ) );
|
||||
return $this->helpers->string->strip_all_tags( $title );
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph type.
|
||||
*/
|
||||
class Type_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'og:type';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* Run the opengraph type content through the `wpseo_opengraph_type` filter.
|
||||
*
|
||||
* @return string The filtered type.
|
||||
*/
|
||||
public function get() {
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_type' - Allow changing the opengraph type.
|
||||
*
|
||||
* @param string $type The type.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
return (string) \apply_filters( 'wpseo_opengraph_type', $this->presentation->open_graph_type, $this->presentation );
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Presenters\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Presentations\Indexable_Presentation;
|
||||
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
|
||||
|
||||
/**
|
||||
* Presenter class for the Open Graph URL.
|
||||
*/
|
||||
class Url_Presenter extends Abstract_Indexable_Tag_Presenter {
|
||||
|
||||
/**
|
||||
* The tag key name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key = 'og:url';
|
||||
|
||||
/**
|
||||
* The tag format including placeholders.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tag_format = self::META_PROPERTY_CONTENT;
|
||||
|
||||
/**
|
||||
* The method of escaping to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $escaping = 'attribute';
|
||||
|
||||
/**
|
||||
* Run the url content through the `wpseo_opengraph_url` filter.
|
||||
*
|
||||
* @return string The filtered url.
|
||||
*/
|
||||
public function get() {
|
||||
/**
|
||||
* Filter: 'wpseo_opengraph_url' - Allow changing the Yoast SEO generated open graph URL.
|
||||
*
|
||||
* @param string $url The open graph URL.
|
||||
* @param Indexable_Presentation $presentation The presentation of an indexable.
|
||||
*/
|
||||
return \urldecode( (string) \apply_filters( 'wpseo_opengraph_url', $this->presentation->open_graph_url, $this->presentation ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user