Jetpack_SSO_Notices

A collection of helper functions used in the SSO module.

Defined (1)

The class is defined in the following location(s).

/modules/sso/class.jetpack-sso-notices.php  
  1. class Jetpack_SSO_Notices { 
  2. /** 
  3. * Error message displayed on the login form when two step is required and 
  4. * the user's account on WordPress.com does not have two step enabled. 
  5. * @since 2.7 
  6. * @param string $message 
  7. * @return string 
  8. **/ 
  9. public static function error_msg_enable_two_step( $message ) { 
  10. $error = sprintf( 
  11. wp_kses( 
  12. __( 
  13. 'Two-Step Authentication is required to access this site. Please visit your <a href="%1$s" target="_blank">Security Settings</a> to configure <a href="%2$s" target="_blank">Two-step Authentication</a> for your account.',  
  14. 'jetpack' 
  15. ),  
  16. array( 'a' => array( 'href' => array() ) ) 
  17. ),  
  18. 'https://wordpress.com/me/security/two-step',  
  19. 'https://support.wordpress.com/security/two-step-authentication/' 
  20. ); 
  21.  
  22. $message .= sprintf( '<p class="message" id="login_error">%s</p>', $error ); 
  23.  
  24. return $message; 
  25.  
  26. /** 
  27. * Error message displayed when the user tries to SSO, but match by email 
  28. * is off and they already have an account with their email address on 
  29. * this site. 
  30. * @param string $message 
  31. * @return string 
  32. */ 
  33. public static function error_msg_email_already_exists( $message ) { 
  34. $error = sprintf( 
  35. wp_kses( 
  36. __( 
  37. 'You already have an account on this site. Please <a href="%1$s">sign in</a> with your username and password and then connect to WordPress.com.',  
  38. 'jetpack' 
  39. ),  
  40. array( 'a' => array( 'href' => array() ) ) 
  41. ),  
  42. esc_url_raw( add_query_arg( 'jetpack-sso-show-default-form', '1', wp_login_url() ) ) 
  43. ); 
  44.  
  45. $message .= sprintf( '<p class="message" id="login_error">%s</p>', $error ); 
  46.  
  47. return $message; 
  48.  
  49. /** 
  50. * Error message that is displayed when the current site is in an identity crisis and SSO can not be used. 
  51. * @since 4.3.2 
  52. * @param $message 
  53. * @return string 
  54. */ 
  55. public static function error_msg_identity_crisis( $message ) { 
  56. $error = esc_html__( 'Logging in with WordPress.com is not currently available because this site is experiencing connection problems.', 'jetpack' ); 
  57. $message .= sprintf( '<p class="message" id="login_error">%s</p>', $error ); 
  58. return $message; 
  59.  
  60. /** 
  61. * Error message that is displayed when we are not able to verify the SSO nonce due to an XML error or 
  62. * failed validation. In either case, we prompt the user to try again or log in with username and password. 
  63. * @since 4.3.2 
  64. * @param $message 
  65. * @return string 
  66. */ 
  67. public static function error_invalid_response_data( $message ) { 
  68. $error = esc_html__( 
  69. 'There was an error logging you in via WordPress.com, please try again or try logging in with your username and password.',  
  70. 'jetpack' 
  71. ); 
  72. $message .= sprintf( '<p class="message" id="login_error">%s</p>', $error ); 
  73. return $message; 
  74.  
  75. /** 
  76. * Error message that is displayed when we were not able to automatically create an account for a user 
  77. * after a user has logged in via SSO. By default, this message is triggered after trying to create an account 5 times. 
  78. * @since 4.3.2 
  79. * @param $message 
  80. * @return string 
  81. */ 
  82. public static function error_unable_to_create_user( $message ) { 
  83. $error = esc_html__( 
  84. 'There was an error creating a user for you. Please contact the administrator of your site.',  
  85. 'jetpack' 
  86. ); 
  87. $message .= sprintf( '<p class="message" id="login_error">%s</p>', $error ); 
  88. return $message; 
  89.  
  90. /** 
  91. * When the default login form is hidden, this method is called on the 'authenticate' filter with a priority of 30. 
  92. * This method disables the ability to submit the default login form. 
  93. * @param $user 
  94. * @return WP_Error 
  95. */ 
  96. public static function disable_default_login_form( $user ) { 
  97. if ( is_wp_error( $user ) ) { 
  98. return $user; 
  99.  
  100. /** 
  101. * Since we're returning an error that will be shown as a red notice, let's remove the 
  102. * informational "blue" notice. 
  103. */ 
  104. remove_filter( 'login_message', array( 'Jetpack_SSO_Notices', 'msg_login_by_jetpack' ) ); 
  105. return new WP_Error( 'jetpack_sso_required', self::get_sso_required_message() ); 
  106.  
  107. /** 
  108. * Message displayed when the site admin has disabled the default WordPress 
  109. * login form in Settings > General > Single Sign On 
  110. * @since 2.7 
  111. * @param string $message 
  112. * @return string 
  113. **/ 
  114. public static function msg_login_by_jetpack( $message ) { 
  115. $message .= sprintf( '<p class="message">%s</p>', self::get_sso_required_message() ); 
  116. return $message; 
  117.  
  118. public static function get_sso_required_message() { 
  119. $msg = esc_html__( 
  120. 'A WordPress.com account is required to access this site. Click the button below to sign in or create a free WordPress.com account.',  
  121. 'jetpack' 
  122. ); 
  123.  
  124. /** 
  125. * Filter the message displayed when the default WordPress login form is disabled. 
  126. * @module sso 
  127. * @since 2.8.0 
  128. * @param string $msg Disclaimer when default WordPress login form is disabled. 
  129. */ 
  130. return apply_filters( 'jetpack_sso_disclaimer_message', $msg ); 
  131.  
  132. /** 
  133. * Message displayed when the user can not be found after approving the SSO process on WordPress.com 
  134. * @param string $message 
  135. * @return string 
  136. */ 
  137. public static function cant_find_user( $message ) { 
  138. $error = esc_html__( 
  139. "We couldn't find your account. If you already have an account, make sure you have connected to WordPress.com.",  
  140. 'jetpack' 
  141. ); 
  142. $message .= sprintf( '<p class="message" id="login_error">%s</p>', $error ); 
  143.  
  144. return $message; 
  145.  
  146. /** 
  147. * Error message that is displayed when the current site is in an identity crisis and SSO can not be used. 
  148. * @since 4.4.0 
  149. * @param $message 
  150. * @return string 
  151. */ 
  152. public static function sso_not_allowed_in_staging( $message ) { 
  153. $error = esc_html__( 
  154. 'Logging in with WordPress.com is disabled for sites that are in staging mode.',  
  155. 'jetpack' 
  156. ); 
  157. $message .= sprintf( '<p class="message">%s</p>', $error ); 
  158. return $message;