-
Notifications
You must be signed in to change notification settings - Fork 30
/
directory.php
708 lines (649 loc) · 24.3 KB
/
directory.php
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
69
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
172
173
174
175
176
177
178
179
180
181
182
183
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
<?php
/*
This shortcode will display the members list and additional content based on the defined attributes.
*/
function pmpromd_shortcode($atts, $content=null, $code="")
{
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [pmpro_member_directory show_avatar="false" show_email="false" levels="1,2"]
extract(shortcode_atts(array(
'avatar_size' => '128',
'fields' => NULL,
'layout' => 'div',
'level' => NULL,
'levels' => NULL,
'limit' => NULL,
'link' => true,
'order_by' => 'u.display_name',
'order' => 'ASC',
'show_avatar' => true,
'show_email' => true,
'show_level' => true,
'show_search' => true,
'show_startdate' => true,
'avatar_align' => NULL
), $atts, "pmpro_member_directory"));
global $wpdb, $post, $pmpro_pages, $pmprorh_registration_fields;
//some page vars
if(!empty($pmpro_pages['directory'])) {
$directory_url = get_permalink($pmpro_pages['directory']);
}
if(!empty($pmpro_pages['profile'])) {
$profile_url = apply_filters( 'pmpromd_profile_url', get_permalink( $pmpro_pages['profile'] ) );
}
//turn 0's into falses
if($link === "0" || $link === "false" || $link === "no" || $link === false)
$link = false;
else
$link = true;
//did they use level instead of levels?
if(empty($levels) && !empty($level))
$levels = $level;
// convert array to string for levels when using the block editor.
if ( is_array( $levels ) ) {
$levels = implode( ',', $levels );
}
if($show_avatar === "0" || $show_avatar === "false" || $show_avatar === "no" || $show_avatar === false)
$show_avatar = false;
else
$show_avatar = true;
if($show_email === "0" || $show_email === "false" || $show_email === "no" || $show_email === false )
$show_email = false;
else
$show_email = true;
if($show_level === "0" || $show_level === "false" || $show_level === "no" || $show_level === false)
$show_level = false;
else
$show_level = true;
if($show_search === "0" || $show_search === "false" || $show_search === "no" || $show_search === false )
$show_search = false;
else
$show_search = true;
if($show_startdate === "0" || $show_startdate === "false" || $show_startdate === "no" || $show_startdate === false )
$show_startdate = false;
else
$show_startdate = true;
if(isset($_REQUEST['ps']))
$s = $_REQUEST['ps'];
else
$s = "";
// Set the default order value to be either ASC or DESC.
if ( $order !== 'DESC' ) {
$order = 'ASC';
}
if(isset($_REQUEST['pn']))
$pn = intval($_REQUEST['pn']);
else
$pn = 1;
if(isset($_REQUEST['limit']))
$limit = intval($_REQUEST['limit']);
elseif(empty($limit))
$limit = 15;
$end = $pn * $limit;
$start = $end - $limit;
// Build SQL into parts to make it easier to add in specific sections to the SQL.
$sql_parts = array();
$sql_parts['SELECT'] = "SELECT SQL_CALC_FOUND_ROWS u.ID, u.user_login, u.user_email, u.user_nicename, u.display_name, UNIX_TIMESTAMP(u.user_registered) as joindate, mu.membership_id, mu.initial_payment, mu.billing_amount, mu.cycle_period, mu.cycle_number, mu.billing_limit, mu.trial_amount, mu.trial_limit, UNIX_TIMESTAMP(mu.startdate) as startdate, UNIX_TIMESTAMP(mu.enddate) as enddate, m.name as membership, umf.meta_value as first_name, uml.meta_value as last_name FROM $wpdb->users u ";
$sql_parts['JOIN'] = "LEFT JOIN $wpdb->usermeta umh ON umh.meta_key = 'pmpromd_hide_directory' AND u.ID = umh.user_id LEFT JOIN $wpdb->usermeta umf ON umf.meta_key = 'first_name' AND u.ID = umf.user_id LEFT JOIN $wpdb->usermeta uml ON uml.meta_key = 'last_name' AND u.ID = uml.user_id LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id ";
$sql_parts['WHERE'] = "WHERE mu.status = 'active' AND (umh.meta_value IS NULL OR umh.meta_value <> '1') AND mu.membership_id > 0 ";
$sql_parts['GROUP'] = "GROUP BY u.ID ";
// Clean up order_by to only include text, underscores and periods.
$order_by = preg_replace( '/[^a-z._]/', '', $order_by );
$sql_parts['ORDER'] = "ORDER BY ". esc_sql( $order_by ) . " " . esc_sql( $order ) . " ";
$sql_parts['LIMIT'] = "LIMIT $start, $limit";
if( $s ) {
$sql_search_where = "
AND (
u.user_login LIKE '%" . esc_sql( $s ) . "%'
OR u.user_email LIKE '%" . esc_sql( $s ) . "%'
OR u.display_name LIKE '%" . esc_sql( $s ) . "%'
OR um.meta_value LIKE '%" . esc_sql( $s ) . "%'
)
";
/**
* Allow filtering the member directory search SQL to be used.
*
* @since TBD
*
* @param string $sql_search_where The member directory search SQL to be used.
* @param string $search_text The search text used.
*/
$sql_search_where = apply_filters( 'pmpro_member_directory_sql_search_where', $sql_search_where, $s );
$sql_parts['WHERE'] .= $sql_search_where;
}
// If levels are passed in.
if ( $levels ) {
$levels = preg_replace('/[^0-9,]/', '', $levels ); // Only allow commas and numeric values.
$sql_parts['WHERE'] .= "AND mu.membership_id IN(" . esc_sql($levels) . ") ";
}
// Allow filters for SQL parts.
$sql_parts = apply_filters( 'pmpro_member_directory_sql_parts', $sql_parts, $levels, $s, $pn, $limit, $start, $end, $order_by, $order );
$sqlQuery = $sql_parts['SELECT'] . $sql_parts['JOIN'] . $sql_parts['WHERE'] . $sql_parts['GROUP'] . $sql_parts['ORDER'] . $sql_parts['LIMIT'];
$sqlQuery = apply_filters("pmpro_member_directory_sql", $sqlQuery, $levels, $s, $pn, $limit, $start, $end, $order_by, $order);
$theusers = $wpdb->get_results($sqlQuery);
$totalrows = $wpdb->get_var("SELECT FOUND_ROWS() as found_rows");
//update end to match totalrows if total rows is small
if($totalrows < $end)
$end = $totalrows;
$theusers = apply_filters( 'pmpromd_user_directory_results', $theusers );
$user_identifier = pmpromd_user_identifier();
ob_start();
?>
<?php if(!empty($show_search)) { ?>
<form role="search" method="post" class="<?php echo pmpro_get_element_class( 'pmpro_member_directory_search search-form', 'directory_search' ); ?>">
<label>
<span class="screen-reader-text"><?php _e('Search for:','pmpro-member-directory'); ?></span>
<input type="search" class="search-field" placeholder="<?php _e('Search Members','pmpro-member-directory'); ?>" name="ps" value="<?php if(!empty($_REQUEST['ps'])) echo stripslashes( esc_attr($_REQUEST['ps']) );?>" title="<?php _e('Search Members','pmpro-member-directory'); ?>" />
<input type="hidden" name="pn" value="1" />
<input type="hidden" name="limit" value="<?php echo esc_attr($limit);?>" />
</label>
<input type="submit" class="search-submit" value="<?php _e('Search Members','pmpro-member-directory'); ?>">
</form>
<?php } ?>
<h2 id="pmpro_member_directory_subheading">
<?php if(!empty($s)) { ?>
<?php /* translators: placeholder is for search string entered */ ?>
<?php printf(__('Profiles Within <em>%s</em>.','pmpro-member-directory'), stripslashes( ucwords(esc_html($s)))); ?>
<?php } else { ?>
<?php _e('Viewing All Profiles','pmpro-member-directory'); ?>
<?php } ?>
<?php if($totalrows > 0) { ?>
<small class="muted">
(<?php
if($totalrows == 1)
printf(__('Showing 1 Result','pmpro-member-directory'), $start + 1, $end, $totalrows);
else
/* translators: placeholders are for result numbers */
printf(__('Showing %1$s-%2$s of %3$s Results','pmpro-member-directory'), $start + 1, $end, $totalrows);
?>)
</small>
<?php } ?>
</h2>
<?php
if(!empty($theusers))
{
if(!empty($fields))
{
// Check to see if the Block Editor is used or the shortcode.
if ( strpos( $fields, "\n" ) !== FALSE ) {
$fields = rtrim( $fields, "\n" ); // clear up a stray \n
$fields_array = explode("\n", $fields); // For new block editor.
} else {
$fields = rtrim( $fields, ';' ); // clear up a stray ;
$fields_array = explode(";",$fields);
}
if(!empty($fields_array))
{
for($i = 0; $i < count($fields_array); $i++ )
$fields_array[$i] = explode(",", trim($fields_array[$i]));
}
}
else
$fields_array = false;
/**
* Allow filtering the fields to include on the member directory list.
*
* @since TBD
*
* @param array $fields_array The list of fields to include.
*/
$fields_array = apply_filters( 'pmpro_member_directory_fields', $fields_array );
// Get Register Helper field options
$rh_fields = array();
if(!empty($pmprorh_registration_fields)) {
foreach($pmprorh_registration_fields as $location) {
foreach($location as $field) {
if(!empty($field->options))
$rh_fields[$field->name] = $field->options;
}
}
}
?>
<?php
/**
* Filter to override the attributes passed into the shortcode.
*
* @param array Contains all of the shortcode attributes used in the directory shortcode
*/
$shortcode_atts = apply_filters( 'pmpro_member_directory_before_atts', array(
'avatar_size' => $avatar_size,
'fields' => $fields,
'layout' => $layout,
'level' => $level,
'levels' => $levels,
'limit' => $limit,
'link' => $link,
'order_by' => $order_by,
'order' => $order,
'show_avatar' => $show_avatar,
'show_email' => $show_email,
'show_level' => $show_level,
'show_search' => $show_search,
'show_startdate' => $show_startdate,
'avatar_align' => $avatar_align,
'fields_array' => $fields_array
) );
do_action( 'pmpro_member_directory_before', $sqlQuery, $shortcode_atts ); ?>
<div class="pmpro_member_directory<?php
if ( ! empty( $layout ) ) {
echo ' pmpro_member_directory-' . $layout;
}
?>">
<?php
if($layout == "table")
{
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<thead>
<?php if(!empty($show_avatar)) { ?>
<th class="pmpro_member_directory_avatar">
<?php _e('Avatar', 'pmpro-member-directory'); ?>
</th>
<?php } ?>
<th class="pmpro_member_directory_display-name">
<?php _e('Member', 'pmpro-member-directory'); ?>
</th>
<?php if(!empty($show_email)) { ?>
<th class="pmpro_member_directory_email">
<?php _e('Email Address', 'pmpro-member-directory'); ?>
</th>
<?php } ?>
<?php if(!empty($fields_array)) { ?>
<th class="pmpro_member_directory_additional">
<?php _e('More Information', 'pmpro-member-directory'); ?>
</th>
<?php } ?>
<?php if(!empty($show_level)) { ?>
<th class="pmpro_member_directory_level">
<?php _e('Level', 'pmpro-member-directory'); ?>
</th>
<?php } ?>
<?php if(!empty($show_startdate)) { ?>
<th class="pmpro_member_directory_date">
<?php _e('Start Date', 'pmpro-member-directory'); ?>
</th>
<?php } ?>
<?php if(!empty($link) && !empty($profile_url)) { ?>
<th class="pmpro_member_directory_link"> </th>
<?php } ?>
</thead>
<tbody>
<?php
$count = 0;
foreach($theusers as $auser)
{
$auser = get_userdata($auser->ID);
$auser->membership_level = pmpro_getMembershipLevelForUser($auser->ID);
$user_fields_array = pmpromd_filter_profile_fields_for_levels( $fields_array, $auser );
$count++;
?>
<tr id="pmpro_member_directory_row-<?php echo $auser->ID; ?>" class="pmpro_member_directory_row<?php if(!empty($link) && !empty($profile_url)) { echo " pmpro_member_directory_linked"; } ?>">
<?php if(!empty($show_avatar)) { ?>
<td class="pmpro_member_directory_avatar">
<?php if(!empty($link) && !empty($profile_url)) { ?>
<a href="<?php echo esc_url( pmpromd_build_profile_url( $auser, $profile_url ) ); ?>"><?php echo get_avatar( $auser->ID, $avatar_size, NULL, $auser->user_nicename ); ?></a>
<?php } else { ?>
<?php echo get_avatar( $auser->ID, $avatar_size, NULL, $auser->user_nicename ); ?>
<?php } ?>
</td>
<?php } ?>
<td>
<h2 class="pmpro_member_directory_display-name">
<?php if(!empty($link) && !empty($profile_url)) { ?>
<a href="<?php echo esc_url( pmpromd_build_profile_url( $auser, $profile_url ), $profile_url, true ); ?>"><?php echo esc_html( pmpro_member_directory_get_member_display_name( $auser ) ); ?></a>
<?php } else { ?>
<?php echo esc_html( pmpro_member_directory_get_member_display_name( $auser ) ); ?>
<?php } ?>
</h2>
</td>
<?php if(!empty($show_email)) { ?>
<td class="pmpro_member_directory_email">
<?php echo pmpromd_format_profile_field( $auser->user_email, 'user_email' ); ?>
</td>
<?php } ?>
<?php
if(!empty($user_fields_array))
{
?>
<td class="pmpro_member_directory_additional">
<?php
foreach($user_fields_array as $field)
{
if ( WP_DEBUG ) {
error_log("Content of field data: " . print_r( $field, true));
}
// Fix for a trailing space in the 'fields' shortcode attribute.
if ( $field[0] === '' ) {
break;
}
$meta_field = $auser->{$field[1]};
if(!empty($meta_field))
{
?>
<p class="pmpro_member_directory_<?php echo $field[1]; ?>">
<?php
if(is_array($meta_field) && !empty($meta_field['filename']) )
{
//this is a file field
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo pmpromd_display_file_field($meta_field); ?>
<?php
}
elseif(is_array($meta_field))
{
//this is a general array, check for Register Helper options first
if(!empty($rh_fields[$field[1]])) {
foreach($meta_field as $key => $value)
$meta_field[$key] = $rh_fields[$field[1]][$value];
}
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo implode(", ",$meta_field); ?>
<?php
}elseif( !empty($rh_fields[$field[1]]) && is_array($rh_fields[$field[1]]) ) {
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo $rh_fields[$field[1]][$meta_field]; ?>
<?php
}
else
{
if($field[1] == 'user_url') {
echo pmpromd_format_profile_field( $meta_field, $field[1], $field[0] );
} else {
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo pmpromd_format_profile_field( $auser->{$field[1]}, $field[1] ); ?>
<?php
}
}
?>
</p>
<?php
}
}
?>
</td>
<?php
}
?>
<?php if(!empty($show_level)) { ?>
<td class="pmpro_member_directory_level">
<?php
$alluserlevels = pmpro_getMembershipLevelsForUser( $auser->ID );
$membership_levels = array();
if ( ! isset( $levels ) ) {
// Show all the user's levels.
foreach ( $alluserlevels as $curlevel ) {
$membership_levels[] = $curlevel->name;
}
} else {
$levels_array = explode(',', $levels);
// Show only the levels included in the directory.
foreach ( $alluserlevels as $curlevel ) {
if ( in_array( $curlevel->id, $levels_array) ) {
$membership_levels[] = $curlevel->name;
}
}
}
$auser->membership_levels = implode( ', ', $membership_levels );
echo ! empty( $auser->membership_levels ) ? $auser->membership_levels : '';
?>
</td>
<?php } ?>
<?php if(!empty($show_startdate)) { ?>
<td class="pmpro_member_directory_date">
<?php
$min_startdate = null;
foreach($alluserlevels as $level) {
if ( empty( $min_startdate ) || $level->startdate < $min_startdate ) {
$min_startdate = $level->startdate;
}
}
echo ! empty( $min_startdate ) ? date_i18n( get_option( 'date_format' ), $min_startdate ) : '';
?>
</td>
<?php } ?>
<?php if(!empty($link) && !empty($profile_url)) { ?>
<td class="pmpro_member_directory_link">
<a href="<?php echo esc_url( pmpromd_build_profile_url( $auser ), $profile_url, true ); ?>"><?php _e('View Profile','pmpro-member-directory'); ?></a>
</td>
<?php } ?>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
else
{
foreach($theusers as $auser):
$auser = get_userdata($auser->ID);
$auser->membership_level = pmpro_getMembershipLevelForUser($auser->ID);
$user_identifier = pmpromd_user_identifier();
$user_fields_array = pmpromd_filter_profile_fields_for_levels( $fields_array, $auser );
?>
<div id="pmpro_member-<?php echo esc_attr( $auser->ID ); ?>" class="<?php echo pmpro_get_element_class( 'pmpro_member_directory-item', 'directory_item' ); ?>">
<?php if(!empty($show_avatar)) { ?>
<div class="pmpro_member_directory_avatar">
<?php if(!empty($link) && !empty($profile_url)) { ?>
<a class="<?php echo $avatar_align; ?>" href="<?php echo esc_url( pmpromd_build_profile_url( $auser ), $profile_url ); ?>"><?php echo get_avatar($auser->ID, $avatar_size, NULL, $auser->display_name); ?></a>
<?php } else { ?>
<span class="<?php echo $avatar_align; ?>"><?php echo get_avatar($auser->ID, $avatar_size, NULL, $auser->display_name); ?></span>
<?php } ?>
</div>
<?php } ?>
<h2 class="pmpro_member_directory_display-name">
<?php if(!empty($link) && !empty($profile_url)) { ?>
<a href="<?php echo esc_url( pmpromd_build_profile_url( $auser ), $profile_url ); ?>"><?php echo esc_html( pmpro_member_directory_get_member_display_name( $auser ) ); ?></a>
<?php } else { ?>
<?php echo esc_html( pmpro_member_directory_get_member_display_name( $auser ) ); ?></a>
<?php } ?>
</h2>
<?php if(!empty($show_email)) { ?>
<p class="pmpro_member_directory_email">
<strong><?php _e('Email Address', 'pmpromd'); ?></strong>
<?php echo pmpromd_format_profile_field( $auser->user_email, 'user_email' ); ?>
</p>
<?php } ?>
<?php if(!empty($show_level)) { ?>
<p class="pmpro_member_directory_level">
<strong><?php _e('Level', 'pmpro-member-directory'); ?></strong>
<?php
$alluserlevels = pmpro_getMembershipLevelsForUser( $auser->ID );
$membership_levels = array();
if ( ! isset( $levels ) ) {
// Show all the user's levels.
foreach ( $alluserlevels as $curlevel ) {
$membership_levels[] = $curlevel->name;
}
} else {
$levels_array = explode(',', $levels);
// Show only the levels included in the directory.
foreach ( $alluserlevels as $curlevel ) {
if ( in_array( $curlevel->id, $levels_array) ) {
$membership_levels[] = $curlevel->name;
}
}
}
$auser->membership_levels = implode( ', ', $membership_levels );
echo ! empty( $auser->membership_levels ) ? $auser->membership_levels : '';
?>
</p>
<?php } ?>
<?php if(!empty($show_startdate)) { ?>
<p class="pmpro_member_directory_date">
<strong><?php _e('Start Date', 'pmpro-member-directory'); ?></strong>
<?php echo date_i18n(get_option("date_format"), $auser->membership_level->startdate); ?>
</p>
<?php } ?>
<?php
if(!empty($user_fields_array))
{
foreach($user_fields_array as $field)
{
if ( WP_DEBUG ) {
error_log("Content of field data: " . print_r( $field, true));
}
// Fix for a trailing space in the 'fields' shortcode attribute.
if ( $field[0] === '' ) {
break;
}
$meta_field = $auser->{$field[1]};
if(!empty($meta_field))
{
?>
<p class="pmpro_member_directory_<?php echo $field[1]; ?>">
<?php
if(is_array($meta_field) && !empty($meta_field['filename']) )
{
//this is a file field
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo pmpromd_display_file_field($meta_field); ?>
<?php
}
elseif(is_array($meta_field))
{
//this is a general array, check for Register Helper options first
if(!empty($rh_fields[$field[1]])) {
foreach($meta_field as $key => $value)
$meta_field[$key] = $rh_fields[$field[1]][$value];
}
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo implode(", ",$meta_field); ?>
<?php
}elseif( !empty($rh_fields[$field[1]]) && is_array($rh_fields[$field[1]]) ) {
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo $rh_fields[$field[1]][$meta_field]; ?>
<?php
}
elseif($field[1] == 'user_url')
{
echo pmpromd_format_profile_field( $meta_field, $field[1], $field[0] );
}
else
{
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo pmpromd_format_profile_field( $auser->{$field[1]}, $field[1] ); ?>
<?php
}
?>
</p>
<?php
}
}
}
?>
<?php if(!empty($link) && !empty($profile_url)) { ?>
<p class="pmpro_member_directory_link">
<a class="more-link" href="<?php echo esc_url( pmpromd_build_profile_url( $auser, $profile_url ) ); ?>"><?php _e('View Profile','pmpro-member-directory'); ?></a>
</p>
<?php } ?>
</div> <!-- end pmpro_member_directory-item -->
<?php
endforeach;
?>
</div> <!-- end pmpro_member_directory -->
<?php
do_action( 'pmpro_member_directory_after', $sqlQuery, $shortcode_atts );
}
}
else
{
?>
<p class="pmpro_member_directory_message pmpro_message pmpro_error">
<?php _e('No matching profiles found','pmpro-member-directory'); ?>
<?php
if($s)
{
/* translators: placeholder is for search string entered */
printf(__('within <em>%s</em>.','pmpro-member-directory'), stripslashes( ucwords(esc_html($s))) );
if(!empty($directory_url))
{
?>
<a class="more-link" href="<?php echo $directory_url; ?>"><?php _e('View All Members','pmpro-member-directory'); ?></a>
<?php
}
}
else
{
echo ".";
}
?>
</p>
<?php
}
//prev/next
?>
<div class="pmpro_pagination">
<?php
//prev
if ( $pn > 1 ) {
$query_args = array(
'ps' => $s,
'pn' => $pn-1,
'limit' => $limit,
);
$query_args = apply_filters( 'pmpromd_pagination_url', $query_args, 'prev' );
?>
<span class="pmpro_prev"><a href="<?php echo esc_url(add_query_arg( $query_args, get_permalink($post->ID)));?>">« <?php _e('Previous','pmpro-member-directory'); ?></a></span>
<?php
}
$number_of_pages = $totalrows / $limit;
//Page Numbers
?>
<span class='pmpro_page_numbers'>
<?php
$counter = 0;
if ( empty( $pn ) || $pn != 1 ) {
echo '<a href="' . esc_url( add_query_arg( $query_args, get_permalink( $post->ID ) ) ) . '" title="' . esc_attr__( 'Previous', 'pmpromd' ) . '">...</a>';
}
if( round( $number_of_pages, 0 ) !== 1 && $pn !== 1 ) {
//If there's only one page, no need to show the page numbers
for( $i = $pn; $i <= $number_of_pages; $i++ ){
if( $counter <= 6 ){
$query_args = array(
'ps' => $s,
'pn' => $i,
'limit' => $limit,
);
if( $i == $pn ){ $active_class = 'class="pmpro_page_active"'; } else { $active_class = ''; }
echo '<a href="' . esc_url( add_query_arg( $query_args, get_permalink( $post->ID ) ) ) . '" ' . $active_class . ' title="' . esc_attr( sprintf( __('Page %s', 'pmpromd' ), $i ) ) . '">' . $i . '</a>';
}
$counter++;
}
}
?>
</span>
<?php
//next
if ( $totalrows > $end ) {
$query_args = array(
'ps' => $s,
'pn' => $pn+1,
'limit' => $limit,
);
$query_args = apply_filters( 'pmpromd_pagination_url', $query_args, 'next' );
?>
<span class="pmpro_next"><a href="<?php echo esc_url( add_query_arg( $query_args, get_permalink( $post->ID ) ) );?>"><?php _e( 'Next', 'pmpro-member-directory' ); ?> »</a></span>
<?php
}
?>
</div>
<?php
?>
<?php
$temp_content = ob_get_contents();
ob_end_clean();
return $temp_content;
}
add_shortcode("pmpro_member_directory", "pmpromd_shortcode");