PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.2
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 / description-data-provider.php

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

87 lines 2.3 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\Description;
8 use Yoast\WP\SEO\Editors\Domain\Seo\Seo_Plugin_Data_Interface;
9 use Yoast\WP\SEO\Editors\Framework\Seo\Description_Data_Provider_Interface;
10 use Yoast\WP\SEO\Helpers\Date_Helper;
11 use Yoast\WP\SEO\Helpers\Options_Helper;
12
13 /**
14 * Describes if the description SEO data.
15 */
16 class Description_Data_Provider extends Abstract_Post_Seo_Data_Provider implements Description_Data_Provider_Interface {
17
18 /**
19 * The date helper.
20 *
21 * @var Date_Helper
22 */
23 private $date_helper;
24
25 /**
26 * The options helper.
27 *
28 * @var Options_Helper
29 */
30 private $options_helper;
31
32 /**
33 * The constructor.
34 *
35 * @param Date_Helper $date_helper The date helper.
36 * @param Options_Helper $options_helper The options helper.
37 */
38 public function __construct( Date_Helper $date_helper, Options_Helper $options_helper ) {
39 $this->date_helper = $date_helper;
40 $this->options_helper = $options_helper;
41 }
42
43 /**
44 * Retrieves the description template.
45 *
46 * @return string The description template.
47 */
48 public function get_description_template(): string {
49 return $this->get_template( 'metadesc' );
50 }
51
52 /**
53 * Determines the date to be displayed in the snippet preview.
54 *
55 * @return string
56 */
57 public function get_description_date(): string {
58 return $this->date_helper->format_translated( $this->post->post_date, 'M j, Y' );
59 }
60
61 /**
62 * Retrieves a template.
63 *
64 * @param string $template_option_name The name of the option in which the template you want to get is saved.
65 *
66 * @return string
67 */
68 private function get_template( string $template_option_name ): string {
69 $needed_option = $template_option_name . '-' . $this->post->post_type;
70
71 if ( $this->options_helper->get( $needed_option, '' ) !== '' ) {
72 return $this->options_helper->get( $needed_option );
73 }
74
75 return '';
76 }
77
78 /**
79 * Method to return the Description domain object with SEO data.
80 *
81 * @return Seo_Plugin_Data_Interface The specific seo data.
82 */
83 public function get_data(): Seo_Plugin_Data_Interface {
84 return new Description( $this->get_description_date(), $this->get_description_template() );
85 }
86 }
87