| @@ -14,8 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * PH_Admin_Dashboard Class. |
| 17 | 17 | */ |
| 18 | +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Admin_Dashboard; preserving the existing PH_* class name is required for plugin and extension compatibility. | |
| 18 | 19 | class PH_Admin_Dashboard { |
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Hook in tabs. |
| @@ -20,12 +21,12 @@ | ||
| 20 | 21 | /** |
| 21 | 22 | * Hook in tabs. |
| 22 | 23 | */ |
| 23 | 24 | public function __construct() { |
| 24 | - // Only hook in admin parts if the user has admin access | |
| 25 | - if ( current_user_can( 'manage_options' ) ) { | |
| 26 | - add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); | |
| 27 | - } | |
| 25 | + | |
| 26 | + add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); | |
| 27 | + | |
| 28 | + add_action( 'wp_dashboard_setup', array( $this, 'hide_non_property_hive_widgets' ), 9999 ); | |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | /** |
| 31 | 32 | * Init dashboard widgets. |
| @@ -30,14 +31,38 @@ | ||
| 30 | 31 | /** |
| 31 | 32 | * Init dashboard widgets. |
| 32 | 33 | */ |
| 33 | 34 | public function init() { |
| 34 | - wp_add_dashboard_widget( 'propertyhive_dashboard_news', __( 'Property Hive News', 'propertyhive' ), array( $this, 'news_widget' ) ); | |
| 35 | + | |
| 36 | + if ( current_user_can( 'manage_options' ) ) | |
| 37 | + { | |
| 38 | + wp_add_dashboard_widget( 'propertyhive_dashboard_news', __( 'Property Hive News', 'propertyhive' ), array( $this, 'news_widget' ) ); | |
| 39 | + } | |
| 35 | 40 | |
| 36 | 41 | if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' ) |
| 37 | 42 | { |
| 38 | 43 | wp_add_dashboard_widget( 'propertyhive_dashboard_viewings_awaiting_applicant_feedback', __( 'Viewings Awaiting Applicant Feedback', 'propertyhive' ), array( $this, 'viewings_awaiting_applicant_feedback_widget' ) ); |
| 39 | 44 | } |
| 45 | + | |
| 46 | + if ( | |
| 47 | + ( | |
| 48 | + get_option('propertyhive_module_disabled_appraisals', '') != 'yes' && | |
| 49 | + get_option('propertyhive_module_disabled_viewings', '') != 'yes' | |
| 50 | + ) | |
| 51 | + || | |
| 52 | + apply_filters( 'propertyhive_show_my_upcoming_appointments_dashboard_widget', false ) === true | |
| 53 | + ) | |
| 54 | + { | |
| 55 | + wp_add_dashboard_widget( 'propertyhive_dashboard_my_upcoming_appointments', __( 'My Upcoming Appointments', 'propertyhive' ), array( $this, 'my_upcoming_appointments_widget' ) ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + if ( | |
| 59 | + get_option( 'propertyhive_module_disabled_tenancies', '' ) != 'yes' && | |
| 60 | + get_option( 'propertyhive_active_departments_lettings' ) == 'yes' | |
| 61 | + ) | |
| 62 | + { | |
| 63 | + wp_add_dashboard_widget( 'propertyhive_dashboard_upcoming_overdue_key_dates', __( 'Upcoming/Overdue Key Dates', 'propertyhive' ), array( $this, 'upcoming_overdue_key_dates_widget' ) ); | |
| 64 | + } | |
| 40 | 65 | } |
| 41 | 66 | |
| 42 | 67 | /* |
| 43 | 68 | * Property Hive News Widget |
| @@ -52,8 +77,59 @@ | ||
| 52 | 77 | */ |
| 53 | 78 | public function viewings_awaiting_applicant_feedback_widget() |
| 54 | 79 | { |
| 55 | 80 | echo '<div id="ph_dashboard_viewings_awaiting_applicant_feedback">Loading...</div>'; |
| 81 | + } | |
| 82 | + | |
| 83 | + /* | |
| 84 | + * Property Hive My Upcoming Appointments Widget | |
| 85 | + */ | |
| 86 | + public function my_upcoming_appointments_widget() | |
| 87 | + { | |
| 88 | + echo '<div id="ph_dashboard_my_upcoming_appointments">Loading...</div>'; | |
| 89 | + } | |
| 90 | + | |
| 91 | + /* | |
| 92 | + * Property Hive Upcoming & Overdue Key Dates Widget | |
| 93 | + */ | |
| 94 | + public function upcoming_overdue_key_dates_widget() | |
| 95 | + { | |
| 96 | + echo '<div id="ph_dashboard_upcoming_overdue_key_dates">Loading...</div>'; | |
| 97 | + } | |
| 98 | + | |
| 99 | + public function hide_non_property_hive_widgets() | |
| 100 | + { | |
| 101 | + $current_user = wp_get_current_user(); | |
| 102 | + | |
| 103 | + $user_id = $current_user->ID; | |
| 104 | + | |
| 105 | + $crm_only_mode = get_user_meta( $user_id, 'crm_only_mode', TRUE ); | |
| 106 | + | |
| 107 | + if ( $crm_only_mode == '1' ) | |
| 108 | + { | |
| 109 | + global $wp_meta_boxes; | |
| 110 | + | |
| 111 | + if ( isset($wp_meta_boxes['dashboard']['normal']['core']) ) | |
| 112 | + { | |
| 113 | + foreach ( $wp_meta_boxes['dashboard']['normal']['core'] as $key => $widget ) | |
| 114 | + { | |
| 115 | + if ( strpos($key, 'property') === false && strpos($key, 'hive') === false ) | |
| 116 | + { | |
| 117 | + unset($wp_meta_boxes['dashboard']['normal']['core'][$key]); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + } | |
| 121 | + if ( isset($wp_meta_boxes['dashboard']['side']['core']) ) | |
| 122 | + { | |
| 123 | + foreach ( $wp_meta_boxes['dashboard']['side']['core'] as $key => $widget ) | |
| 124 | + { | |
| 125 | + if ( strpos($key, 'property') === false && strpos($key, 'hive') === false ) | |
| 126 | + { | |
| 127 | + unset($wp_meta_boxes['dashboard']['side']['core'][$key]); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + } | |
| 131 | + } | |
| 56 | 132 | } |
| 57 | 133 | } |
| 58 | 134 | |
| 59 | 135 | endif; |