| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters\Admin; |
| 4 |
|
| 5 |
use WPSEO_Addon_Manager; |
| 6 |
use Yoast\WP\SEO\Helpers\Product_Helper; |
| 7 |
use Yoast\WP\SEO\Helpers\Short_Link_Helper; |
| 8 |
use Yoast\WP\SEO\Presenters\Abstract_Presenter; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class Indexing_Failed_Notification_Presenter. |
| 12 |
* |
| 13 |
* @package Yoast\WP\SEO\Presenters\Notifications |
| 14 |
*/ |
| 15 |
class Indexing_Failed_Notification_Presenter extends Abstract_Presenter { |
| 16 |
|
| 17 |
/** |
| 18 |
* The product helper. |
| 19 |
* |
| 20 |
* @var Product_Helper |
| 21 |
*/ |
| 22 |
protected $product_helper; |
| 23 |
|
| 24 |
/** |
| 25 |
* The addon manager. |
| 26 |
* |
| 27 |
* @var WPSEO_Addon_Manager |
| 28 |
*/ |
| 29 |
protected $class_addon_manager; |
| 30 |
|
| 31 |
/** |
| 32 |
* The short link helper. |
| 33 |
* |
| 34 |
* @var Short_Link_Helper |
| 35 |
*/ |
| 36 |
protected $short_link_helper; |
| 37 |
|
| 38 |
/** |
| 39 |
* Indexing_Failed_Notification_Presenter constructor. |
| 40 |
* |
| 41 |
* @param Product_Helper $product_helper The product helper. |
| 42 |
* @param Short_Link_Helper $short_link_helper The addon manager. |
| 43 |
* @param WPSEO_Addon_Manager $class_addon_manager The addon manager. |
| 44 |
*/ |
| 45 |
public function __construct( $product_helper, $short_link_helper, $class_addon_manager ) { |
| 46 |
$this->class_addon_manager = $class_addon_manager; |
| 47 |
$this->short_link_helper = $short_link_helper; |
| 48 |
$this->product_helper = $product_helper; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns the notification as an HTML string. |
| 53 |
* |
| 54 |
* @return string The notification in an HTML string representation. |
| 55 |
*/ |
| 56 |
public function present() { |
| 57 |
$notification_text = \sprintf( |
| 58 |
/* Translators: %1$s expands to an opening anchor tag for a link leading to the Yoast SEO tools page, %2$s expands to a closing anchor tag. */ |
| 59 |
\esc_html__( |
| 60 |
'Something has gone wrong and we couldn\'t complete the optimization of your SEO data. Please %1$sre-start the process%2$s.', |
| 61 |
'wordpress-seo', |
| 62 |
), |
| 63 |
'<a href="' . \get_admin_url( null, 'admin.php?page=wpseo_tools' ) . '">', |
| 64 |
'</a>', |
| 65 |
); |
| 66 |
|
| 67 |
if ( $this->product_helper->is_premium() ) { |
| 68 |
if ( $this->has_valid_premium_subscription() ) { |
| 69 |
// Add a support message for premium customers. |
| 70 |
$notification_text .= ' '; |
| 71 |
$notification_text .= \esc_html__( 'If the problem persists, please contact support.', 'wordpress-seo' ); |
| 72 |
} |
| 73 |
else { |
| 74 |
// Premium plugin with inactive addon; overwrite the entire error message. |
| 75 |
$notification_text = \sprintf( |
| 76 |
/* Translators: %1$s expands to an opening anchor tag for a link leading to the Premium installation page, %2$s expands to a closing anchor tag. */ |
| 77 |
\esc_html__( |
| 78 |
'Oops, something has gone wrong and we couldn\'t complete the optimization of your SEO data. Please make sure to activate your subscription in MyYoast by completing %1$sthese steps%2$s.', |
| 79 |
'wordpress-seo', |
| 80 |
), |
| 81 |
'<a href="' . \esc_url( $this->short_link_helper->get( 'https://yoa.st/3wv' ) ) . '">', |
| 82 |
'</a>', |
| 83 |
); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return '<p>' . $notification_text . '</p>'; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Determines if the site has a valid Premium subscription. |
| 92 |
* |
| 93 |
* @return bool |
| 94 |
*/ |
| 95 |
protected function has_valid_premium_subscription() { |
| 96 |
return $this->class_addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG ); |
| 97 |
} |
| 98 |
} |
| 99 |
|