Yoast\WP\SEO\Editors\Framework\Seo\Posts
Description_Data_Provider{}└─ Description_Data_Provider_Interface, Abstract_Post_Seo_Data_Provider
Describes if the description SEO data.
Хуков нет.
Использование
$Description_Data_Provider = new Description_Data_Provider(); // use class methods
Методы
- public __construct( Date_Helper $date_helper, Options_Helper $options_helper )
- public get_data()
- public get_description_date()
- public get_description_template()
- ERROR: no method name found on line `$this->date_helper = $date_helper;`
- ERROR: no method name found on line `private $options_helper;`
- ERROR: no method name found on line `* @var Date_Helper`
- private get_template( string $template_option_name )
Код Description_Data_Provider{} Description Data Provider{} Yoast 27.4
class Description_Data_Provider extends Abstract_Post_Seo_Data_Provider implements Description_Data_Provider_Interface {
/**
* The date helper.
*
* @var Date_Helper
*/
private $date_helper;
/**
* The options helper.
*
* @var Options_Helper
*/
private $options_helper;
/**
* The constructor.
*
* @param Date_Helper $date_helper The date helper.
* @param Options_Helper $options_helper The options helper.
*/
public function __construct( Date_Helper $date_helper, Options_Helper $options_helper ) {
$this->date_helper = $date_helper;
$this->options_helper = $options_helper;
}
/**
* Retrieves the description template.
*
* @return string The description template.
*/
public function get_description_template(): string {
return $this->get_template( 'metadesc' );
}
/**
* Determines the date to be displayed in the snippet preview.
*
* @return string
*/
public function get_description_date(): string {
return $this->date_helper->format_translated( $this->post->post_date, 'M j, Y' );
}
/**
* Retrieves a template.
*
* @param string $template_option_name The name of the option in which the template you want to get is saved.
*
* @return string
*/
private function get_template( string $template_option_name ): string {
$needed_option = $template_option_name . '-' . $this->post->post_type;
if ( $this->options_helper->get( $needed_option, '' ) !== '' ) {
return $this->options_helper->get( $needed_option );
}
return '';
}
/**
* Method to return the Description domain object with SEO data.
*
* @return Seo_Plugin_Data_Interface The specific seo data.
*/
public function get_data(): Seo_Plugin_Data_Interface {
return new Description( $this->get_description_date(), $this->get_description_template() );
}
}