Changeset 10655
- Timestamp:
- 02/11/2021 02:05:04 AM (5 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins
- Files:
-
- 4 edited
-
support-forums/inc/class-user-notes.php (modified) (1 diff)
-
support-forums/inc/class-users.php (modified) (2 diffs)
-
wporg-bbp-also-viewing/wporg-bbp-also-viewing.js (modified) (5 diffs)
-
wporg-bbp-also-viewing/wporg-bbp-also-viewing.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php
r10615 r10655 31 31 add_action( 'bbp_theme_before_reply_content', array( $this, 'display_user_notes_in_content' ) ); 32 32 add_action( 'bbp_template_after_user_profile', array( $this, 'display_user_notes_in_profile' ) ); 33 add_action( 'bbp_user_edit_after', array( $this, 'display_user_notes_in_profile_edit' ) );33 add_action( 'bbp_user_edit_after', array( $this, 'display_user_notes_in_profile_edit' ), 20 ); 34 34 } 35 35 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php
r10321 r10655 8 8 // Add custom fields to user's profile. 9 9 add_action( 'bbp_user_edit_after_name', array( $this, 'add_custom_title_input' ) ); 10 add_action( 'bbp_user_edit_after', array( $this, 'add_options_section_header' ), 0 ); 10 11 add_action( 'bbp_user_edit_after', array( $this, 'add_auto_topic_subscription_checkbox' ) ); 11 12 … … 80 81 </div> 81 82 <?php 83 } 84 85 /** 86 * Add a section header to the extra user options. 87 */ 88 public function add_options_section_header() { 89 printf( 90 '<h2 id="user-settings" class="entry-title">%s</h2>', 91 esc_html__( 'User Options', 'wporg-forums' ) 92 ); 82 93 } 83 94 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js
r10653 r10655 10 10 page = options.currentPage || '', 11 11 banner = false, 12 bannerOffset = 200, 12 13 isTyping = false, 13 14 _n = wp.i18n._n, … … 43 44 44 45 jQuery('#main').before( 45 '<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>'46 '<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>' 46 47 ); 47 48 banner = jQuery( '#also-viewing-banner' ); … … 49 50 50 51 if ( ! userCount ) { 51 banner. show( false);52 banner.hide(); 52 53 } else { 53 54 userList = currentlyViewing.map( function( item ) { 54 return item.who + ( item.isTyping ? ' ' + __( '(is typing)', 'wporg- bbp-also-viewing' ) : '' );55 return item.who + ( item.isTyping ? ' ' + __( '(is typing)', 'wporg-forums' ) : '' ); 55 56 } ); 56 57 57 58 if ( userCount > 1 ) { 58 userlistPretty = __( '%1$s and %2$s' )59 userlistPretty = __( '%1$s and %2$s', 'wporg-forums' ) 59 60 .replace( '%1$s', userList.slice( 0, -1 ).join( ', ' ) + ( userCount > 2 ? ',' : '' ) ) 60 61 .replace( '%2$s', userList.slice( -1 ) ); … … 64 65 65 66 banner.text( 66 _n( '%s is also viewing this page.', '%s are also viewing this page.', userCount, 'wporg- bbp-also-viewing' )67 _n( '%s is also viewing this page.', '%s are also viewing this page.', userCount, 'wporg-forums' ) 67 68 .replace( '%s', userlistPretty ) 68 69 ); 69 banner.show( true ); 70 banner.show(); 71 bannerOffset = banner.offset().top - jQuery('#wpadminbar').height(); 70 72 } 71 73 } … … 77 79 } 78 80 79 if ( jQuery(window).scrollTop() > 200 ) { 81 var $main = jQuery('#main'); 82 if ( jQuery(window).scrollTop() > bannerOffset ) { 80 83 banner.css( 'position', 'fixed' ); 84 $main.css( 'padding-top', banner.height() ); 81 85 } else { 82 86 banner.css( 'position', 'initial' ); 87 $main.css( 'padding-top', 0 ); 83 88 } 84 } );89 } ); 85 90 86 91 // When a textarea is focused, mark the user as typing. -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.php
r10654 r10655 27 27 */ 28 28 29 const TOGGLE_KEY = 'toggle-also-viewing';30 29 const USER_OPTION = 'also-viewing'; 31 const NONCE = 'also-viewing';32 30 const TIMEOUT = 5 * \MINUTE_IN_SECONDS; 33 const REFRESH_INT = 45; // How often the client should check for new viewers .31 const REFRESH_INT = 45; // How often the client should check for new viewers in seconds. 34 32 const CACHE_GROUP = 'also-viewing'; 35 33 const CACHE_TIME = 5 * \MINUTE_IN_SECONDS; 34 const REPLY_THRESH = 20; // The number of replies a user must have before the feature can be opt'd into. 36 35 37 36 function init() { … … 51 50 52 51 // Add a UI to enable/disable the feature. 53 add_action( ' admin_bar_menu', __NAMESPACE__ . '\admin_bar_menu', 1000);54 maybe_toggle();52 add_action( 'bbp_user_edit_after', __NAMESPACE__ . '\bbp_user_edit_after' ); 53 add_action( 'bbp_profile_update', __NAMESPACE__ . '\bbp_profile_update', 10, 1 ); 55 54 56 55 // If enabled, queue up the JS, and register the API endpoints. … … 59 58 60 59 // Record the user as being on the page. 61 add_action( 'wp_head', __NAMESPACE__ . '\user_viewing', 10, 0 ); 60 add_action( 'wp_head', function() { 61 user_viewing(); // Record the user as being on the current page. 62 } ); 62 63 } 63 64 … … 87 88 */ 88 89 function allowed_for_user() { 89 // TODO: Enable for non-moderator? users with more than x replies? 90 return is_user_logged_in() && current_user_can( 'moderate' ); 90 return 91 is_user_logged_in() && 92 ( 93 current_user_can( 'moderate' ) || 94 bbp_get_user_reply_count( get_current_user_id(), true ) >= REPLY_THRESH 95 ); 91 96 } 92 97 … … 148 153 filemtime( __DIR__ . '/wporg-bbp-also-viewing.js' ) 149 154 ); 150 wp_set_script_translations( 'also-viewing', 'wporg- bbp-also-viewing' );155 wp_set_script_translations( 'also-viewing', 'wporg-forums' ); 151 156 152 157 wp_localize_script( … … 166 171 167 172 /** 168 * Add a Admin bar entry to enable/disable the Also Viewing tool. 169 */ 170 function admin_bar_menu( $wp_admin_bar ) { 171 $args = [ 172 'id' => 'toggle_translator', 173 'title' => '<span class="ab-icon dashicons-welcome-view-site"></span> ' . __( 'Also Viewing', 'wporg-bbp-also-viewing' ), 174 'href' => wp_nonce_url( add_query_arg( TOGGLE_KEY, (int)( ! enabled() ) ), NONCE ), 175 'meta' => [ 176 'class' => 'toggle-also-viewing', 177 'title' => ( enabled() ? __( 'Disable also viewing', 'wporg-bbp-also-viewing' ) : __( 'Enable also viewing', 'wporg-bbp-also-viewing' ) ) 178 ] 179 ]; 180 $wp_admin_bar->add_node( $args ); 181 182 // Add a descriptive sub-child menu. 183 $args['title'] = $args['meta']['title']; 184 $args['parent'] = $args['id']; 185 $args['id'] .= '-child'; 186 $wp_admin_bar->add_node( $args ); 187 } 188 189 /** 190 * Handle the admin bar toggle actions. 191 */ 192 function maybe_toggle() { 193 if ( 194 ! isset( $_GET[ TOGGLE_KEY ] ) || 195 ! isset( $_GET['_wpnonce'] ) || 196 ! wp_verify_nonce( $_GET['_wpnonce'], NONCE ) 197 ) { 173 * Add an option to the user profile to enable/disable it. 174 */ 175 function bbp_user_edit_after() { 176 if ( ! allowed_for_user() ) { 198 177 return; 199 178 } 200 179 201 update_user_meta( get_current_user_id(), USER_OPTION, (int) $_GET[ TOGGLE_KEY ] ); 180 printf( 181 '<p> 182 <input name="also_viewing" id="also_viewing_toggle" type="checkbox" value="yes" %s> 183 <label for="also_viewing_toggle">%s</label> 184 </p>', 185 checked( enabled(), true, false ), 186 sprintf( 187 'Enable the <a href="%s">Also Viewing</a> feature.', // TODO: Translate once text is figured out __( , 'wporg-forums' ), 188 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. 189 ) 190 ); 191 } 192 193 /** 194 * Save the user option to enable/disable. 195 */ 196 function bbp_profile_update( $user_id ) { 197 $enabled = ! empty( $_REQUEST['also_viewing'] ) && 'yes' === $_REQUEST['also_viewing']; 198 199 update_user_meta( $user_id, USER_OPTION, (int) $enabled ); 202 200 203 201 // Cleanup. 204 if ( ! enabled() ) { 205 clear_viewing( null, get_current_user_id() ); 206 } 207 208 wp_safe_redirect( remove_query_arg( [ TOGGLE_KEY, '_wpnonce' ] ) ); 209 die(); 202 if ( ! $enabled ) { 203 clear_viewing( null, $user_id ); 204 } 205 210 206 } 211 207
Note: See TracChangeset
for help on using the changeset viewer.