Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force unconfirmed tickets to log in. #1421

Open
wants to merge 6 commits into
base: production
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions public_html/wp-content/plugins/camptix/addons/require-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,22 @@ public function block_unauthenticated_actions() {
return;
}

// Temporary: We don't want to block users from editing tickets.
// See: https://github.com/WordPress/wordcamp.org/issues/1393.
if ( ! is_user_logged_in() && ! $this->user_is_editing_ticket() ) {
if ( ! is_user_logged_in() ) {

// Temporary: We don't want to block users from editing tickets unless they are unconfirmed.
// See: https://github.com/WordPress/wordcamp.org/issues/1393.
// See: https://github.com/WordPress/wordcamp.org/issues/1420.
if ( $this->user_is_editing_ticket() && ! $this->user_must_confirm_ticket( $_REQUEST['tix_attendee_id'] ) ) {
return;
}

$args = array();
// If this was a registration, pass through the selected tickets and coupon.
if ( 'attendee_info' === $_REQUEST['tix_action'] && isset( $_REQUEST['tix_tickets_selected'] ) ) {
$args['tix_action'] = $_REQUEST['tix_action'];
$args['tix_tickets_selected'] = $_REQUEST['tix_tickets_selected'];
if ( isset( $_REQUEST['tix_coupon'] ) ) {
$args['tix_coupon'] = $_REQUEST['tix_coupon'];
if ( in_array( $_REQUEST['tix_action'], array( 'attendee_info', 'edit_attendee' ) ) ) {
// Pass along all `tix_` information.
foreach ( $_REQUEST as $key => $value ) {
StevenDufresne marked this conversation as resolved.
Show resolved Hide resolved
if ( strpos( $key, 'tix' ) === 0 ) {
$args[ $key ] = $value;
}
}
}

Expand Down Expand Up @@ -148,7 +154,7 @@ public function ticket_form_message() {
}

// Ask the attendee to confirm their registration
if ( isset( $_REQUEST['tix_action'] ) && 'edit_attendee' == $_REQUEST['tix_action'] && self::UNCONFIRMED_USERNAME == get_post_meta( $_REQUEST['tix_attendee_id'], 'tix_username', true ) ) {
if ( $this->user_is_editing_ticket() && $this->user_must_confirm_ticket( $_REQUEST['tix_attendee_id'] ) ) {
$tickets_selected = array( get_post_meta( $_REQUEST['tix_attendee_id'], 'tix_ticket_id', true ) => 1 ); // mimic $_REQUEST['tix_tickets_selected']

if ( $this->tickets_have_questions( $tickets_selected ) ) {
Expand Down Expand Up @@ -430,7 +436,7 @@ public function use_custom_email_templates( $template, $attendee ) {

if ( $unknown_attendee_info['email'] == get_post_meta( $attendee->ID, 'tix_email', true ) ) {
$template = 'email_template_multiple_purchase_unknown_attendee';
} elseif ( self::UNCONFIRMED_USERNAME == get_post_meta( $attendee->ID, 'tix_username', true ) ) {
} elseif ( $this->user_must_confirm_ticket( $attendee->ID ) ) {
$template = 'email_template_multiple_purchase_unconfirmed_attendee';
}

Expand Down Expand Up @@ -755,7 +761,7 @@ public function update_attendee_post_meta( $new_ticket_info, $attendee ) {
* @return string
*/
public function rename_save_attendee_info_label( $label, $attendee, $ticket, $questions ) {
if ( self::UNCONFIRMED_USERNAME == get_post_meta( $attendee->ID, 'tix_username', true ) ) {
if ( $this->user_must_confirm_ticket( $attendee->ID ) ) {
$label = __( 'Confirm Registration', 'wordcamporg' );
}

Expand Down Expand Up @@ -841,6 +847,18 @@ public function prevent_unknown_attendees_viewing_private_content( $parameters )
protected function user_is_editing_ticket() {
return isset( $_REQUEST['tix_action'] ) && in_array( $_REQUEST['tix_action'], array( 'access_tickets', 'edit_attendee' ) );
}

/**
* Checks if the user associated with the given attendee ID must confirm their ticket.
* Unconfirmed tickets exist when one user purchases multiple tickets.
*
* @param int $attendee_id The ID of the attendee. If null or invalid, the function returns false.
*
* @return bool True if the attendee must confirm their ticket, false otherwise.
*/
protected function user_must_confirm_ticket( $attendee_id ) {
return isset( $attendee_id ) && self::UNCONFIRMED_USERNAME == get_post_meta( $attendee_id, 'tix_username', true );
}
} // CampTix_Require_Login

camptix_register_addon( 'CampTix_Require_Login' );
Loading