<!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][11870] trunk/src/bp-messages/classes: Notices Admin List: Handle status change action links.</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://buddypress.trac.wordpress.org/changeset/11870">11870</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/11870","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>2018-02-28 19:25:32 +0000 (Wed, 28 Feb 2018)</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'>Notices Admin List: Handle status change action links.

?\226?\128?\162 Add support for activating, deactivating and deleting site wide notices via action links on the notices list.
?\226?\128?\162 Use notice- and action-specific nonces for status change links.
?\226?\128?\162 Change success/error parameters to allow more specific feedback messages.
?\226?\128?\162 Reformat the code that creates the status change action links.
?\226?\128?\162 Prepend the currently active notice with the tag "Active:".</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpmessagesclassesclassbpmessagesnoticesadminphp">trunk/src/bp-messages/classes/class-bp-messages-notices-admin.php</a></li>
<li><a href="#trunksrcbpmessagesclassesclassbpmessagesnoticeslisttablephp">trunk/src/bp-messages/classes/class-bp-messages-notices-list-table.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpmessagesclassesclassbpmessagesnoticesadminphp"></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/classes/class-bp-messages-notices-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/classes/class-bp-messages-notices-admin.php 2018-02-28 19:25:26 UTC (rev 11869)
+++ trunk/src/bp-messages/classes/class-bp-messages-notices-admin.php   2018-02-28 19:25:32 UTC (rev 11870)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -114,6 +114,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function admin_load() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $redirect_to = false;
+
+               // Catch new notice saves.
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! empty( $_POST['bp_notice']['send'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        check_admin_referer( 'new-notice', 'ns-nonce' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -124,13 +127,46 @@
</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 ( messages_send_notice( $notice['subject'], $notice['content'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $redirect_to = add_query_arg( 'success', 1, $this->url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $redirect_to = add_query_arg( 'success', 'create', $this->url );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Notice could not be sent.
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $redirect_to = add_query_arg( 'error', 1, $this->url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $redirect_to = add_query_arg( 'error', 'create', $this->url );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Catch activation/deactivation/delete requests
+               if ( ! empty( $_GET['notice_id'] ) && ! empty( $_GET['notice_action'] ) ) {
+                       $notice_id = absint( $_GET['notice_id'] );
+
+                       check_admin_referer( 'messages-' . $_GET['notice_action'] . '-notice-' . $notice_id );
+
+                       $success = false;
+                       switch ( $_GET['notice_action'] ) {
+                               case 'activate':
+                                       $notice = new BP_Messages_Notice( $notice_id );
+                                       $success = $notice->activate();
+                                       break;
+                               case 'deactivate':
+                                       $notice = new BP_Messages_Notice( $notice_id );
+                                       $success = $notice->deactivate();
+                                       break;
+                               case 'delete':
+                                       $notice = new BP_Messages_Notice( $notice_id );
+                                       $success = $notice->delete();
+                                       break;                  
+                       }
+                       if ( $success ) {
+                               $redirect_to = add_query_arg( 'success', 'update', $this->url );
+
+                       // Notice could not be updated.
+                       } else {
+                               $redirect_to = add_query_arg( 'error', 'update', $this->url );
+                       }
+
+               }
+
+               if ( $redirect_to ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         wp_safe_redirect( $redirect_to );
</span><span class="cx" style="display: block; padding: 0 10px">                        exit();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -190,11 +226,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                        <p>
</span><span class="cx" style="display: block; padding: 0 10px">                                                <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                if ( isset( $_GET['error'] ) ) :
-                                                       esc_html_e( 'Notice was not created. Please try again.', 'buddypress' );
-                                               else :
-                                                       esc_html_e( 'Notice successfully created.', 'buddypress' );
-                                               endif;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( isset( $_GET['error'] ) ) {
+                                                       if ( 'create' === $_GET['error'] ) {
+                                                               esc_html_e( 'Notice was not created. Please try again.', 'buddypress' );
+                                                       } else {
+                                                               esc_html_e( 'Notice was not updated. Please try again.', 'buddypress' );                                                        
+                                                       }
+                                                } else {
+                                                       if ( 'create' === $_GET['success'] ) {
+                                                               esc_html_e( 'Notice successfully created.', 'buddypress' );
+                                                       } else {
+                                                               esc_html_e( 'Notice successfully updated.', 'buddypress' );
+                                                       }
+                                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                        </p>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcbpmessagesclassesclassbpmessagesnoticeslisttablephp"></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/classes/class-bp-messages-notices-list-table.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/classes/class-bp-messages-notices-list-table.php    2018-02-28 19:25:26 UTC (rev 11869)
+++ trunk/src/bp-messages/classes/class-bp-messages-notices-list-table.php      2018-02-28 19:25:32 UTC (rev 11870)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -109,21 +109,34 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function column_subject( $item ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $actions = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'activate_deactivate' => '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
-                               'page' => 'bp-notices',
-                               'activate' => $item->id
-                       ), bp_get_admin_url( 'users.php' ) ) ), 'messages_activate_notice' ) . '" data-bp-notice-id="' . $item->id . '" data-bp-action="activate">' . esc_html__( 'Activate Notice', 'buddypress' ) . '</a>',
-                       'delete' => '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
-                               'page' => 'bp-notices',
-                               'delete' => $item->id
-                       ), bp_get_admin_url( 'users.php' ) ) ), 'messages_delete_thread' ) . '" data-bp-notice-id="' . $item->id . '" data-bp-action="delete">' . esc_html__( 'Delete Notice', 'buddypress' ) . '</a>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'activate_deactivate' => sprintf( '<a href="%s" data-bp-notice-id="%d" data-bp-action="activate">%s</a>', 
+                               esc_url( wp_nonce_url( add_query_arg( array(
+                                       'page'          => 'bp-notices',
+                                       'notice_action' => 'activate',
+                                       'notice_id'     => $item->id
+                               ), bp_get_admin_url( 'users.php' ) ), 'messages-activate-notice-' . $item->id ) ),
+                               (int) $item->id,
+                               esc_html__( 'Activate Notice', 'buddypress' ) ),
+                       'delete' => sprintf( '<a href="%s" data-bp-notice-id="%d" data-bp-action="delete">%s</a>', 
+                               esc_url( wp_nonce_url( add_query_arg( array(
+                                       'page'          => 'bp-notices',
+                                       'notice_action' => 'delete',
+                                       'notice_id'     => $item->id
+                               ), bp_get_admin_url( 'users.php' ) ), 'messages-delete-notice-' . $item->id ) ),
+                               (int) $item->id,
+                               esc_html__( 'Delete Notice', 'buddypress' ) )
</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 ( ! empty( $item->is_active ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $actions['activate_deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
-                               'page' => 'bp-notices',
-                               'deactivate' => $item->id
-                       ), bp_get_admin_url( 'users.php' ) ) ), 'messages_deactivate_notice' ) . '" data-bp-notice-id="' . $item->id . '" data-bp-action="deactivate">' . esc_html__( 'Deactivate Notice', 'buddypress' ) . '</a>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $item->subject = sprintf( _x( 'Active: %s', 'Tag prepended to active site-wide notice titles on WP Admin notices list table', 'buddypress' ), $item->subject );
+                       $actions['activate_deactivate'] = sprintf( '<a href="%s" data-bp-notice-id="%d" data-bp-action="deactivate">%s</a>', 
+                               esc_url( wp_nonce_url( add_query_arg( array(
+                                       'page'          => 'bp-notices',
+                                       'notice_action' => 'deactivate',
+                                       'notice_id'     => $item->id
+                               ), bp_get_admin_url( 'users.php' ) ), 'messages-deactivate-notice-' . $item->id ) ),
+                               (int) $item->id,
+                               esc_html__( 'Deactivate Notice', 'buddypress' ) );
</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">                echo '<strong>' . apply_filters( 'bp_get_message_notice_subject', $item->subject ) . '</strong> ' . $this->row_actions( $actions );
</span></span></pre>
</div>
</div>

</body>
</html>