Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/adminpages/dashboard.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* The Memberships Dashboard admin page for Paid Memberships Pro
4
+
* Updated for 3-column grid layout
5
+
*
6
+
* @since 2.0
7
+
*/
8
+
// Exit if accessed directly.
9
+
if ( ! defined( 'ABSPATH' ) ) {
10
+
exit;
11
+
}
12
+
13
+
/**
14
+
* Load the Paid Memberships Pro dashboard metaboxes.
15
+
* This will include any custom metaboxes defined in the /metaboxes/ directory.
16
+
*/
17
+
$metaboxes_dir = __DIR__ . '/metaboxes/';
18
+
$metaboxes_files = glob( $metaboxes_dir . '*.php' );
19
+
foreach ( $metaboxes_files as $file ) {
20
+
if ( file_exists( $file ) ) {
21
+
require_once $file;
22
+
}
23
+
}
24
+
25
+
/**
26
+
* Filter the meta boxes to display on the Paid Memberships Pro dashboard.
27
+
*
28
+
* @since 3.1
29
+
*
30
+
* @param array $pmpro_dashboard_meta_boxes Array of meta boxes to display on the dashboard. Hint: Use the associative array key as the meta box ID.
31
+
*/
32
+
// The meta boxes array for the dashboard - Updated for 3-column grid
33
+
$pmpro_dashboard_meta_boxes = apply_filters(
34
+
'pmpro_dashboard_meta_boxes',
35
+
array(
36
+
'pmpro_dashboard_welcome' => array(
37
+
'title' => esc_html__( 'Welcome to Paid Memberships Pro', 'paid-memberships-pro' ),
38
+
'callback' => 'pmpro_dashboard_welcome_callback',
39
+
'capability' => '',
40
+
'header_link' => '',
41
+
'header_link_text' => '',
42
+
'columns' => 4,
43
+
'grid_column_start' => 1,
44
+
),
45
+
'pmpro_dashboard_quick_links' => array(
46
+
'title' => esc_html__( 'Quick Links', 'paid-memberships-pro' ),
47
+
'callback' => 'pmpro_dashboard_quick_links_callback',
48
+
'capability' => '',
49
+
'header_link' => '',
50
+
'header_link_text' => '',
51
+
'columns' => 3,
52
+
'grid_column_start' => 1,
53
+
),
54
+
'pmpro_dashboard_license_status' => array(
55
+
'title' => esc_html__( 'License Status', 'paid-memberships-pro' ),
56
+
'callback' => 'pmpro_dashboard_license_status_callback',
57
+
'capability' => '',
58
+
'header_link' => '',
59
+
'header_link_text' => '',
60
+
'columns' => 1,
61
+
'grid_column_start' => 4,
62
+
),
63
+
'pmpro_dashboard_report_sales' => array(
64
+
'title' => esc_html__( 'Sales and Revenue', 'paid-memberships-pro' ),
65
+
'callback' => 'pmpro_report_sales_widget',
66
+
'capability' => 'pmpro_reports',
67
+
'header_link' => esc_url( admin_url( 'admin.php?page=pmpro-reports&report=sales' ) ),
68
+
'header_link_text' => esc_html__( 'View All Sales', 'paid-memberships-pro' ),
69
+
'columns' => 2,
70
+
'grid_column_start' => 1,
71
+
),
72
+
'pmpro_dashboard_report_stats' => array(
73
+
'title' => esc_html__( 'Membership Stats', 'paid-memberships-pro' ),
74
+
'callback' => 'pmpro_report_memberships_widget',
75
+
'capability' => '',
76
+
'header_link' => esc_url( admin_url( 'admin.php?page=pmpro-reports&report=memberships' ) ),
77
+
'header_link_text' => esc_html__( 'View All Memberships', 'paid-memberships-pro' ),
78
+
'columns' => 2,
79
+
'grid_column_start' => 3,
80
+
),
81
+
'pmpro_dashboard_recent_orders' => array(
82
+
'title' => esc_html__( 'Recent Orders', 'paid-memberships-pro' ),
83
+
'callback' => 'pmpro_dashboard_report_recent_orders_callback',
84
+
'capability' => 'pmpro_orders',
85
+
'header_link' => esc_url( admin_url( 'admin.php?page=pmpro-orders' ) ),
86
+
'header_link_text' => esc_html__( 'View All Orders', 'paid-memberships-pro' ),
87
+
'columns' => 2,
88
+
'grid_column_start' => 2,
89
+
),
90
+
'pmpro_dashboard_recent_members' => array(
91
+
'title' => esc_html__( 'Recent Members', 'paid-memberships-pro' ),
92
+
'callback' => 'pmpro_dashboard_report_recent_members_callback',
93
+
'capability' => 'pmpro_memberslist',
94
+
'header_link' => esc_url( admin_url( 'admin.php?page=pmpro-memberslist' ) ),
95
+
'header_link_text' => esc_html__( 'View All Members', 'paid-memberships-pro' ),
96
+
'columns' => 2,
97
+
'grid_column_start' => 1,
98
+
),
99
+
'pmpro_dashboard_get_involved' => array(
100
+
'title' => esc_html__( 'Get Involved', 'paid-memberships-pro' ),
101
+
'callback' => 'pmpro_dashboard_get_involved_callback',
102
+
'capability' => '',
103
+
'header_link' => '',
104
+
'header_link_text' => '',
105
+
'columns' => 1,
106
+
'grid_column_start' => 1,
107
+
),
108
+
'pmpro_dashboard_follow_us' => array(
109
+
'title' => esc_html__( 'Follow Us', 'paid-memberships-pro' ),
110
+
'callback' => 'pmpro_dashboard_follow_us_callback',
111
+
'capability' => '',
112
+
'header_link' => '',
113
+
'header_link_text' => '',
114
+
'columns' => 1,
115
+
'grid_column_start' => 2,
116
+
),
117
+
'pmpro_dashboard_events' => array(
118
+
'title' => esc_html__( 'Upcoming Events', 'paid-memberships-pro' ),
119
+
'callback' => 'pmpro_dashboard_events_callback',
120
+
'capability' => '',
121
+
'header_link' => '',
122
+
'header_link_text' => '',
123
+
'columns' => 1,
124
+
'grid_column_start' => 3,
125
+
),
126
+
'pmpro_dashboard_news_updates' => array(
127
+
'title' => esc_html__( 'News and Updates', 'paid-memberships-pro' ),
128
+
'callback' => 'pmpro_dashboard_news_updates_callback',
129
+
'capability' => '',
130
+
'header_link' => '',
131
+
'header_link_text' => '',
132
+
'columns' => 1,
133
+
'grid_column_start' => 4,
134
+
),
135
+
)
136
+
);
137
+
138
+
/**
139
+
* Render dashboard metaboxes in the grid layout.
140
+
* This function will reorder the metaboxes based on the saved user preferences.
141
+
* Updated for 3-column grid support.
142
+
*
143
+
* @since 3.5
144
+
* @param array $meta_boxes Array of metaboxes to render.
145
+
* @param string $screen_id The screen ID where the metaboxes are being rendered.
146
+
* @return void
147
+
*/
148
+
function pmpro_render_dashboard_grid_metaboxes( $meta_boxes, $screen_id ) {
149
+
150
+
// Get saved order for current user
151
+
$saved_order = get_user_meta( get_current_user_id(), 'pmpro_dashboard_metabox_order', true );
152
+
153
+
// If we have a saved order, reorder the metaboxes array
154
+
if ( ! empty( $saved_order ) ) {
155
+
$order_array = explode( ',', $saved_order );
156
+
$ordered_metaboxes = array();
157
+
158
+
// First, add metaboxes in the saved order
159
+
foreach ( $order_array as $metabox_id ) {
160
+
if ( isset( $meta_boxes[ $metabox_id ] ) ) {
161
+
$ordered_metaboxes[ $metabox_id ] = $meta_boxes[ $metabox_id ];
162
+
}
163
+
}
164
+
165
+
// Then add any metaboxes that weren't in the saved order (new ones)
166
+
foreach ( $meta_boxes as $id => $meta_box ) {
167
+
if ( ! isset( $ordered_metaboxes[ $id ] ) ) {
168
+
$ordered_metaboxes[ $id ] = $meta_box;
169
+
}
170
+
}
171
+
172
+
$meta_boxes = $ordered_metaboxes;
173
+
}
174
+
175
+
// Render the metaboxes in order
176
+
foreach ( $meta_boxes as $id => $meta_box ) {
177
+
if ( ! empty( $meta_box['capability'] ) && ! current_user_can( $meta_box['capability'] ) ) {
178
+
continue;
179
+
}
180
+
181
+
// Sanitize and validate column span (1-4 for 4-column grid)
182
+
$span = isset( $meta_box['columns'] ) ? max( 1, min( intval( $meta_box['columns'] ), 4 ) ) : 1;
183
+
184
+
// Build the CSS classes
185
+
$classes = array(
186
+
'postbox',
187
+
'pmpro-colspan-' . $span,
188
+
);
189
+
190
+
$class_string = implode( ' ', $classes );
191
+
192
+
echo '<div id="' . esc_attr( $id ) . '" class="' . esc_attr( $class_string ) . '" role="listitem" aria-grabbed="false">';
193
+
194
+
// Simplified metabox header - just title and drag handle
195
+
echo '<div class="postbox-header">';
196
+
echo '<span class="screen-reader-text">' . esc_html__( 'Spacebar to pickup. Use arrow keys to move. Press Enter to drop.', 'paid-memberships-pro' ) . '</span>';
197
+
echo '<h2 class="hndle ui-sortable-handle pmpro-drag-handle" tabindex="0" role="button" aria-label="' . esc_attr__( 'Move ', 'paid-memberships-pro' ) . esc_attr( $meta_box['title'] ) . '"><span>' . esc_html( $meta_box['title'] ) . '</span></h2>'; // If a header link is provided, display it
198
+
if ( ! empty( $meta_box['header_link'] ) && ! empty( $meta_box['header_link_text'] ) ) {
199
+
echo '<p class="pmpro_report-button">';
200
+
echo '<a class="button button-secondary" style="text-decoration: none;" href="' . esc_url( $meta_box['header_link'] ) . '">' . esc_html( $meta_box['header_link_text'] ) . ' →</a>';
201
+
echo '</p>';
202
+
}
203
+
echo '</h2>';
204
+
echo '</div>';
205
+
echo '<div class="inside">';
206
+
if ( is_callable( $meta_box['callback'] ) ) {
207
+
// Start output buffering to capture the callback output
208
+
ob_start();
209
+
call_user_func( $meta_box['callback'] );
210
+
$output = ob_get_clean();
211
+
212
+
// Remove "Details" button if it exists, we now use the header link from $pmpro_dashboard_meta_boxes
213
+
$output = preg_replace(
214
+
'#<p class="pmpro_report-button">.*?</p>#is',
215
+
'',
216
+
$output
217
+
);
218
+
219
+
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
220
+
}
221
+
echo '</div>';
222
+
echo '</div>'; // Close the postbox div
223
+
}
224
+
}
225
+
226
+
/**
227
+
* Load the Paid Memberships Pro dashboard-area header
228
+
*/
229
+
require_once __DIR__ . '/admin_header.php'; ?>
230
+
231
+
<hr class="wp-header-end">
232
+
<form id="pmpro-dashboard-form" method="post" action="admin-post.php">
233
+
<div class="dashboard-widgets-wrap">
234
+
<div id="dashboard-widgets" class="metabox-holder" role="list">
235
+
<?php pmpro_render_dashboard_grid_metaboxes( $pmpro_dashboard_meta_boxes, 'toplevel_page_pmpro-dashboard' ); ?>
236
+
</div>
237
+
<?php wp_nonce_field( 'pmpro_metabox_order', 'pmpro_metabox_nonce' ); ?>
238
+
</div>
239
+
</form>
240
+
241
+
<?php
242
+
243
+
/**
244
+
* Delete transients when orders are updated.
245
+
*
246
+
* @since 3.0
247
+
*/
248
+
function pmpro_report_dashboard_delete_transients() {
249
+
delete_transient( 'pmpro_dashboard_report_recent_members' );
250
+
delete_transient( 'pmpro_dashboard_report_recent_orders' );
251
+
}
252
+
add_action( 'pmpro_updated_order', 'pmpro_report_dashboard_delete_transients' );
253
+
add_action( 'pmpro_after_checkout', 'pmpro_report_dashboard_delete_transients' );
254
+
add_action( 'pmpro_after_change_membership_level', 'pmpro_report_dashboard_delete_transients' );
255
+
256
+
/**
257
+
* Load the Paid Memberships Pro dashboard-area footer
258
+
*/
259
+
require_once __DIR__ . '/admin_footer.php';
260
+
261
+
// Register and enqueue the dashboard script.
262
+
wp_register_script(
263
+
'pmpro_dashboard',
264
+
plugins_url( 'js/pmpro-dashboard.js', PMPRO_BASE_FILE ),
265
+
array( 'jquery' ),
266
+
PMPRO_VERSION
267
+
);
268
+
wp_enqueue_script( 'pmpro_dashboard' );