<!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>[BuddyPress][12990] trunk/src: Add php fallback for dismissing site-wide notices.</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://buddypress.trac.wordpress.org/changeset/12990">12990</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/12990","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dcavins</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-07-08 17:23:32 +0000 (Thu, 08 Jul 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'>Add php fallback for dismissing site-wide notices.

Dismissal of sitewide notices has been handled
solely via JavaScript in the Legacy and Nouveau
template packs. This commit adds a new action
URI at `{user_profile}/messages/notices/dismiss`
that will dismiss the currently active notice for
the logged-in user.

We also add a new template function to create the
nonced link, `bp_get_message_notice_dismiss_link()`,
and make use of it in the core template function
`bp_message_get_notices()` and in the Nouveau
template for site-wide notices. In both cases, `button`
elements have been converted to `anchor` elements
linking to the new dismissal URI, so the action can be
completed even if there is a problem with JavaScript.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpmessagesactionsnoticesphp">trunk/src/bp-messages/actions/notices.php</a></li>
<li><a href="#trunksrcbpmessagesbpmessagestemplatephp">trunk/src/bp-messages/bp-messages-template.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacycssbuddypressrtlcss">trunk/src/bp-templates/bp-legacy/css/buddypress-rtl.css</a></li>
<li><a href="#trunksrcbptemplatesbplegacycssbuddypresscss">trunk/src/bp-templates/bp-legacy/css/buddypress.css</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaubuddypresscommonnoticestemplatenoticesphp">trunk/src/bp-templates/bp-nouveau/buddypress/common/notices/template-notices.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpmessagesactionsnoticesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-messages/actions/notices.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/actions/notices.php 2021-07-08 17:23:19 UTC (rev 12989)
+++ trunk/src/bp-messages/actions/notices.php   2021-07-08 17:23:32 UTC (rev 12990)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -91,4 +91,48 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        bp_core_redirect( $redirect_to );
</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_action( 'bp_actions', 'bp_messages_action_edit_notice' );
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_action( 'bp_actions', 'bp_messages_action_edit_notice' );
+
+/**
+ * Handle user dismissal of sitewide notices.
+ *
+ * @since 9.0.0
+ *
+ * @return bool False on failure.
+ */
+function bp_messages_action_dismiss_notice() {
+
+       // Bail if not viewing a notice dismissal URL.
+       if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || 'dismiss' !== sanitize_key( bp_action_variable( 0 ) ) ) {
+               return false;
+       }
+
+       // Bail if the current user isn't logged in.
+       if ( ! is_user_logged_in() ) {
+               return false;
+       }
+
+       // Check the nonce.
+       check_admin_referer( 'messages_dismiss_notice' );
+
+       // Dismiss the notice.
+       $success = bp_messages_dismiss_sitewide_notice();
+
+       // User feedback.
+       if ( $success ) {
+               $feedback = __( 'Notice has been dismissed.', 'buddypress' );
+               $type     = 'success';
+       } else {
+               $feedback = __( 'There was a problem dismissing the notice.', 'buddypress');
+               $type     = 'error';
+       }
+
+       // Add feedback message.
+       bp_core_add_message( $feedback, $type );
+
+       // Redirect.
+       $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );
+
+       bp_core_redirect( $redirect_to );
+}
+add_action( 'bp_actions', 'bp_messages_action_dismiss_notice' );
</ins></span></pre></div>
<a id="trunksrcbpmessagesbpmessagestemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-messages/bp-messages-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/bp-messages-template.php    2021-07-08 17:23:19 UTC (rev 12989)
+++ trunk/src/bp-messages/bp-messages-template.php      2021-07-08 17:23:32 UTC (rev 12990)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1311,6 +1311,35 @@
</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">+ * Output the URL for dismissing the current notice for the current user.
+ *
+ * @since 9.0.0
+ * @return string URL for dismissing the current notice for the current user.
+ */
+function bp_message_notice_dismiss_link() {
+       echo esc_url( bp_get_message_notice_dismiss_link() );
+}
+       /**
+        * Get the URL for dismissing the current notice for the current user.
+        *
+        * @since 9.0.0
+        * @return string URL for dismissing the current notice for the current user.
+        */
+       function bp_get_message_notice_dismiss_link() {
+
+               $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/dismiss/' ), 'messages_dismiss_notice' );
+
+               /**
+                * Filters the URL for dismissing the current notice for the current user.
+                *
+                * @since 9.0.0
+                *
+                * @param string $link URL for dismissing the current notice.
+                */
+               return apply_filters( 'bp_get_message_notice_dismiss_link', $link );
+       }
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Output the messages component slug.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 1.5.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1359,7 +1388,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        <div id="message" class="info notice" rel="n-<?php echo esc_attr( $notice->id ); ?>">
</span><span class="cx" style="display: block; padding: 0 10px">                                <strong><?php bp_message_notice_subject( $notice ); ?></strong>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                <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">&Chi;</span></button>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <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">&Chi;</span></a>
</ins><span class="cx" style="display: block; padding: 0 10px">                                 <?php bp_message_notice_text( $notice ); ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                <?php wp_nonce_field( 'bp_messages_close_notice', 'close-notice-nonce' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        </div>
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacycssbuddypressrtlcss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/css/buddypress-rtl.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/css/buddypress-rtl.css   2021-07-08 17:23:19 UTC (rev 12989)
+++ trunk/src/bp-templates/bp-legacy/css/buddypress-rtl.css     2021-07-08 17:23:32 UTC (rev 12990)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1428,7 +1428,9 @@
</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"> .bp-site-wide-message #message button,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-.admin-bar-on #message button {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.bp-site-wide-message #message a.button,
+.admin-bar-on #message button,
+.admin-bar-on #message a.button {
</ins><span class="cx" style="display: block; padding: 0 10px">         font-size: 0.8em;
</span><span class="cx" style="display: block; padding: 0 10px">        padding: 2px 4px;
</span><span class="cx" style="display: block; padding: 0 10px">        position: absolute;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1436,7 +1438,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        top: 0;
</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">-.admin-bar-on #message button {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.admin-bar-on #message button,
+.admin-bar-on #message a.button {
</ins><span class="cx" style="display: block; padding: 0 10px">         left: 10px;
</span><span class="cx" style="display: block; padding: 0 10px">        top: 7px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacycssbuddypresscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/css/buddypress.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/css/buddypress.css       2021-07-08 17:23:19 UTC (rev 12989)
+++ trunk/src/bp-templates/bp-legacy/css/buddypress.css 2021-07-08 17:23:32 UTC (rev 12990)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1428,7 +1428,9 @@
</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"> .bp-site-wide-message #message button,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-.admin-bar-on #message button {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.bp-site-wide-message #message a.button,
+.admin-bar-on #message button,
+.admin-bar-on #message a.button {
</ins><span class="cx" style="display: block; padding: 0 10px">         font-size: 0.8em;
</span><span class="cx" style="display: block; padding: 0 10px">        padding: 2px 4px;
</span><span class="cx" style="display: block; padding: 0 10px">        position: absolute;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1436,7 +1438,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        top: 0;
</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">-.admin-bar-on #message button {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.admin-bar-on #message button,
+.admin-bar-on #message a.button {
</ins><span class="cx" style="display: block; padding: 0 10px">         right: 10px;
</span><span class="cx" style="display: block; padding: 0 10px">        top: 7px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveaubuddypresscommonnoticestemplatenoticesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/buddypress/common/notices/template-notices.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/buddypress/common/notices/template-notices.php  2021-07-08 17:23:19 UTC (rev 12989)
+++ trunk/src/bp-templates/bp-nouveau/buddypress/common/notices/template-notices.php    2021-07-08 17:23:32 UTC (rev 12990)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,7 +12,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        <?php if ( bp_nouveau_has_dismiss_button() ) : ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                <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>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         <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>
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </aside>
</span></span></pre>
</div>
</div>

</body>
</html>