Making WordPress.org


Ignore:
Timestamp:
07/11/2017 07:32:32 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: When editing a link, only save new text, don't overwrite existing meta data.

Don't show "Edit" or "Delete" links for notes made on another forum.

See #2272.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php

    r5646 r5647  
    9191
    9292        $edit_note = isset( $user_notes[ $note_id ] );
     93
    9394        if ( ! $edit_note ) {
    9495            $note_id = count( $user_notes ) + 1;
    95         }
    96 
    97         // Add the new note to the array of notes.
    98         $user_notes[ $note_id ] = (object) array(
    99             'text'      => $note_text,
    100             'date'      => current_time( 'mysql' ),
    101             'post_id'   => $post_id,
    102             'site_id'   => get_current_blog_id(),
    103             'moderator' => wp_get_current_user()->user_nicename
    104         );
     96
     97            // Add the new note to the array of notes.
     98            $user_notes[ $note_id ] = (object) array(
     99                'text'      => $note_text,
     100                'date'      => current_time( 'mysql' ),
     101                'post_id'   => $post_id,
     102                'site_id'   => get_current_blog_id(),
     103                'moderator' => wp_get_current_user()->user_nicename
     104            );
     105        } else {
     106            // Save new text for an existing note.
     107            $user_notes[ $note_id ]->text = $note_text;
     108
     109            // Add site ID if missing.
     110            if ( ! isset( $user_notes[ $note_id ]->site_id ) ) {
     111                $user_notes[ $note_id ]->site_id = get_current_blog_id();
     112            }
     113        }
    105114
    106115        update_user_meta( $user_id, '_wporg_bbp_user_notes', $user_notes );
     
    260269            $redirect_on_delete = $this->get_user_note_post_permalink( get_the_ID(), $user_id, get_current_blog_id() );
    261270
     271            $note_meta = array(
     272                /* translators: 1: user note author's display name, 2: link to post, 3: date, 4: time */
     273                'author' => sprintf( __( 'By %1$s on <a href="%2$s">%3$s at %4$s</a>', 'wporg-forums' ),
     274                    sprintf( '<a href="%s">%s</a>', esc_url( home_url( "/users/$moderator/" ) ), $moderator ),
     275                    esc_url( $post_permalink ),
     276                    /* translators: localized date format, see https://secure.php.net/date */
     277                    mysql2date( __( 'F j, Y', 'wporg-forums' ), $note->date ),
     278                    /* translators: localized time format, see https://secure.php.net/date */
     279                    mysql2date( __( 'g:i a', 'wporg-forums' ), $note->date )
     280                )
     281            );
     282
     283            if ( $post_site_id == get_current_blog_id() ) {
     284
     285                $note_meta['edit'] = sprintf( '<a href="%s">%s</a>',
     286                    esc_url(
     287                        add_query_arg( array(
     288                            'action'  => 'wporg_bbp_edit_user_note',
     289                            'user_id' => $user_id,
     290                            'note_id' => $key,
     291                        ), $post_permalink )
     292                    ),
     293                    __( 'Edit', 'wporg-forums' )
     294                );
     295
     296                $note_meta['delete'] = sprintf( '<a href="%s">%s</a>',
     297                    esc_url( wp_nonce_url(
     298                        add_query_arg( array(
     299                            'action'  => 'wporg_bbp_delete_user_note',
     300                            'user_id' => $user_id,
     301                            'note_id' => $key,
     302                        ), $redirect_on_delete ),
     303                        sprintf( 'wporg-bbp-delete-user-note_%d_%d', $user_id, $key )
     304                    ) ),
     305                    __( 'Delete', 'wporg-forums' )
     306                );
     307
     308            }
     309
    262310            printf( '<div class="bbp-template-notice warning"><p>%s</p> %s</div>' . "\n",
    263311                wp_kses( $note->text, array( 'a' => array( 'href' => true ) ) ),
    264                 sprintf( '<p class="wporg-bbp-user-note-meta">%s | %s | %s</p>' . "\n",
    265                     /* translators: 1: author's display name, 2: link to post, 3: user note date, 4: user note time */
    266                     sprintf( __( 'By %1$s on <a href="%2$s">%3$s at %4$s</a>', 'wporg-forums' ),
    267                         sprintf( '<a href="%s">%s</a>', esc_url( home_url( "/users/$moderator/" ) ), $moderator ),
    268                         esc_url( $post_permalink ),
    269                         /* translators: localized date format, see https://secure.php.net/date */
    270                         mysql2date( __( 'F j, Y', 'wporg-forums' ), $note->date ),
    271                         /* translators: localized time format, see https://secure.php.net/date */
    272                         mysql2date( __( 'g:i a', 'wporg-forums' ), $note->date )
    273                     ),
    274                     sprintf( '<a href="%s">%s</a>',
    275                         esc_url(
    276                             add_query_arg( array(
    277                                 'action'  => 'wporg_bbp_edit_user_note',
    278                                 'user_id' => $user_id,
    279                                 'note_id' => $key,
    280                             ), $post_permalink )
    281                         ),
    282                         __( 'Edit', 'wporg-forums' )
    283                     ),
    284                     sprintf( '<a href="%s">%s</a>',
    285                         esc_url( wp_nonce_url(
    286                             add_query_arg( array(
    287                                 'action'  => 'wporg_bbp_delete_user_note',
    288                                 'user_id' => $user_id,
    289                                 'note_id' => $key,
    290                             ), $redirect_on_delete ),
    291                             sprintf( 'wporg-bbp-delete-user-note_%d_%d', $user_id, $key )
    292                         ) ),
    293                         __( 'Delete', 'wporg-forums' )
    294                     )
     312                sprintf( '<p class="wporg-bbp-user-note-meta">%s</p>' . "\n",
     313                    implode( ' | ', $note_meta )
    295314                )
    296315            );
Note: See TracChangeset for help on using the changeset viewer.