• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / b05d07fc5b184095141e8ead75857d0154e04580

23 Jul 2024 07:52AM UTC coverage: 48.579% (-5.4%) from 53.976%
b05d07fc5b184095141e8ead75857d0154e04580

push

github

YoastBot
Bump version to 23.1

7399 of 13400 branches covered (55.22%)

Branch coverage included in aggregate %.

25129 of 53559 relevant lines covered (46.92%)

41942.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/editors/framework/seo/posts/title-data-provider.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
3
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
4
namespace Yoast\WP\SEO\Editors\Framework\Seo\Posts;
5

6
use Yoast\WP\SEO\Editors\Domain\Seo\Seo_Plugin_Data_Interface;
7
use Yoast\WP\SEO\Editors\Domain\Seo\Title;
8
use Yoast\WP\SEO\Editors\Framework\Seo\Title_Data_Provider_Interface;
9
use Yoast\WP\SEO\Helpers\Options_Helper;
10

11
/**
12
 * Describes if the title SEO data.
13
 */
14
class Title_Data_Provider extends Abstract_Post_Seo_Data_Provider implements Title_Data_Provider_Interface {
15

16
        /**
17
         * The options helper.
18
         *
19
         * @var Options_Helper $options_helper
20
         */
21
        private $options_helper;
22

23
        /**
24
         * The constructor.
25
         *
26
         * @param Options_Helper $options_helper The options helper.
27
         */
28
        public function __construct( Options_Helper $options_helper ) {
×
29
                $this->options_helper = $options_helper;
×
30
        }
31

32
        /**
33
         * Retrieves the title template.
34
         *
35
         * @param bool $fallback Whether to return the hardcoded fallback if the template value is empty.
36
         *
37
         * @return string The title template.
38
         */
39
        public function get_title_template( bool $fallback = true ): string {
×
40
                $title = $this->get_template( 'title' );
×
41

42
                if ( $title === '' && $fallback === true ) {
×
43
                        return '%%title%% %%page%% %%sep%% %%sitename%%';
×
44
                }
45

46
                return $title;
×
47
        }
48

49
        /**
50
         * Retrieves a template.
51
         *
52
         * @param string $template_option_name The name of the option in which the template you want to get is saved.
53
         *
54
         * @return string
55
         */
56
        private function get_template( string $template_option_name ): string {
×
57
                $needed_option = $template_option_name . '-' . $this->post->post_type;
×
58

59
                if ( $this->options_helper->get( $needed_option, '' ) !== '' ) {
×
60
                        return $this->options_helper->get( $needed_option );
×
61
                }
62

63
                return '';
×
64
        }
65

66
        /**
67
         * Method to return the Title domain object with SEO data.
68
         *
69
         * @return Seo_Plugin_Data_Interface The specific seo data.
70
         */
71
        public function get_data(): Seo_Plugin_Data_Interface {
×
72
                return new Title( $this->get_title_template(), $this->get_title_template( false ) );
×
73
        }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc