PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.4
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / presenters / abstract-indexable-tag-presenter.php

abstract-indexable-tag-presenter.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.4, at src/presenters/abstract-indexable-tag-presenter.php

69 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Presenters;
4
5 /**
6 * Abstract presenter class for indexable tag presentations.
7 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
8 * @phpcs:disable Yoast.Files.FileName.InvalidClassFileName
9 */
10 abstract class Abstract_Indexable_Tag_Presenter extends Abstract_Indexable_Presenter {
11
12 const META_PROPERTY_CONTENT = '<meta property="%2$s" content="%1$s" />';
13 const META_NAME_CONTENT = '<meta name="%2$s" content="%1$s" />';
14 const LINK_REL_HREF = '<link rel="%2$s" href="%1$s" />';
15 const DEFAULT_TAG_FORMAT = self::META_NAME_CONTENT;
16
17 /**
18 * The tag format including placeholders.
19 *
20 * @var string
21 */
22 protected $tag_format = self::DEFAULT_TAG_FORMAT;
23
24 /**
25 * The method of escaping to use.
26 *
27 * @var string
28 */
29 protected $escaping = 'attribute';
30
31 /**
32 * Returns a tag in the head.
33 *
34 * @return string The tag.
35 */
36 public function present() {
37 $value = $this->get();
38
39 if ( ! \is_string( $value ) || $value === '' ) {
40 return '';
41 }
42
43 /**
44 * There may be some classes that are derived from this class that do not use the $key property
45 * in their $tag_format string. In that case the key property will simply not be used.
46 */
47 return \sprintf( $this->tag_format, $this->escape_value( $value ), $this->key );
48 }
49
50 /**
51 * Escaped the output.
52 *
53 * @param string $value The desired method of escaping; 'html', 'url' or 'attribute'.
54 *
55 * @return string The escaped value.
56 */
57 protected function escape_value( $value ) {
58 switch ( $this->escaping ) {
59 case 'html':
60 return \esc_html( $value );
61 case 'url':
62 return \esc_url( $value );
63 case 'attribute':
64 default:
65 return \esc_attr( $value );
66 }
67 }
68 }
69