Skip to content

Commit

Permalink
Merge branch 'dev' into prep-for-release
Browse files Browse the repository at this point in the history
  • Loading branch information
kimcoleman committed Dec 5, 2023
2 parents 168cf02 + 4fe721f commit 60848e8
Show file tree
Hide file tree
Showing 8 changed files with 726 additions and 208 deletions.
12 changes: 9 additions & 3 deletions includes/edit-level.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function pmprogroupacct_pmpro_membership_level_before_content_settings( $level )
<label for="pmprogroupacct_total_seats"><?php esc_html_e( 'Total Seats', 'pmpro-group-accounts' ); ?></label>
</th>
<td>
<input id="pmprogroupacct_total_seats" name="pmprogroupacct_total_seats" type="number" min="0" value="<?php echo esc_attr( $settings['min_seats'] ); ?>" />
<input id="pmprogroupacct_total_seats" name="pmprogroupacct_total_seats" type="number" min="0" max="4294967295" value="<?php echo esc_attr( $settings['min_seats'] ); ?>" />
<p class="description"><?php esc_html_e( 'The total number of seats that are included in this group. Note: the group account owner does not count toward this total.', 'pmpro-group-accounts' ); ?></p>
</td>
</tr>
Expand All @@ -82,7 +82,7 @@ function pmprogroupacct_pmpro_membership_level_before_content_settings( $level )
<label for="pmprogroupacct_min_seats"><?php esc_html_e( 'Minimum Seats', 'pmpro-group-accounts' ); ?></label>
</th>
<td>
<input id="pmprogroupacct_min_seats" name="pmprogroupacct_min_seats" type="number" min="0" value="<?php echo esc_attr( $settings['min_seats'] ); ?>" />
<input id="pmprogroupacct_min_seats" name="pmprogroupacct_min_seats" type="number" min="0" max="4294967295" value="<?php echo esc_attr( $settings['min_seats'] ); ?>" />
<p class="description"><?php esc_html_e( 'The minimum number of seats that can be added at checkout.', 'pmpro-group-accounts' ); ?></p>
</td>
</tr>
Expand All @@ -91,7 +91,7 @@ function pmprogroupacct_pmpro_membership_level_before_content_settings( $level )
<label for="pmprogroupacct_max_seats"><?php esc_html_e( 'Maximum Seats', 'pmpro-group-accounts' ); ?></label>
</th>
<td>
<input id="pmprogroupacct_max_seats" name="pmprogroupacct_max_seats" type="number" min="0" value="<?php echo esc_attr( $settings['max_seats'] ); ?>" />
<input id="pmprogroupacct_max_seats" name="pmprogroupacct_max_seats" type="number" min="0" max="4294967295" value="<?php echo esc_attr( $settings['max_seats'] ); ?>" />
<p class="description"><?php esc_html_e( 'The maximum number of seats that can be added at checkout. Note: the group account owner does not count toward this limit.', 'pmpro-group-accounts' ); ?></p>
</td>
</tr>
Expand All @@ -105,6 +105,9 @@ function pmprogroupacct_pmpro_membership_level_before_content_settings( $level )
<option value="fixed" <?php selected( 'fixed', $settings['pricing_model'] ); ?>><?php esc_html_e( 'Per Seat - Set a specific price per additional seat.', 'pmpro-group-accounts' ); ?></option>
</select>
<p class="description"><?php esc_html_e( 'The pricing model to use for purchasing seats.', 'pmpro-group-accounts' ); ?></p>
<div id="pmprogroupacct_pricing_model_warning_free_level" style="display: none;" class="pmpro_message pmpro_alert">
<p><?php esc_html_e( 'WARNING: This level does not have any pricing set up. We highly recommend that you set up an initial payment or recurring billing for a better checkout experience.', 'pmpro-group-accounts' ); ?></p>
</div>
</td>
</tr>
<tr class="pmprogroupacct_setting pmprogroupacct_pricing_setting pmprogroupacct_pricing_setting_fixed">
Expand Down Expand Up @@ -135,6 +138,9 @@ function pmprogroupacct_pmpro_membership_level_before_content_settings( $level )
<option value="recurring" <?php selected( 'recurring', $settings['price_application'] ); ?>><?php esc_html_e( 'Recurring subscription only', 'pmpro-group-accounts' ); ?></option>
</select>
<p class="description"><?php esc_html_e( 'Define whether the seat cost should be applied for the initial payment, recurring payment, or both.', 'pmpro-group-accounts' ); ?></p>
<div id="pmprogroupacct_pricing_model_warning_recurring_billing" style="display: none;" class="pmpro_message pmpro_alert">
<p><?php esc_html_e( 'WARNING: This level does not have a recurring subscription. Child accounts will assume a monthly billing period unless you configure the subscription on this parent level.', 'pmpro-group-accounts' ); ?></p>
</div>
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion includes/edit-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function pmprogroupacct_after_membership_level_profile_fields( $user ) {
}
?>
</td>
<td><?php echo esc_html( $group->get_active_members( true ) ) . '/' . esc_html( $group->group_total_seats ); ?></td>
<td><?php echo esc_html( number_format_i18n( $group->get_active_members( true ) ) ) . '/' . esc_html( number_format_i18n( $group->group_total_seats ) ); ?></td>
<td>
<?php
$manage_group_url = pmpro_url( 'pmprogroupacct_manage_group' );
Expand Down
15 changes: 12 additions & 3 deletions includes/manage-group-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,20 @@ function pmprogroupacct_shortcode_manage_group() {

// Make sure that the email addresses are valid. Each should be on a new line.
if ( empty( $invite_message ) ) {
$emails = explode( "\n", $_REQUEST['pmprogroupacct_invite_new_members_emails'] );
$emails = explode( "\n", trim( $_REQUEST['pmprogroupacct_invite_new_members_emails'] ) );
$valid_emails = array();
$invalid_emails = array();

foreach ( $emails as $email ) {
// Trim whitespace from the email.
$email = trim( $email );

// If it's empty after trimming, skip it.
if ( empty( $email ) ) {
continue;
}

// Check the email and add to the appropriate array.
if ( is_email( $email ) ) {
$valid_emails[] = $email;
} else {
Expand Down Expand Up @@ -339,7 +348,7 @@ function pmprogroupacct_shortcode_manage_group() {
<div class="<?php echo pmpro_get_element_class( 'pmpro_checkout-fields' ); ?>">
<div class="<?php echo pmpro_get_element_class( 'pmpro_checkout-field pmpro_checkout-field-text' ); ?>">
<label for="pmprogroupacct_group_total_seats"><?php esc_html_e( 'Total Seats', 'pmpro-group-accounts' ); ?></label>
<input type="number" name="pmprogroupacct_group_total_seats" id="pmprogroupacct_group_total_seats" class="<?php echo pmpro_get_element_class( 'input' ); ?>" value="<?php echo esc_attr( $group->group_total_seats ); ?>">
<input type="number" max="4294967295" name="pmprogroupacct_group_total_seats" id="pmprogroupacct_group_total_seats" class="<?php echo pmpro_get_element_class( 'input' ); ?>" value="<?php echo esc_attr( $group->group_total_seats ); ?>">
</div> <!-- end .pmpro_checkout-field -->
</div> <!-- end .pmpro_checkout-fields -->
<div class="<?php echo pmpro_get_element_class( 'pmpro_submit' ); ?>">
Expand All @@ -352,7 +361,7 @@ function pmprogroupacct_shortcode_manage_group() {
}
?>
<div id="pmprogroupacct_manage_group_members">
<h2><?php esc_html_e( 'Group Members', 'pmpro-group-accounts' ); ?> (<?php echo count( $active_members ) . '/' . (int)$group->group_total_seats ?>)</h2>
<h2><?php esc_html_e( 'Group Members', 'pmpro-group-accounts' ); ?> (<?php echo esc_html( number_format_i18n( count( $active_members ) ) ) . '/' . esc_html( number_format_i18n( (int)$group->group_total_seats ) ); ?>)</h2>
<?php
echo wp_kses_post( $removal_message );
if ( empty( $active_members ) ) {
Expand Down
48 changes: 29 additions & 19 deletions includes/parents.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,31 @@ function pmprogroupacct_pmpro_checkout_boxes_parent() {
$seat_count = (int)$settings['min_seats'];
switch ( $settings['pricing_model'] ) {
case 'none':
/* translators: %d: Number of seats */
printf(
esc_html__(
_n(
'This purchase includes %d additional seat.',
'This purchase includes %d additional seats.',
'This purchase includes %s additional seat.',
'This purchase includes %s additional seats.',
$seat_count,
'pmpro-group-accounts'
)
),
$seat_count
esc_html( number_format_i18n( $seat_count ) )
);
break;
case 'fixed':
/* translators: %d: Number of seats */
printf(
esc_html__(
_n(
'You are purchasing %d additional seat.',
'You are purchasing %d additional seats.',
'You are purchasing %s additional seat.',
'You are purchasing %s additional seats.',
$seat_count,
'pmpro-group-accounts'
)
),
$seat_count
esc_html( number_format_i18n( $seat_count ) )
);
break;
}
Expand All @@ -76,7 +78,7 @@ function pmprogroupacct_pmpro_checkout_boxes_parent() {
<div class="pmpro_checkout-field pmpro_checkout-field-seats">
<label for="pmprogroupacct_seats"><?php esc_html_e( 'Number of Seats', 'pmpro-group-accounts' ); ?></label>
<input id="pmprogroupacct_seats" name="pmprogroupacct_seats" type="number" min="<?php echo esc_attr( $settings['min_seats'] ); ?>" max="<?php echo esc_attr( $settings['max_seats'] ); ?>" value="<?php echo esc_attr( $settings['min_seats'] ); ?>" />
<p class="description"><?php printf( esc_html__( 'Choose the number of seats to purchase. You can purchase between %d and %d seats.', 'pmpro-group-accounts' ), (int)$settings['min_seats'], (int)$settings['max_seats'] ); ?></p>
<p class="description"><?php printf( esc_html__( 'Choose the number of seats to purchase. You can purchase between %s and %s seats.', 'pmpro-group-accounts' ), esc_html( number_format_i18n( ( (int)$settings['min_seats'] ) ) ), esc_html( number_format_i18n( (int)$settings['max_seats'] ) ) ); ?></p>
</div> <!-- end .pmpro_checkout-field-seats -->
<?php
}
Expand Down Expand Up @@ -104,12 +106,6 @@ function pmprogroupacct_pmpro_checkout_boxes_parent() {
</p>
<?php
break;
case 'tiered':
break;
case 'volume':
break;
case 'dropdown':
break;
}

// Show child levels.
Expand Down Expand Up @@ -170,13 +166,13 @@ function pmprogroupacct_pmpro_registration_checks_parent( $continue_checkout ) {
// If the number of seats is less than the minimum, show an error.
if ( $seats < $settings['min_seats'] ) {
$continue_checkout = false;
pmpro_setMessage( sprintf( esc_html__( 'You must purchase at least %d seats.', 'pmpro-group-accounts' ), (int)$settings['min_seats'] ), 'pmpro_error' );
pmpro_setMessage( sprintf( esc_html__( 'You must purchase at least %s seats.', 'pmpro-group-accounts' ), esc_html( number_format_i18n( (int)$settings['min_seats'] ) ) ), 'pmpro_error' );
}

// If the number of seats is greater than the maximum, show an error.
if ( $seats > $settings['max_seats'] ) {
$continue_checkout = false;
pmpro_setMessage( sprintf( esc_html__( 'You cannot purchase more than %d seats.', 'pmpro-group-accounts' ), (int)$settings['max_seats'] ), 'pmpro_error' );
pmpro_setMessage( sprintf( esc_html__( 'You cannot purchase more than %s seats.', 'pmpro-group-accounts' ), esc_html( number_format_i18n( (int)$settings['max_seats'] ) ) ), 'pmpro_error' );
}

// Check if this parent already has a group for this level. If so, check if $seats is greater than the number of seats in the group.
Expand All @@ -186,7 +182,7 @@ function pmprogroupacct_pmpro_registration_checks_parent( $continue_checkout ) {
$member_count = $existing_group->get_active_members( true );
if ( $seats < $member_count ) {
$continue_checkout = false;
pmpro_setMessage( sprintf( esc_html__( 'There are currently %d members in your group. You must purchase at least that many seats.', 'pmpro-group-accounts' ), $member_count ), 'pmpro_error' );
pmpro_setMessage( sprintf( esc_html__( 'There are currently %s members in your group. You must purchase at least that many seats.', 'pmpro-group-accounts' ), esc_html( number_format_i18n( (int)$member_count ) ) ) , 'pmpro_error' );
}
}

Expand Down Expand Up @@ -243,12 +239,26 @@ function pmprogroupacct_pmpro_checkout_level_parent( $level ) {
case 'both':
$level->initial_payment += $seat_cost;
$level->billing_amount += $seat_cost;
// If the level is not already recurring, default to 1 per Month.
if ( empty ( $level->cycle_number ) ) {
$level->cycle_number = 1;
}
if ( empty( $level->cycle_period ) ) {
$level->cycle_period = 'Month';
}
break;
case 'initial':
$level->initial_payment += $seat_cost;
break;
case 'recurring':
$level->billing_amount += $seat_cost;
// If the level is not already recurring, default to 1 per Month.
if ( empty ( $level->cycle_number ) ) {
$level->cycle_number = 1;
}
if ( empty( $level->cycle_period ) ) {
$level->cycle_period = 'Month';
}
break;
}

Expand Down Expand Up @@ -372,10 +382,10 @@ function pmprogroupacct_pmpro_invoice_bullets_bottom_parent( $invoice ) {
echo '<strong>' . esc_html__( 'Group Account', 'pmpro-group-accounts' ) . '</strong>: ';
/* translators: 1: Group code, 2: Number of seats claimed, 3: Total number of seats in the group. */
printf(
esc_html__( 'Users can join your group by using the %1$s code at checkout (%2$d/%3$d seats claimed).', 'pmpro-group-accounts' ),
esc_html__( 'Users can join your group by using the %1$s code at checkout (%2$s/%3$s seats claimed).', 'pmpro-group-accounts' ),
'<strong>' . esc_html( $group->group_checkout_code ) . '</strong>',
(int)$group->get_active_members( true ),
(int)$group->group_total_seats
esc_html( number_format_i18n( (int)$group->get_active_members( true ) ) ),
esc_html( number_format_i18n( (int)$group->group_total_seats ) )
);

// Check if we have a "manage group" page set.
Expand Down
49 changes: 49 additions & 0 deletions js/pmprogroupacct-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,53 @@ jQuery( document ).ready( function( $ ) {
$( '#pmprogroupacct_pricing_model' ).change( function() {
pmprogroupacct_update_edit_level_pricing_model_field_visibility();
} );

// Function to update the min value of max seats based on min seats.
function pmprogroupacct_update_max_seats() {
var minSeats = $( '#pmprogroupacct_min_seats' ).val();
$( '#pmprogroupacct_max_seats' ).attr( 'min', minSeats );
}
pmprogroupacct_update_max_seats();
$('#pmprogroupacct_min_seats').change(function() {
pmprogroupacct_update_max_seats();
});

// Function to toggle the warning based on the recurring checkbox
function pmprogroupacct_toggle_recurring_warning() {
var priceApplication = $('#pmprogroupacct_price_application').val();
var isRecurringUnchecked = $('#recurring').is(':not(:checked)');

// Show the warning if price application is 'both' or 'recurring' and the recurring checkbox is unchecked
if ( ( priceApplication === 'both' || priceApplication === 'recurring' ) && isRecurringUnchecked ) {
$( '#pmprogroupacct_pricing_model_warning_recurring_billing').show();
} else {
$( '#pmprogroupacct_pricing_model_warning_recurring_billing').hide();
}
}
$( '#recurring, #pmprogroupacct_price_application' ).change(function() {
pmprogroupacct_toggle_recurring_warning();
});

// Initial check to set the correct state when the page loads
pmprogroupacct_toggle_recurring_warning();

// Function to toggle the warning based on the level pricing
function pmprogroupacct_toggle_free_level_warning() {
var priceModel = $('#pmprogroupacct_pricing_model').val();
var initialPayment = parseFloat( $( 'input[name="initial_payment"]' ).val() );
var isRecurringUnchecked = $('#recurring').is(':not(:checked)');

// Show the warning if priceModel is 'fixed' and the level is free.
if ( priceModel === 'fixed' && initialPayment === 0 && isRecurringUnchecked ) {
$( '#pmprogroupacct_pricing_model_warning_free_level').show();
} else {
$( '#pmprogroupacct_pricing_model_warning_free_level').hide();
}
}
$( 'input[name="initial_payment"], #recurring, #pmprogroupacct_pricing_model' ).change(function() {
pmprogroupacct_toggle_free_level_warning();
});

// Initial check to set the correct state when the page loads
pmprogroupacct_toggle_free_level_warning();
} );
Binary file modified languages/pmpro-group-accounts.mo
Binary file not shown.
Loading

0 comments on commit 60848e8

Please sign in to comment.