<!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>[5657] sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc: Support Forums: Add "Always notify me via email of follow-up posts in any topics I reply to" checkbox to user profile.</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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/5657">5657</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/5657","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-07-12 02:43:36 +0000 (Wed, 12 Jul 2017)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Support Forums: Add "Always notify me via email of follow-up posts in any topics I reply to" checkbox to user profile.

Fixes <a href="http://meta.trac.wordpress.org/ticket/6">#6</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclasshooksphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusersphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclasshooksphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php       2017-07-12 02:30:42 UTC (rev 5656)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php 2017-07-12 02:43:36 UTC (rev 5657)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,13 +50,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Check "Notify me of follow-up replies via email" checkbox for new topics by default.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Check "Notify me of follow-up replies via email" box for new topics by default.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * If the user has enabled "Always notify me via email of follow-up posts" option
+        * in their profile, check the box for new replies as well.
+        *
</ins><span class="cx" style="display: block; padding: 0 10px">          * @param string $checked Checked value of topic subscription.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string Checked value of topic subscription.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function check_topic_subscription_checkbox( $checked ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( bbp_is_single_forum() || bbp_is_single_view() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if (
+                       bbp_is_single_forum() || bbp_is_single_view()
+               ||
+                       get_user_option( 'auto_topic_subscription' )
+               ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $checked = checked( true, true, false );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php       2017-07-12 02:30:42 UTC (rev 5656)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php 2017-07-12 02:43:36 UTC (rev 5657)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,22 +5,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class Users {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function __construct() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Add a Custom Title input to user's profile.
-               add_action( 'bbp_user_edit_after_name', array( $this, 'add_custom_title_input' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Add custom fields to user's profile.
+               add_action( 'bbp_user_edit_after_name',        array( $this, 'add_custom_title_input' ) );
+               add_action( 'bbp_user_edit_after',             array( $this, 'add_auto_topic_subscription_checkbox' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Save Custom Title input value.
-               add_action( 'personal_options_update', array( $this, 'save_custom_title' ), 10, 2 );
-               add_action( 'edit_user_profile_update', array( $this, 'save_custom_title' ), 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Save custom field values.
+               add_action( 'personal_options_update',         array( $this, 'save_custom_fields' ), 10, 2 );
+               add_action( 'edit_user_profile_update',        array( $this, 'save_custom_fields' ), 10, 2 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Custom user contact methods.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_filter( 'user_contactmethods', array( $this, 'custom_contact_methods' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_filter( 'user_contactmethods',             array( $this, 'custom_contact_methods' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Only allow 3 published topics from a user in the first 24 hours.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_action( 'bbp_new_topic_pre_insert', array( $this, 'limit_new_user_topics' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_action( 'bbp_new_topic_pre_insert',        array( $this, 'limit_new_user_topics' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Add query vars and rewrite rules for user's topic and review queries.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_filter( 'query_vars',            array( $this, 'add_query_vars' ) );
-               add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_filter( 'query_vars',                      array( $this, 'add_query_vars' ) );
+               add_action( 'bbp_add_rewrite_rules',           array( $this, 'add_rewrite_rules' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Parse user's topic and review queries.
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'parse_query',                     array( $this, 'parse_user_topics_query' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,25 +57,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $title = get_user_option( 'title', bbp_get_displayed_user_id() );
</ins><span class="cx" style="display: block; padding: 0 10px">                 ?>
</span><span class="cx" style="display: block; padding: 0 10px">                <div>
</span><span class="cx" style="display: block; padding: 0 10px">                        <label for="title"><?php esc_html_e( 'Custom Title', 'wporg-forums' ); ?></label>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        <input type="text" name="title" id="title" value="<?php echo esc_attr( get_user_option( 'title', bbpress()->displayed_user->ID ) ); ?>" class="regular-text" />
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 <input type="text" name="title" id="title" value="<?php echo esc_attr( $title ); ?>" class="regular-text" />
</ins><span class="cx" style="display: block; padding: 0 10px">                 </div>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        <?php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         <?php
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Save Custom Title input value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Add an auto topic subscription checkbox to user's profile.
+        */
+       public function add_auto_topic_subscription_checkbox() {
+               $auto_topic_subscription = get_user_option( 'auto_topic_subscription', bbp_get_displayed_user_id() );
+               ?>
+               <p>
+                       <input name="auto_topic_subscription" id="auto_topic_subscription" type="checkbox" value="yes" <?php checked( $auto_topic_subscription ); ?> />
+                       <label for="auto_topic_subscription"><?php esc_html_e( 'Always notify me via email of follow-up posts in any topics I reply to', 'wporg-forums' ); ?></label>
+               </p>
+               <?php
+       }
+
+       /**
+        * Save custom field values.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param int $user_id The user ID.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function save_custom_title( $user_id ) {
-               if ( ! current_user_can( 'moderate' ) || ! isset( $_POST['title'] ) ) {
-                       return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function save_custom_fields( $user_id ) {
+               if ( current_user_can( 'moderate' ) && isset( $_POST['title'] ) ) {
+                       update_user_option( $user_id, 'title', sanitize_text_field( $_POST['title'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                update_user_option( $user_id, 'title', sanitize_text_field( $_POST['title'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $auto_topic_subscription = isset( $_POST['auto_topic_subscription'] );
+               update_user_option( $user_id, 'auto_topic_subscription', $auto_topic_subscription );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre>
</div>
</div>

</body>
</html>