Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*
*/
// This file must not accessed directly.
if (!defined('ABSPATH')) {
exit;
}
/**
* Define CiviCRM_For_WordPress_Admin_Page_Error Class.
*
* @since 5.40
*/
class CiviCRM_For_WordPress_Admin_Page_Error {
/**
* @var object
* Plugin object reference.
* @since 5.40
* @access public
*/
public $civi;
/**
* @var object
* Admin object reference.
* @since 5.40
* @access public
*/
public $admin;
/**
* Instance constructor.
*
* This class is constructed during the "admin_menu" action at priority 9.
*
* @since 5.40
*
* @param str $logo The CiviCRM logo.
* @param str $position The default menu position expressed as a float.
*/
public function __construct($logo, $position) {
// Store reference to CiviCRM plugin object.
$this->civi = civi_wp();
// Store reference to admin object.
$this->admin = civi_wp()->admin;
// Add items to the CiviCRM admin menu.
$this->add_menu_items($logo, $position);
// Add our meta boxes.
add_action('civicrm/page/error/add_meta_boxes', [$this, 'meta_boxes_error_add']);
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
}
/**
* Get the capability required to access the Settings Page.
*
* @since 5.40
*/
public function access_capability() {
/**
* Return default capability but allow overrides.
*
* @since 5.40
*
* @param str The default access capability.
*/
return apply_filters('civicrm/admin/error/cap', 'manage_options');
}
/**
* Adds CiviCRM sub-menu items to WordPress admin menu.
*
* @since 5.40
*
* @param str $logo The CiviCRM logo.
* @param str $position The default menu position expressed as a float.
*/
public function add_menu_items($logo, $position) {
// Get access capability.
$capability = $this->access_capability();
// Add our top level menu item.
$error_page = add_menu_page(
__('Troubleshooting', 'civicrm'),
__('CiviCRM', 'civicrm'),
$capability,
'CiviCRM',
[$this, 'page_error'],
$logo,
$position
);
// Add scripts for this page.
add_action('admin_head-' . $error_page, [$this, 'admin_head']);
add_action('admin_print_styles-' . $error_page, [$this, 'admin_css']);
}
/**
* Enqueue WordPress scripts on the pages that need them.
*
* @since 5.40
*/
public function admin_head() {
// Enqueue WordPress scripts.
wp_enqueue_script('common');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('dashboard');
}
/**
* Enqueue stylesheet on this page.
*
* @since 5.40
*/
public function admin_css() {
// Enqueue common CSS.
wp_enqueue_style(
'civicrm-admin-styles',
CIVICRM_PLUGIN_URL . 'assets/css/civicrm.admin.css',
NULL,
CIVICRM_PLUGIN_VERSION,
'all'
);
}
// ---------------------------------------------------------------------------
// Page Loader
// ---------------------------------------------------------------------------
/**
* Render the CiviCRM Error page.
*
* @since 5.40
*/
public function page_error() {
// Get the current screen object.
$screen = get_current_screen();
/**
* Allow meta boxes to be added to this screen.
*
* The Screen ID to use is: "civicrm_page_civi_error".
*
* Used internally by:
*
* - self::meta_boxes_error_add()
*
* @since 5.40
*
* @param str $screen_id The ID of the current screen.
*/
do_action('civicrm/page/error/add_meta_boxes', $screen->id);
$columns = (1 === $screen->get_columns() ? '1' : '2');
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Include template file.
include CIVICRM_PLUGIN_DIR . 'assets/templates/pages/page.error.php';
}
// ---------------------------------------------------------------------------
// Meta Box Loaders
// ---------------------------------------------------------------------------
/**
* Register Error Page meta boxes.
*
* @since 5.40
*
* @param str $screen_id The Admin Page Screen ID.
*/
public function meta_boxes_error_add($screen_id) {
// Define valid Screen IDs.
$screen_ids = [
'toplevel_page_CiviCRM',
];
// Bail if not the Screen ID we want.
if (!in_array($screen_id, $screen_ids)) {
return;
}
// Bail if user cannot access the Error Page.
$capability = $this->access_capability();
if (!current_user_can($capability)) {
return;
}
// Init data.
$data = [];
// Check for PHP version flag.
if (civi_wp()->admin->error_flag === 'php-version') {
// Create "PHP Error Information" metabox.
add_meta_box(
'civicrm_error_php',
__('PHP Error Information', 'civicrm'),
// Callback.
[$this, 'meta_box_error_php_render'],
// Screen ID.
$screen_id,
// Column: options are 'normal' and 'side'.
'normal',
// Vertical placement: options are 'core', 'high', 'low'.
'core',
$data
);
}
else {
// Create "Path Error Information" metabox.
add_meta_box(
'civicrm_error_path',
__('Path Error Information', 'civicrm'),
// Callback.
[$this, 'meta_box_error_path_render'],
// Screen ID.
$screen_id,
// Column: options are 'normal' and 'side'.
'normal',
// Vertical placement: options are 'core', 'high', 'low'.
'core',
$data
);
}
// Create "General Information" metabox.
add_meta_box(
'civicrm_error_help',
__('General Information', 'civicrm'),
// Callback.
[$this, 'meta_box_error_help_render'],
// Screen ID.
$screen_id,
// Column: options are 'normal' and 'side'.
'normal',
// Vertical placement: options are 'core', 'high', 'low'.
'core',
$data
);
}
// ---------------------------------------------------------------------------
// Meta Box Renderers
// ---------------------------------------------------------------------------
/**
* Render "General Information" meta box.
*
* @since 5.40
*
* @param mixed $unused Unused param.
* @param array $metabox Array containing id, title, callback, and args elements.
*/
public function meta_box_error_help_render($unused, $metabox) {
// Include template file.
include CIVICRM_PLUGIN_DIR . 'assets/templates/metaboxes/metabox.error.help.php';
}
/**
* Render "PHP Error Information" meta box.
*
* @since 5.40
*
* @param mixed $unused Unused param.
* @param array $metabox Array containing id, title, callback, and args elements.
*/
public function meta_box_error_php_render($unused, $metabox) {
global $civicrm_root;
// Include template file.
include CIVICRM_PLUGIN_DIR . 'assets/templates/metaboxes/metabox.error.php.php';
}
/**
* Render "Path Error Information" meta box.
*
* @since 5.40
*
* @param mixed $unused Unused param.
* @param array $metabox Array containing id, title, callback, and args elements.
*/
public function meta_box_error_path_render($unused, $metabox) {