| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Class WPSEO_Premium_Upsell_Admin_Block |
| 10 |
*/ |
| 11 |
class WPSEO_Premium_Upsell_Admin_Block { |
| 12 |
|
| 13 |
/** |
| 14 |
* Hook to display the block on. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $hook; |
| 19 |
|
| 20 |
/** |
| 21 |
* Identifier to use in the dismissal functionality. |
| 22 |
* |
| 23 |
* @var string |
| 24 |
*/ |
| 25 |
protected $identifier = 'premium_upsell'; |
| 26 |
|
| 27 |
/** |
| 28 |
* Registers which hook the block will be displayed on. |
| 29 |
* |
| 30 |
* @param string $hook Hook to display the block on. |
| 31 |
*/ |
| 32 |
public function __construct( $hook ) { |
| 33 |
$this->hook = $hook; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Registers WordPress hooks. |
| 38 |
* |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public function register_hooks() { |
| 42 |
add_action( $this->hook, [ $this, 'render' ] ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Renders the upsell block. |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function render() { |
| 51 |
$url = WPSEO_Shortlinker::get( 'https://yoa.st/17h' ); |
| 52 |
|
| 53 |
$arguments = [ |
| 54 |
'<strong>' . esc_html__( 'Multiple keyphrases', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Increase your SEO reach', 'wordpress-seo' ), |
| 55 |
'<strong>' . esc_html__( 'No more dead links', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Easy redirect manager', 'wordpress-seo' ), |
| 56 |
'<strong>' . esc_html__( 'Superfast internal linking suggestions', 'wordpress-seo' ) . '</strong>', |
| 57 |
'<strong>' . esc_html__( 'Social media preview', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Facebook & Twitter', 'wordpress-seo' ), |
| 58 |
'<strong>' . esc_html__( '24/7 email support', 'wordpress-seo' ) . '</strong>', |
| 59 |
'<strong>' . esc_html__( 'No ads!', 'wordpress-seo' ) . '</strong>', |
| 60 |
]; |
| 61 |
|
| 62 |
$arguments_html = implode( '', array_map( [ $this, 'get_argument_html' ], $arguments ) ); |
| 63 |
|
| 64 |
$class = $this->get_html_class(); |
| 65 |
|
| 66 |
/* translators: %s expands to Yoast SEO Premium */ |
| 67 |
$button_text = sprintf( esc_html__( 'Get %s', 'wordpress-seo' ), 'Yoast SEO Premium' ); |
| 68 |
$button_text .= '<span class="screen-reader-text">' . esc_html__( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>' . |
| 69 |
'<span aria-hidden="true" class="yoast-button-upsell__caret"></span>'; |
| 70 |
|
| 71 |
$upgrade_button = sprintf( |
| 72 |
'<a id="%1$s" class="yoast-button-upsell" href="%2$s" target="_blank">%3$s</a>', |
| 73 |
esc_attr( 'wpseo-' . $this->identifier . '-popup-button' ), |
| 74 |
esc_url( $url ), |
| 75 |
$button_text |
| 76 |
); |
| 77 |
|
| 78 |
echo '<div class="' . esc_attr( $class ) . '">'; |
| 79 |
|
| 80 |
echo '<div>'; |
| 81 |
echo '<h2 class="' . esc_attr( $class . '--header' ) . '">' . |
| 82 |
sprintf( |
| 83 |
/* translators: %s expands to Yoast SEO Premium */ |
| 84 |
esc_html__( 'Upgrade to %s', 'wordpress-seo' ), |
| 85 |
'Yoast SEO Premium' |
| 86 |
) . |
| 87 |
'</h2>'; |
| 88 |
|
| 89 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in $this->get_argument_html() method. |
| 90 |
echo '<ul class="' . esc_attr( $class . '--motivation' ) . '">' . $arguments_html . '</ul>'; |
| 91 |
|
| 92 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in $upgrade_button and $button_text above. |
| 93 |
echo '<p>' . $upgrade_button . '</p>'; |
| 94 |
echo '</div>'; |
| 95 |
|
| 96 |
echo '</div>'; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Formats the argument to a HTML list item. |
| 101 |
* |
| 102 |
* @param string $argument The argument to format. |
| 103 |
* |
| 104 |
* @return string Formatted argument in HTML. |
| 105 |
*/ |
| 106 |
protected function get_argument_html( $argument ) { |
| 107 |
$class = $this->get_html_class(); |
| 108 |
|
| 109 |
return sprintf( |
| 110 |
'<li><div class="%1$s">%2$s</div></li>', |
| 111 |
esc_attr( $class . '--argument' ), |
| 112 |
$argument |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Returns the HTML base class to use. |
| 118 |
* |
| 119 |
* @return string The HTML base class. |
| 120 |
*/ |
| 121 |
protected function get_html_class() { |
| 122 |
return 'yoast_' . $this->identifier; |
| 123 |
} |
| 124 |
} |
| 125 |
|