Skip to content

Commit

Permalink
WPCIVIUX-183 Version 1.19.0. Membership row shortcode, if the optiona…
Browse files Browse the repository at this point in the history
…l renewal_url parameter is not provided, then do not output the renewal link at all; change from isset to empty for some variable checks
  • Loading branch information
agileware-justin committed Oct 9, 2024
1 parent 9f81a8f commit 8ec4597
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion civicrm-ux.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: WP CiviCRM UX
* Plugin URI: https://github.com/agileware/wp-civicrm-ux
* Description: A better user experience for integrating WordPress and CiviCRM
* Version: 1.18.0
* Version: 1.19.0
* Requires at least: 5.8
* Requires PHP: 7.4
* Requires Plugins: civicrm
Expand Down
6 changes: 3 additions & 3 deletions shortcodes/membership/membership-row.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public function shortcode_callback( $atts = [], $content = null, $tag = '' ) {
// normalize attribute keys, lowercase
$atts = array_change_key_case( (array) $atts, CASE_LOWER );

if ( isset($atts['membership_type']) ) {
if ( !empty($atts['membership_type']) ) {
$atts['membership_type'] = explode(',', $atts['membership_type']);
}

if ( isset($atts['membership_status']) ) {
if ( !empty($atts['membership_status']) ) {
$atts['membership_status'] = explode(',', $atts['membership_status']);
}

Expand All @@ -50,7 +50,7 @@ public function shortcode_callback( $atts = [], $content = null, $tag = '' ) {
return;
}

$memberships = Civicrm_Ux_Membership_Utils::get_all_memberships_for_contact( $contactAuth['cid'], $atts['membership_type'], $atts['membership_status'], $atts['expiration_offset'] );
$memberships = Civicrm_Ux_Membership_Utils::get_all_memberships_for_contact( $contactAuth['cid'], $atts['membership_type'], $atts['membership_status'] );

// Buffer the output
ob_start();
Expand Down
72 changes: 38 additions & 34 deletions templates/shortcode/shortcode-membership-row.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Default template for the [ux_membership_row] shortcode.
*
Expand All @@ -12,48 +13,51 @@
* There may be multiple memberships returned depending on the parameters fed to the shortcode.
* In this case, we want to output a row for each membership.
*/
foreach($args['memberships'] as $membership) {

if (isset($membership['end_date'])) {
$endDate = date_create($membership['end_date']);

// Format the datetime value using the default date format
$formattedEndDate = date_i18n($dateFormat, $endDate->getTimestamp());
} else {
$formattedEndDate = '-';
}

if ($args['expiration_offset'] != null) {
$expiration_offset_date = strtotime($args['expiration_offset']);
} else {
$expiration_offset_date = FALSE;
}

// Build the renewal link
// If cid and cs are used for user authentication, the renewal links will also contain them.
// Logged in users do not need a checksum in their link.
foreach ($args['memberships'] as $membership) {

if (!empty($membership['end_date'])) {
$endDate = date_create($membership['end_date']);

// Format the datetime value using the default date format
$formattedEndDate = date_i18n($dateFormat, $endDate->getTimestamp());
} else {
$formattedEndDate = '-';
}

if (!empty($args['expiration_offset'])) {
$expiration_offset_date = strtotime($args['expiration_offset']);
} else {
$expiration_offset_date = FALSE;
}

// Build the renewal link
// If cid and cs are used for user authentication, the renewal links will also contain them.
// Logged in users do not need a checksum in their link.
$renewalUrl = FALSE;
if (!empty($args['renewal_url'])) {
$queryArgs = [
'cid' => $args['cid'],
'cs' => $args['cs'],
'mid' => $membership['id']
];
$renewalUrl = add_query_arg( $queryArgs, $args['renewal_url'] );
$renewalUrl = add_query_arg($queryArgs, $args['renewal_url']);
}
?>

<tr>
<td><?php echo $membership['contact_owner.display_name'] ?? $membership['contact.display_name']; ?></td>
<td><?php echo $membership['membership_type_id:label']; ?></td>
<td><?php echo $membership['status_id:label']; ?></td>
<td><?php echo $formattedEndDate; ?></td>
<td>
<?php if (($expiration_offset_date && $endDate->getTimestamp() <= $expiration_offset_date) || $endDate->getTimestamp() <= time()) { ?>
<a href="<?php echo esc_url($renewalUrl); ?>" target="_blank">Renew this membership</a></td>
<tr>
<td><?php echo $membership['contact_owner.display_name'] ?? $membership['contact.display_name']; ?></td>
<td><?php echo $membership['membership_type_id:label']; ?></td>
<td><?php echo $membership['status_id:label']; ?></td>
<td><?php echo $formattedEndDate; ?></td>
<td>
<?php if ($renewalUrl && (($expiration_offset_date && $endDate->getTimestamp() <= $expiration_offset_date) || $endDate->getTimestamp() <= time())) { ?>
<a href="<?php echo esc_url($renewalUrl); ?>" target="_blank">Renew this membership</a>
</td>
<?php } else { ?>
No renewal required</td>
No renewal required</td>
<?php } ?>
</tr>
</tr>

<?php
}
?>

}
?>

0 comments on commit 8ec4597

Please sign in to comment.