Sin descripción

class-jetpack-pre-connection-jitms.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Jetpack's Pre-Connection JITMs class.
  4. *
  5. * @package jetpack
  6. */
  7. use Automattic\Jetpack\Redirect;
  8. /**
  9. * Jetpack's Pre-Connection JITMs. These can be displayed with the JITM package.
  10. */
  11. class Jetpack_Pre_Connection_JITMs {
  12. /**
  13. * Returns all the pre-connection messages.
  14. *
  15. * @return array An array containing the pre-connection JITM messages.
  16. */
  17. private function get_raw_messages() {
  18. $button_caption = __( 'Set up Jetpack', 'jetpack' );
  19. /* Translators: placeholders are links. */
  20. $media_description = __( 'Click on the <strong>Set up Jetpack</strong> button to agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com, and gain access to Site Accelerator.', 'jetpack' );
  21. /* Translators: placeholders are links. */
  22. $widgets_description = __( 'Click on the <strong>Set up Jetpack</strong> button to agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com, and gain access to great additional widgets.', 'jetpack' );
  23. /* Translators: placeholders are links. */
  24. $posts_description = __( 'Click on the <strong>Set up Jetpack</strong> button to agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com, and gain access to in-depth stats about your site.', 'jetpack' );
  25. $messages = array(
  26. array(
  27. 'id' => 'jpsetup-upload',
  28. 'message_path' => '/wp:upload:admin_notices/',
  29. 'message' => __( 'Do you want lightning-fast images?', 'jetpack' ),
  30. 'description' => $this->generate_description_with_tos( $media_description ),
  31. 'button_caption' => $button_caption,
  32. ),
  33. array(
  34. 'id' => 'jpsetup-widgets',
  35. 'message_path' => '/wp:widgets:admin_notices/',
  36. 'message' => __( 'Looking for even more widgets?', 'jetpack' ),
  37. 'description' => $this->generate_description_with_tos( $widgets_description ),
  38. 'button_caption' => $button_caption,
  39. ),
  40. );
  41. if ( wp_count_posts()->publish >= 5 ) {
  42. $messages[] = array(
  43. 'id' => 'jpsetup-posts',
  44. 'message_path' => '/wp:edit-post:admin_notices/',
  45. 'message' => __( 'Do you know which of these posts gets the most traffic?', 'jetpack' ),
  46. 'description' => $this->generate_description_with_tos( $posts_description ),
  47. 'button_caption' => $button_caption,
  48. );
  49. }
  50. foreach ( $messages as $key => $message ) {
  51. /*
  52. * Add Connect URL to each message, with from including jitm id.
  53. */
  54. $jetpack_setup_url = $this->generate_admin_url(
  55. array(
  56. 'page' => 'jetpack#/setup',
  57. 'from' => sprintf( 'pre-connection-jitm-%s', $message['id'] ),
  58. )
  59. );
  60. $messages[ $key ]['button_link'] = $jetpack_setup_url;
  61. }
  62. return $messages;
  63. }
  64. /**
  65. * Generate a description text with links to ToS documents.
  66. *
  67. * Those messages must mention the ToS agreement message,
  68. * but do not use the standard message defined in jetpack_render_tos_blurb.
  69. * Instead, they use their own custom messages.
  70. *
  71. * @param string $description Description string with placeholders.
  72. *
  73. * @return string
  74. */
  75. private function generate_description_with_tos( $description ) {
  76. return sprintf(
  77. wp_kses(
  78. $description,
  79. array(
  80. 'a' => array(
  81. 'href' => array(),
  82. 'target' => array(),
  83. 'rel' => array(),
  84. ),
  85. 'strong' => true,
  86. )
  87. ),
  88. esc_url( Redirect::get_url( 'wpcom-tos' ) ),
  89. esc_url( Redirect::get_url( 'jetpack-support-what-data-does-jetpack-sync' ) )
  90. );
  91. }
  92. /**
  93. * Adds the input query arguments to the admin url.
  94. *
  95. * @param array $args The query arguments.
  96. *
  97. * @return string The admin url.
  98. */
  99. private function generate_admin_url( $args ) {
  100. $url = add_query_arg( $args, admin_url( 'admin.php' ) );
  101. return $url;
  102. }
  103. /**
  104. * Add the Jetpack pre-connection JITMs to the list of pre-connection JITM messages.
  105. *
  106. * @param array $pre_connection_messages An array of pre-connection JITMs.
  107. *
  108. * @return array The array of pre-connection JITMs.
  109. */
  110. public function add_pre_connection_jitms( $pre_connection_messages ) {
  111. $jetpack_messages = $this->get_raw_messages();
  112. if ( ! is_array( $pre_connection_messages ) ) {
  113. // The incoming messages aren't an array, so just return Jetpack's messages.
  114. return $jetpack_messages;
  115. }
  116. return array_merge( $pre_connection_messages, $jetpack_messages );
  117. }
  118. }