<!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>[10655] sites/trunk/wordpress.org/public_html/wp-content/plugins: Support Forums: Also Viewing: Move the toggle into the forum profile screen.</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 { white-space: pre-line; 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/10655">10655</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/10655","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-02-11 02:05:04 +0000 (Thu, 11 Feb 2021)</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: Also Viewing: Move the toggle into the forum profile screen.
This allows non-moderators with at least 20 replies to opt-in to the feature.
This change also adds a heading to the user options page to give the checkboxes a heading, and makes the banner fixing to the page smoother and more inline with the forum styling.
See <a href="http://meta.trac.wordpress.org/ticket/2552">#2552</a>. </pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusernotesphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.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>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpalsoviewingwporgbbpalsoviewingjs">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpalsoviewingwporgbbpalsoviewingphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusernotesphp"></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-user-notes.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-user-notes.php 2021-02-11 00:25:54 UTC (rev 10654)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php 2021-02-11 02:05:04 UTC (rev 10655)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,7 +30,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bbp_theme_before_topic_content', array( $this, 'display_user_notes_in_content' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bbp_theme_before_reply_content', array( $this, 'display_user_notes_in_content' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bbp_template_after_user_profile', array( $this, 'display_user_notes_in_profile' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'bbp_user_edit_after', array( $this, 'display_user_notes_in_profile_edit' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'bbp_user_edit_after', array( $this, 'display_user_notes_in_profile_edit' ), 20 );
</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>
<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 2021-02-11 00:25:54 UTC (rev 10654)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php 2021-02-11 02:05:04 UTC (rev 10655)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7,6 +7,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function __construct() {
</span><span class="cx" style="display: block; padding: 0 10px"> // Add custom fields to user's profile.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bbp_user_edit_after_name', array( $this, 'add_custom_title_input' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'bbp_user_edit_after', array( $this, 'add_options_section_header' ), 0 );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bbp_user_edit_after', array( $this, 'add_auto_topic_subscription_checkbox' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Save custom field values.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,6 +83,16 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Add a section header to the extra user options.
+ */
+ public function add_options_section_header() {
+ printf(
+ '<h2 id="user-settings" class="entry-title">%s</h2>',
+ esc_html__( 'User Options', 'wporg-forums' )
+ );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Add an auto topic subscription checkbox to user's profile.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function add_auto_topic_subscription_checkbox() {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpalsoviewingwporgbbpalsoviewingjs"></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/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js</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/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js 2021-02-11 00:25:54 UTC (rev 10654)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js 2021-02-11 02:05:04 UTC (rev 10655)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,6 +9,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> currentlyViewing = options.currentlyViewing || [],
</span><span class="cx" style="display: block; padding: 0 10px"> page = options.currentPage || '',
</span><span class="cx" style="display: block; padding: 0 10px"> banner = false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ bannerOffset = 200,
</ins><span class="cx" style="display: block; padding: 0 10px"> isTyping = false,
</span><span class="cx" style="display: block; padding: 0 10px"> _n = wp.i18n._n,
</span><span class="cx" style="display: block; padding: 0 10px"> __ = wp.i18n.__,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -42,20 +43,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"> jQuery('#main').before(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '<div id="also-viewing-banner" style="display: none; font-size: 14px; color: #fff; line-height: 30px; font-family: Helvetica,sans-serif; background: #d54e21; border-bottom: 1px solid #dfdfdf; width:100%; height:30px; text-align: center; position: initial; top: 32px; left: 0; z-index: 9999;"></div>'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '<div id="also-viewing-banner" style="display: none; font-size: 0.8rem; color: #fff; line-height: 2rem; background: #d54e21; width:100%; text-align: center; position: initial; top: 32px; left: 0; z-index: 9999;"></div>'
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> banner = jQuery( '#also-viewing-banner' );
</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"> if ( ! userCount ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- banner.show( false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ banner.hide();
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> userList = currentlyViewing.map( function( item ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return item.who + ( item.isTyping ? ' ' + __( '(is typing)', 'wporg-bbp-also-viewing' ) : '' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return item.who + ( item.isTyping ? ' ' + __( '(is typing)', 'wporg-forums' ) : '' );
</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"> if ( userCount > 1 ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- userlistPretty = __( '%1$s and %2$s' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ userlistPretty = __( '%1$s and %2$s', 'wporg-forums' )
</ins><span class="cx" style="display: block; padding: 0 10px"> .replace( '%1$s', userList.slice( 0, -1 ).join( ', ' ) + ( userCount > 2 ? ',' : '' ) )
</span><span class="cx" style="display: block; padding: 0 10px"> .replace( '%2$s', userList.slice( -1 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -63,10 +64,11 @@
</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"> banner.text(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- _n( '%s is also viewing this page.', '%s are also viewing this page.', userCount, 'wporg-bbp-also-viewing' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _n( '%s is also viewing this page.', '%s are also viewing this page.', userCount, 'wporg-forums' )
</ins><span class="cx" style="display: block; padding: 0 10px"> .replace( '%s', userlistPretty )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- banner.show( true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ banner.show();
+ bannerOffset = banner.offset().top - jQuery('#wpadminbar').height();
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -76,12 +78,15 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( jQuery(window).scrollTop() > 200 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var $main = jQuery('#main');
+ if ( jQuery(window).scrollTop() > bannerOffset ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> banner.css( 'position', 'fixed' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $main.css( 'padding-top', banner.height() );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> banner.css( 'position', 'initial' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $main.css( 'padding-top', 0 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // When a textarea is focused, mark the user as typing.
</span><span class="cx" style="display: block; padding: 0 10px"> jQuery(document).on( 'keydown', 'textarea', function() {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpalsoviewingwporgbbpalsoviewingphp"></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/wporg-bbp-also-viewing/wporg-bbp-also-viewing.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/wporg-bbp-also-viewing/wporg-bbp-also-viewing.php 2021-02-11 00:25:54 UTC (rev 10654)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.php 2021-02-11 02:05:04 UTC (rev 10655)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,13 +26,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * along with this program; if not, see <http://www.gnu.org/licenses/>.
</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">-const TOGGLE_KEY = 'toggle-also-viewing';
</del><span class="cx" style="display: block; padding: 0 10px"> const USER_OPTION = 'also-viewing';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-const NONCE = 'also-viewing';
</del><span class="cx" style="display: block; padding: 0 10px"> const TIMEOUT = 5 * \MINUTE_IN_SECONDS;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-const REFRESH_INT = 45; // How often the client should check for new viewers.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const REFRESH_INT = 45; // How often the client should check for new viewers in seconds.
</ins><span class="cx" style="display: block; padding: 0 10px"> const CACHE_GROUP = 'also-viewing';
</span><span class="cx" style="display: block; padding: 0 10px"> const CACHE_TIME = 5 * \MINUTE_IN_SECONDS;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const REPLY_THRESH = 20; // The number of replies a user must have before the feature can be opt'd into.
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function init() {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,8 +49,8 @@
</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"> // Add a UI to enable/disable the feature.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'admin_bar_menu', __NAMESPACE__ . '\admin_bar_menu', 1000 );
- maybe_toggle();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'bbp_user_edit_after', __NAMESPACE__ . '\bbp_user_edit_after' );
+ add_action( 'bbp_profile_update', __NAMESPACE__ . '\bbp_profile_update', 10, 1 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If enabled, queue up the JS, and register the API endpoints.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( enabled() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -58,7 +57,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\wp_enqueue_scripts' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Record the user as being on the page.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'wp_head', __NAMESPACE__ . '\user_viewing', 10, 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'wp_head', function() {
+ user_viewing(); // Record the user as being on the current page.
+ } );
</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"> // Add some REST API endpoints for JS usage:
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -86,8 +87,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function allowed_for_user() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // TODO: Enable for non-moderator? users with more than x replies?
- return is_user_logged_in() && current_user_can( 'moderate' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return
+ is_user_logged_in() &&
+ (
+ current_user_can( 'moderate' ) ||
+ bbp_get_user_reply_count( get_current_user_id(), true ) >= REPLY_THRESH
+ );
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,7 +152,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> [ 'jquery', 'wp-i18n' ],
</span><span class="cx" style="display: block; padding: 0 10px"> filemtime( __DIR__ . '/wporg-bbp-also-viewing.js' )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_set_script_translations( 'also-viewing', 'wporg-bbp-also-viewing' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_script_translations( 'also-viewing', 'wporg-forums' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_localize_script(
</span><span class="cx" style="display: block; padding: 0 10px"> 'also-viewing',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -165,48 +170,39 @@
</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">- * Add a Admin bar entry to enable/disable the Also Viewing tool.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Add an option to the user profile to enable/disable it.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function admin_bar_menu( $wp_admin_bar ) {
- $args = [
- 'id' => 'toggle_translator',
- 'title' => '<span class="ab-icon dashicons-welcome-view-site"></span> ' . __( 'Also Viewing', 'wporg-bbp-also-viewing' ),
- 'href' => wp_nonce_url( add_query_arg( TOGGLE_KEY, (int)( ! enabled() ) ), NONCE ),
- 'meta' => [
- 'class' => 'toggle-also-viewing',
- 'title' => ( enabled() ? __( 'Disable also viewing', 'wporg-bbp-also-viewing' ) : __( 'Enable also viewing', 'wporg-bbp-also-viewing' ) )
- ]
- ];
- $wp_admin_bar->add_node( $args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function bbp_user_edit_after() {
+ if ( ! allowed_for_user() ) {
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Add a descriptive sub-child menu.
- $args['title'] = $args['meta']['title'];
- $args['parent'] = $args['id'];
- $args['id'] .= '-child';
- $wp_admin_bar->add_node( $args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ printf(
+ '<p>
+ <input name="also_viewing" id="also_viewing_toggle" type="checkbox" value="yes" %s>
+ <label for="also_viewing_toggle">%s</label>
+ </p>',
+ checked( enabled(), true, false ),
+ sprintf(
+ 'Enable the <a href="%s">Also Viewing</a> feature.', // TODO: Translate once text is figured out __( , 'wporg-forums' ),
+ esc_attr( 'javascript:alert("The Also Viewing feature allows regular support forum contributors to opt-in to allowing other users of this feature to see who else is viewing the current page.");' ) // TODO: This needs a support page explaining what it is.
+ )
+ );
</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">- * Handle the admin bar toggle actions.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Save the user option to enable/disable.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function maybe_toggle() {
- if (
- ! isset( $_GET[ TOGGLE_KEY ] ) ||
- ! isset( $_GET['_wpnonce'] ) ||
- ! wp_verify_nonce( $_GET['_wpnonce'], NONCE )
- ) {
- return;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function bbp_profile_update( $user_id ) {
+ $enabled = ! empty( $_REQUEST['also_viewing'] ) && 'yes' === $_REQUEST['also_viewing'];
</ins><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_meta( get_current_user_id(), USER_OPTION, (int) $_GET[ TOGGLE_KEY ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ update_user_meta( $user_id, USER_OPTION, (int) $enabled );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Cleanup.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! enabled() ) {
- clear_viewing( null, get_current_user_id() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $enabled ) {
+ clear_viewing( null, $user_id );
</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">- wp_safe_redirect( remove_query_arg( [ TOGGLE_KEY, '_wpnonce' ] ) );
- die();
</del><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>