DDWPinfo_Admin_Pages

Main class to setup the admin info pages.

Defined (1)

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

/includes/ddwpinfo/ddwpinfo.php  
  1. class DDWPinfo_Admin_Pages { 
  2.  
  3. /** 
  4. * Holds a copy of the object for easy reference. 
  5. * @since 1.0.0 
  6. * @var object 
  7. */ 
  8. private static $_this; 
  9.  
  10.  
  11. /** 
  12. * Constructor. Hooks all interactions into correct areas to start the class. 
  13. * @since 1.0.0 
  14. */ 
  15. public function __construct() { 
  16.  
  17. /** 
  18. * Disallowing a Second Instantiation of our class. 
  19. * @link http://hardcorewp.com/2013/using-singleton-classes-for-wordpress-plugins/ 
  20. * @since 1.0.0 
  21. * @uses wp_die() 
  22. */ 
  23. if ( isset( self::$_this ) ) { 
  24.  
  25. $ddwpinfo_notice = sprintf( 
  26. '%s is a singleton class and you cannot create a second instance.',  
  27. get_class( $this ) 
  28. ); 
  29.  
  30. wp_die( $ddwpinfo_notice ); 
  31.  
  32. } // end if 
  33.  
  34. /** Store the object in a static property */ 
  35. self::$_this = $this; 
  36.  
  37. /** Include our helper functions */ 
  38. require_once( DDWPINFO_LIB_DIR . 'ddwpinfo-functions.php' ); 
  39.  
  40. /** Add new submenu of Dashboard admin page */ 
  41. add_action( 'admin_menu', array( 'DDWPinfo_Admin_Pages', 'admin_pages' ), 1 ); 
  42. add_action( 'network_admin_menu', array( 'DDWPinfo_Admin_Pages', 'admin_pages' ), 1 ); 
  43.  
  44. /** Hook some info into Dashboard widget */ 
  45. require_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-dashboard.php' ); 
  46. add_action( 'rightnow_end', 'ddwpinfo_dashboard_info' ); 
  47. add_action( 'mu_rightnow_end', 'ddwpinfo_dashboard_info' ); 
  48.  
  49. /** Enqueue a few helper styles for Dashboard */ 
  50. add_action( 'admin_enqueue_scripts', array( 'DDWPinfo_Admin_Pages', 'dashboard_styles' ) ); 
  51.  
  52. } // end of method __construct 
  53.  
  54.  
  55. /** 
  56. * Returns the value of "self::$_this". 
  57. * This function will be public by default. 
  58. * providing read-only access to the single instance used by the plugin's 
  59. * class. 
  60. * @link http://hardcorewp.com/2012/enabling-action-and-filter-hook-removal-from-class-based-wordpress-plugins/ 
  61. * @since 1.0.0 
  62. * @return the value of self::$_this. 
  63. */ 
  64. static function this() { 
  65.  
  66. return $_this; 
  67.  
  68. } // end of method this 
  69.  
  70.  
  71. /** 
  72. * Setup the Admin menu in WordPress 
  73. * @since 1.0.0 
  74. * @return void 
  75. */ 
  76. static function admin_pages() { 
  77.  
  78. $ddwpinfo_main_page = add_dashboard_page( 
  79. 'DECKERWEB bersetzungen Informationen',  
  80. 'bersetzungen Info',  
  81. 'manage_options',  
  82. 'deckerweb-translations',  
  83. array( 'DDWPinfo_Admin_Pages', 'setup_default_admin_pages' ) 
  84. ); 
  85.  
  86. /** Let helper styles load only on this admin page */ 
  87. add_action( 'load-' . $ddwpinfo_main_page, array( 'DDWPinfo_Admin_Pages', 'load_admin_styles' ) ); 
  88.  
  89. /** Setup help tab system */ 
  90. add_action( 'load-' . $ddwpinfo_main_page, array( 'DDWPinfo_Admin_Pages', 'admin_help_tab' ), 5 ); 
  91.  
  92. if ( is_admin() ) { 
  93.  
  94. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-admin-help.php' ); 
  95. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-content-blocks.php' ); 
  96.  
  97. } // end if 
  98.  
  99. } // end method admin_pages 
  100.  
  101.  
  102. /** 
  103. * Helper method for returning string for minifying stylesheets. 
  104. * @since 1.0.0 
  105. * @return string String for minifying stylesheets. 
  106. */ 
  107. static function script_suffix() { 
  108.  
  109. return ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) ? '' : '.min'; 
  110.  
  111. } // end of method script_suffix 
  112.  
  113.  
  114. /** 
  115. * Helper method for returning string for versioning scripts/ stylesheets. 
  116. * @since 1.0.0 
  117. * @return string Version string for versioning scripts/ stylesheets. 
  118. */ 
  119. static function script_version() { 
  120.  
  121. return ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) ? time() : filemtime( plugin_dir_path( __FILE__ ) ); 
  122.  
  123. } // end of method script_version 
  124.  
  125.  
  126. /** 
  127. * Helper method to let load our admin styles only on our own pagehook. 
  128. * @since 1.0.0 
  129. */ 
  130. function load_admin_styles() { 
  131.  
  132. /** Enqueue a few helper styles */ 
  133. add_action( 'admin_enqueue_scripts', array( 'DDWPinfo_Admin_Pages', 'admin_styles' ) ); 
  134.  
  135. /** Enqueue core Thickbox script */ 
  136. add_action( 'admin_enqueue_scripts', 'add_thickbox' ); 
  137.  
  138. } // end of method load_admin_styles 
  139.  
  140.  
  141. /** 
  142. * Enqueue our used admin styles. 
  143. * @since 1.0.0 
  144. * @uses wp_register_style() 
  145. * @uses wp_enqueue_style() 
  146. */ 
  147. function admin_styles() { 
  148.  
  149. /** First, register our stylesheet */ 
  150. wp_register_style( 
  151. 'ddwpinfo-admin-styles',  
  152. DDWPINFO_LIB_URI . 'css/ddwpinfo-admin-styles' . self::script_suffix() . '.css',  
  153. array( 'dashicons' ),  
  154. self::script_version(),  
  155. 'all' 
  156. ); 
  157.  
  158. /** Second, enqueue our stylesheet */ 
  159. wp_enqueue_style( 'ddwpinfo-admin-styles' ); 
  160.  
  161. } // end of method admin_styles 
  162.  
  163.  
  164. /** 
  165. * Enqueue our used Dashboard styles. 
  166. * @since 1.0.0 
  167. * @uses wp_register_style() 
  168. * @uses wp_enqueue_style() 
  169. */ 
  170. static function dashboard_styles( $hook ) { 
  171.  
  172. /** Bail early if not on site/ network Dashboard page */ 
  173. if ( 'index.php' != $hook ) { 
  174.  
  175. return; 
  176.  
  177. } // end if 
  178.  
  179. /** First, register our stylesheet */ 
  180. wp_register_style( 
  181. 'ddwpinfo-dashboard-styles',  
  182. DDWPINFO_LIB_URI . 'css/ddwpinfo-admin-styles' . self::script_suffix() . '.css',  
  183. array( 'dashicons' ),  
  184. self::script_version(),  
  185. 'all' 
  186. ); 
  187.  
  188. /** Second, enqueue our stylesheet */ 
  189. wp_enqueue_style( 'ddwpinfo-dashboard-styles' ); 
  190.  
  191. } // end of method dashboard_styles 
  192.  
  193.  
  194. /** 
  195. * Setup our 2 default admin pages/tabs: "General" and "Imprint". 
  196. * Add hooks and filters for plugins to hook in and add their own tabs. 
  197. * @since 1.0.0 
  198. * @global mixed $ddwpinfo_current_tab 
  199. */ 
  200. function setup_default_admin_pages() { 
  201.  
  202. global $ddwpinfo_current_tab; 
  203.  
  204. do_action( 'ddwpinfo_admin_page_start' ); 
  205.  
  206. /** Get current tab */ 
  207. $ddwpinfo_current_tab = ( empty( $_GET[ 'tab' ] ) ) ? 'general' : sanitize_text_field( urldecode( $_GET[ 'tab' ] ) ); 
  208.  
  209. /** Begin HTML template markup */ 
  210. ?> 
  211.  
  212. <div class="wrap ddwpinfo"> 
  213. <h2><?php echo 'DECKERWEB bersetzungen – Wichtige Benutzerinformationen'; ?></h2> 
  214. <div class="ddwpinfo-subtitle">Schlssige, sachgemge und geschftstaugliche bersetzungen fr WordPress</div> 
  215. <div id="ddwpinfo-tab-group" class="ddwpinfo-tab-group vertical-tabs"> 
  216.  
  217. <ul id="ddwpinfo-tabs" class="ddwpinfo-tabs"> 
  218. <?php 
  219. $ddwpinfo_tabs = array( 
  220. 'general' => 'Grundlegendes',  
  221. 'values' => 'bersetzungs­prinzipien',  
  222. 'donations' => '<strong>Spenden</strong>',  
  223. 'imprint' => 'Rechtliche Infos' 
  224. ); 
  225.  
  226. /** Allows for hooking in more page tabs */ 
  227. $ddwpinfo_tabs = apply_filters( 'ddwpinfo_filter_tabs_array', $ddwpinfo_tabs ); 
  228.  
  229. foreach ( $ddwpinfo_tabs as $tab_id => $tab_label ) { 
  230.  
  231. echo '<li class="' . $tab_id; 
  232.  
  233. if ( $ddwpinfo_current_tab == $tab_id ) { 
  234.  
  235. echo ' active'; 
  236.  
  237. } // end if 
  238.  
  239. echo '"><a href="' . admin_url( 'index.php?page=deckerweb-translations&tab=' . $tab_id ) . '" title="' . esc_attr( $tab_label ) . '">' . $tab_label . '</a></li>'; 
  240.  
  241. } // end foreach 
  242.  
  243. /** Action Hook after tabs area */ 
  244. do_action( 'ddwpinfo_admin_page_tabs' ); 
  245. ?> 
  246. </ul><!-- end ddwpinfo-tabs .ddwpinfo-tabs //--> 
  247.  
  248. <div id="ddwpinfo-tab-container" class="ddwpinfo-tab-container"> 
  249. <?php 
  250. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-donations-button.php' ); 
  251. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-donations-box.php' ); 
  252.  
  253. switch ( $ddwpinfo_current_tab ) : 
  254.  
  255. case "general" : 
  256. do_action( 'ddwpinfo_before_general_view' ); 
  257. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-general.php' ); 
  258. do_action( 'ddwpinfo_after_general_view' ); 
  259. break; 
  260.  
  261. case "values" : 
  262. do_action( 'ddwpinfo_before_values_view' ); 
  263. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-values.php' ); 
  264. do_action( 'ddwpinfo_after_values_view' ); 
  265. break; 
  266.  
  267. case "donations" : 
  268. do_action( 'ddwpinfo_before_donations_view' ); 
  269. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-donations-action.php' ); 
  270. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-donations.php' ); 
  271. do_action( 'ddwpinfo_after_donations_view' ); 
  272. break; 
  273.  
  274. case "imprint" : 
  275. do_action( 'ddwpinfo_before_imprint_view' ); 
  276. include_once( DDWPINFO_LIB_DIR . 'views/ddwpinfo-imprint.php' ); 
  277. do_action( 'ddwpinfo_after_imprint_view' ); 
  278. break; 
  279.  
  280. default : 
  281. do_action( 'ddwpinfo_admin_page_tabs_' . $ddwpinfo_current_tab ); 
  282. break; 
  283.  
  284. endswitch; 
  285. ?> 
  286.  
  287. <?php do_action( 'ddwpinfo_admin_page_tabs_footer' ); ?> 
  288.  
  289. </div><!-- end #ddwpinfo-tab-container .ddwpinfo-tab-container //--> 
  290.  
  291. </div><!-- end #ddwpinfo-tab-group .ddwpinfo-tab-group.vertical-tabs //--> 
  292.  
  293. </div><!-- end .wrap.ddwpinfo //--> 
  294.  
  295. <?php 
  296. /** ^ End HTML template markup */ 
  297.  
  298. } // end of method setup_default_admin_pages 
  299.  
  300.  
  301. /** 
  302. * Set up the Help Tab system. 
  303. * @since 1.0.0 
  304. * @uses callback functions located in library file 
  305. * 'views/ddwpinfo-admin-help.php' with the actual help tab content 
  306. * @uses get_current_screen() 
  307. * @uses WP_Screen::add_help_tab() 
  308. * @uses WP_Screen::set_help_sidebar() 
  309. * @uses ddwpinfo_help_sidebar_content() 
  310. * @uses ddwpinfo_help_sidebar_content_extra() 
  311. */ 
  312. function admin_help_tab() { 
  313.  
  314. global $screen; 
  315.  
  316. /** Get current screen */ 
  317. $screen = get_current_screen(); 
  318.  
  319. /** Display help tabs only for WordPress 3.3 or higher */ 
  320. if ( ! class_exists( 'WP_Screen' ) || ! $screen ) { 
  321.  
  322. return; 
  323.  
  324. } // end if 
  325.  
  326. /** Add starting/ general help tab */ 
  327. $screen->add_help_tab( array( 
  328. 'id' => 'ddwpinfo-start-help',  
  329. 'title' => 'DECKERWEB bersetzungen',  
  330. 'callback' => apply_filters( 'ddwpinfo_filter_help_content_start', 'ddwpinfo_help_content_start' ),  
  331. ) ); 
  332.  
  333. /** Add help sidebar */ 
  334. $screen->set_help_sidebar( ddwpinfo_help_sidebar_content_extra() . ddwpinfo_help_sidebar_content() ); 
  335.  
  336. } // end of method admin_help_tab 
  337.  
  338. } // end of main class DDWPinfo_Admin_Pages