PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.9
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.9
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Remove_DashboardWidgets.php

Remove_DashboardWidgets.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.2.9, at Inc/Classes/Remove_DashboardWidgets.php

144 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc\Classes;
4
5 use PXLBSAdminify\Inc\Admin\AdminSettings;
6 use PXLBSAdminify\Inc\Admin\AdminSettingsModel;
7
8 // no direct access allowed
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12 /**
13 * PXLBSAdminify
14 * Dashboard Widgets
15 *
16 * @author Jewel Theme <support@jeweltheme.com>
17 */
18 class Remove_DashboardWidgets extends AdminSettingsModel
19 {
20 public $widget_list;
21
22 public function __construct()
23 {
24 $this->widget_list = (array) AdminSettings::get_instance()->get('remove_widgets')['dashboard_widgets_list'];
25 // $this->restrict_for = (array) AdminSettings::get_instance()->get('dashboard_widgets_user_roles');
26
27 // Dashboard widgets by WP Adminify
28 add_action('admin_init', [$this, 'add_hooks']);
29
30 // add_action('admin_enqueue_scripts', [$this, 'dashboard_styles'], 100);
31 }
32
33 public function add_hooks()
34 {
35 add_action('wp_dashboard_setup', [$this, 'disable_dashboard_widgets'], 100);
36 // add_action('wp_network_dashboard_setup', [$this, 'disable_dashboard_widgets'], 100);
37 }
38
39 public static function get_dashboard_widgets_checkbox()
40 {
41 $widgets = (new self())->get_default_dashboard_widgets();
42 $flat_widgets = [];
43 foreach ($widgets as $context => $priority) {
44 foreach ($priority as $data) {
45 foreach ($data as $id => $widget) {
46 if (!$widget) {
47 continue;
48 }
49 $key = $id . '|' . $context;
50 $widget['title'] = (isset($widget['title']) ? $widget['title'] : '');
51 $flat_widgets[$key] = wp_strip_all_tags($widget['title']);
52 }
53 }
54 }
55 $widgets = wp_list_sort( $flat_widgets, [ 'title_stripped' => 'ASC' ], null, true );
56 return $widgets;
57 }
58
59 public static function render_dashboard_checkboxes()
60 {
61 (new self())->get_default_dashboard_widgets();
62 $dom = new \DOMDocument();
63 $widgets = get_option('dashboard_widgets', []);
64 $new_list = [];
65 foreach ($widgets as $key => $value) {
66 if ($value != $value) {
67 libxml_use_internal_errors(true);
68 $dom->loadHTML($value);
69 $value = $dom->getElementsByTagName('span')->item(0)->nodeValue;
70 }
71 $new_list[$key] = $value;
72 }
73 return $new_list;
74 }
75
76 /**
77 * Get the default dashboard widgets.
78 *
79 * @return array Sidebar widgets.
80 */
81 public function get_default_dashboard_widgets()
82 {
83 global $wp_meta_boxes;
84 $screen = (is_network_admin() ? 'dashboard-network' : 'dashboard');
85 $current_screen = get_current_screen();
86 if (!isset($wp_meta_boxes[$screen]) || !is_array($wp_meta_boxes[$screen])) {
87 require_once ABSPATH . '/wp-admin/includes/dashboard.php';
88 set_current_screen($screen);
89 wp_dashboard_setup();
90 if (is_callable(['Antispam_Bee', 'add_dashboard_chart'])) {
91 \Antispam_Bee::add_dashboard_chart();
92 }
93 }
94 if (isset($wp_meta_boxes[$screen][0])) {
95 unset($wp_meta_boxes[$screen][0]);
96 }
97 $widgets = [];
98 if (isset($wp_meta_boxes[$screen])) {
99 $widgets = $wp_meta_boxes[$screen];
100 }
101 set_current_screen($current_screen);
102 /**
103 * Filters the available dashboard widgets.
104 *
105 * @param array $widgets The globally available dashboard widgets.
106 */
107 return apply_filters('pxlbsadminify_dashboard_widgets', $widgets);
108 }
109
110 public function disable_dashboard_widgets()
111 {
112 $widgets = $this->widget_list;
113 $_widgets = self::get_dashboard_widgets_checkbox();
114 update_option('dashboard_widgets', $_widgets);
115 if (!$widgets) {
116 return;
117 }
118 foreach ($widgets as $meta_box) {
119 $widget_data = explode('|', $meta_box);
120 $widget_id = $widget_data[0];
121 $widget_pos = '';
122 if (!empty($widget_data[1])) {
123 $widget_pos = $widget_data[1];
124 }
125 if ('dashboard_welcome_panel' === $widget_id) {
126 remove_action('welcome_panel', 'wp_welcome_panel');
127 continue;
128 }
129 if ('try_gutenberg_panel' === $widget_id) {
130 remove_action('try_gutenberg_panel', 'wp_try_gutenberg_panel');
131 continue;
132 }
133 if ('dashboard_browser_nag' === $widget_id || 'dashboard_php_nag' === $widget_id) {
134 continue;
135 }
136 /**
137 * Docs: https://developer.wordpress.org/reference/functions/remove_meta_box/
138 * Example: remove_meta_box('dashboard_right_now', 'dashboard', 'normal'); // Right Now
139 */
140 remove_meta_box($widget_id, get_current_screen()->base, $widget_pos);
141 }
142 }
143 }
144