| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Services\Health_Check; |
| 4 |
|
| 5 |
use WPSEO_Admin_Utils; |
| 6 |
use WPSEO_Shortlinker; |
| 7 |
|
| 8 |
/** |
| 9 |
* Presents a set of different messages for the Links_Table health check. |
| 10 |
*/ |
| 11 |
class Links_Table_Reports { |
| 12 |
|
| 13 |
use Reports_Trait; |
| 14 |
|
| 15 |
/** |
| 16 |
* Shortlinker object used to create short links for reports. |
| 17 |
* |
| 18 |
* @var WPSEO_Shortlinker |
| 19 |
*/ |
| 20 |
private $shortlinker; |
| 21 |
|
| 22 |
/** |
| 23 |
* Constructor |
| 24 |
* |
| 25 |
* @param Report_Builder_Factory $report_builder_factory The factory for result builder objects. |
| 26 |
* This class uses the report builder to generate WordPress-friendly |
| 27 |
* health check results. |
| 28 |
* @param WPSEO_Shortlinker $shortlinker Object used to add short links to the report description. |
| 29 |
*/ |
| 30 |
public function __construct( |
| 31 |
Report_Builder_Factory $report_builder_factory, |
| 32 |
WPSEO_Shortlinker $shortlinker |
| 33 |
) { |
| 34 |
$this->report_builder_factory = $report_builder_factory; |
| 35 |
$this->shortlinker = $shortlinker; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Returns the message for a successful health check. |
| 40 |
* |
| 41 |
* @return string[] The message as a WordPress site status report. |
| 42 |
*/ |
| 43 |
public function get_success_result() { |
| 44 |
return $this->get_report_builder() |
| 45 |
->set_label( \__( 'The text link counter is working as expected', 'wordpress-seo' ) ) |
| 46 |
->set_status_good() |
| 47 |
->set_description( $this->get_success_description() ) |
| 48 |
->build(); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns the message for a failed health check. |
| 53 |
* |
| 54 |
* @return string[] The message as a WordPress site status report. |
| 55 |
*/ |
| 56 |
public function get_links_table_not_accessible_result() { |
| 57 |
return $this->get_report_builder() |
| 58 |
->set_label( \__( 'The text link counter feature is not working as expected', 'wordpress-seo' ) ) |
| 59 |
->set_status_recommended() |
| 60 |
->set_description( $this->get_links_table_not_accessible_description() ) |
| 61 |
->set_actions( $this->get_actions() ) |
| 62 |
->build(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Returns the description for when the health check was successful. |
| 67 |
* |
| 68 |
* @return string The description as a string. |
| 69 |
*/ |
| 70 |
private function get_success_description() { |
| 71 |
return \sprintf( |
| 72 |
/* translators: 1: Link to the Yoast SEO blog, 2: Link closing tag. */ |
| 73 |
\esc_html__( 'The text link counter helps you improve your site structure. %1$sFind out how the text link counter can enhance your SEO%2$s.', 'wordpress-seo' ), |
| 74 |
'<a href="' . $this->shortlinker->get( 'https://yoa.st/3zw' ) . '" target="_blank">', |
| 75 |
WPSEO_Admin_Utils::get_new_tab_message() . '</a>', |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Returns the description for when the health couldn't access the links table. |
| 81 |
* |
| 82 |
* @return string The description as a string. |
| 83 |
*/ |
| 84 |
private function get_links_table_not_accessible_description() { |
| 85 |
return \sprintf( |
| 86 |
/* translators: 1: Yoast SEO. */ |
| 87 |
\__( 'For this feature to work, %1$s needs to create a table in your database. We were unable to create this table automatically.', 'wordpress-seo' ), |
| 88 |
'Yoast SEO', |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Returns the actions that the user should take when the links table is not accessible. |
| 94 |
* |
| 95 |
* @return string The actions as a string. |
| 96 |
*/ |
| 97 |
private function get_actions() { |
| 98 |
return \sprintf( |
| 99 |
/* translators: 1: Link to the Yoast help center, 2: Link closing tag. */ |
| 100 |
\esc_html__( '%1$sFind out how to solve this problem on our help center%2$s.', 'wordpress-seo' ), |
| 101 |
'<a href="' . $this->shortlinker->get( 'https://yoa.st/3zv' ) . '" target="_blank">', |
| 102 |
WPSEO_Admin_Utils::get_new_tab_message() . '</a>', |
| 103 |
); |
| 104 |
} |
| 105 |
} |
| 106 |
|