Jetpack_Landing_Page

The Jetpack by WordPress.com Jetpack Landing Page class.

Defined (1)

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

/_inc/lib/admin-pages/class.jetpack-landing-page.php  
  1. class Jetpack_Landing_Page extends Jetpack_Admin_Page { 
  2. protected $dont_show_if_not_active = false; 
  3.  
  4. function get_page_hook() { 
  5. $title = _x( 'Jetpack', 'The menu item label', 'jetpack' ); 
  6.  
  7. list( $jetpack_version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); 
  8. if ( 
  9. $jetpack_version 
  10. && 
  11. $jetpack_version != JETPACK__VERSION 
  12. && 
  13. ( $new_modules = Jetpack::get_default_modules( $jetpack_version, JETPACK__VERSION ) ) 
  14. && 
  15. is_array( $new_modules ) 
  16. && 
  17. ( $new_modules_count = count( $new_modules ) ) 
  18. && 
  19. ( Jetpack::is_active() || Jetpack::is_development_mode() ) 
  20. ) { 
  21. $new_count_i18n = number_format_i18n( $new_modules_count ); 
  22. $span_title = esc_attr( sprintf( _n( 'One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack' ), $new_count_i18n ) ); 
  23. $format = _x( 'Jetpack %s', 'The menu item label with a new module count as %s', 'jetpack' ); 
  24. $update_markup = "<span class='update-plugins count-{$new_modules_count}' title='$span_title'><span class='update-count'>$new_count_i18n</span></span>"; 
  25. $title = sprintf( $format, $update_markup ); 
  26.  
  27. // Add the main admin Jetpack menu with possible information about new 
  28. // modules 
  29. add_menu_page( 'Jetpack', $title, 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div' ); 
  30. // also create the submenu 
  31. return add_submenu_page( 'jetpack', $title, $title, 'jetpack_admin_page', 'jetpack' ); 
  32.  
  33. function add_page_actions( $hook ) { 
  34. // Add landing page specific underscore templates 
  35. /** 
  36. * Filters the js_templates callback value 
  37. * @since 3.6.0 
  38. * @param array array( $this, 'js_templates' ) js_templates callback. 
  39. * @param string $hook Specific admin page. 
  40. */ 
  41. add_action( "admin_footer-$hook", apply_filters( 'jetpack_landing_page_js_templates_callback', array( $this, 'js_templates' ), $hook ) ); 
  42. /** This action is documented in class.jetpack.php */ 
  43. do_action( 'jetpack_admin_menu', $hook ); 
  44.  
  45. // Place the Jetpack menu item on top and others in the order they 
  46. // appear 
  47. add_filter( 'custom_menu_order', '__return_true' ); 
  48. add_filter( 'menu_order', array( $this, 'jetpack_menu_order' ) ); 
  49.  
  50. add_action( 'jetpack_notices_update_settings', array( $this, 'show_notices_update_settings' ), 10, 1 ); 
  51.  
  52. /** 
  53. * Build an array of a specific module tag. 
  54. * @param string Name of the module tag 
  55. * @return array The module slug, config url, and name of each Jump Start module 
  56. */ 
  57. function jumpstart_module_tag( $tag ) { 
  58. $modules = Jetpack_Admin::init()->get_modules(); 
  59.  
  60. $module_info = array(); 
  61. foreach ( $modules as $module => $value ) { 
  62. if ( in_array( $tag, $value['feature'] ) ) { 
  63. $module_info[] = array( 
  64. 'module_slug' => $value['module'],  
  65. 'module_name' => $value['name'],  
  66. 'configure_url' => $value['configure_url'],  
  67. ); 
  68. return $module_info; 
  69.  
  70. /** 
  71. * Only show Jump Start on first activation. 
  72. * Any option 'jumpstart' other than 'new connection' will hide it. 
  73. * The option can be of 4 things, and will be stored as such: 
  74. * new_connection : Brand new connection - Show 
  75. * jumpstart_activated : Jump Start has been activated - dismiss 
  76. * jetpack_action_taken: Manual activation of a module already happened - dismiss 
  77. * jumpstart_dismissed : Manual dismissal of Jump Start - dismiss 
  78. * @return bool | show or hide 
  79. */ 
  80. function jetpack_show_jumpstart() { 
  81. $jumpstart_option = Jetpack_Options::get_option( 'jumpstart' ); 
  82.  
  83. $hide_options = array( 
  84. 'jumpstart_activated',  
  85. 'jetpack_action_taken',  
  86. 'jumpstart_dismissed' 
  87. ); 
  88.  
  89. if ( ! $jumpstart_option || in_array( $jumpstart_option, $hide_options ) ) { 
  90. return false; 
  91.  
  92. return true; 
  93.  
  94. /** 
  95. * List of recommended modules for the Jump Start paragraph text. 
  96. * Will only show up in the paragraph if they are not active. 
  97. * @return string | comma-separated recommended modules that are not active 
  98. */ 
  99. function jumpstart_list_modules() { 
  100. $jumpstart_recommended = $this->jumpstart_module_tag( 'Jumpstart' ); 
  101.  
  102. $module_name = array(); 
  103. foreach ( $jumpstart_recommended as $module => $val ) { 
  104. if ( ! Jetpack::is_module_active( $val['module_slug'] ) ) { 
  105. $module_name[] = $val['module_name']; 
  106. $last_item = array_pop( $module_name ); 
  107. $jumpstart_module_list = implode( $module_name, ', ' ) . ', and ' . $last_item; 
  108.  
  109. return $jumpstart_module_list; 
  110.  
  111. function jetpack_menu_order( $menu_order ) { 
  112. $jp_menu_order = array(); 
  113.  
  114. foreach ( $menu_order as $index => $item ) { 
  115. if ( $item != 'jetpack' ) 
  116. $jp_menu_order[] = $item; 
  117.  
  118. if ( $index == 0 ) 
  119. $jp_menu_order[] = 'jetpack'; 
  120.  
  121. return $jp_menu_order; 
  122.  
  123. function js_templates() { 
  124. Jetpack::init()->load_view( 'admin/landing-page-templates.php' ); 
  125.  
  126. function page_render() { 
  127. // Handle redirects to configuration pages 
  128. if ( ! empty( $_GET['configure'] ) ) { 
  129. return $this->render_nojs_configurable(); 
  130.  
  131. global $current_user; 
  132.  
  133. $is_connected = Jetpack::is_active(); 
  134. $user_token = Jetpack_Data::get_access_token( $current_user->ID ); 
  135. $is_user_connected = $user_token && ! is_wp_error( $user_token ); 
  136. $is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' ); 
  137.  
  138. if ( Jetpack::is_development_mode() ) { 
  139. $is_connected = true; 
  140. $is_user_connected = true; 
  141. $is_master_user = false; 
  142.  
  143. // Set template data for the admin page template 
  144. $data = array( 
  145. 'is_connected' => $is_connected,  
  146. 'is_user_connected' => $is_user_connected,  
  147. 'is_master_user' => $is_master_user,  
  148. 'show_jumpstart' => $this->jetpack_show_jumpstart(),  
  149. 'jumpstart_list' => $this->jumpstart_list_modules(),  
  150. 'recommended_list' => $this->jumpstart_module_tag( 'Recommended' ),  
  151. ); 
  152. Jetpack::init()->load_view( 'admin/admin-page.php', $data ); 
  153.  
  154. /** 
  155. * Shows a notice message to users after they save Module config settings 
  156. * @param string $module_id 
  157. * @return null 
  158. */ 
  159. function show_notices_update_settings( $module_id ) { 
  160. $state = Jetpack::state( 'message' ); 
  161.  
  162. switch( $state ) { 
  163. case 'module_activated' : 
  164. if ( $module = Jetpack::get_module( Jetpack::state( 'module' ) ) ) { 
  165. $message = sprintf( __( '<strong>%s Activated!</strong> You can change the setting of it here.', 'jetpack' ), $module['name'] ); 
  166. break; 
  167. case 'module_configured': 
  168. $message = __( '<strong>Module settings were saved.</strong> ', 'jetpack' ); 
  169. break; 
  170. case 'no_message' : 
  171. break; 
  172.  
  173. if ( isset( $message ) ) { 
  174. ?> 
  175. <div id="message" class="jetpack-message"> 
  176. <div class="squeezer"> 
  177. <h4><?php echo wp_kses( $message, array( 'strong' => array(), 'a' => array( 'href' => true ), 'br' => true ) ); ?></h4> 
  178. <?php 
  179. /** 
  180. * Fires within the displayed message when a feature configuation is updated. 
  181. * This is a dynamic hook with `$module_id` being the slug of the module being updated. 
  182. * @since 3.4.0 
  183. */ 
  184. do_action( 'jetpack_notices_update_settings_' . $module_id ); ?> 
  185. </div> 
  186. </div> 
  187. <?php 
  188. add_action( 'jetpack_notices', array( Jetpack::init(), 'admin_notices' ) ); 
  189.  
  190. // Render the configuration page for the module if it exists and an error 
  191. // screen if the module is not configurable 
  192. function render_nojs_configurable() { 
  193. echo '<div class="clouds-sm"></div>'; 
  194. echo '<div class="wrap configure-module">'; 
  195.  
  196. $module_name = preg_replace( '/[^\da-z\-]+/', '', $_GET['configure'] ); 
  197. if ( Jetpack::is_module( $module_name ) && current_user_can( 'jetpack_configure_modules' ) ) { 
  198. Jetpack::admin_screen_configure_module( $module_name ); 
  199. } else { 
  200. echo '<h2>' . esc_html__( 'Error, bad module.', 'jetpack' ) . '</h2>'; 
  201.  
  202. echo '</div><!-- /wrap -->'; 
  203.  
  204. /** 
  205. * Build an array of Jump Start stats urls. 
  206. * requires the build URL args passed as an array 
  207. * @param array $jumpstart_stats 
  208. * @return (array) of built stats urls 
  209. */ 
  210. function build_jumpstart_stats_urls( $jumpstart_stats ) { 
  211. $jumpstart_urls = array(); 
  212.  
  213. foreach ( $jumpstart_stats as $value) { 
  214. $jumpstart_urls[$value] = Jetpack::build_stats_url( array( 'x_jetpack-jumpstart' => $value ) ); 
  215.  
  216. return $jumpstart_urls; 
  217.  
  218.  
  219. /** 
  220. * Build an array of NUX admin stats urls. 
  221. * requires the build URL args passed as an array 
  222. * @param array $nux_admin_stats 
  223. * @return (array) of built stats urls 
  224. */ 
  225. function build_nux_admin_stats_urls( $nux_admin_stats ) { 
  226. $nux_admin_urls = array(); 
  227.  
  228. foreach ( $nux_admin_stats as $value) { 
  229. $nux_admin_urls[ $value ] = Jetpack::build_stats_url( array( 'x_jetpack-nux' => $value ) ); 
  230.  
  231. return $nux_admin_urls; 
  232.  
  233.  
  234. function page_admin_scripts() { 
  235. // Enqueue jp.js and localize it 
  236. wp_enqueue_script( 'jetpack-js', plugins_url( '_inc/jp.js', JETPACK__PLUGIN_FILE ),  
  237. array( 'jquery', 'wp-util' ), JETPACK__VERSION . '-20121111' ); 
  238. wp_localize_script( 
  239. 'jetpack-js',  
  240. 'jetpackL10n',  
  241. array( 
  242. 'ays_disconnect' => __( "This will deactivate all Jetpack modules.\nAre you sure you want to disconnect?", 'jetpack' ),  
  243. 'ays_unlink' => __( "This will prevent user-specific modules such as Publicize, Notifications and Post By Email from working.\nAre you sure you want to unlink?", 'jetpack' ),  
  244. 'ays_dismiss' => __( "This will deactivate Jetpack.\nAre you sure you want to deactivate Jetpack?", 'jetpack' ),  
  245. 'view_all_features' => __( 'View all Jetpack features', 'jetpack' ),  
  246. 'no_modules_found' => sprintf( __( 'Sorry, no modules were found for the search term "%s"', 'jetpack' ), '{term}' ),  
  247. 'modules' => array_values( Jetpack_Admin::init()->get_modules() ),  
  248. 'currentVersion' => JETPACK__VERSION,  
  249. 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  250. 'jumpstart_modules' => $this->jumpstart_module_tag( 'Jumpstart' ),  
  251. 'show_jumpstart' => $this->jetpack_show_jumpstart(),  
  252. 'activate_nonce' => wp_create_nonce( 'jetpack-jumpstart-nonce' ),  
  253. 'admin_nonce' => wp_create_nonce( 'jetpack-admin-nonce' ),  
  254. 'jumpstart_stats_urls' => $this->build_jumpstart_stats_urls( array( 'dismiss', 'jumpstarted', 'learnmore', 'viewed', 'manual' ) ),  
  255. 'admin_stats_urls' => $this->build_nux_admin_stats_urls( array( 'enabled', 'deactivated', 'learnmore' ) ),  
  256. 'site_url_manage' => Jetpack::build_raw_urls( get_site_url() ),  
  257. );