/_inc/lib/admin-pages/class.jetpack-admin-page.php

  1. <?php 
  2.  
  3. // Shared logic between Jetpack admin pages 
  4. abstract class Jetpack_Admin_Page { 
  5. // Add page specific actions given the page hook 
  6. abstract function add_page_actions( $hook ); 
  7.  
  8. // Create a menu item for the page and returns the hook 
  9. abstract function get_page_hook(); 
  10.  
  11. // Enqueue and localize page specific scripts 
  12. abstract function page_admin_scripts(); 
  13.  
  14. // Render page specific HTML 
  15. abstract function page_render(); 
  16.  
  17. function __construct() { 
  18. $this->jetpack = Jetpack::init(); 
  19.  
  20. function add_actions() { 
  21. /** 
  22. * Don't add in the modules page unless modules are available! 
  23. */ 
  24. if ( $this->dont_show_if_not_active && ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) { 
  25. return; 
  26.  
  27. // Initialize menu item for the page in the admin 
  28. $hook = $this->get_page_hook(); 
  29.  
  30. // Attach hooks common to all Jetpack admin pages based on the created 
  31. // hook 
  32. add_action( "load-$hook", array( $this, 'admin_help' ) ); 
  33. add_action( "load-$hook", array( $this, 'admin_page_load' ) ); 
  34. add_action( "admin_head-$hook", array( $this, 'admin_head' ) ); 
  35.  
  36. add_action( "admin_footer-$hook", array( $this, 'module_modal_js_template' ) ); 
  37.  
  38. add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) ); 
  39. add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) ); 
  40.  
  41. // Attach page specific actions in addition to the above 
  42. $this->add_page_actions( $hook ); 
  43.  
  44. function admin_head() { 
  45. if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) { 
  46. /** 
  47. * Fires in the <head> of a particular Jetpack configuation page. 
  48. * 
  49. * The dynamic portion of the hook name, `$_GET['configure']`,  
  50. * refers to the slug of module, such as 'stats', 'sso', etc. 
  51. * A complete hook for the latter would be 
  52. * 'jetpack_module_configuation_head_sso'. 
  53. * 
  54. * @since 3.0.0 
  55. */ 
  56. do_action( 'jetpack_module_configuration_head_' . $_GET['configure'] ); 
  57.  
  58. // Render the page with a common top and bottom part, and page specific 
  59. // content 
  60. function render() { 
  61. $this->admin_page_top(); 
  62. $this->page_render(); 
  63. $this->admin_page_bottom(); 
  64.  
  65. function admin_help() { 
  66. $this->jetpack->admin_help(); 
  67.  
  68. function admin_page_load() { 
  69. // This is big. For the moment, just call the existing one. 
  70. $this->jetpack->admin_page_load(); 
  71.  
  72. // Load underscore template for the landing page and settings page modal 
  73. function module_modal_js_template() { 
  74. Jetpack::init()->load_view( 'admin/module-modal-template.php' ); 
  75.  
  76. function admin_page_top() { 
  77. include_once( JETPACK__PLUGIN_DIR . '_inc/header.php' ); 
  78.  
  79. function admin_page_bottom() { 
  80. include_once( JETPACK__PLUGIN_DIR . '_inc/footer.php' ); 
  81.  
  82. // Add page specific scripts and jetpack stats for all menu pages 
  83. function admin_scripts() { 
  84. $this->page_admin_scripts(); // Delegate to inheriting class 
  85. add_action( 'admin_footer', array( $this->jetpack, 'do_stats' ) ); 
  86.  
  87. // Enqueue the Jetpack admin stylesheet 
  88. function admin_styles() { 
  89. $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; 
  90.  
  91. wp_enqueue_style( 'jetpack-google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400italic, 400, 700, 600, 800' ); 
  92.  
  93. wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons' ), JETPACK__VERSION . '-20121016' ); 
  94. wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' ); 
  95. wp_style_add_data( 'jetpack-admin', 'suffix', $min ); 
.