<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[821] sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-participation-notifier/wordcamp-participation-notifier.php: WordCamp Participation Notifier: Split attendee_registered() into two functions.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://meta.trac.wordpress.org/changeset/821">821</a></dd>
<dt>Author</dt> <dd>iandunn</dd>
<dt>Date</dt> <dd>2014-09-01 19:41:48 +0000 (Mon, 01 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>WordCamp Participation Notifier: Split attendee_registered() into two functions.

Previously it was triggered when the buyer's username was saved, but that happens before the ticket is successfully
purchased, resulting in a bug where a notification would be sent even if the transaction eventually failed.

The notification shouldn't be sent until the buyer's attendee post has moved to the publish state. Consequentially,
that event is separate from the event when the additional attendees confirm their registration, so we now have
seprate methods to handle each event.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampparticipationnotifierwordcampparticipationnotifierphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-participation-notifier/wordcamp-participation-notifier.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampparticipationnotifierwordcampparticipationnotifierphp"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-participation-notifier/wordcamp-participation-notifier.php (820 => 821)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-participation-notifier/wordcamp-participation-notifier.php      2014-08-29 18:06:24 UTC (rev 820)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-participation-notifier/wordcamp-participation-notifier.php 2014-09-01 19:41:48 UTC (rev 821)
</span><span class="lines">@@ -15,8 +15,9 @@
</span><span class="cx">   * Constructor
</span><span class="cx">   */
</span><span class="cx">  public function __construct() {
</span><del>-               add_action( 'transition_post_status',                 array( $this, 'post_updated' ), 5, 3 );
-               add_action( 'camptix_require_login_confirm_username', array( $this, 'attendee_registered' ), 10, 2 );
</del><ins>+                add_action( 'transition_post_status',                  array( $this, 'post_updated' ), 5, 3 );
+               add_action( 'camptix_rl_buyer_completed_registration', array( $this, 'primary_attendee_registered' ), 10, 2 );
+               add_action( 'camptix_rl_registration_confirmed',       array( $this, 'additional_attendee_confirmed_registration' ), 10, 2 );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><span class="lines">@@ -27,7 +28,7 @@
</span><span class="cx">   * This hooks in before the custom post types save their post meta fields, so that we can access the
</span><span class="cx">   * WordPress.org username from the previous revision and from the current one.
</span><span class="cx">   *
</span><del>-        * @todo Maybe refactor this to work more like attendee_registered(), so the speaker/sponsor plugins just fire a
</del><ins>+         * @todo Maybe refactor this to work more like primary_attendee_registered(), so the speaker/sponsor plugins just fire a
</ins><span class="cx">    *       hook when they're ready to send the notification, rather than this plugin having to be aware of (and
</span><span class="cx">   *       coupled to) the internal logic of those plugins.
</span><span class="cx">   * 
</span><span class="lines">@@ -54,6 +55,7 @@
</span><span class="cx">   * because the logic differs based on the payload being generated.
</span><span class="cx">   *
</span><span class="cx">   * @param WP_Post $post The post
</span><ins>+        *
</ins><span class="cx">    * @return boolean true if the post can be notified about; false if it can't
</span><span class="cx">   */
</span><span class="cx">  protected function is_post_notifiable( $post ) {
</span><span class="lines">@@ -127,16 +129,34 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><del>-        * Adds new activity to a user's profile when they register for a ticket.
</del><ins>+         * Send a notification when someone successfully registered for a ticket.
</ins><span class="cx">    *
</span><del>-        * @todo Handle cases where the user changes, either from the admin editing the back-end post, or a from a
</del><ins>+         * If they purchased multiple tickets, this will only send a notification for the one they bought for theirself.
+        * Notifications for the other attendees will be sent in additional_attendee_confirmed_registration().
+        *
+        * @todo Handle cases where the username changes, either from the admin editing the back-end post, or a from a
</ins><span class="cx">    *       different user updating via the edit token?
</span><span class="cx">   * @todo The handler doesn't support removing activity, but maybe do that here if support is added.
</span><span class="cx">   *
</span><ins>+        * @param WP_Post $attendee
+        * @param string  $username
+        */
+       public function primary_attendee_registered( $attendee, $username ) {
+               $user_id = $this->get_saved_wporg_user_id( $attendee );
+               $this->remote_post( self::PROFILES_HANDLER_URL, $this->get_post_activity_payload( $attendee, $user_id ) );
+       }
+
+       /**
+        * Send a notification when an attendee whose ticked was bought on their behalf confirms their registration.
+        *
+        * @todo Handle cases where the username changes, either from the admin editing the back-end post, or a from a
+        *       different user updating via the edit token?
+        * @todo The handler doesn't support removing activity, but maybe do that here if support is added.
+        *
</ins><span class="cx">    * @param int $attendee_id
</span><span class="cx">   * @param string $username
</span><span class="cx">   */
</span><del>-       public function attendee_registered( $attendee_id, $username ) {
</del><ins>+        public function additional_attendee_confirmed_registration( $attendee_id, $username ) {
</ins><span class="cx">           $attendee = get_post( $attendee_id );
</span><span class="cx">          $user_id  = $this->get_saved_wporg_user_id( $attendee );
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>