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 / editors / framework / seo / posts / title-data-provider.php

title-data-provider.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/editors/framework/seo/posts/title-data-provider.php

76 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 // phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
5 namespace Yoast\WP\SEO\Editors\Framework\Seo\Posts;
6
7 use Yoast\WP\SEO\Editors\Domain\Seo\Seo_Plugin_Data_Interface;
8 use Yoast\WP\SEO\Editors\Domain\Seo\Title;
9 use Yoast\WP\SEO\Editors\Framework\Seo\Title_Data_Provider_Interface;
10 use Yoast\WP\SEO\Helpers\Options_Helper;
11
12 /**
13 * Describes if the title SEO data.
14 */
15 class Title_Data_Provider extends Abstract_Post_Seo_Data_Provider implements Title_Data_Provider_Interface {
16
17 /**
18 * The options helper.
19 *
20 * @var Options_Helper
21 */
22 private $options_helper;
23
24 /**
25 * The constructor.
26 *
27 * @param Options_Helper $options_helper The options helper.
28 */
29 public function __construct( Options_Helper $options_helper ) {
30 $this->options_helper = $options_helper;
31 }
32
33 /**
34 * Retrieves the title template.
35 *
36 * @param bool $fallback Whether to return the hardcoded fallback if the template value is empty.
37 *
38 * @return string The title template.
39 */
40 public function get_title_template( bool $fallback = true ): string {
41 $title = $this->get_template( 'title' );
42
43 if ( $title === '' && $fallback === true ) {
44 return '%%title%% %%page%% %%sep%% %%sitename%%';
45 }
46
47 return $title;
48 }
49
50 /**
51 * Retrieves a template.
52 *
53 * @param string $template_option_name The name of the option in which the template you want to get is saved.
54 *
55 * @return string
56 */
57 private function get_template( string $template_option_name ): string {
58 $needed_option = $template_option_name . '-' . $this->post->post_type;
59
60 if ( $this->options_helper->get( $needed_option, '' ) !== '' ) {
61 return $this->options_helper->get( $needed_option );
62 }
63
64 return '';
65 }
66
67 /**
68 * Method to return the Title domain object with SEO data.
69 *
70 * @return Seo_Plugin_Data_Interface The specific seo data.
71 */
72 public function get_data(): Seo_Plugin_Data_Interface {
73 return new Title( $this->get_title_template(), $this->get_title_template( false ) );
74 }
75 }
76