class-premium-upsell-admin-block.php 3.3 KB

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