PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
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 / admin / indexing-notification-presenter.php

indexing-notification-presenter.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/presenters/admin/indexing-notification-presenter.php

148 lines 5.6 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\Admin;
4
5 use Yoast\WP\SEO\Config\Indexing_Reasons;
6 use Yoast\WP\SEO\Helpers\Short_Link_Helper;
7 use Yoast\WP\SEO\Presenters\Abstract_Presenter;
8
9 /**
10 * Class Indexing_Notification_Presenter.
11 *
12 * @package Yoast\WP\SEO\Presenters\Admin
13 */
14 class Indexing_Notification_Presenter extends Abstract_Presenter {
15
16 /**
17 * The total number of unindexed objects.
18 *
19 * @var int
20 */
21 protected $total_unindexed;
22
23 /**
24 * The message to show in the notification.
25 *
26 * @var string
27 */
28 protected $reason;
29
30 /**
31 * The short link helper.
32 *
33 * @var Short_Link_Helper
34 */
35 protected $short_link_helper;
36
37 /**
38 * Indexing_Notification_Presenter constructor.
39 *
40 * @param Short_Link_Helper $short_link_helper The short link helper.
41 * @param int $total_unindexed Total number of unindexed objects.
42 * @param string $reason The reason to show in the notification.
43 */
44 public function __construct( $short_link_helper, $total_unindexed, $reason ) {
45 $this->short_link_helper = $short_link_helper;
46 $this->total_unindexed = $total_unindexed;
47 $this->reason = $reason;
48 }
49
50 /**
51 * Returns the notification as an HTML string.
52 *
53 * @return string The HTML string representation of the notification.
54 */
55 public function present() {
56 $notification_text = '<p>' . $this->get_message( $this->reason );
57 $notification_text .= $this->get_time_estimate( $this->total_unindexed ) . '</p>';
58 $notification_text .= '<a class="button" href="' . \get_admin_url( null, 'admin.php?page=wpseo_tools&start-indexation=true' ) . '">';
59 $notification_text .= \esc_html__( 'Start SEO data optimization', 'wordpress-seo' );
60 $notification_text .= '</a>';
61
62 return $notification_text;
63 }
64
65 /**
66 * Determines the message to show in the indexing notification.
67 *
68 * @param string $reason The reason identifier.
69 *
70 * @return string The message to show in the notification.
71 */
72 protected function get_message( $reason ) {
73 switch ( $reason ) {
74 case Indexing_Reasons::REASON_PERMALINK_SETTINGS:
75 $text = \esc_html__( 'Because of a change in your permalink structure, some of your SEO data needs to be reprocessed.', 'wordpress-seo' );
76 break;
77 case Indexing_Reasons::REASON_HOME_URL_OPTION:
78 $text = \esc_html__( 'Because of a change in your home URL setting, some of your SEO data needs to be reprocessed.', 'wordpress-seo' );
79 break;
80 case Indexing_Reasons::REASON_CATEGORY_BASE_PREFIX:
81 $text = \esc_html__( 'Because of a change in your category base setting, some of your SEO data needs to be reprocessed.', 'wordpress-seo' );
82 break;
83 case Indexing_Reasons::REASON_TAG_BASE_PREFIX:
84 $text = \esc_html__( 'Because of a change in your tag base setting, some of your SEO data needs to be reprocessed.', 'wordpress-seo' );
85 break;
86 case Indexing_Reasons::REASON_POST_TYPE_MADE_PUBLIC:
87 $text = \esc_html__( 'We need to re-analyze some of your SEO data because of a change in the visibility of your post types. Please help us do that by running the SEO data optimization.', 'wordpress-seo' );
88 break;
89 case Indexing_Reasons::REASON_TAXONOMY_MADE_PUBLIC:
90 $text = \esc_html__( 'We need to re-analyze some of your SEO data because of a change in the visibility of your taxonomies. Please help us do that by running the SEO data optimization.', 'wordpress-seo' );
91 break;
92 case Indexing_Reasons::REASON_ATTACHMENTS_MADE_ENABLED:
93 $text = \esc_html__( 'It looks like you\'ve enabled media pages. We recommend that you help us to re-analyze your site by running the SEO data optimization.', 'wordpress-seo' );
94 break;
95 default:
96 $text = \esc_html__( 'You can speed up your site and get insight into your internal linking structure by letting us perform a few optimizations to the way SEO data is stored.', 'wordpress-seo' );
97 }
98
99 /**
100 * Filter: 'wpseo_indexables_indexation_alert' - Allow developers to filter the reason of the indexation
101 *
102 * @param string $text The text to show as reason.
103 * @param string $reason The reason value.
104 */
105 return (string) \apply_filters( 'wpseo_indexables_indexation_alert', $text, $reason );
106 }
107
108 /**
109 * Creates a time estimate based on the total number on unindexed objects.
110 *
111 * @param int $total_unindexed The total number of unindexed objects.
112 *
113 * @return string The time estimate as a HTML string.
114 */
115 protected function get_time_estimate( $total_unindexed ) {
116 if ( $total_unindexed < 400 ) {
117 return \esc_html__( ' We estimate this will take less than a minute.', 'wordpress-seo' );
118 }
119
120 if ( $total_unindexed < 2500 ) {
121 return \esc_html__( ' We estimate this will take a couple of minutes.', 'wordpress-seo' );
122 }
123
124 $estimate = \esc_html__( ' We estimate this could take a long time, due to the size of your site. As an alternative to waiting, you could:', 'wordpress-seo' );
125 $estimate .= '<ul class="ul-disc">';
126 $estimate .= '<li>';
127 $estimate .= \sprintf(
128 /* translators: 1: Expands to Yoast SEO */
129 \esc_html__( 'Wait for a week or so, until %1$s automatically processes most of your content in the background.', 'wordpress-seo' ),
130 'Yoast SEO',
131 );
132 $estimate .= '</li>';
133 $estimate .= '<li>';
134 $estimate .= \sprintf(
135 /* translators: 1: Link to article about indexation command, 2: Anchor closing tag, 3: Link to WP CLI. */
136 \esc_html__( '%1$sRun the indexation process on your server%2$s using %3$sWP CLI%2$s.', 'wordpress-seo' ),
137 '<a href="' . \esc_url( $this->short_link_helper->get( 'https://yoa.st/3-w' ) ) . '" target="_blank">',
138 '</a>',
139 '<a href="https://wp-cli.org/" target="_blank">',
140 );
141
142 $estimate .= '</li>';
143 $estimate .= '</ul>';
144
145 return $estimate;
146 }
147 }
148