WPCubeDashboardWidget

Dashboard Widget.

Defined (1)

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

/_modules/dashboard/dashboard.php  
  1. class WPCubeDashboardWidget {  
  2. /** 
  3. * Constructor 
  4. * @param object $plugin Plugin Object (name, displayName, version, folder, url) 
  5. */ 
  6. function __construct($plugin) { 
  7. // Plugin Details 
  8. $this->dashboard = $plugin; 
  9. $this->dashboardURL = plugin_dir_url( __FILE__ ); 
  10.  
  11. // Hooks 
  12. add_action('admin_enqueue_scripts', array(&$this, 'adminScriptsAndCSS')); 
  13. add_filter('admin_footer_text', array(&$this, 'adminFooterText')); 
  14. add_action('wp_dashboard_setup', array(&$this, 'dashboardWidget')); 
  15. add_action('wp_network_dashboard_setup', array(&$this, 'dashboardWidget'));  
  16. }  
  17.  
  18. /** 
  19. * Register and enqueue shared Admin UI CSS for WP Cube Plugins 
  20. */ 
  21. function adminScriptsAndCSS() {  
  22. // JS 
  23. // This will only enqueue once, despite this hook being called by up to several plugins,  
  24. // as we have set a single, distinct name 
  25. wp_enqueue_script('wpcube-admin', $this->dashboardURL.'js/admin.js', array('jquery'), $this->dashboard->version, true); 
  26.  
  27. // CSS 
  28. // This will only enqueue once, despite this hook being called by up to several plugins,  
  29. // as we have set a single, distinct name 
  30. wp_enqueue_style('wpcube-admin', $this->dashboardURL.'css/admin.css');  
  31. }  
  32.  
  33. /** 
  34. * Replaces the footer text with the plugin name when viewing the plugin 
  35. */ 
  36. function adminFooterText($default) { 
  37. if (isset($_GET['page']) AND $_GET['page'] == $this->dashboard->name) { 
  38. echo $this->dashboard->displayName; 
  39. } else { 
  40. echo $default; 
  41.  
  42. /** 
  43. * Adds a dashboard widget to list WP Cube Products + News 
  44. * Checks if another WP Cube plugin has already created this widget - if so, doesn't duplicate it 
  45. */ 
  46. function dashboardWidget() { 
  47. global $wp_meta_boxes; 
  48.  
  49. if (isset($wp_meta_boxes['dashboard']['normal']['core']['wp_cube'])) return; // Another plugin has already registered this widget 
  50. wp_add_dashboard_widget('wp_cube', 'WP Cube', array(&$this, 'outputDashboardWidget')); 
  51.  
  52. /** 
  53. * Called by dashboardWidget(), includes dashboard.php to output the Dashboard Widget 
  54. */ 
  55. function outputDashboardWidget() { 
  56. $result = wp_remote_get('http://www.wpcube.co.uk/feed/products'); 
  57. if (!is_wp_error($result)) { 
  58. if ($result['response']['code'] == 200) { 
  59. $xml = simplexml_load_string($result['body']); 
  60. $products = $xml->channel; 
  61.  
  62. include_once(WP_PLUGIN_DIR.'/'.$this->dashboard->name.'/_modules/dashboard/views/dashboard.php'); 
  63. } else { 
  64. include_once(WP_PLUGIN_DIR.'/'.$this->dashboard->name.'/_modules/dashboard/views/dashboard-nodata.php');