Ticket #8505: 8505.1.patch
| File 8505.1.patch, 10.7 KB (added by , 5 years ago) |
|---|
-
src/bp-messages/actions/notices.php
diff --git src/bp-messages/actions/notices.php src/bp-messages/actions/notices.php index 8a70e56cb..d39a3811a 100644
function bp_messages_action_edit_notice() { 91 91 92 92 bp_core_redirect( $redirect_to ); 93 93 } 94 add_action( 'bp_actions', 'bp_messages_action_edit_notice' ); 95 No newline at end of file 94 add_action( 'bp_actions', 'bp_messages_action_edit_notice' ); 95 96 /** 97 * Handle user dismissal of sitewide notices. 98 * 99 * @since 9.0.0 100 * 101 * @return bool False on failure. 102 */ 103 function bp_messages_action_dismiss_notice() { 104 105 // Bail if not viewing a notice dismissal URL. 106 if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || 'dismiss' !== sanitize_key( bp_action_variable( 0 ) ) ) { 107 return false; 108 } 109 110 // Bail if the current user isn't logged in. 111 if ( ! is_user_logged_in() ) { 112 return false; 113 } 114 115 // Check the nonce. 116 check_admin_referer( 'messages_dismiss_notice' ); 117 118 // Dismiss the notice. 119 $success = bp_messages_dismiss_sitewide_notice(); 120 121 // User feedback. 122 if ( $success ) { 123 $feedback = __( 'Notice has been dismissed.', 'buddypress' ); 124 $type = 'success'; 125 } else { 126 $feedback = __( 'There was a problem dismissing the notice.', 'buddypress'); 127 $type = 'error'; 128 } 129 130 // Add feedback message. 131 bp_core_add_message( $feedback, $type ); 132 133 // Redirect. 134 $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 135 136 bp_core_redirect( $redirect_to ); 137 } 138 add_action( 'bp_actions', 'bp_messages_action_dismiss_notice' ); -
src/bp-messages/bp-messages-functions.php
diff --git src/bp-messages/bp-messages-functions.php src/bp-messages/bp-messages-functions.php index 5cd08b510..07b45fb3b 100644
function bp_messages_personal_data_exporter( $email_address, $page ) { 739 739 'done' => true, 740 740 ); 741 741 } 742 743 /** 744 * Dismiss a sitewide notice for a user. 745 * 746 * @since 9.0.0 747 * 748 * @param int $user_id ID of the user to dismiss the notice for. 749 * Defaults to the logged-in user. 750 * @param int $notice_id ID of the notice to be dismissed. 751 * Defaults to the currently active notice. 752 * @return bool False on failure, true if notice is dismissed 753 * (or was already dismissed). 754 */ 755 function bp_messages_dismiss_sitewide_notice( $user_id = 0, $notice_id = 0 ) { 756 $retval = false; 757 if ( ! $user_id ) { 758 $user_id = bp_loggedin_user_id(); 759 } 760 // Bail if no user is set. 761 if ( ! $user_id ) { 762 return $retval; 763 } 764 765 if ( $notice_id ) { 766 $notice = new BP_Messages_Notice( $notice_id ); 767 } else { 768 $notice = BP_Messages_Notice::get_active(); 769 } 770 // Bail if no notice is set. 771 if ( empty( $notice->id ) ) { 772 return $retval; 773 } 774 775 // Fetch the user's closed notices and add the new item. 776 $closed_notices = bp_get_user_meta( $user_id, 'closed_notices', true ); 777 if ( empty( $closed_notices ) || ! is_array( $closed_notices ) ) { 778 $closed_notices = array(); 779 } 780 781 if ( in_array( (int) $notice->id, $closed_notices, true ) ) { 782 // The notice has already been dismissed, so there's nothing to do. 783 $retval = true; 784 } else { 785 // Add the notice to the closed_notices meta. 786 $closed_notices[] = (int) $notice->id; 787 $closed_notices = array_map( 'absint', array_unique( $closed_notices ) ); 788 $success = bp_update_user_meta( $user_id, 'closed_notices', $closed_notices ); 789 // The return value from update_user_meta() could be an integer or a boolean. 790 $retval = (bool) $success; 791 } 792 793 return $retval; 794 } -
src/bp-messages/bp-messages-template.php
diff --git src/bp-messages/bp-messages-template.php src/bp-messages/bp-messages-template.php index d6971563f..28fd25e9d 100644
function bp_message_activate_deactivate_text() { 1310 1310 return apply_filters( 'bp_message_activate_deactivate_text', $text ); 1311 1311 } 1312 1312 1313 /** 1314 * Output the URL for dismissing the current notice for the current user. 1315 * 1316 * @since 9.0.0 1317 * @return string URL for dismissing the current notice for the current user. 1318 */ 1319 function bp_message_notice_dismiss_link() { 1320 echo esc_url( bp_get_message_notice_dismiss_link() ); 1321 } 1322 /** 1323 * Get the URL for dismissing the current notice for the current user. 1324 * 1325 * @since 9.0.0 1326 * @return string URL for dismissing the current notice for the current user. 1327 */ 1328 function bp_get_message_notice_dismiss_link() { 1329 1330 $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/dismiss/' ), 'messages_dismiss_notice' ); 1331 1332 /** 1333 * Filters the URL for dismissing the current notice for the current user. 1334 * 1335 * @since 9.0.0 1336 * 1337 * @param string $link URL for dismissing the current notice. 1338 */ 1339 return apply_filters( 'bp_get_message_notice_dismiss_link', $link ); 1340 } 1341 1313 1342 /** 1314 1343 * Output the messages component slug. 1315 1344 * … … function bp_message_get_notices() { 1359 1388 ?> 1360 1389 <div id="message" class="info notice" rel="n-<?php echo esc_attr( $notice->id ); ?>"> 1361 1390 <strong><?php bp_message_notice_subject( $notice ); ?></strong> 1362 < button type="button" id="close-notice" class="bp-tooltip" data-bp-tooltip="<?php esc_attr_e( 'Dismiss this notice', 'buddypress' ) ?>"><span class="bp-screen-reader-text"><?php _e( 'Dismiss this notice', 'buddypress' ) ?></span> <span aria-hidden="true">Χ</span></button>1391 <a href="<?php bp_message_notice_dismiss_link(); ?>" id="close-notice" class="bp-tooltip button" data-bp-tooltip="<?php esc_attr_e( 'Dismiss this notice', 'buddypress' ) ?>"><span class="bp-screen-reader-text"><?php _e( 'Dismiss this notice', 'buddypress' ) ?></span> <span aria-hidden="true">Χ</span></a> 1363 1392 <?php bp_message_notice_text( $notice ); ?> 1364 1393 <?php wp_nonce_field( 'bp_messages_close_notice', 'close-notice-nonce' ); ?> 1365 1394 </div> -
src/bp-templates/bp-legacy/buddypress-functions.php
diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php index c27a6597d..2316ab487 100644
function bp_legacy_theme_ajax_close_notice() { 1623 1623 echo "-1<div id='message' class='error'><p>" . __( 'There was a problem closing the notice.', 'buddypress' ) . '</p></div>'; 1624 1624 1625 1625 } else { 1626 $user_id = get_current_user_id(); 1627 $notice_ids = bp_get_user_meta( $user_id, 'closed_notices', true ); 1628 if ( ! is_array( $notice_ids ) ) { 1629 $notice_ids = array(); 1630 } 1631 1632 $notice_ids[] = (int) $_POST['notice_id']; 1633 1634 bp_update_user_meta( $user_id, 'closed_notices', $notice_ids ); 1626 bp_messages_dismiss_sitewide_notice( bp_loggedin_user_id(), (int) $_POST['notice_id'] ); 1635 1627 } 1636 1628 1637 1629 exit; -
src/bp-templates/bp-legacy/css/buddypress-rtl.css
diff --git src/bp-templates/bp-legacy/css/buddypress-rtl.css src/bp-templates/bp-legacy/css/buddypress-rtl.css index df05d6fc6..d99591d63 100644
fieldset.create-site label { 1428 1428 } 1429 1429 1430 1430 .bp-site-wide-message #message button, 1431 .admin-bar-on #message button { 1431 .bp-site-wide-message #message a.button, 1432 .admin-bar-on #message button, 1433 .admin-bar-on #message a.button { 1432 1434 font-size: 0.8em; 1433 1435 padding: 2px 4px; 1434 1436 position: absolute; … … fieldset.create-site label { 1436 1438 top: 0; 1437 1439 } 1438 1440 1439 .admin-bar-on #message button { 1441 .admin-bar-on #message button, 1442 .admin-bar-on #message a.button { 1440 1443 left: 10px; 1441 1444 top: 7px; 1442 1445 } -
src/bp-templates/bp-legacy/css/buddypress.css
diff --git src/bp-templates/bp-legacy/css/buddypress.css src/bp-templates/bp-legacy/css/buddypress.css index 32d669fe9..be7270d71 100644
fieldset.create-site label { 1428 1428 } 1429 1429 1430 1430 .bp-site-wide-message #message button, 1431 .admin-bar-on #message button { 1431 .bp-site-wide-message #message a.button, 1432 .admin-bar-on #message button, 1433 .admin-bar-on #message a.button { 1432 1434 font-size: 0.8em; 1433 1435 padding: 2px 4px; 1434 1436 position: absolute; … … fieldset.create-site label { 1436 1438 top: 0; 1437 1439 } 1438 1440 1439 .admin-bar-on #message button { 1441 .admin-bar-on #message button, 1442 .admin-bar-on #message a.button { 1440 1443 right: 10px; 1441 1444 top: 7px; 1442 1445 } -
src/bp-templates/bp-nouveau/buddypress/common/notices/template-notices.php
diff --git src/bp-templates/bp-nouveau/buddypress/common/notices/template-notices.php src/bp-templates/bp-nouveau/buddypress/common/notices/template-notices.php index 61912fb9b..92164cf80 100644
12 12 13 13 <?php if ( bp_nouveau_has_dismiss_button() ) : ?> 14 14 15 < button type="button" class="bp-tooltip" data-bp-tooltip="<?php echo esc_attr_x( 'Close', 'button', 'buddypress' ); ?>" aria-label="<?php esc_attr_e( 'Close this notice', 'buddypress' ); ?>" data-bp-close="<?php bp_nouveau_dismiss_button_type(); ?>"><span class="dashicons dashicons-dismiss" aria-hidden="true"></span></button>15 <a href="<?php bp_message_notice_dismiss_link(); ?>" class="bp-tooltip" data-bp-tooltip="<?php echo esc_attr_x( 'Close', 'button', 'buddypress' ); ?>" aria-label="<?php esc_attr_e( 'Close this notice', 'buddypress' ); ?>" data-bp-close="<?php bp_nouveau_dismiss_button_type(); ?>"><span class="dashicons dashicons-dismiss" aria-hidden="true"></span></a> 16 16 17 17 <?php endif; ?> 18 18 </aside> -
src/bp-templates/bp-nouveau/includes/messages/ajax.php
diff --git src/bp-templates/bp-nouveau/includes/messages/ajax.php src/bp-templates/bp-nouveau/includes/messages/ajax.php index 7c5f396f8..1ab7b4259 100644
function bp_nouveau_ajax_dismiss_sitewide_notice() { 766 766 } 767 767 768 768 // Mark the active notice as closed. 769 $notice = BP_Messages_Notice::get_active(); 770 771 if ( ! empty( $notice->id ) ) { 772 $user_id = bp_loggedin_user_id(); 773 774 $closed_notices = bp_get_user_meta( $user_id, 'closed_notices', true ); 775 776 if ( empty( $closed_notices ) ) { 777 $closed_notices = array(); 778 } 779 780 // Add the notice to the array of the user's closed notices. 781 $closed_notices[] = (int) $notice->id; 782 bp_update_user_meta( $user_id, 'closed_notices', array_map( 'absint', array_unique( $closed_notices ) ) ); 769 $success = bp_messages_dismiss_sitewide_notice(); 783 770 771 if ( $success ) { 784 772 wp_send_json_success( array( 785 773 'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Sitewide notice dismissed', 'buddypress' ) . '</p></div>', 786 774 'type' => 'success', 787 775 ) ); 776 } else { 777 wp_send_json_error( array( 778 'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'There was a problem dismissing that sitewide notice', 'buddypress' ) . '</p></div>', 779 'type' => 'error', 780 ) ); 788 781 } 789 782 }