PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.1
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 / presenters / slack / enhanced-data-presenter.php

enhanced-data-presenter.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.1, at src/presenters/slack/enhanced-data-presenter.php

66 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 namespace Yoast\WP\SEO\Presenters\Slack;
4
5 use Yoast\WP\SEO\Presentations\Indexable_Presentation;
6 use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
7
8 /**
9 * Presenter class for the Slack enhanced data.
10 */
11 class Enhanced_Data_Presenter extends Abstract_Indexable_Presenter {
12
13 /**
14 * The tag key name.
15 *
16 * @var string
17 */
18 protected $key = 'twitter:misc';
19
20 /**
21 * Presents the enhanced data for Slack
22 *
23 * @return string The Twitter tags for Slack.
24 */
25 public function present() {
26 $enhanced_data = $this->get();
27 $twitter_tags = '';
28 $i = 1;
29 foreach ( $enhanced_data as $label => $value ) {
30 $twitter_tags .= \sprintf( "\t" . '<meta name="twitter:label%1$d" content="%2$s" />' . "\n", $i, $label );
31 $twitter_tags .= \sprintf( "\t" . '<meta name="twitter:data%1$d" content="%2$s" />' . "\n", $i, $value );
32 ++$i;
33 }
34 return \trim( $twitter_tags );
35 }
36
37 /**
38 * Gets the enhanced data array.
39 *
40 * @return array The enhanced data array
41 */
42 public function get() {
43 $data = [];
44 $author_id = $this->presentation->source->post_author;
45 $estimated_reading_time = $this->presentation->estimated_reading_time_minutes;
46
47 if ( $this->presentation->model->object_sub_type === 'post' && $author_id ) {
48 $data[ \__( 'Written by', 'wordpress-seo' ) ] = \get_the_author_meta( 'display_name', $author_id );
49 }
50
51 if ( ! empty( $estimated_reading_time ) ) {
52 /* translators: %s expands to the reading time number, in minutes */
53 $data[ \__( 'Est. reading time', 'wordpress-seo' ) ] = \sprintf( \_n( '%s minute', '%s minutes', $estimated_reading_time, 'default' ), $estimated_reading_time );
54 }
55
56 /**
57 * Filter: 'wpseo_enhanced_slack_data' - Allows filtering of the enhanced data for sharing on Slack.
58 *
59 * @api array $data The enhanced Slack sharing data.
60 *
61 * @param Indexable_Presentation $presentation The presentation of an indexable.
62 */
63 return \apply_filters( 'wpseo_enhanced_slack_data', $data, $this->presentation );
64 }
65 }
66