+
+ $field_val;
+ // Fix for a trailing space in the 'fields' shortcode attribute.
+ if ( $field[0] === ' ' ) {
+ break;
+ }
- // If using PMPro 2.10, try use User Field function to display labels.
- if ( function_exists( 'pmpro_get_label_for_user_field_value' ) && ! empty( $field_val ) && ! empty( $meta_field ) ) {
- $meta_field = pmpro_get_label_for_user_field_value( $field_val, $meta_field );
- }
+ // Get the field name and value here.
+ $field_val = $field[1];
+ $meta_field = $pu->$field_val;
- if(!empty($meta_field))
- {
- ?>
-
+ ID === $current_user->ID ) {
- // User viewing their own profile. Show an edit profile link if 'Member Profile Edit Page' is set or dashboard access is allowed.
- if ( ! empty( get_option( 'pmpro_member_profile_edit_page_id' ) ) ) {
- $edit_profile_url = pmpro_url( 'member_profile_edit' );
- } elseif ( ! pmpro_block_dashboard() ) {
- $edit_profile_url = admin_url( 'profile.php' );
- }
+ if ( ! empty( $directory_url ) ) {
+ $pmpro_member_profile_action_links['view-directory'] = sprintf( '%s', esc_url( $directory_url ), esc_html__( 'View All Members', 'pmpro-member-directory' ) );
+ }
- if ( ! empty( $edit_profile_url) ) {
- $pmpro_member_profile_action_links['edit-profile'] = sprintf( '%s', esc_url( $edit_profile_url ), esc_html__( 'Edit Profile', 'paid-memberships-pro' ) );
- }
- }
+ if ( ! empty( $pu ) && $pu->ID === $current_user->ID ) {
+ // User viewing their own profile. Show an edit profile link if 'Member Profile Edit Page' is set or dashboard access is allowed.
+ if ( ! empty( get_option( 'pmpro_member_profile_edit_page_id' ) ) ) {
+ $edit_profile_url = pmpro_url( 'member_profile_edit' );
+ } elseif ( ! pmpro_block_dashboard() ) {
+ $edit_profile_url = admin_url( 'profile.php' );
+ }
+
+ if ( ! empty( $edit_profile_url) ) {
+ $pmpro_member_profile_action_links['edit-profile'] = sprintf( '%s', esc_url( $edit_profile_url ), esc_html__( 'Edit Profile', 'paid-memberships-pro' ) );
+ }
+ }
- /**
- * Filter which links are displayed on the single Member Directory Profile page.
- *
- * @since 1.0
- *
- * @param array $pmpro_member_profile_action_links Can be view-directory, edit-profile, or or custom.
- *
- * @return array $pmpro_member_profile_action_links
- */
- $pmpro_member_profile_action_links = apply_filters( 'pmpromd_member_profile_action_links', $pmpro_member_profile_action_links );
-
- $allowed_html = array(
- 'a' => array (
- 'class' => array(),
- 'href' => array(),
- 'id' => array(),
- 'target' => array(),
- 'title' => array(),
- ),
- );
- echo wp_kses( implode( pmpro_actions_nav_separator(), $pmpro_member_profile_action_links ), $allowed_html );
- ?>
-
-
+ /**
+ * Filter which links are displayed on the single Member Directory Profile page.
+ *
+ * @since 1.0
+ *
+ * @param array $pmpro_member_profile_action_links Can be view-directory, edit-profile, or or custom.
+ *
+ * @return array $pmpro_member_profile_action_links
+ */
+ $pmpro_member_profile_action_links = apply_filters( 'pmpromd_member_profile_action_links', $pmpro_member_profile_action_links );
+
+ $allowed_html = array(
+ 'a' => array (
+ 'class' => array(),
+ 'href' => array(),
+ 'id' => array(),
+ 'target' => array(),
+ 'title' => array(),
+ ),
+ );
+ echo wp_kses( implode( pmpro_actions_nav_separator(), $pmpro_member_profile_action_links ), $allowed_html );
+ ?>
+
+
+
+
Date: Thu, 14 Nov 2024 13:31:56 -0500
Subject: [PATCH 02/24] Removing unnecessary query data
---
templates/directory.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/templates/directory.php b/templates/directory.php
index 9242aad..e9803d0 100644
--- a/templates/directory.php
+++ b/templates/directory.php
@@ -99,9 +99,9 @@ function pmpromd_shortcode($atts, $content=null, $code="")
// 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['SELECT'] = "SELECT SQL_CALC_FOUND_ROWS u.ID 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['JOIN'] = "LEFT JOIN $wpdb->usermeta umh ON umh.meta_key = 'pmpromd_hide_directory' AND u.ID = umh.user_id LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id ";
$sql_parts['WHERE'] = "WHERE mu.status = 'active' AND (umh.meta_value IS NULL OR umh.meta_value <> '1') AND mu.membership_id > 0 ";
@@ -131,6 +131,7 @@ function pmpromd_shortcode($atts, $content=null, $code="")
*/
$sql_search_where = apply_filters( 'pmpro_member_directory_sql_search_where', $sql_search_where, $s );
+ $sql_parts['JOIN'] .= "LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id ";
$sql_parts['WHERE'] .= $sql_search_where;
}
From f149f42338bb24fe5aa5cdc3f476642380ac535d Mon Sep 17 00:00:00 2001
From: David Parker
Date: Thu, 14 Nov 2024 13:56:58 -0500
Subject: [PATCH 03/24] Return early when no results, clean up whitespace
---
templates/directory.php | 666 ++++++++++++++++++++--------------------
1 file changed, 329 insertions(+), 337 deletions(-)
diff --git a/templates/directory.php b/templates/directory.php
index 9242aad..f771702 100644
--- a/templates/directory.php
+++ b/templates/directory.php
@@ -193,90 +193,112 @@ function pmpromd_shortcode($atts, $content=null, $code="")
+
+ %s.', 'pmpro-member-directory' ), stripslashes( ucwords( esc_html( $s ) ) ) ) );
- 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.
+ // If there is a directory URL, display a link to view all members.
+ if ( ! empty( $directory_url ) ) {
+ ?>
+
+
+
';
break;
case 'avatar':
- /**
- * Filter the size of the avatar displayed in the member directory.
- *
- * @since TBD
- * @param int $avatar_size The size of the avatar in pixels.
- * @param string $page The page where the avatar is being displayed.
- *
- * @return int The size of the avatar in pixels.
- */
- $avatar_size = apply_filters( 'pmpro_member_directory_avatar_size', 128, $page );
$value = get_avatar( $pu->ID, $avatar_size, NULL, $pu->display_name );
break;
case 'membership_name':
diff --git a/templates/profile.php b/templates/profile.php
index 6f5b422..6eeae5d 100644
--- a/templates/profile.php
+++ b/templates/profile.php
@@ -39,6 +39,9 @@ function pmpromd_profile_shortcode( $atts, $content=null, $code="" ) {
$show_search = filter_var( $show_search, FILTER_VALIDATE_BOOLEAN );
$show_startdate = filter_var( $show_startdate, FILTER_VALIDATE_BOOLEAN );
+ // Validate the avatar size.
+ $avatar_size = intval( $avatar_size );
+
// Build our elements array. If we have an elements attribute on the shortcode, use that and ignore any other legacy attributes.
if ( ! empty( $elements ) ) {
$elements_array = pmpromd_prepare_elements_array( $elements );
@@ -49,11 +52,7 @@ function pmpromd_profile_shortcode( $atts, $content=null, $code="" ) {
$elements .= 'display_name;';
}
if ( ! empty( $show_avatar ) ) {
- if ( ! empty( $avatar_size ) ) {
- $elements .= 'avatar|' . $avatar_size . ';';
- } else {
- $elements .= 'avatar;';
- }
+ $elements .= 'avatar|' . $avatar_size . ';';
}
if ( ! empty( $show_bio ) ) {
$elements .= __( 'Biographical Info', 'pmpro-member-directory' ) . ',description;';
From db46cb205113f060452aefdfd31484306df5dfdb Mon Sep 17 00:00:00 2001
From: Kim Coleman
Date: Sun, 17 Nov 2024 13:17:33 -0500
Subject: [PATCH 10/24] Fixing lost heading
---
templates/directory.php | 749 ++++++++++++++++++++--------------------
1 file changed, 374 insertions(+), 375 deletions(-)
diff --git a/templates/directory.php b/templates/directory.php
index 86432e0..3a469b5 100644
--- a/templates/directory.php
+++ b/templates/directory.php
@@ -181,416 +181,414 @@ function pmpromd_shortcode($atts, $content=null, $code="")
- 0) { ?>
-
- ()
-
-
-
-
-
- %s.', 'pmpro-member-directory' ), stripslashes( ucwords( esc_html( $s ) ) ) ) );
- // If there is a directory URL, display a link to view all members.
- if ( ! empty( $directory_url ) ) {
- ?>
-
-
-
+ %s.', 'pmpro-member-directory' ), stripslashes( ucwords( esc_html( $s ) ) ) ) );
- 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 there is a directory URL, display a link to view all members.
+ if ( ! empty( $directory_url ) ) {
+ ?>
+
+
+
-
- ID ) ) ) . '" title="' . esc_attr__( 'Previous', 'pmpromd' ) . '">...';
- }
-
- 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 '' . $i . '';
+
+ ID ) ) ) . '" title="' . esc_attr__( 'Previous', 'pmpromd' ) . '">...';
}
- $counter++;
- }
- }
- ?>
-
+
+ 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 '' . $i . '';
+ }
+ $counter++;
+ }
+ }
+ ?>
+
+
$end ) {
From 3573c88f1016c299b8aeb479c0eeef069f77e3eb Mon Sep 17 00:00:00 2001
From: Kim Coleman
Date: Sun, 17 Nov 2024 13:30:58 -0500
Subject: [PATCH 11/24] Fixing search form not to wrap in pmpro class unless
used as standalone shortcode
---
includes/search.php | 26 ++++++++++++--------------
shortcodes/search.php | 11 ++++++++++-
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/includes/search.php b/includes/search.php
index 2d77284..83ad5c1 100644
--- a/includes/search.php
+++ b/includes/search.php
@@ -14,19 +14,17 @@ function pmpromd_search_form() {
// Get the limit for the search results.
$limit = ! empty( $_REQUEST['limit'] ) ? intval( $_REQUEST['limit'] ) : 10;
?>
-
-
-
+
+
+
+
+
Date: Sun, 17 Nov 2024 13:32:48 -0500
Subject: [PATCH 12/24] Do not filter the_title if we are in the admin
---
includes/functions.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/includes/functions.php b/includes/functions.php
index 8f0f222..c620165 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -204,6 +204,11 @@ function pmpromd_build_profile_url( $pu, $profile_url = false, $separator = fals
* Update the_title for the Profile page.
*/
function pmpromd_the_title_profile_page( $title, $post_id = NULL ) {
+ // If we're in the admin, don't do anything.
+ if ( is_admin() ) {
+ return $title;
+ }
+
global $main_post_id, $current_user, $wp_query;
if( $post_id == $main_post_id ) {
$pu = pmpromd_get_user();
From e5993779d40b7ffbed0398279715bbb779576aab Mon Sep 17 00:00:00 2001
From: Kim Coleman
Date: Sun, 17 Nov 2024 14:33:54 -0500
Subject: [PATCH 13/24] Verifying there is a permalink structure before adding
a rewrite rule
---
includes/functions.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/includes/functions.php b/includes/functions.php
index bc1d6ba..2ab54f0 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -121,6 +121,11 @@ function pmpromd_custom_rewrite_rules() {
return;
}
+ $structure = get_option( 'permalink_structure' );
+ if ( empty( $structure ) ) {
+ return;
+ }
+
$profile_permalink = get_the_permalink( $pmpro_pages['profile'] );
$base_site_url = get_site_url();
$profile_base = str_replace( $base_site_url . '/', '', $profile_permalink );
From d9f67d7905a1c45c23a7ad3f85f1439af2c87780 Mon Sep 17 00:00:00 2001
From: Kim Coleman
Date: Sun, 17 Nov 2024 15:35:42 -0500
Subject: [PATCH 14/24] Cleaning up line breaks in the fields array that the
block editor versions use
---
includes/functions.php | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/includes/functions.php b/includes/functions.php
index c620165..eb7aacf 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -377,7 +377,12 @@ function pmpromd_prepare_elements_array( $elements ) {
// Remove a trailing comma or semicolon if it exists.
$elements = rtrim( $elements, ',;' );
- // Explode the elements string.
+ // Convert line breaks to semicolons (for the block editor).
+ if ( strpos( $elements, "\n" ) !== FALSE ) {
+ $elements = str_replace( "\n", ';', $elements );
+ }
+
+ // Build the elements array.
$elements = explode( ';', $elements );
foreach ( $elements as $element ) {
// Remove spaces from the beginning and end of the element.
From 7489a2f718d33fe7415b5ebdb7097d681bb61d45 Mon Sep 17 00:00:00 2001
From: Kim Coleman
Date: Sun, 17 Nov 2024 16:33:55 -0500
Subject: [PATCH 15/24] Deprecating the pmpro_member_directory_fields filter
---
includes/deprecated.php | 1 +
templates/profile.php | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/includes/deprecated.php b/includes/deprecated.php
index d54ee66..0bff9da 100644
--- a/includes/deprecated.php
+++ b/includes/deprecated.php
@@ -14,6 +14,7 @@ function pmpromd_init_check_for_deprecated_filters() {
// Deprecated filter name => new filter name (or null if there is no alternative).
$pmpromd_map_deprecated_filters = array(
'pmpro_member_profile_fields' => 'pmpro_member_profile_elements',
+ 'pmpro_member_directory_fields' => 'pmpro_member_directory_elements',
);
foreach ( $pmpromd_map_deprecated_filters as $old => $new ) {
diff --git a/templates/profile.php b/templates/profile.php
index 6eeae5d..29dd8d6 100644
--- a/templates/profile.php
+++ b/templates/profile.php
@@ -123,7 +123,7 @@ function pmpromd_profile_shortcode( $atts, $content=null, $code="" ) {
From a1bef517a30fde3798cf218132f5a00709a038bb Mon Sep 17 00:00:00 2001
From: Kim Coleman
Date: Sun, 17 Nov 2024 16:34:12 -0500
Subject: [PATCH 16/24] Adding a location parameter to format values
differently based on if this is the profile or directory page
---
includes/functions.php | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/includes/functions.php b/includes/functions.php
index eb7aacf..5e99f6e 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -409,7 +409,7 @@ function pmpromd_prepare_elements_array( $elements ) {
/**
* Get the value of a specific element from a string of HTML.
*/
-function pmpromd_get_display_value( $element, $pu ) {
+function pmpromd_get_display_value( $element, $pu, $location = 'profile' ) {
// Is this a user field?
if ( class_exists( 'PMPro_Field_Group' ) ) {
$user_field = PMPro_Field_Group::get_field( $element[1] );
@@ -463,7 +463,10 @@ function pmpromd_get_display_value( $element, $pu ) {
// Additional formatting and special cases.
switch ( $element ) {
case 'display_name':
- $value = '
+ %s.', 'pmpro-member-directory' ), stripslashes( ucwords( esc_html( $s ) ) ) ) );
+
+ // If there is a directory URL, display a link to view all members.
+ if ( ! empty( $directory_url ) ) {
+ ?>
+
+
+
%s.', 'pmpro-member-directory' ), stripslashes( ucwords( esc_html( $s ) ) ) ) );
+ $temp_content = ob_get_contents();
+ ob_end_clean();
+ return $temp_content;
+ }
+ ?>
- // If there is a directory URL, display a link to view all members.
- if ( ! empty( $directory_url ) ) {
- ?>
-
-
-
-
-
- $avatar_size,
- 'elements' => $elements,
- '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,
- 'elements_array' => $elements_array,
- 'fields_array' => $elements_array, // Backwards compatibility. We can remove this in a future version.
- ) );
-
- // Set the displayed_levels variable to use for displaying values.
- $displayed_levels = empty( $levels ) ? 'all' : $levels;
-
- do_action( 'pmpro_member_directory_before', $sqlQuery, $shortcode_atts );
- ?>
+ /**
+ * 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,
+ 'elements' => $elements,
+ '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,
+ 'elements_array' => $elements_array,
+ 'fields_array' => $elements_array, // Backwards compatibility. We can remove this in a future version.
+ ) );
+
+ // Set the displayed_levels variable to use for displaying values.
+ $displayed_levels = empty( $levels ) ? 'all' : $levels;
+
+ /**
+ * Action to add content before the member directory.
+ *
+ * @since 0.8
+ * @param string $sqlQuery The SQL query used to get the members.
+ * @param array $shortcode_atts The attributes passed into the shortcode.
+ */
+ do_action( 'pmpro_member_directory_before', $sqlQuery, $shortcode_atts );
+ ?>
+
' . $value . '';
}
?>
@@ -334,7 +343,7 @@ function pmpromd_shortcode( $atts, $content=null, $code="" ) {
$value = pmpromd_get_display_value( $element[1], $auser, $displayed_levels );
if ( ! empty( $value ) ) {
// Wrap the value in a link if the element is in the linked elements array.
- if ( ! empty( $link ) && in_array( $element[1], $linked_elements ) ) {
+ if ( ! empty( $link ) && ! empty( $profile_url ) &&in_array( $element[1], $linked_elements ) ) {
$value = '' . $value . '';
}
if ( 'display_name' === $element[1] ) {
@@ -372,77 +381,80 @@ function pmpromd_shortcode( $atts, $content=null, $code="" ) {
}
?>
-
-
+
1 ) {
- $query_args = array(
- 'ps' => $s,
- 'pn' => $pn-1,
- 'limit' => $limit,
- );
- $query_args = apply_filters( 'pmpromd_pagination_url', $query_args, 'prev' );
- ?>
-
+ /**
+ * Action to add content after the member directory.
+ *
+ * @since 0.8
+ * @param string $sqlQuery The SQL query used to get the members.
+ * @param array $shortcode_atts The attributes passed into the shortcode.
+ */
+ do_action( 'pmpro_member_directory_after', $sqlQuery, $shortcode_atts );
+ ?>
+
+