PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
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 / deprecated / frontend / breadcrumbs.php

breadcrumbs.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/deprecated/frontend/breadcrumbs.php

143 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Backwards compatibility class for breadcrumbs.
4 *
5 * @package Yoast\YoastSEO\Backwards_Compatibility
6 */
7
8 use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
9 use Yoast\WP\SEO\Presenters\Breadcrumbs_Presenter;
10 use Yoast\WP\SEO\Surfaces\Helpers_Surface;
11
12 /**
13 * Class WPSEO_Breadcrumbs
14 *
15 * @codeCoverageIgnore Because of deprecation.
16 */
17 class WPSEO_Breadcrumbs {
18
19 /**
20 * Instance of this class.
21 *
22 * @var WPSEO_Breadcrumbs
23 */
24 public static $instance;
25
26 /**
27 * Last used 'before' string.
28 *
29 * @var string
30 */
31 public static $before = '';
32
33 /**
34 * Last used 'after' string.
35 *
36 * @var string
37 */
38 public static $after = '';
39
40 /**
41 * The memoizer for the meta tags context.
42 *
43 * @var Meta_Tags_Context_Memoizer
44 */
45 protected $context_memoizer;
46
47 /**
48 * The helpers surface.
49 *
50 * @var Helpers_Surface
51 */
52 protected $helpers;
53
54 /**
55 * The replace vars helper
56 *
57 * @var WPSEO_Replace_Vars
58 */
59 protected $replace_vars;
60
61 /**
62 * WPSEO_Breadcrumbs constructor.
63 */
64 public function __construct() {
65 $this->context_memoizer = YoastSEO()->classes->get( Meta_Tags_Context_Memoizer::class );
66 $this->helpers = YoastSEO()->classes->get( Helpers_Surface::class );
67 $this->replace_vars = YoastSEO()->classes->get( WPSEO_Replace_Vars::class );
68 }
69
70 /**
71 * Get breadcrumb string using the singleton instance of this class.
72 *
73 * @param string $before Optional string to prepend.
74 * @param string $after Optional string to append.
75 * @param bool $display Echo or return flag.
76 *
77 * @return string Returns the breadcrumbs as a string.
78 */
79 public static function breadcrumb( $before = '', $after = '', $display = true ) {
80 // Remember the last used before/after for use in case the object goes __toString().
81 self::$before = $before;
82 self::$after = $after;
83 $output = $before . self::get_instance()->render() . $after;
84
85 if ( $display === true ) {
86 echo $output;
87
88 return '';
89 }
90
91 return $output;
92 }
93
94 /**
95 * Magic method to use in case the class would be send to string.
96 *
97 * @return string The rendered breadcrumbs.
98 */
99 public function __toString() {
100 return self::$before . $this->render() . self::$after;
101 }
102
103 /**
104 * Retrieves an instance of the class.
105 *
106 * @return static The instance.
107 */
108 public static function get_instance() {
109 self::$instance ??= new self();
110
111 return self::$instance;
112 }
113
114 /**
115 * Returns the collected links for the breadcrumbs.
116 *
117 * @return array The collected links.
118 */
119 public function get_links() {
120 $context = $this->context_memoizer->for_current_page();
121
122 return $context->presentation->breadcrumbs;
123 }
124
125 /**
126 * Renders the breadcrumbs.
127 *
128 * @return string The rendered breadcrumbs.
129 */
130 private function render() {
131 $presenter = new Breadcrumbs_Presenter();
132 $context = $this->context_memoizer->for_current_page();
133
134 /** This filter is documented in src/integrations/front-end-integration.php */
135 $presentation = apply_filters( 'wpseo_frontend_presentation', $context->presentation, $context );
136 $presenter->presentation = $presentation;
137 $presenter->replace_vars = $this->replace_vars;
138 $presenter->helpers = $this->helpers;
139
140 return $presenter->present();
141 }
142 }
143