Jetpack_JITM

Jetpack just in time messaging through out the admin.

Defined (1)

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

/class.jetpack-jitm.php  
  1. class Jetpack_JITM { 
  2.  
  3. /** 
  4. * @var Jetpack_JITM 
  5. **/ 
  6. private static $instance = null; 
  7.  
  8. static function init() { 
  9. if ( is_null( self::$instance ) ) { 
  10. self::$instance = new Jetpack_JITM; 
  11.  
  12. return self::$instance; 
  13.  
  14. private function __construct() { 
  15. if ( ! Jetpack::is_active() ) { 
  16. return; 
  17. global $pagenow; 
  18. $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); 
  19. $showphoton = empty( $jetpack_hide_jitm['photon'] ) ? 'show' : $jetpack_hide_jitm['photon']; 
  20. $showmanage = empty( $jetpack_hide_jitm['manage'] ) ? 'show' : $jetpack_hide_jitm['manage']; 
  21. if ( 'media-new.php' == $pagenow && ! Jetpack::is_module_active( 'photon' ) && 'hide' != $showphoton ) { 
  22. add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); 
  23. add_action( 'post-plupload-upload-ui', array( $this, 'photon_msg' ) ); 
  24. else if ( 'update-core.php' == $pagenow && 'hide' != $showmanage ) { 
  25. add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); 
  26. add_action( 'admin_notices', array( $this, 'manage_msg' ) ); 
  27.  
  28.  
  29. /** 
  30. * Present Manage just in time activation msg on update-core.php 
  31. */ 
  32. function manage_msg() { 
  33. if ( current_user_can( 'jetpack_manage_modules' ) ) { 
  34. $normalized_site_url = Jetpack::build_raw_urls( get_home_url() ); 
  35. $manage_active = Jetpack::is_module_active( 'manage' ); 
  36. ?> 
  37. <div class="jp-jitm"> 
  38. <a href="#" data-module="manage" class="dismiss"><span class="genericon genericon-close"></span></a> 
  39. <div class="jp-emblem"> 
  40. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0" y="0" viewBox="0 0 172.9 172.9" enable-background="new 0 0 172.9 172.9" xml:space="preserve"> 
  41. <path d="M86.4 0C38.7 0 0 38.7 0 86.4c0 47.7 38.7 86.4 86.4 86.4s86.4-38.7 86.4-86.4C172.9 38.7 134.2 0 86.4 0zM83.1 106.6l-27.1-6.9C49 98 45.7 90.1 49.3 84l33.8-58.5V106.6zM124.9 88.9l-33.8 58.5V66.3l27.1 6.9C125.1 74.9 128.4 82.8 124.9 88.9z"/> 
  42. </svg> 
  43. </div> 
  44. <p class="msg"> 
  45. <?php _e( 'Reduce security risks with automated plugin updates.', 'jetpack' ); ?> 
  46. </p> 
  47. <p> 
  48. <img class="jetpack-spinner hide" style="margin-top: 13px;" width="17" height="17" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="Loading ..." /><a href="#" data-module="manage" class="activate button button-jetpack <?php if( Jetpack::is_module_active( 'manage' ) ) { echo 'hide'; } ?>"><?php esc_html_e( 'Activate Now', 'jetpack' ); ?></a><a href="<?php echo esc_url( 'https://wordpress.com/plugins/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Go to WordPress.com to try these features', 'jetpack' ); ?>" id="jetpack-wordpressdotcom" class="button button-jetpack <?php if( ! Jetpack::is_module_active( 'manage' ) ) { echo 'hide'; } ?>"><?php esc_html_e( 'Go to WordPress.com', 'jetpack' ); ?></a> 
  49. </p> 
  50. </div> 
  51. <?php 
  52. //jitm is being viewed, track it 
  53. $jetpack = Jetpack::init(); 
  54. $jetpack->stat( 'jitm', 'manage-viewed-' . JETPACK__VERSION ); 
  55. $jetpack->do_stats( 'server_side' ); 
  56.  
  57. /** 
  58. * Present Photon just in time activation msg 
  59. */ 
  60. function photon_msg() { 
  61. if ( current_user_can( 'jetpack_manage_modules' ) ) { ?> 
  62. <div class="jp-jitm"> 
  63. <a href="#" data-module="photon" class="dismiss"><span class="genericon genericon-close"></span></a> 
  64. <div class="jp-emblem"> 
  65. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0" y="0" viewBox="0 0 172.9 172.9" enable-background="new 0 0 172.9 172.9" xml:space="preserve"> 
  66. <path d="M86.4 0C38.7 0 0 38.7 0 86.4c0 47.7 38.7 86.4 86.4 86.4s86.4-38.7 86.4-86.4C172.9 38.7 134.2 0 86.4 0zM83.1 106.6l-27.1-6.9C49 98 45.7 90.1 49.3 84l33.8-58.5V106.6zM124.9 88.9l-33.8 58.5V66.3l27.1 6.9C125.1 74.9 128.4 82.8 124.9 88.9z"/> 
  67. </svg> 
  68. </div> 
  69. <p class="msg"> 
  70. <?php _e( 'Speed up your photos and save bandwidth costs by using a free content delivery network.', 'jetpack' ); ?> 
  71. </p> 
  72. <p> 
  73. <img class="jetpack-spinner hide" style="margin-top: 13px;" width="17" height="17" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="Loading ..." /><a href="#" data-module="photon" class="activate button button-jetpack"><?php esc_html_e( 'Activate Photon', 'jetpack' ); ?></a> 
  74. </p> 
  75. </div> 
  76. <?php 
  77. //jitm is being viewed, track it 
  78. $jetpack = Jetpack::init(); 
  79. $jetpack->stat( 'jitm', 'photon-viewed-' . JETPACK__VERSION ); 
  80. $jetpack->do_stats( 'server_side' ); 
  81.  
  82. /** 
  83. * Function to enqueue jitm css and js 
  84. */ 
  85. function jitm_enqueue_files( $hook ) { 
  86.  
  87. $wp_styles = new WP_Styles(); 
  88. $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; 
  89. wp_enqueue_style( 'jetpack-jitm-css', plugins_url( "css/jetpack-admin-jitm{$min}.css", JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION . '-201243242' ); 
  90. $wp_styles->add_data( 'jetpack-jitm-css', 'rtl', true ); 
  91.  
  92. //Build stats url for tracking manage button 
  93. $jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'wordpresstools' ) ); 
  94.  
  95. // Enqueue javascript to handle jitm notice events 
  96. wp_enqueue_script( 'jetpack-jitm-js', plugins_url( '_inc/jetpack-jitm.js', JETPACK__PLUGIN_FILE ),  
  97. array( 'jquery' ), JETPACK__VERSION, true ); 
  98. wp_localize_script( 
  99. 'jetpack-jitm-js',  
  100. 'jitmL10n',  
  101. array( 
  102. 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  103. 'jitm_nonce' => wp_create_nonce( 'jetpack-jitm-nonce' ),  
  104. 'photon_msgs' => array( 
  105. 'success' => __( 'Success! Photon is now actively optimizing and serving your images for free.', 'jetpack' ),  
  106. 'fail' => __( 'We are sorry but unfortunately Photon did not activate.', 'jetpack' ) 
  107. ),  
  108. 'manage_msgs' => array( 
  109. 'success' => __( 'Success! WordPress.com tools are now active.', 'jetpack' ),  
  110. 'fail' => __( 'We are sorry but unfortunately Manage did not activate.', 'jetpack' ) 
  111. ),  
  112. 'jitm_stats_url' => $jitm_stats_url 
  113. );