| | |
| | | // Add hooks for processing accepted invitations |
| | | add_action('user_register', [$this, 'checkInvitation'], 10, 1); |
| | | |
| | | |
| | | add_filter('jvbLoginLabels', [$this, 'modifyLoginLabels'], 10, 2); |
| | | |
| | | |
| | | |
| | | add_action('jvb_daily_maintenance', [$this, 'cleanupExpiredInvitations']); |
| | | |
| | | // Add filter for bulk operation handling |
| | |
| | | $toTerm = (array_key_exists('to_term', $data)) ? (int)$data['to_term'] : false; |
| | | $taxonomy = (array_key_exists('taxonomy', $data) && in_array($data['taxonomy'], $this->inviteTypes[$role]['to_terms']??[])) ? $data['taxonomy'] : false; |
| | | |
| | | $args = [ |
| | | 'user' => (array_key_exists('user', $data)) ? (int)$data['user'] : false, |
| | | 'role' => $role, |
| | | 'to_term' => $toTerm, |
| | | 'taxonomy' => $taxonomy, |
| | | 'status' => array_key_exists('status', $data) && in_array($data['status'], ['all', 'pending', 'accepted', 'rejected', 'expired', 'revoked']) ? $data['status'] : 'all', |
| | | 'page' => array_key_exists('page', $data) ? (int)$data['page'] : 1, |
| | | ]; |
| | | |
| | | return $args; |
| | | return [ |
| | | 'user' => (array_key_exists('user', $data)) ? (int)$data['user'] : false, |
| | | 'role' => $role, |
| | | 'to_term' => $toTerm, |
| | | 'taxonomy' => $taxonomy, |
| | | 'status' => array_key_exists('status', $data) && in_array($data['status'], ['all', 'pending', 'accepted', 'rejected', 'expired', 'revoked']) ? $data['status'] : 'all', |
| | | 'page' => array_key_exists('page', $data) ? (int)$data['page'] : 1, |
| | | ]; |
| | | } |
| | | /** |
| | | * @param object $request the request object |
| | |
| | | } |
| | | $toContentTax = implode(' ', $toContentTax); |
| | | |
| | | $button = jvbMailButton($signup_url, 'Join the Scene!'); |
| | | $link = jvbEmailLink($signup_url); |
| | | $signature = jvbSignature(); |
| | | $button = JVB()->email()->button($signup_url, 'Join the Scene!'); |
| | | $link = JVB()->email()->link($signup_url); |
| | | $signature = JVB()->email()->signature(); |
| | | |
| | | $message = sprintf( |
| | | '<p>Hi %s!</p> |
| | |
| | | ); |
| | | |
| | | |
| | | $success = jvbMail($email, $subject, $message); |
| | | $success = JVB()->email()->sendEmail($email, $subject, $message); |
| | | |
| | | |
| | | if (!$success) { |
| | |
| | | $name |
| | | ); |
| | | |
| | | $success = jvbMail($email, $subject, $content, 'INVITATION REVOKED'); |
| | | $success = JVB()->email()->sendEmail($email, $subject, $content, 'INVITATION REVOKED'); |
| | | if (!$success) { |
| | | JVB()->error()->log( |
| | | 'invitation_revoke_email', |
| | |
| | | |
| | | $key = $this->cache->generateKey($args); |
| | | $cache = $this->cache->get($key); |
| | | $cache = false; |
| | | if ($cache) { |
| | | return new WP_REST_Response($cache); |
| | | } |
| | |
| | | ]; |
| | | } |
| | | } |
| | | |
| | | public function modifyLoginLabels(array $labels, array $get_params): array |
| | | { |
| | | // Only modify if invitation params present |
| | | if (!array_key_exists('invite', $get_params) || !array_key_exists('email', $get_params)) { |
| | | return $labels; |
| | | } |
| | | $email = sanitize_email($get_params['email']); |
| | | $token = sanitize_text_field($get_params['invite']); |
| | | $user = email_exists($email); |
| | | if (!$user) { |
| | | return $labels; |
| | | } |
| | | $role = jvbUserRole($user); |
| | | // Get invitation data |
| | | $data = $this->verifyInvitation( |
| | | $token, |
| | | $email, |
| | | $role, |
| | | ); |
| | | |
| | | if (!$data) { |
| | | return $labels; |
| | | } |
| | | |
| | | // Build custom message |
| | | $inviters = json_decode($data->inviters, true); |
| | | $name = $data->name; |
| | | $names = array_map(function($inviter) { |
| | | $artist = jvbContentFromUser((int)$inviter['user_id']); |
| | | return $artist['name'] ?: $artist['display_name']; |
| | | }, $inviters); |
| | | |
| | | $message = count($names) > 1 |
| | | ? 'are already here, and have invited you to join in!' |
| | | : ' is already here, and invited you to join in!'; |
| | | |
| | | // Modify labels |
| | | $labels['title'] = 'Join the Scene, ' . $data->name; |
| | | $labels['description'] = [jvbCommaList($names) . ' ' . $message]; |
| | | |
| | | return $labels; |
| | | } |
| | | } |