UM_Admin_Dashboard

The Ultimate Member UM Admin Dashboard class.

Defined (1)

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

/admin/core/um-admin-dashboard.php  
  1. class UM_Admin_Dashboard { 
  2.  
  3. function __construct() { 
  4.  
  5. $this->slug = 'ultimatemember'; 
  6.  
  7. $this->about_tabs['about'] = 'About'; 
  8. $this->about_tabs['start'] = 'Getting Started'; 
  9.  
  10. add_action('admin_menu', array(&$this, 'primary_admin_menu'), 0); 
  11. add_action('admin_menu', array(&$this, 'secondary_menu_items'), 1000); 
  12. add_action('admin_menu', array(&$this, 'extension_menu'), 9999);  
  13.  
  14. add_action( 'admin_head', array( $this, 'menu_order_count' ) ); 
  15.  
  16. add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1000 ); 
  17.  
  18. add_action( 'wp_ajax_ultimatemember_rated', array( $this, 'ultimatemember_rated' ) ); 
  19. add_action( 'wp_ajax_nopriv_ultimatemember_rated', array( $this, 'ultimatemember_rated' ) ); 
  20.  
  21.  
  22. /** 
  23. * Change the admin footer text on UM admin pages 
  24. */ 
  25. public function admin_footer_text( $footer_text ) { 
  26. $current_screen = get_current_screen(); 
  27.  
  28. // Add the dashboard pages 
  29. $um_pages[] = 'toplevel_page_ultimatemember'; 
  30. $um_pages[] = 'admin_page_ultimatemember-about'; 
  31. $um_pages[] = 'ultimate-member_page_um_options'; 
  32. $um_pages[] = 'edit-um_form'; 
  33. $um_pages[] = 'edit-um_role'; 
  34. $um_pages[] = 'edit-um_directory'; 
  35. $um_pages[] = 'ultimate-member_page_ultimatemember-extensions'; 
  36.  
  37. if ( isset( $current_screen->id ) && in_array( $current_screen->id, $um_pages ) ) { 
  38. // Change the footer text 
  39. if ( ! get_option( 'um_admin_footer_text_rated' ) ) { 
  40.  
  41. $footer_text = sprintf( __( 'If you like Ultimate Member please consider leaving a %s★★★★★%s review. It will help us to grow the plugin and make it more popular. Thank you.', 'ultimatemember' ), '<a href="https://wordpress.org/support/plugin/ultimate-member/reviews/?filter=5" target="_blank" class="um-admin-rating-link" data-rated="' . __( 'Thanks :)', 'ultimatemember' ) . '">', '</a>' ); 
  42.  
  43. $footer_text .= "<script type='text/javascript'> 
  44. jQuery('a.um-admin-rating-link').click(function() { 
  45. jQuery.post( '" . admin_url( 'admin-ajax.php', 'relative' ) . "', { action: 'ultimatemember_rated' } ); 
  46. jQuery(this).parent().text( jQuery(this).data( 'rated' ) ); 
  47. }); 
  48. </script>"; 
  49.  
  50. return $footer_text; 
  51.  
  52. /** 
  53. * When user clicks the review link in backend 
  54. */ 
  55. function ultimatemember_rated() { 
  56. update_option('um_admin_footer_text_rated', 1 ); 
  57. die(); 
  58.  
  59. /** 
  60. * Get pending users (in queue) 
  61. */ 
  62. function get_pending_users_count() { 
  63.  
  64. if ( get_option('um_cached_users_queue') > 0 && ! isset( $_REQUEST['delete_count'] ) ) { 
  65. return get_option('um_cached_users_queue'); 
  66.  
  67. $args = array( 'fields' => 'ID', 'number' => 100 ); 
  68. $args['meta_query']['relation'] = 'OR'; 
  69. $args['meta_query'][] = array( 
  70. 'key' => 'account_status',  
  71. 'value' => 'awaiting_email_confirmation',  
  72. 'compare' => '=' 
  73. ); 
  74. $args['meta_query'][] = array( 
  75. 'key' => 'account_status',  
  76. 'value' => 'awaiting_admin_review',  
  77. 'compare' => '=' 
  78. ); 
  79. $args = apply_filters('um_admin_pending_queue_filter', $args ); 
  80. $users = new WP_User_Query( $args ); 
  81.  
  82. delete_option('um_cached_users_queue'); 
  83. add_option('um_cached_users_queue', count($users->results), '', 'no' ); 
  84.  
  85. return count($users->results); 
  86.  
  87. /** 
  88. * Manage order of admin menu items 
  89. */ 
  90. public function menu_order_count() { 
  91. global $menu, $submenu; 
  92.  
  93. if ( !current_user_can( 'list_users' ) ) return; 
  94.  
  95. $count = $this->get_pending_users_count(); 
  96. if(is_array($menu)) { 
  97. foreach( $menu as $key => $menu_item ) { 
  98. if ( 0 === strpos( $menu_item[0], _x( 'Users', 'Admin menu name' ) ) ) { 
  99. $menu[ $key ][0] .= ' <span class="update-plugins count-'.$count.'"><span class="processing-count">'.$count.'</span></span>'; 
  100.  
  101. if(is_array($submenu)) { 
  102. foreach ( $submenu['users.php'] as $key => $menu_item ) { 
  103. if ( 0 === strpos( $menu_item[0], _x( 'All Users', 'Admin menu name' ) ) ) { 
  104. $submenu['users.php'][ $key ][0] .= ' <span class="update-plugins count-'.$count.'"><span class="processing-count">'.$count.'</span></span>'; 
  105.  
  106. /*** 
  107. *** @setup admin menu 
  108. ***/ 
  109. function primary_admin_menu() { 
  110.  
  111. $this->pagehook = add_menu_page( __('Ultimate Member', $this->slug), __('Ultimate Member', $this->slug), 'manage_options', $this->slug, array(&$this, 'admin_page'), 'dashicons-admin-users', '42.78578'); 
  112. add_action('load-'.$this->pagehook, array(&$this, 'on_load_page')); 
  113.  
  114. add_submenu_page( $this->slug, __('Dashboard', $this->slug), __('Dashboard', $this->slug), 'manage_options', $this->slug, array(&$this, 'admin_page') ); 
  115.  
  116. foreach( $this->about_tabs as $k => $tab ) { 
  117. add_submenu_page( '_'. $k . '_um', sprintf(__('%s | Ultimate Member', $this->slug), $tab), sprintf(__('%s | Ultimate Member', $this->slug), $tab), 'manage_options', $this->slug . '-' . $k, array(&$this, 'admin_page') ); 
  118.  
  119.  
  120. /*** 
  121. *** @secondary admin menu (after settings) 
  122. ***/ 
  123. function secondary_menu_items() { 
  124.  
  125. add_submenu_page( $this->slug, __('Forms', $this->slug), __('Forms', $this->slug), 'manage_options', 'edit.php?post_type=um_form', '', '' ); 
  126. add_submenu_page( $this->slug, __('User Roles', $this->slug), __('User Roles', $this->slug), 'manage_options', 'edit.php?post_type=um_role', '', '' ); 
  127.  
  128. if ( um_get_option('members_page' ) || !get_option('um_options') ) { 
  129. add_submenu_page( $this->slug, __('Member Directories', $this->slug), __('Member Directories', $this->slug), 'manage_options', 'edit.php?post_type=um_directory', '', '' ); 
  130.  
  131. do_action('um_extend_admin_menu'); 
  132.  
  133.  
  134. /*** 
  135. *** @extension menu 
  136. ***/ 
  137. function extension_menu() { 
  138.  
  139. add_submenu_page( $this->slug, __('Extensions', $this->slug), '<span style="color: #00B9EB">' .__('Extensions', $this->slug) . '</span>', 'manage_options', $this->slug . '-extensions', array(&$this, 'admin_page') ); 
  140.  
  141. remove_submenu_page('tools.php', 'redux-about'); 
  142.  
  143.  
  144. /*** 
  145. *** @load metabox stuff 
  146. ***/ 
  147. function on_load_page() { 
  148. global $ultimatemember; 
  149.  
  150. wp_enqueue_script('common'); 
  151. wp_enqueue_script('wp-lists'); 
  152. wp_enqueue_script('postbox'); 
  153.  
  154. /** custom metaboxes for dashboard defined here **/ 
  155.  
  156. add_meta_box('um-metaboxes-contentbox-1', __('Users Overview', 'ultimatemember'), array(&$this, 'users_overview'), $this->pagehook, 'core', 'core'); 
  157.  
  158. add_meta_box('um-metaboxes-mainbox-1', __('Latest from our blog', 'ultimatemember'), array(&$this, 'um_news'), $this->pagehook, 'normal', 'core'); 
  159.  
  160. add_meta_box('um-metaboxes-sidebox-1', __('Purge Temp Files', 'ultimatemember'), array(&$this, 'purge_temp'), $this->pagehook, 'side', 'core'); 
  161. add_meta_box('um-metaboxes-sidebox-2', __('User Cache', 'ultimatemember'), array(&$this, 'user_cache'), $this->pagehook, 'side', 'core'); 
  162.  
  163. if ( $this->language_avaialable_not_installed() ) { 
  164. add_meta_box('um-metaboxes-sidebox-2', __('Language', 'ultimatemember'), array(&$this, 'dl_language'), $this->pagehook, 'side', 'core'); 
  165. } else if ( $this->language_avaialable_installed() ) { 
  166. add_meta_box('um-metaboxes-sidebox-2', __('Language', 'ultimatemember'), array(&$this, 'up_language'), $this->pagehook, 'side', 'core'); 
  167. } else if ( $this->language_not_available() ) { 
  168. add_meta_box('um-metaboxes-sidebox-2', __('Language', 'ultimatemember'), array(&$this, 'ct_language'), $this->pagehook, 'side', 'core'); 
  169.  
  170.  
  171. function up_language() { 
  172. global $ultimatemember; 
  173. $locale = get_option('WPLANG'); 
  174. include_once um_path . 'admin/templates/dashboard/language-update.php'; 
  175.  
  176. function dl_language() { 
  177. global $ultimatemember; 
  178. $locale = get_option('WPLANG'); 
  179. include_once um_path . 'admin/templates/dashboard/language-download.php'; 
  180.  
  181. function ct_language() { 
  182. global $ultimatemember; 
  183. $locale = get_option('WPLANG'); 
  184. include_once um_path . 'admin/templates/dashboard/language-contrib.php'; 
  185.  
  186. function um_news() { 
  187. global $ultimatemember; 
  188. include_once um_path . 'admin/templates/dashboard/feed.php'; 
  189.  
  190. function users_overview() { 
  191. global $ultimatemember; 
  192. include_once um_path . 'admin/templates/dashboard/users.php'; 
  193.  
  194. function purge_temp() { 
  195. global $ultimatemember; 
  196. include_once um_path . 'admin/templates/dashboard/purge.php'; 
  197.  
  198. function user_cache() { 
  199. global $ultimatemember; 
  200. include_once um_path . 'admin/templates/dashboard/cache.php'; 
  201.  
  202. /*** 
  203. *** @language not available 
  204. ***/ 
  205. function language_not_available() { 
  206. $locale = get_option('WPLANG'); 
  207. if ( $locale && !strstr($locale, 'en_') && !isset( $ultimatemember->available_languages[$locale] ) && !file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) ) 
  208. return true; 
  209. return false; 
  210.  
  211. /*** 
  212. *** @language available but not installed 
  213. ***/ 
  214. function language_avaialable_not_installed() { 
  215. global $ultimatemember; 
  216. $locale = get_option('WPLANG'); 
  217. if ( $locale && isset( $ultimatemember->available_languages[$locale] ) && !file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) ) 
  218. return true; 
  219. return false; 
  220.  
  221. /*** 
  222. *** @language available and installed 
  223. ***/ 
  224. function language_avaialable_installed() { 
  225. global $ultimatemember; 
  226. $locale = get_option('WPLANG'); 
  227. if ( $locale && isset( $ultimatemember->available_languages[$locale] ) && file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) ) 
  228. return true; 
  229. return false; 
  230.  
  231. /*** 
  232. *** @get a directory size 
  233. ***/ 
  234. function dir_size( $directory ) { 
  235. global $ultimatemember; 
  236. if ( $directory == 'temp' ) { 
  237. $directory = $ultimatemember->files->upload_temp; 
  238. $size = 0; 
  239. foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) { 
  240. $size+=$file->getSize(); 
  241. return round ( $size / 1048576, 2); 
  242. return 0; 
  243.  
  244. /*** 
  245. *** @which admin page to show? 
  246. ***/ 
  247. function admin_page() { 
  248.  
  249. $page = $_REQUEST['page']; 
  250. if ( $page == 'ultimatemember' && ! isset( $_REQUEST['um-addon'] ) ) { 
  251.  
  252. ?> 
  253.  
  254. <div id="um-metaboxes-general" class="wrap"> 
  255.  
  256. <h2>Ultimate Member <sup><?php echo ultimatemember_version; ?></sup></h2> 
  257.  
  258. <?php wp_nonce_field('um-metaboxes-general'); ?> 
  259. <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?> 
  260. <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?> 
  261.  
  262. <input type="hidden" name="action" value="save_um_metaboxes_general" /> 
  263.  
  264. <div id="dashboard-widgets-wrap"> 
  265.  
  266. <div id="dashboard-widgets" class="metabox-holder um-metabox-holder">  
  267.  
  268. <div id="postbox-container-1" class="postbox-container"><?php do_meta_boxes($this->pagehook, 'core', null); ?></div> 
  269. <div id="postbox-container-2" class="postbox-container"><?php do_meta_boxes($this->pagehook, 'normal', null); ?></div> 
  270. <div id="postbox-container-3" class="postbox-container"><?php do_meta_boxes($this->pagehook, 'side', null); ?></div> 
  271.  
  272. </div> 
  273.  
  274. </div> 
  275.  
  276. </div><div class="um-admin-clear"></div> 
  277.  
  278. <div class="um-admin-dash-share"><?php global $reduxConfig; foreach ( $reduxConfig->args['share_icons'] as $k => $arr ) { ?><a href="<?php echo $arr['url']; ?>" class="um-about-icon um-admin-tipsy-n" title="<?php echo $arr['title']; ?>" target="_blank"><i class="<?php echo $arr['icon']; ?>"></i></a><?php } ?>  
  279. </div><div class="um-admin-clear"></div> 
  280.  
  281. <script type="text/javascript"> 
  282. //<![CDATA[ 
  283. jQuery(document).ready( function($) { 
  284. // postboxes setup 
  285. postboxes.add_postbox_toggles('<?php echo $this->pagehook; ?>'); 
  286. }); 
  287. //]]> 
  288. </script> 
  289.  
  290. <?php 
  291.  
  292. } else if ( $page == 'ultimatemember-extensions' ) { 
  293.  
  294. include_once um_path . 'admin/templates/extensions.php'; 
  295.  
  296. } else if ( $page == 'ultimatemember-about' ) { 
  297.  
  298. include_once um_path . 'admin/templates/welcome/about.php'; 
  299.  
  300. } else if ( $page == 'ultimatemember-start' ) { 
  301.  
  302. include_once um_path . 'admin/templates/welcome/start.php'; 
  303.  
  304. }  
  305.  
  306.