PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.12.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.12.2
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / admin / dashboard.php

dashboard.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.12.2, at admin/dashboard.php

344 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 /**
4 * Create the "Dashboard" submenu page
5 *
6 */
7 function wppb_register_dashboard_submenu_page() {
8 if( isset( $_GET['subpage'] ) && $_GET['subpage'] == 'wppb-setup' )
9 $page_title = __( 'Setup Wizard', 'profile-builder' );
10 else
11 $page_title = __( 'Dashboard', 'profile-builder' );
12
13 add_submenu_page( 'profile-builder', $page_title, $page_title, 'manage_options', 'profile-builder-dashboard', 'wppb_dashboard_content_output' );
14 }
15 add_action( 'admin_menu', 'wppb_register_dashboard_submenu_page', 2 );
16
17 function wppb_dashboard_content_output() {
18 if( isset( $_GET['subpage'] ) && $_GET['subpage'] == 'wppb-setup' )
19 do_action( 'wppb_output_dashboard_setup_wizard' );
20 else
21 wppb_dashboard_page_content();
22 }
23
24 /**
25 * Add content to the "Dashboard" submenu page
26 *
27 */
28 function wppb_dashboard_page_content() {
29
30 ?>
31
32 <div class="wrap cozmoslabs-wrap cozmoslabs-wrap--big">
33
34 <div class="cozmoslabs-page-header">
35 <div class="cozmoslabs-section-title">
36 <h3 class="cozmoslabs-page-title"><?php esc_html_e( 'Dashboard', 'profile-builder' ); ?></h3>
37 </div>
38 </div>
39
40 <div class="cozmoslabs-page-grid wppb-dashboard-overview">
41
42 <div class="postbox cozmoslabs-form-subsection-wrapper">
43
44 <div class="wppb-dashboard-stats__title">
45 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Totals', 'profile-builder' ); ?></h4>
46
47 <select name="wppb_dashboard_stats_select" id="wppb-dashboard-stats-select">
48 <option value="30days" selected>30 days</option>
49 <option value="this_month">This Month</option>
50 <option value="last_month">Last Month</option>
51 <option value="this_year">This Year</option>
52 </select>
53
54 <input type="hidden" id="wppb-dashboard-stats-select__nonce" value="<?php echo esc_html( wp_create_nonce( 'wppb_dashboard_get_stats' ) ); ?>" />
55 </div>
56
57 <div class="wppb-dashboard-stats">
58 <?php
59 $stats = wppb_users_stats();
60 $stats_labels = wppb_users_stats_labels();
61
62 if( !empty( $stats ) ){
63 foreach( $stats as $key => $value ) : ?>
64
65 <div class="wppb-dashboard-box <?php echo esc_html( $key ); ?>">
66 <div class="label">
67 <?php echo esc_html( $stats_labels[ $key ] ); ?>
68 </div>
69
70 <div class="value">
71 <?php
72 echo esc_html( $value );
73 ?>
74 </div>
75 </div>
76
77 <?php endforeach;
78 }
79 ?>
80 </div>
81
82 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Recent Registrations', 'profile-builder' ); ?></h4>
83
84 <div class="wppb-dashboard-registrations">
85 <?php $recent_registrations = wppb_recent_registrations(); ?>
86
87 <?php if( !empty( $recent_registrations ) ): ?>
88 <?php foreach( $recent_registrations as $user_data ): ?>
89 <div class="wppb-dashboard-registrations__row">
90 <a href="<?php echo esc_url( add_query_arg( array( 'user_id' => $user_data['id'] ), admin_url( 'user-edit.php' ) ) ); ?>">
91 <?php printf( esc_html__( '%1s registered as a %2s role', 'profile-builder' ), esc_html( $user_data['display_name'] ), esc_html( $user_data['role'] ) ); ?>
92 </a>
93 <div class="wppb-dashboard-registrations__date">
94 <?php printf( '%1s', esc_html( $user_data['reg_date'] ) ) ?>
95 </div>
96 </div>
97 <?php endforeach; ?>
98 <?php endif; ?>
99 </div>
100
101 <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'users.php' ) ); ?>"><?php esc_html_e( 'View All Users', 'profile-builder' ); ?></a>
102 </div>
103
104 <?php if ( !defined( 'WPPB_PAID_PLUGIN_DIR' ) ) : ?>
105 <div class="postbox cozmoslabs-form-subsection-wrapper">
106 <h4 class="cozmoslabs-subsection-title"> Have a question? Not sure how to proceed?<span class="dashicons dashicons-editor-help" style="color: #0F15B0;"> </span></h4>
107
108 <p><strong><span class="dashicons dashicons-plus" style="color: #0F15B0;"></span> Open a new ticket over at</strong>
109
110 <br>
111
112 <a href="https://wordpress.org/support/plugin/profile-builder/" target="_blank" style="display:block;padding-left:24px;margin-top:4px;">https://wordpress.org/support/plugin/profile-builder/</a></p>
113
114 <p><strong><span class="dashicons dashicons-welcome-write-blog" style="color: #0F15B0;"></span> Describe your problem:</strong></p>
115
116 <ul style="padding-left:24px;">
117 <li>What you tried to do</li><li>What you expected to happen</li>
118 <li>What actually happened</li>
119 <li>Screenshots help. Use a service like <a href="https://snipboard.io/">snipboard.io</a> and share the link.</li>
120 </ul>
121
122 <p><strong><span class="dashicons dashicons-yes" style="color: #0F15B0;"></span>Get help from our team </strong></p>
123
124 </div>
125 <?php endif; ?>
126
127 <div class="postbox cozmoslabs-form-subsection-wrapper wppb-dashboard-progress">
128 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Setup Progress Review', 'profile-builder' ); ?></h4>
129
130 <?php WPPB_Setup_Wizard::output_progress_steps(); ?>
131
132 <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=profile-builder-dashboard&subpage=wppb-setup' ) ); ?>"><?php esc_html_e( 'Open the Setup Wizard', 'profile-builder' ); ?></a>
133 </div>
134
135 <div class="postbox cozmoslabs-form-subsection-wrapper">
136 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Useful shortcodes for setup', 'profile-builder' ); ?></h4>
137
138 <p class="wppb-dashboard-shortcodes__description"><?php esc_html_e( 'Use these shortcodes to quickly setup and customize your membership website.', 'profile-builder' ); ?></p>
139
140 <div class="wppb-dashboard-shortcodes">
141 <div class="wppb-dashboard-shortcodes__row">
142 <div class="wppb-dashboard-shortcodes__row__wrap">
143 <div class="label">Register</div>
144 <p>Add registration forms where users can sign-up and enter their initial details.</p>
145 </div>
146
147 <div title='Click to copy' class="wppb-shortcode_copy-text wppb-dashboard-shortcodes__row__input">
148 [wppb-register]
149 </div>
150 <span style='display: none; margin-left: 10px' class='wppb-copy-message'>Shortcode copied</span>
151 </div>
152 <div class="wppb-dashboard-shortcodes__row">
153 <div class="wppb-dashboard-shortcodes__row__wrap">
154 <div class="label">Login</div>
155 <p>Allow members to login.</p>
156 </div>
157
158 <div title='Click to copy' class="wppb-shortcode_copy-text wppb-dashboard-shortcodes__row__input">
159 [wppb-login]
160 </div>
161 <span style='display: none; margin-left: 10px' class='wppb-copy-message'>Shortcode copied</span>
162 </div>
163 <div class="wppb-dashboard-shortcodes__row">
164 <div class="wppb-dashboard-shortcodes__row__wrap">
165 <div class="label">Edit Profile</div>
166 <p>Allow members to edit their account information.</p>
167 </div>
168
169 <div title='Click to copy' class="wppb-shortcode_copy-text wppb-dashboard-shortcodes__row__input">
170 [wppb-edit-profile]
171 </div>
172 <span style='display: none; margin-left: 10px' class='wppb-copy-message'>Shortcode copied</span>
173 </div>
174 <div class="wppb-dashboard-shortcodes__row">
175 <div class="wppb-dashboard-shortcodes__row__wrap">
176 <div class="label">Restrict Content</div>
177 <p>Restrict pieces of content on individual posts and pages based on user role.</p>
178 </div>
179
180 <div title='Click to copy' class="wppb-shortcode_copy-text wppb-dashboard-shortcodes__row__input">
181 [wppb-restrict user_roles="subscriber"]
182 </div>
183 <span style='display: none; margin-left: 10px' class='wppb-copy-message'>Shortcode copied</span>
184 </div>
185 </div>
186
187 <a class="button button-secondary" href="https://www.cozmoslabs.com/docs/profile-builder/shortcodes/?utm_source=wpbackend&utm_medium=pb-shortcodes-dashboard&utm_campaign=PBDocs" target="_blank"><?php esc_html_e( 'Learn more about shortcodes', 'profile-builder' ); ?></a>
188 </div>
189 </div>
190
191 </div>
192 <?php
193 }
194
195
196 /**
197 * Get Dashboard stats
198 *
199 */
200 function wppb_get_dashboard_stats(){
201 check_admin_referer( 'wppb_dashboard_get_stats' );
202
203 if( empty( $_POST['interval'] ) )
204 return;
205
206 $interval = sanitize_text_field( $_POST['interval'] );
207 $return = array(
208 'success' => true,
209 'data' => array(),
210 );
211
212 // generate filter data
213 $args = array();
214
215 if( $interval == 'this_month' ){
216
217 $args['interval'][] = date( 'Y-m-01', time() );
218 $args['interval'][] = date( 'Y-m-d', time() );
219
220 } else if( $interval == 'last_month' ){
221
222 $args['interval'][] = date( 'Y-m-01', strtotime( '-1 month' ) );
223 $args['interval'][] = date( 'Y-m-t', strtotime( '-1 month' ) );
224
225 } else if( $interval == 'this_year' ){
226
227 $args['interval'][] = date( 'Y-01-01', time() );
228 $args['interval'][] = date( 'Y-m-d', time() );
229
230 }
231
232 $return['data'] = wppb_users_stats( $args );
233
234 echo json_encode( $return );
235 die();
236 }
237 add_action( 'wp_ajax_wppb_get_dashboard_stats', 'wppb_get_dashboard_stats' );
238
239
240 /**
241 * Get User stats
242 *
243 */
244 function wppb_users_stats( $args = array() ) {
245
246 $total_users = count_users();
247 $users_stats = array(
248 'all_users' => $total_users['total_users'],
249 'newly_registered' => '',
250 );
251
252 if ( empty( $args ) ) {
253 $reg_start_date = date('Y-m-d', strtotime('-30 days'));
254 $reg_end_date = date('Y-m-d' );
255 }
256 else {
257 $reg_start_date = $args['interval'][0];
258 $reg_end_date = $args['interval'][1];
259 }
260
261 $query_args = array(
262 'date_query' => array(
263 array(
264 'after' => $reg_start_date,
265 'before' => $reg_end_date,
266 'inclusive' => true,
267 ),
268 ),
269 );
270
271 $user_query = new WP_User_Query( $query_args );
272 $users_stats['newly_registered'] = $user_query->get_total();
273
274 return $users_stats;
275 }
276
277
278 /**
279 * Get the Labels for User stats
280 *
281 */
282 function wppb_users_stats_labels() {
283 $labels = array(
284 'all_users' => __( 'All Users', 'profile-builder' ),
285 'newly_registered' => __( 'New Registered Users', 'profile-builder' ),
286 );
287 return $labels;
288 }
289
290
291 /**
292 * Get recently registered Users
293 *
294 */
295 function wppb_recent_registrations( $args = array() ) {
296
297 $query_args = array(
298 'orderby' => 'user_registered',
299 'order' => 'DESC',
300 'number' => 5,
301 );
302
303 $user_query = new WP_User_Query( $query_args );
304
305 $users_stats = array();
306
307 if( !empty( $user_query->results ) ){
308 foreach ( $user_query->results as $user_data ) {
309 $user_roles = wppb_user_role_names( $user_data->roles );
310
311 $user_info = array(
312 'id' => $user_data->ID,
313 'display_name' => $user_data->display_name,
314 'role' => $user_roles,
315 'reg_date' => $user_data->user_registered,
316 );
317
318 $users_stats[] = $user_info;
319 }
320 }
321
322
323 return $users_stats;
324 }
325
326
327 /**
328 * Get a list of User Role Names out of Role Slugs
329 *
330 */
331 function wppb_user_role_names( $role_slugs ) {
332 if ( empty( $role_slugs ) )
333 return '';
334
335 $role_names = array();
336 foreach ( $role_slugs as $slug ) {
337 $role_names[] = wp_roles()->get_names()[$slug];
338 }
339
340 if ( !empty( $role_names ) )
341 $role_names = implode(', ', $role_names);
342
343 return $role_names;
344 }