| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Dashboard |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @category Admin |
| 7 |
* @package PropertyHive/Admin |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly |
| 12 |
} |
| 13 |
if ( ! class_exists( 'PH_Admin_Dashboard' ) ) : |
| 14 |
|
| 15 |
/** |
| 16 |
* PH_Admin_Dashboard Class. |
| 17 |
*/ |
| 18 |
class PH_Admin_Dashboard { |
| 19 |
|
| 20 |
/** |
| 21 |
* Hook in tabs. |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
|
| 25 |
add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); |
| 26 |
|
| 27 |
add_action( 'wp_dashboard_setup', array( $this, 'hide_non_property_hive_widgets' ), 9999 ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Init dashboard widgets. |
| 32 |
*/ |
| 33 |
public function init() { |
| 34 |
|
| 35 |
if ( current_user_can( 'manage_options' ) ) |
| 36 |
{ |
| 37 |
wp_add_dashboard_widget( 'propertyhive_dashboard_news', __( 'Property Hive News', 'propertyhive' ), array( $this, 'news_widget' ) ); |
| 38 |
} |
| 39 |
|
| 40 |
if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' ) |
| 41 |
{ |
| 42 |
wp_add_dashboard_widget( 'propertyhive_dashboard_viewings_awaiting_applicant_feedback', __( 'Viewings Awaiting Applicant Feedback', 'propertyhive' ), array( $this, 'viewings_awaiting_applicant_feedback_widget' ) ); |
| 43 |
} |
| 44 |
|
| 45 |
if ( |
| 46 |
( |
| 47 |
get_option('propertyhive_module_disabled_appraisals', '') != 'yes' && |
| 48 |
get_option('propertyhive_module_disabled_viewings', '') != 'yes' |
| 49 |
) |
| 50 |
|| |
| 51 |
apply_filters( 'propertyhive_show_my_upcoming_appointments_dashboard_widget', false ) === true |
| 52 |
) |
| 53 |
{ |
| 54 |
wp_add_dashboard_widget( 'propertyhive_dashboard_my_upcoming_appointments', __( 'My Upcoming Appointments', 'propertyhive' ), array( $this, 'my_upcoming_appointments_widget' ) ); |
| 55 |
} |
| 56 |
|
| 57 |
if ( |
| 58 |
get_option( 'propertyhive_module_disabled_tenancies', '' ) != 'yes' && |
| 59 |
get_option( 'propertyhive_active_departments_lettings' ) == 'yes' |
| 60 |
) |
| 61 |
{ |
| 62 |
wp_add_dashboard_widget( 'propertyhive_dashboard_upcoming_overdue_key_dates', __( 'Upcoming/Overdue Key Dates', 'propertyhive' ), array( $this, 'upcoming_overdue_key_dates_widget' ) ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/* |
| 67 |
* Property Hive News Widget |
| 68 |
*/ |
| 69 |
public function news_widget() |
| 70 |
{ |
| 71 |
echo '<div id="ph_dashboard_news">Loading...</div>'; |
| 72 |
} |
| 73 |
|
| 74 |
/* |
| 75 |
* Property Hive Viewings Awaiting Applicant Feedback Widget |
| 76 |
*/ |
| 77 |
public function viewings_awaiting_applicant_feedback_widget() |
| 78 |
{ |
| 79 |
echo '<div id="ph_dashboard_viewings_awaiting_applicant_feedback">Loading...</div>'; |
| 80 |
} |
| 81 |
|
| 82 |
/* |
| 83 |
* Property Hive My Upcoming Appointments Widget |
| 84 |
*/ |
| 85 |
public function my_upcoming_appointments_widget() |
| 86 |
{ |
| 87 |
echo '<div id="ph_dashboard_my_upcoming_appointments">Loading...</div>'; |
| 88 |
} |
| 89 |
|
| 90 |
/* |
| 91 |
* Property Hive Upcoming & Overdue Key Dates Widget |
| 92 |
*/ |
| 93 |
public function upcoming_overdue_key_dates_widget() |
| 94 |
{ |
| 95 |
echo '<div id="ph_dashboard_upcoming_overdue_key_dates">Loading...</div>'; |
| 96 |
} |
| 97 |
|
| 98 |
public function hide_non_property_hive_widgets() |
| 99 |
{ |
| 100 |
$current_user = wp_get_current_user(); |
| 101 |
|
| 102 |
$user_id = $current_user->ID; |
| 103 |
|
| 104 |
$crm_only_mode = get_user_meta( $user_id, 'crm_only_mode', TRUE ); |
| 105 |
|
| 106 |
if ( $crm_only_mode == '1' ) |
| 107 |
{ |
| 108 |
global $wp_meta_boxes; |
| 109 |
|
| 110 |
if ( isset($wp_meta_boxes['dashboard']['normal']['core']) ) |
| 111 |
{ |
| 112 |
foreach ( $wp_meta_boxes['dashboard']['normal']['core'] as $key => $widget ) |
| 113 |
{ |
| 114 |
if ( strpos($key, 'property') === false && strpos($key, 'hive') === false ) |
| 115 |
{ |
| 116 |
unset($wp_meta_boxes['dashboard']['normal']['core'][$key]); |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
if ( isset($wp_meta_boxes['dashboard']['side']['core']) ) |
| 121 |
{ |
| 122 |
foreach ( $wp_meta_boxes['dashboard']['side']['core'] as $key => $widget ) |
| 123 |
{ |
| 124 |
if ( strpos($key, 'property') === false && strpos($key, 'hive') === false ) |
| 125 |
{ |
| 126 |
unset($wp_meta_boxes['dashboard']['side']['core'][$key]); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
endif; |
| 135 |
|
| 136 |
return new PH_Admin_Dashboard(); |