PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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 28.5, at src/presenters/slack/enhanced-data-presenter.php

67 lines 2.1 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 $class = \is_admin_bar_showing() ? ' class="yoast-seo-meta-tag"' : '';
30 foreach ( $enhanced_data as $label => $value ) {
31 $twitter_tags .= \sprintf( "\t" . '<meta name="twitter:label%1$d" content="%2$s"' . $class . ' />' . "\n", $i, \esc_attr( $label ) );
32 $twitter_tags .= \sprintf( "\t" . '<meta name="twitter:data%1$d" content="%2$s"' . $class . ' />' . "\n", $i, \esc_attr( $value ) );
33 ++$i;
34 }
35
36 return \trim( $twitter_tags );
37 }
38
39 /**
40 * Gets the enhanced data array.
41 *
42 * @return array The enhanced data array
43 */
44 public function get() {
45 $data = [];
46 $author_id = $this->presentation->source->post_author;
47 $estimated_reading_time = $this->presentation->estimated_reading_time_minutes;
48
49 if ( $this->presentation->model->object_sub_type === 'post' && $author_id ) {
50 $data[ \__( 'Written by', 'wordpress-seo' ) ] = \get_the_author_meta( 'display_name', $author_id );
51 }
52
53 if ( ! empty( $estimated_reading_time ) ) {
54 /* translators: %s expands to the reading time number, in minutes */
55 $data[ \__( 'Est. reading time', 'wordpress-seo' ) ] = \sprintf( \_n( '%s minute', '%s minutes', $estimated_reading_time, 'default' ), $estimated_reading_time );
56 }
57
58 /**
59 * Filter: 'wpseo_enhanced_slack_data' - Allows filtering of the enhanced data for sharing on Slack.
60 *
61 * @param array $data The enhanced Slack sharing data.
62 * @param Indexable_Presentation $presentation The presentation of an indexable.
63 */
64 return \apply_filters( 'wpseo_enhanced_slack_data', $data, $this->presentation );
65 }
66 }
67