Making WordPress.org

Ticket #3572: 3572.8.patch

File 3572.8.patch, 49.1 KB (added by keesiemeijer, 7 years ago)

Don't allow empty comments when editing

  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/comments-edit.php

     
     1<?php namespace DevHub;
     2/**
     3 * The Template for editing user contributed notes.
     4 *
     5 * This template is used if the current user can edit a note.
     6 * The global post data is set with the pre_get_posts action.
     7 *
     8 * @package wporg-developer
     9 */
     10
     11get_header();
     12
     13$comment_id = get_query_var( 'feedback_id' );
     14$comment    = get_comment( $comment_id );
     15$post       = get_queried_object();
     16$post_id    = get_queried_object_id();
     17
     18if ( ! ( $comment && $post && $post_id ) ) {
     19        // Bail if the comment or global post data is not found.
     20        include get_404_template();
     21        return;
     22}
     23
     24$is_parent   = $comment->comment_parent ?  true : false;
     25$parent      = $is_parent ? get_comment( $comment->comment_parent ) : false;
     26$post_url    = get_permalink( $post_id );
     27$post_title  = single_post_title( '', false );
     28$post_types  = get_parsed_post_types( 'labels' );
     29$type_single = get_post_type_object( $post->post_type )->labels->singular_name;
     30$type_url    = get_post_type_archive_link( $post->post_type );
     31$type_label  = $post_types[ $post->post_type ];
     32$ref_url     = get_site_section_url();
     33$ref_link    = "<a href='{$ref_url}'>Reference</a>";
     34$post_link   = "<a href='{$post_url}'>{$post_title}</a>";
     35$note_link   = "<a href='{$post_url}#comment-{$comment_id}'>note {$comment_id}</a>";
     36$type_link   = "<a href='{$type_url}'>{$type_label}</a>";
     37
     38$parent_link   = '';
     39$parent_author = '';
     40if ( $is_parent && isset( $parent->comment_ID ) ) {
     41        $parent_author = get_note_author_link( $parent );
     42        $parent_label  = sprintf( __('note %d', 'wporg'), $parent->comment_ID );
     43        $parent_link   = "<a href='{$post_url}#comment-{$parent->comment_ID}'>{$parent_label}</a>";
     44}
     45
     46add_filter( 'breadcrumb_trail_items', function($items) use ( $ref_link, $type_link, $post_link, $note_link  ) {
     47        $items[] = $ref_link;
     48        $items[] = $type_link;
     49        $items[] = $post_link;
     50        $items[] = $note_link;
     51        $items[] = __('Edit', 'wporg');
     52        return $items;
     53} );
     54?>
     55
     56        <div id="content-area" <?php body_class( 'code-reference' ); ?>>
     57
     58                <?php breadcrumb_trail( array( 'show_title' => false ) ); ?>
     59
     60                <main id="main" class="site-main" role="main">
     61
     62                        <h1><?php printf( __( 'Edit Note %d', 'wporg' ), $comment_id ); ?></h1>
     63
     64                        <p>
     65                                <?php if ( $is_parent ) : ?>
     66                                        <?php
     67                                                /* translators: 1: comment title, 2: comment author name, 3: reference type (function, class, method, hook), 4: post title */
     68                                                printf( __( 'This is a feedback note to %1$s by %2$s for the %3$s %4$s.', 'wporg' ), $parent_link, $parent_author, strtolower( $type_single ), $post_link );
     69                                        ?>
     70                                <?php else : ?>
     71                                        <?php
     72                                                /* translators: 1: reference type (function, class, method, hook), 2: post title */
     73                                                printf( __( 'This is a note for the %1$s %2$s.', 'wporg' ), strtolower( $type_single ), $post_link ); ?>
     74                                <?php endif; ?>
     75
     76                                <?php echo ' ' . __( "You can edit this note as long as it's in moderation.", 'wporg' ); ?>
     77                        </p>
     78                        <?php
     79                                if ( \DevHub\can_user_edit_note( $comment_id ) ) {
     80
     81                                        if ( $is_parent ) {
     82                                                echo \DevHub_User_Submitted_Content::wp_editor_feedback( $comment, 'show', true );
     83                                        } else {
     84                                                $args = \DevHub_User_Submitted_Content::comment_form_args( $comment, 'edit');
     85                                                comment_form( $args );
     86                                        }
     87                                }
     88                        ?>
     89
     90                </main><!-- #main -->
     91        </div><!-- #primary -->
     92<?php get_footer(); ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/comments.php

     
    4545                                } else {
    4646                                        $ordered_comments = wporg_developer_get_ordered_notes();
    4747                                        if ( $ordered_comments ) {
    48                                                 $feedback_editor = array_filter(  wp_list_pluck( $ordered_comments, 'show_editor') );
     48                                                $feedback_editor = array_filter( wp_list_pluck( $ordered_comments, 'show_editor' ) );
    4949                                                wporg_developer_list_notes( $ordered_comments, array( 'avatar_size' => 32 ) );
    5050                                        }
    5151                                }
     
    6464
    6565        <?php if ( \DevHub\is_parsed_post_type() && DevHub\can_user_post_note( true, get_the_ID() ) ) : ?>
    6666
    67                 <?php $add_note_style = empty( $feedback_editor ) ? 'display:none;' : ''; ?>
    68                 <p id="add-user-note" style="<?php echo $add_note_style; ?>"><a href="<?php echo user_trailingslashit( get_permalink() ) . '#respond'; ?>"><?php _e( 'Have a note or feedback to contribute?', 'wporg' ); ?></a></p>
     67                <p id="add-user-note"><a href="<?php echo user_trailingslashit( get_permalink() ) . '#respond'; ?>"><?php _e( 'Have a note or feedback to contribute?', 'wporg' ); ?></a></p>
    6968
    7069                <?php
    71                 $args = array(
    72                         'logged_in_as'        => '<p class="logged-in-as">'
    73                                 . sprintf(
    74                                         /* translators: 1: user profile link, 2: accessibility text, 3: user name, 4: logout URL */
    75                                         __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
    76                                         'https://profiles.wordpress.org/' . esc_attr( wp_get_current_user()->user_nicename ),
    77                                         /* translators: %s: user name */
    78                                         esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
    79                                         $user_identity,
    80                                         wp_logout_url( apply_filters( 'the_permalink', get_permalink() ) )
    81                                 )
    82                                 . '</p><p><ul><li>'
    83                                 . __( 'Notes should supplement code reference entries, for example examples, tips, explanations, use-cases, and best practices.', 'wporg' )
    84                                 . '</li><li>'
    85                                 . __( 'Feedback can be to report errors or omissions with the documentation on this page. Such feedback will not be publicly posted.', 'wporg' )
    86                                 . '</li><li>'
    87                                 /* translators: 1: php button, 2: js button, 3: inline code button */
    88                                 . sprintf(
    89                                         __( 'You can enter text and code. Use the %1$s, %2$s, or %3$s buttons to wrap code snippets.', 'wporg' ),
    90                                         '<span class="text-button">php</span>',
    91                                         '<span class="text-button">js</span>',
    92                                         '<span class="text-button">' . __( 'inline code', 'wporg' ) . '</span>'
    93                                 )
    94                                 . '</li></ul></p>',
    95                         'comment_notes_after' => '<p>'
    96                                 . __( 'Submission Notes:', 'wporg' )
    97                                 . '<ul><li>'
    98                                 . __( 'This form is not for support requests, discussions, spam, bug reports, complaints, or self-promotion. Entries of this nature will be deleted.', 'wporg' )
    99                                 . '</li><li>'
    100                                 . __( 'In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key. In some cases the Esc key will need to be pressed twice before the Tab key will allow you to continue.', 'wporg' )
    101                                 . '</li><li class="user-notes-are-gpl">'
    102                                 . sprintf(
    103                                         /* translators: 1: GFDL link */
    104                                         __( '<strong>NOTE:</strong> All contributions are licensed under %s and are moderated before appearing on the site.', 'wporg' ),
    105                                         '<a href="https://gnu.org/licenses/fdl.html">GFDL</a>'
    106                                 )
    107                                 . '</li></ul></p>',
    108                         'label_submit'        => __( 'Add Note or Feedback', 'wporg' ),
    109                         'cancel_reply_link'   => '',
    110                         'must_log_in'         => '<p>' . sprintf(
    111                                 __( 'You must <a href="%s">log in</a> before being able to contribute a note or feedback.', 'wporg' ),
    112                                 'https://login.wordpress.org/?redirect_to=' . urlencode( get_comments_link() )
    113                         ) . '</p>',
    114                         'title_reply'         => '', //'Add Example'
    115                         'title_reply_to'      => '',
    116                 );
    117 
    118                 if ( class_exists( 'DevHub_Note_Preview' ) ) {
    119                         $args['comment_notes_after'] = DevHub_Note_Preview::comment_preview() . $args['comment_notes_after'];
    120                         $args['class_form']          = 'comment-form tab-container';
    121                 }
    122 
    123                 if ( class_exists( 'DevHub_User_Submitted_Content' ) ) {
    124                         $args['comment_field'] = DevHub_User_Submitted_Content::wp_editor_comments();
    125                 }
    126 
    127                 // Insert comment form if feedback form is not already used.
    128                 if ( empty( $feedback_editor ) ) {
     70                /* Display the comment form if the feedback form is not already displayed.
     71                 * If the feedback form is displayed Javascript is disabled.
     72                 * To display the comment form again users have to click the add-user-note link above.
     73                 */
     74                if ( empty( $feedback_editor ) && class_exists( 'DevHub_User_Submitted_Content' ) )  {
     75                        $args = \DevHub_User_Submitted_Content::comment_form_args();
    12976                        comment_form( $args );
    13077                }
    13178                ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

     
    5656require __DIR__ . '/inc/user-content-voting.php';
    5757
    5858/**
     59 * Editing for user-submitted content.
     60 */
     61require __DIR__ . '/inc/user-content-edit.php';
     62
     63/**
    5964 * CLI commands custom post type and importer.
    6065 */
    6166require __DIR__ . '/inc/cli.php';
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

     
    202202                                // Feedback links to log in, add feedback or show feedback.
    203203                                echo "<footer class='feedback-links' >\n";
    204204                                if ( $can_user_post_note ) {
    205                                         echo "EEE";
    206205                                        $feedback_link = trailingslashit( get_permalink() ) . "?replytocom={$comment_id}#feedback-editor-{$comment_id}";
    207206                                        $display       = '';
    208207                                        $aria          = '';
     
    243242                        $approved       = ( 0 < (int) $comment->comment_approved ) ? true : false;
    244243                        $is_parent      = ( 0 === (int) $comment->comment_parent ) ? true : false;
    245244                        $is_voting      = class_exists( 'DevHub_User_Contributed_Notes_Voting' );
     245                        $is_edit        = class_exists( 'DevHub_User_Content_Edit' );
    246246                        $count          = $is_voting ? (int)  DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' ) : 0;
    247247                        $curr_user_note = $is_voting ? (bool) DevHub_User_Contributed_Notes_Voting::is_current_user_note( $comment->comment_ID ) : false;
     248                        $edited_note_id = $is_edit ? DevHub_User_Content_Edit::get_edited_note() : 0;
     249                        $is_edited_note = $edited_note_id && ( (int) $comment->comment_ID === $edited_note_id );
     250                        $note_author    = \DevHub\get_note_author_link( $comment );
     251                        $can_edit_note  = \DevHub\can_user_edit_note( $comment->comment_ID );
     252                        $has_edit_cap   = current_user_can( 'edit_comment', $comment->comment_ID );
    248253
    249                         // Classes
     254                        // CSS Classes
    250255                        $comment_class = array();
    251256
    252257                        if ( -1 > $count ) {
     
    261266                                $comment_class[] = 'user-note-moderated';
    262267                        }
    263268
    264                         // This would all be moot if core passed the $comment context for 'get_comment_author_link' filter.
    265                         if ( $comment->user_id ) {
    266                                 $commenter = get_user_by( 'id', $comment->user_id );
    267                                 $url = 'https://profiles.wordpress.org/' . sanitize_key( $commenter->user_nicename ) . '/';
    268                                 $author = get_the_author_meta( 'display_name', $comment->user_id );
    269                         } else {
    270                                 $url = $comment->comment_author_url;
    271                                 $author = $comment->comment_author;
    272                         }
    273 
    274                         $comment_author_link = $author;
    275                         if ( $url ) {
    276                                 $comment_author_link = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
    277                         }
    278 
    279269                        $date = sprintf( _x( '%1$s ago', '%1$s = human-readable time difference', 'wporg' ),
    280270                                human_time_diff( get_comment_time( 'U' ),
    281271                                current_time( 'timestamp' ) )
     
    300290                                                        echo get_avatar( $comment, $args['avatar_size'] );
    301291                                                }
    302292
    303                                                 printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) );
     293                                                printf( __( 'Contributed by %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $note_author ) );
    304294                                                ?>
    305295
    306296                                                </span>
    307297                                                &mdash;
    308                                                 <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
     298                                                <a class="comment-date" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
    309299                                                        <time datetime="<?php comment_time( 'c' ); ?>">
    310300                                                        <?php echo $date; ?>
    311301                                                        </time>
    312302                                                </a>
    313303                                                <?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link">&mdash; ', '</span>' ); ?>
     304                                                <?php if ( ! $has_edit_cap && $can_edit_note ) : ?>
     305                                                        &mdash; <span class="comment-author-edit-link">
     306                                                                <a class="comment-edit-link" href="<?php echo site_url( "/reference/comment/edit/{$comment->comment_ID}" ); ?>"><?php _e( 'Edit', 'wporg' ); ?></a>
     307                                                        </span>
     308                                                <?php endif; ?>
     309                                                <?php if ( $can_edit_note && $is_edited_note ) : ?>
     310                                                        &mdash; <span class="comment-edited">
     311                                                        <?php _e( 'edited', 'wporg' ); ?>
     312                                                        </span>
     313                                                <?php endif; ?>
    314314                                                <?php if ( ! $approved ) : ?>
    315315                                                        &mdash; <span class="comment-awaiting-moderation"><?php _e( 'awaiting moderation', 'wporg' ); ?></span>
    316316                                                <?php endif; ?>
     
    325325                                        comment_text();
    326326                                } else {
    327327                                        $text = get_comment_text()  . ' &mdash; ';
    328                                         $text .= sprintf( __( 'By %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $comment_author_link ) ) . ' &mdash; ';
    329                                         $text .= ' <a href="'. esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
     328                                        $text .= sprintf( __( 'By %s', 'wporg' ), sprintf( '<cite class="fn">%s</cite>', $note_author ) ) . ' &mdash; ';
     329                                        $text .= ' <a class="comment-date" href="'. esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
    330330                                        $text .= '<time datetime="' . get_comment_time( 'c' ) . '">' . $date . '</time></a>';
    331331
    332                                         if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
     332                                        if ( $has_edit_cap ) {
    333333                                                $text .= ' &mdash; <a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) .'">';
    334334                                                $text .= __( 'Edit', 'wporg' ) . '</a>';
     335                                        } elseif ( $can_edit_note ) {
     336                                                $text .= ' &mdash; <a class="comment-edit-link" href="' . site_url( "/reference/comment/edit/{$comment->comment_ID}" ) . '">';
     337                                                $text .= __( 'Edit', 'wporg' ) . '</a>';
    335338                                        }
    336339
     340                                        if( $can_edit_note && $is_edited_note ) {
     341                                                $text .= ' &mdash; <span class="comment-edited">' . __( 'edited', 'wporg' ) . '</span>';
     342                                        }
     343
    337344                                        if ( ! $approved ) {
    338345                                                $text .= ' &mdash; <span class="comment-awaiting-moderation">' . __( 'awaiting moderation', 'wporg' ) . '</span>';
    339346                                        }
     
    13971404        }
    13981405
    13991406        /**
     1407         * Indicates if the current user can edit a user contibuted note.
     1408         *
     1409         * A user can edit a note if the note is from a parsed post type, and
     1410         *     the note is from the current user and it's not yet approved.
     1411         *     Or if the user has the 'edit_comment' capability.
     1412         *
     1413         * @param integer $note_id Note ID.
     1414         * @return bool True if the current user can edit the note.
     1415         */
     1416        function can_user_edit_note( $note_id = 0 ) {
     1417                $user = get_current_user_id();
     1418                $note = get_comment( $note_id );
     1419                if ( ! $user || ! $note ) {
     1420                        return false;
     1421                }
     1422
     1423                $post_id        = isset( $note->comment_post_ID ) ? (int) $note->comment_post_ID : 0;
     1424                $is_note_author = isset( $note->user_id ) && ( (int) $note->user_id === $user );
     1425                $is_approved    = isset( $note->comment_approved ) && ( 0 < (int) $note->comment_approved );
     1426                $can_edit_notes = isset( $note->comment_ID ) && current_user_can( 'edit_comment', $note->comment_ID );
     1427                $is_parsed_type = is_parsed_post_type( get_post_type( $post_id ) );
     1428
     1429                if ( $is_parsed_type && ( $can_edit_notes || ( $is_note_author && ! $is_approved ) ) ) {
     1430                        return true;
     1431                }
     1432
     1433                return false;
     1434        }
     1435
     1436        /**
     1437         * Get the note author link to the profiles.wordpress.org author's URL.
     1438         *
     1439         * @param WP_Comment|int $comment Comment object or comment ID.
     1440         * @return string The HTML link to the profiles.wordpress.org author's URL.
     1441         */
     1442        function get_note_author_link( $comment ) {
     1443                return get_note_author( $comment, true );
     1444        }
     1445
     1446        /**
     1447         * Get the note author nicename.
     1448         *
     1449         * @param WP_Comment|int $comment Comment object or comment ID.
     1450         * @param bool           $link. Whether to return a link to the author's profiles. Default false.
     1451         * @return string The comment author name or HTML link.
     1452         */
     1453        function get_note_author( $comment, $link = false ) {
     1454                $comment   = get_comment( $comment );
     1455                $user_id   = isset( $comment->user_id ) ? $comment->user_id : 0;
     1456                $commenter = get_user_by( 'id', $comment->user_id );
     1457                $author    = '';
     1458
     1459                if ( $user_id && isset( $commenter->user_nicename ) ) {
     1460                        $url    = 'https://profiles.wordpress.org/' . sanitize_key( $commenter->user_nicename ) . '/';
     1461                        $author = get_the_author_meta( 'display_name', $comment->user_id );
     1462                } else {
     1463                        $url    = isset( $comment->comment_author_url ) ?  $comment->comment_author_url : '';
     1464                        $author = isset( $comment->comment_author ) ?  $comment->comment_author : '';
     1465                }
     1466
     1467                if ( $link && ( $url && $author ) ) {
     1468                        $author = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
     1469                }
     1470
     1471                return $author;
     1472        }
     1473
     1474        /**
    14001475         * Gets the summary.
    14011476         *
    14021477         * The summary (aka short description) is stored in the 'post_excerpt' field.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content-edit.php

     
     1<?php
     2/**
     3 * Code Reference edit user submitted content (comments, notes, etc).
     4 *
     5 * Allows users to edit top level and child comments.
     6 *
     7 * @package wporg-developer
     8 */
     9
     10/**
     11 * Class to handle editing user submitted content.
     12 */
     13class DevHub_User_Content_Edit {
     14
     15        private static $updated_note = 0;
     16
     17        /**
     18         * Initializer
     19         */
     20        public static function init() {
     21                add_action( 'init', array( __CLASS__, 'do_init' ) );
     22        }
     23
     24        /**
     25         * Handles adding hooks to enable editing comments.
     26         * Adds rewrite rules for editing comments in the front end.
     27         */
     28        public static function do_init() {
     29                // Add the edit comment rewrite rule
     30                add_rewrite_rule( 'reference/comment/edit/([0-9]{1,})/?$', 'index.php?feedback_id=$matches[1]', 'top' );
     31
     32                // Add feedback_id query var for editing.
     33                add_filter( 'query_vars',                      array( __CLASS__, 'comment_query_var' ) );
     34
     35                // Redirect to home page if the edit request is invalid.
     36                add_action( 'template_redirect',               array( __CLASS__, 'redirect_invalid_edit_request' ) );
     37
     38                // Include the comment edit template.
     39                add_filter( 'template_include',                array( __CLASS__, 'template_include' ) );
     40
     41                // Set the post_type and post for an edit request.
     42                add_action( 'pre_get_posts',                   array( __CLASS__, 'pre_get_posts' ) );
     43
     44                // Update the comment.
     45                add_action( 'wp', array( __CLASS__, 'update_comment' ) );
     46        }
     47
     48        /**
     49         * Get the note ID that was edited.
     50         *
     51         * @return int Note ID that was edited or 0.
     52         */
     53        public static function get_edited_note() {
     54                return self::$updated_note ? (int) self::$updated_note : 0;
     55        }
     56
     57        /**
     58         * Add feedback_id to the public query vars.
     59         *
     60         * @param array $query_vars Array with public query vars.
     61         * @return array Public query vars.
     62         */
     63        public static function comment_query_var( $query_vars ) {
     64                $query_vars[] = 'feedback_id';
     65                return $query_vars;
     66        }
     67
     68        /**
     69         * Update a comment after editing.
     70         */
     71        public static function update_comment() {
     72                self::$updated_note = 0;
     73
     74                if ( ! is_single() ||  ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) ) {
     75                        return;
     76                }
     77
     78                $comment_data = wp_unslash( $_POST );
     79
     80                $defaults = array(
     81                        'edit_contributed_note',
     82                        '_wpnonce',
     83                        'comment_ID',
     84                        'comment',
     85                        'comment_parent',
     86                        'comment_post_ID'
     87                );
     88
     89                foreach ( $defaults as $value ) {
     90                        if ( ! isset( $comment_data[ $value ] ) ) {
     91                                // Return if any of the $_POST keys are missing.
     92                                return;
     93                        }
     94                }
     95
     96                $comment = trim( (string) $comment_data['comment'] );
     97                if ( ! $comment ) {
     98                        // Bail and provide a way back to the edit form if a comment is empty.
     99                        $msg  = __( '<strong>ERROR</strong>: please type a comment.', 'wporg' );
     100                        $args = array( 'response' => 200, 'back_link' => true );
     101                        wp_die( '<p>' . $msg . '</p>', __( 'Comment Submission Failure', 'wporg' ), $args );
     102                }
     103
     104                $post_id       = absint( $comment_data['comment_post_ID'] );
     105                $comment_id    = absint( $comment_data['comment_ID'] );
     106                $can_user_edit = DevHub\can_user_edit_note( $comment_id );
     107                $action        = 'update-note_' . $comment_id;
     108                $is_nonce      = wp_verify_nonce( $comment_data['_wpnonce'], $action );
     109                $is_post_type  = $post_id && is_singular( get_post_type( $post_id ) );
     110                $is_id         = $post_id && ( $post_id === get_the_ID() );
     111
     112                if ( $is_id && $is_post_type && $is_nonce && $can_user_edit ) {
     113                        self::$updated_note = $comment_id;
     114                        $comment = trim( (string) $comment_data['comment'] );
     115                        $comment_data['comment_content'] = $comment;
     116                        wp_update_comment( $comment_data );
     117                }
     118        }
     119
     120        /**
     121         * Redirects to the home page if the edit request is invalid for the current user.
     122         *
     123         * Redirects if the comment doesn't exist.
     124         * Redirects if the comment is not for a parsed post type.
     125         * Redirects if the current user is not the comment author.
     126         * Redirects if a comment is already approved.
     127         *
     128         * Doesn't redirect for users with the edit_comment capability.
     129         */
     130        public static function redirect_invalid_edit_request() {
     131                $comment_id = absint( get_query_var( 'feedback_id' ) );
     132                if ( ! $comment_id ) {
     133                        // Not a query for editing a note.
     134                        return;
     135                }
     136
     137                if ( ! DevHub\can_user_edit_note( $comment_id ) ) {
     138                        wp_redirect( home_url() );
     139                        exit();
     140                }
     141        }
     142
     143        /**
     144         * Use the 'comments-edit.php' template for editing comments.
     145         *
     146         * The current user has already been verified in the template_redirect action.
     147         *
     148         * @param string $template Template to include.
     149         * @return string Template to include.
     150         */
     151        public static function template_include( $template ) {
     152                $comment = get_query_var( 'feedback_id' );
     153                if ( ! $comment ) {
     154                        // Not a query for editing a note.
     155                        return $template;
     156                }
     157
     158                $comment_template = get_query_template( "comments-edit" );
     159                if ( $comment_template ) {
     160                        $template = $comment_template;
     161                }
     162                return $template;
     163        }
     164
     165        /**
     166         * Sets the post and post type for an edit request.
     167         *
     168         * Trows a 404 if the current user can't edit the requested note.
     169         *
     170         * @param WP_Query $query The WP_Query instance (passed by reference)
     171         */
     172        public static function pre_get_posts( $query ) {
     173                $comment_id = $query->get( 'feedback_id' );
     174
     175                if ( is_admin() || ! ( $query->is_main_query() && $comment_id ) ) {
     176                        // Not a query for editing a note.
     177                        return;
     178                }
     179
     180                if ( DevHub\can_user_edit_note( $comment_id ) ) {
     181                        $comment = get_comment( $comment_id );
     182                        if ( isset( $comment->comment_post_ID ) ) {
     183                                $query->is_singular = true;
     184                                $query->is_single = true;
     185                                $query->set( 'post_type', get_post_type( $comment->comment_post_ID ) );
     186                                $query->set( 'p', $comment->comment_post_ID );
     187
     188                                return;
     189                        }
     190                }
     191
     192                // Set 404 if a user can't edit a note.
     193                $query->set_404();
     194        }
     195
     196} // DevHub_User_Content_Edit
     197
     198DevHub_User_Content_Edit::init();
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php

     
    5050                remove_filter( 'comment_text',                 'capital_P_dangit',   31 );
    5151
    5252                // Enable shortcodes for comments
    53                 add_filter( 'comment_text',                    'do_shortcode');
     53                add_filter( 'comment_text',                    'do_shortcode' );
    5454
    5555                // Customize allowed tags
    5656                add_filter( 'wp_kses_allowed_html',            array( __CLASS__, 'wp_kses_allowed_html' ), 10, 2 );
     
    6767                // Allowed HTML for an edited child comment (There is no decent hook to filter child comments only)
    6868                add_action( 'edit_comment',                    array( __CLASS__, 'comment_edit_allowed_html' ) );
    6969
     70                // Adds hidden fields for editing to a comment form
     71                add_filter( 'comment_form_submit_field',       array( __CLASS__, 'add_hidden_fields' ), 10, 2 );
    7072        }
    7173
    7274        /**
     
    167169                        wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array( 'jquery', 'quicktags' ), '20180323', true );
    168170                        wp_enqueue_script( 'wporg-developer-user-notes-feedback', get_template_directory_uri() . '/js/user-notes-feedback.js', array( 'jquery', 'quicktags' ), '20180323', true );
    169171                        wp_localize_script( 'wporg-developer-user-notes-feedback', 'wporg_note_feedback', array(
    170                                 'show' => __( 'Show Feedback', 'wporg' ),
    171                                 'hide' => __( 'Hide Feedback', 'wporg' ),
    172                         ) );
     172                                        'show' => __( 'Show Feedback', 'wporg' ),
     173                                        'hide' => __( 'Hide Feedback', 'wporg' ),
     174                                ) );
    173175                }
    174176        }
    175177
     
    176178        /**
    177179         * Sets the default language for SyntaxHighlighter shortcode.
    178180         *
    179          * @param  array $atts Shortcode attributes.
     181         * @param array $atts Shortcode attributes.
    180182         * @return array
    181183         */
    182184        public static function syntaxhighlighter_shortcodeatts( $atts ) {
     
    187189        /**
    188190         * Subverts capital_P_dangit for SyntaxHighlighter shortcode.
    189191         *
    190          * @param  string $code
     192         * @param string $code
    191193         * @return string
    192194         */
    193195        public static function syntaxhighlighter_precode( $code ) {
     
    195197        }
    196198
    197199        /**
     200         * Add hidden fields to the comment form if the context is 'edit'
     201         *
     202         * @param string $submit_field HTML string with the submit button fields.
     203         * @param array  $args         Arguments for the comment form.
     204         * @return HTML string with the submit button fields.
     205         */
     206        public static function add_hidden_fields( $submit_field, $args ) {
     207                $context = isset( $args['context'] ) ? $args['context'] : '';
     208                $comment = isset( $args['comment_edit'] ) ? $args['comment_edit'] : false;
     209                if ( ! ( $comment && ( 'edit' === $context ) ) ) {
     210                        return $submit_field;
     211                }
     212
     213                $comment_id = isset( $comment->comment_ID ) ? $comment->comment_ID : 0;
     214
     215                return $submit_field . self::get_edit_fields( $comment_id, $instance = 0 );
     216        }
     217
     218        /**
     219         * Get the comment form arguments by context.
     220         *
     221         * @param WP_Comment|false $comment Comment object or false. Default false.
     222         * @param string           $context Context of arguments. Accepts 'edit' or empty string.
     223         * @return array Array with comment form arguments.
     224         */
     225        public static function comment_form_args( $comment = false, $context = '' ) {
     226                $label = _x( 'Add Note or Feedback', 'noun', 'wporg' );
     227                if ( 'edit' === $context ) {
     228                        $label = _x( 'Edit Note', 'noun', 'wporg' );
     229                }
     230
     231                $args = array(
     232                        'logged_in_as'        => '<p class="logged-in-as">'
     233                        . sprintf(
     234                                /* translators: 1: user profile link, 2: accessibility text, 3: user name, 4: logout URL */
     235                                __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
     236                                'https://profiles.wordpress.org/' . esc_attr( wp_get_current_user()->user_nicename ),
     237                                /* translators: %s: user name */
     238                                esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
     239                                $user_identity,
     240                                wp_logout_url( apply_filters( 'the_permalink', get_permalink() ) )
     241                        )
     242                        . '</p><p><ul><li>'
     243                        . __( 'Notes should supplement code reference entries, for example examples, tips, explanations, use-cases, and best practices.', 'wporg' )
     244                        . '</li><li>'
     245                        . __( 'Feedback can be to report errors or omissions with the documentation on this page. Such feedback will not be publicly posted.', 'wporg' )
     246                        . '</li><li>'
     247                        /* translators: 1: php button, 2: js button, 3: inline code button */
     248                        . sprintf(
     249                                __( 'You can enter text and code. Use the %1$s, %2$s, or %3$s buttons to wrap code snippets.', 'wporg' ),
     250                                '<span class="text-button">php</span>',
     251                                '<span class="text-button">js</span>',
     252                                '<span class="text-button">' . __( 'inline code', 'wporg' ) . '</span>'
     253                        )
     254                        . '</li></ul></p>',
     255                        'comment_notes_after' => '<p>' . __( 'Submission Notes:', 'wporg' ) . '</p>' . self::get_editor_rules(),
     256                        'label_submit'        => $label,
     257                        'cancel_reply_link'   => '',
     258                        'must_log_in'         => '<p>' . sprintf(
     259                                __( 'You must <a href="%s">log in</a> before being able to contribute a note or feedback.', 'wporg' ),
     260                                'https://login.wordpress.org/?redirect_to=' . urlencode( get_comments_link() )
     261                        ) . '</p>',
     262                        'title_reply'         => '', //'Add Example'
     263                        'title_reply_to'      => '',
     264                );
     265
     266                if ( class_exists( 'DevHub_Note_Preview' ) ) {
     267                        $args['comment_notes_after'] = DevHub_Note_Preview::comment_preview() . $args['comment_notes_after'];
     268                        $args['class_form']          = "comment-form tab-container";
     269                }
     270
     271                $args['comment_field'] = self::wp_editor_comments( $label, $comment );
     272                $args['context'] = $context;
     273                $args['comment_edit'] = $comment;
     274
     275                if ( $comment && ( 'edit' === $context ) ) {
     276                        $comment_id = isset( $comment->comment_ID ) ? $comment->comment_ID : 0;
     277                        $post_id    = isset( $comment->comment_post_ID ) ? $comment->comment_post_ID : 0;
     278
     279                        $args['action'] = get_permalink( $post_id ) . '#comment-' . $comment_id;
     280                }
     281
     282                return $args;
     283        }
     284
     285        /**
    198286         * Capture an {@see wp_editor()} instance as the 'User Contributed Notes' comment form.
    199287         *
    200288         * Uses output buffering to capture the editor instance for use with the {@see comments_form()}.
    201289         *
     290         * @param string           $label   Label used for the editor.
     291         * @param WP_Comment|false $comment Comment object or false. Default false.
    202292         * @return string HTML output for the wp_editor-ized comment form.
    203293         */
    204         public static function wp_editor_comments() {
     294        public static function wp_editor_comments( $label, $comment = false ) {
     295                $content = isset( $comment->comment_content ) ? trim( $comment->comment_content ) : '';
     296
     297                // wp_kses() converts htmlspecialchars in source code.
     298                $content = $content ? htmlspecialchars_decode( $content ) : '';
     299
    205300                ob_start();
    206                 echo '<h3><label for="comment">' . _x( 'Add Note or Feedback', 'noun', 'wporg' ) . '</label></h3>';
     301                echo '<h3><label for="comment">' . $label . '</label></h3>';
    207302
    208303                if ( class_exists( 'DevHub_Note_Preview' ) ) {
    209                         echo '<ul class="tablist" style="display:none;">';
     304                        echo "<ul class='tablist' style='display: none;'>";
    210305                        echo '<li><a href="#comment-form-comment">' . __( 'Write', 'wporg' ) . '</a></li>';
    211306                        echo '<li><a href="#comment-preview">' . __( 'Preview', 'wporg' ) . '</a></li></ul>';
    212307                }
    213308
    214                 $style = '<style type="text/css">';
    215                 ob_start();
    216                 include get_stylesheet_directory() . '/stylesheets/editor-style.css';
    217                 $style .= ob_get_clean();
    218                 $style .=' </style>';
    219 
    220309                echo '<div class="comment-form-comment tab-section" id="comment-form-comment">';
    221                 wp_editor( '', 'comment', array(
    222                         'media_buttons' => false,
    223                         'editor_css'    => $style,
    224                         'textarea_name' => 'comment',
    225                         'textarea_rows' => 8,
    226                         'quicktags'     => array(
    227                                 'buttons' => 'strong,em,ul,ol,li'
    228                         ),
    229                         'teeny'         => true,
    230                         'tinymce'       => false,
    231                 ) );
     310                wp_editor( $content, 'comment', array(
     311                                'media_buttons' => false,
     312                                'editor_css'    => self::get_editor_style(),
     313                                'textarea_name' => 'comment',
     314                                'textarea_rows' => 8,
     315                                'quicktags'     => array(
     316                                        'buttons' => 'strong,em,ul,ol,li'
     317                                ),
     318                                'teeny'         => true,
     319                                'tinymce'       => false,
     320                        ) );
    232321                echo '</div>';
    233322                return ob_get_clean();
    234323        }
     
    238327         *
    239328         * Uses output buffering to capture the editor instance.
    240329         *
     330         * @param WP_Comment|false $comment Comment object or false. Default false.
     331         * @param string           $display Display the editor. Default 'show'.
     332         * @param bool             $edit    True if the editor used for editing a note. Default false.
    241333         * @return string HTML output for the wp_editor-ized feedback form.
    242334         */
    243         public static function wp_editor_feedback( $comment, $display = 'show', $content = '' ) {
     335        public static function wp_editor_feedback( $comment, $display = 'show', $edit = false ) {
    244336
    245337                if ( ! ( isset( $comment->comment_ID ) && absint( $comment->comment_ID ) ) ) {
    246338                        return '';
     
    251343                static $instance = 0;
    252344                $instance++;
    253345
    254                 $display     = ( 'hide' === $display ) ? ' style="display: none;"' : '';
    255                 $title       = __( 'Add feedback to this note', 'wporg' );
    256                 $form_type   = '';
    257                 $button_text = __( 'Add Feedback', 'wporg' );
     346                $display       = ( 'hide' === $display ) ? ' style="display: none;"' : '';
     347                $parent        = $comment_id;
     348                $action        = site_url( '/wp-comments-post.php' );
     349                $content       = '';
     350                $title         = __( 'Add feedback to this note', 'wporg' );
     351                $form_type     = '';
     352                $button_text   = __( 'Add Feedback', 'wporg' );
     353                $post_id       = isset( $comment->comment_post_ID ) ? $comment->comment_post_ID : get_the_ID();
     354                $note_link     = '';
    258355
    259                 if ( $content ) {
     356                if ( $edit ) {
     357                        $content     = isset( $comment->comment_content ) ? $comment->comment_content : '';
    260358                        $title       = __( 'Edit feedback', 'wporg' );
    261359                        $form_type   = '-edit';
    262                         $button_text = __( 'Edit Feedback', 'wporg' );
     360                        $button_text = __( 'Edit Note', 'wporg' );
     361                        $action      = get_permalink( $post_id ) . '#comment-' . $comment_id;
     362
     363                        $parent        = isset( $comment->comment_parent ) ? $comment->comment_parent : 0;
     364                        $parent_url    = get_permalink( $post_id ) . '#comment-' . $parent;
     365                        $parent_author = \DevHub\get_note_author( $parent );
     366                        $parent_note   = sprintf( __( 'note %d', 'wporg' ), $parent );
     367
     368                        /* translators: 1: note, 2: note author name */
     369                        $note_link = sprintf( __( '%1$s by %2$s', 'wporg' ), "<a href='{$parent_url}'>{$parent_note}</a>", $parent_author );
    263370                }
    264371
    265372                $allowed_tags = '';
     
    269376
    270377                ob_start();
    271378                echo "<div id='feedback-editor-{$comment_id}' class='feedback-editor'{$display}>\n";
    272                 echo "<p class='feedback-editor-title'>{$title}</p>\n";
    273                 echo '<form id="feedback-form-' . $instance . $form_type . '" class="feedback-form" method="post" action="' . site_url( '/wp-comments-post.php' ) . '" name="feedback-form-' . $instance ."\">\n";
     379                if ( ! $edit ) {
     380                        echo "<p class='feedback-editor-title'>{$title}</p>\n";
     381                }
    274382
    275                 wp_editor( '', 'feedback-' . $instance, array(
    276                         'media_buttons' => false,
    277                         'textarea_name' => 'comment',
    278                         'textarea_rows' => 3,
    279                         'quicktags'     => array(
    280                                 'buttons' => 'strong,em'
    281                         ),
    282                         'teeny'         => true,
    283                         'tinymce'       => false,
    284                 ) );
     383                echo "<form id='feedback-form-{$instance}{$form_type}' class='feedback-form' method='post' action='{$action}' name='feedback-form-{$instance}'>\n";
     384                echo self::get_editor_rules( 'feedback', $note_link );
     385                wp_editor( $content, 'feedback-' . $instance, array(
     386                                'media_buttons' => false,
     387                                'textarea_name' => 'comment',
     388                                'textarea_rows' => 3,
     389                                'quicktags'     => array(
     390                                        'buttons' => 'strong,em'
     391                                ),
     392                                'editor_css'    => self::get_editor_style(),
     393                                'teeny'         => true,
     394                                'tinymce'       => false,
     395                        ) );
    285396
    286397                echo '<p><strong>' . __( 'Note', 'wporg' ) . '</strong>: ' . __( 'No newlines allowed', 'wporg' ) . '. ';
    287398                printf( __( 'Allowed tags: %s', 'wporg' ), trim( $allowed_tags, ', ' ) ) . "</p>\n";
    288                 echo "<p><input id='submit-{$instance}' class='submit' type='submit' value='Add Feedback' name='submit-{$instance}'>\n";
    289                 echo "<input type='hidden' name='comment_post_ID' value='" . get_the_ID() . "' id='comment_post_ID-{$instance}' />\n";
    290                 echo "<input type='hidden' name='comment_parent' id='comment_parent-{$instance}' value='{$comment_id}' />\n";
     399                echo "<p><input id='submit-{$instance}' class='submit' type='submit' value='{$button_text}' name='submit-{$instance}'>\n";
     400                echo "<input type='hidden' name='comment_post_ID' value='{$post_id}' id='comment_post_ID-{$instance}' />\n";
     401                echo "<input type='hidden' name='comment_parent' id='comment_parent-{$instance}' value='{$parent}' />\n";
     402
     403                if ( $edit ) {
     404                        echo self::get_edit_fields( $comment_id, $instance );
     405                }
     406
    291407                echo "</p>\n</form>\n</div><!-- #feedback-editor-{$comment_id} -->\n";
    292408                return ob_get_clean();
    293409        }
    294410
     411        /**
     412         * Get the rules list for the comment form.
     413         *
     414         * @param string $context Accepts 'feedback' or empty sring
     415         * @return string Editor rules.
     416         */
     417        function get_editor_rules( $context = '', $note_link = '' ) {
     418                $license_rule = sprintf(
     419                        /* translators: 1: GFDL link */
     420                        __( '<strong>NOTE:</strong> All contributions are licensed under %s and are moderated before appearing on the site.', 'wporg' ),
     421                        '<a href="https://gnu.org/licenses/fdl.html">GFDL</a>'
     422                );
     423
     424                if ( 'feedback' === $context ) {
     425                        $feedback_rule = __( 'Use this form to report errors or to add additional information to this note.', 'wporg' );
     426                        if ( $note_link ) {
     427                                $feedback_rule = sprintf( __( 'Use this form to report errors or to add additional information to %s.', 'wporg' ), $note_link );
     428                        }
     429
     430                        return '<ul><li>'
     431                                . __( 'Feedback is part of the documentation.', 'wporg' ) . ' '
     432                                . $feedback_rule
     433                                . '</li><li>'
     434                                . __( 'This form is not for support requests, spam, bug reports, complaints, or self-promotion. Entries of this nature will be deleted.', 'wporg' )
     435                                . '</li><li class="user-notes-are-gpl">'
     436                                . $license_rule
     437                                . '</li></ul>';
     438                }
     439
     440                return '<ul><li>'
     441                        . __( 'This form is not for support requests, discussions, spam, bug reports, complaints, or self-promotion. Entries of this nature will be deleted.', 'wporg' )
     442                        . '</li><li>'
     443                        . __( 'In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key. In some cases the Esc key will need to be pressed twice before the Tab key will allow you to continue.', 'wporg' )
     444                        . '</li><li class="user-notes-are-gpl">'
     445                        . $license_rule
     446                        . '</li></ul>';
     447        }
     448
     449        /**
     450         * Get the editor styles.
     451         *
     452         * @return string Editor styles.
     453         */
     454        function get_editor_style() {
     455                $style = '<style type="text/css">';
     456                ob_start();
     457                include get_stylesheet_directory() . '/stylesheets/editor-style.css';
     458                $style .= ob_get_clean();
     459                $style .= ' </style>';
     460                return $style;
     461        }
     462
     463        /**
     464         * Get the hidden input fields HTML used when editing.
     465         *
     466         * @param int     $comment_id Comment ID.
     467         * @param integer $instance   Comment form instance number used in HTML id's.
     468         * @return string Hidden input fields HTML.
     469         */
     470        function get_edit_fields( $comment_id, $instance = 0 ) {
     471                $fields = "<input type='hidden' name='comment_ID' id='comment_ID-{$instance}' value='{$comment_id}' />\n";
     472                $fields .= "<input type='hidden' name='edit_contributed_note' id='edit_note_feedback-{$instance}' value='1' />\n";
     473                $fields .= wp_nonce_field( 'update-note_' . $comment_id, '_wpnonce', true, false );
     474
     475                return $fields;
     476        }
     477
    295478} // DevHub_User_Submitted_Content
    296479
    297480DevHub_User_Submitted_Content::init();
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes-feedback.js

     
    44                return;
    55        }
    66
     7        var wpAdminBar     = 0;
    78        var options        = wporg_note_feedback;
    8         var wpAdminBar     = $('#page.admin-bar').length ? 32 : 0;
    99        var feedbackToggle = $( '<a class="feedback-toggle" href="#">' + options.show + '</a>' );
    1010        var hash           = window.location.hash;
    1111
     
    7878
    7979        // Show hidden child comments if the fragment identifier is a comment ID (e.g. #comment-63). 
    8080        $( document ).ready( function() {
    81 
     81                wpAdminBar = $('#wpadminbar').length ? 32 : 0
    8282                var childComments = $( '.comment' ).find( 'ul.children' );
    8383
    84                 if ( !( hash.length && childComments.length ) ) {
     84                if ( ! ( hash.length && childComments.length ) ) {
    8585                        return;
    8686                }
    8787
    88                 var hashComment = childComments.find( hash ).first();
    89                 if ( hashComment.length ) {
    90                         // Child comment exists.
     88                var hashComment = childComments.find( hash + '.depth-2' ).first();
     89                if ( ! hashComment.length ) {
     90                        return;
     91                }
     92                // Child comment exists.
    9193
    92                         var parent = hashComment.closest( '.comment.depth-1' );
    93                         if ( parent.find( '.feedback' ).hasClass( 'hide-if-js' ) ) {
    94                                 // Show child comments.
    95                                 parent.find( '.feedback-toggle' ).first().trigger( 'click' );
    96                         }
     94                var parent = hashComment.closest( '.comment.depth-1' );
     95                if ( parent.find( '.feedback' ).hasClass( 'hide-if-js' ) ) {
     96                        // Show child comments.
     97                        parent.find( '.feedback-toggle' ).first().trigger( 'click' );
     98                }
    9799
    98                         // Scroll to the child comment.
    99                         var pos = hashComment.offset();
    100                         $( 'html,body' ).animate( {
    101                                 scrollTop: pos.top - wpAdminBar
    102                         }, 1 );
    103                 }
     100                // Scroll to child comment and adjust for admin bar
     101                var pos = hashComment.offset();
     102                $( 'html,body' ).animate( {
     103                        scrollTop: pos.top - wpAdminBar
     104                }, 1 );
     105
    104106        } );
    105107
    106108        // Show/Hide feedback toggle link.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes-preview.js

     
    2020                text = '';
    2121                processing = false;
    2222
     23                // Show tabs with Javascript.
     24                $( '#commentform .tablist').show();
     25
    2326                if ( textarea.length && preview.length && tabs.length ) {
    2427
    2528                        // Append spinner to preview tab
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes.js

     
    55
    66( function( $ ) {
    77
    8         var commentForm = $( '.comment-form textarea' );
     8        var commentForm = $( '.comment-form textarea' );       
     9        var hash = window.location.hash;
     10        var wpAdminBar = 0;
    911
    10         if ( !commentForm.length ) {
    11                 return;
     12        // Check if the fragment identifier is a comment ID (e.g. #comment-63)
     13        if ( ! hash.match( /#comment\-[0-9]+$/ ) ) {
     14                hash = '';
    1215        }
    1316
     17        // Scroll to top level comments
     18        $( document ).ready( function() {
     19                wpAdminBar = $( '#wpadminbar' ).length ? 32 : 0;
     20                if( ! wpAdminBar || ! hash ) {
     21                        return;
     22                }
     23
     24                var hashComment = $('#comments').find( hash + '.depth-1' ).first();
     25                if( ! hashComment.length  ) {
     26                        return;
     27                }
     28
     29                // Scroll to top level comment and adjust for admin bar.
     30                var pos = hashComment.offset();
     31                $( 'html,body' ).animate( {
     32                        scrollTop: pos.top - wpAdminBar
     33                }, 1 );
     34        } );
     35
     36        // Scroll to comment if comment date link is clicked
     37        $( '#comments' ).on( 'click', '.comment-date', function( e ) {
     38                e.preventDefault();
     39
     40                // Scroll to comment and adjust for admin bar
     41                // Add 16px for child comments
     42                var pos = $( this ).offset();
     43                $( 'html,body' ).animate( {
     44                        scrollTop: pos.top - wpAdminBar - 16
     45                }, 1 );
     46        } );
     47
    1448        function showCommentForm() {
     49                $( '#add-user-note' ).hide();
    1550                $( '#respond' ).show();
    16                 $( '#add-user-note' ).hide();
    1751
    18                 var wpAdminBar = $( '#page.admin-bar' ).length ? 32 : 0;
    1952                var target     = $( '#commentform #add-note-or-feedback' );
    2053                if ( target.length ) {
    2154                        var pos = target.offset();
     
    2861                }
    2962        }
    3063
    31         $( '#respond, #add-user-note' ).toggle();
     64        if ( ! commentForm.length ) {
     65                return;
     66        }
     67
     68        if( $('#add-user-note').length ) {
     69                // Hide by default if #add-user-note exists
     70                $( '#respond' ).hide();
     71        }
     72
    3273        $( '#add-user-note, .table-of-contents a[href="#add-note-or-feedback"]' ).click( function( e ) {
    3374                e.preventDefault();
    3475
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

     
    11371137                        opacity: 1;
    11381138                }
    11391139
    1140                 .comment-awaiting-moderation {
     1140                .comment-awaiting-moderation,
     1141                .comment-edited {
    11411142                        background-color: #fff8e5;
    11421143                        padding: .2em .5em;
     1144                        margin-right: .5em;
    11431145                        border-radius: 3px;
    11441146                        border: 1px solid #ffb900;
    11451147                }
    11461148
    1147                 .depth-2 .comment-awaiting-moderation {
     1149                .depth-2 .comment-awaiting-moderation,
     1150                .depth-2 .comment-edited {
    11481151                        display: inline-block;
    11491152                        margin: 2px 0;
    11501153                }
     
    11701173                .comment-list li.depth-1,
    11711174                #comment-preview {
    11721175                        border: 1px solid #dfdfdf;
    1173                         border-radius: 2px;
     1176                        border-radius: 2px;     
     1177                        width: 100%;
    11741178                }
    11751179
    11761180                // Feedback
     
    13621366                        padding: 0 5px;
    13631367                }
    13641368
    1365                 .comment-form ul {
     1369                .comment-form ul, .feedback-form ul {
    13661370                        margin-left: 1.5em;
    13671371                }
     1372
     1373                .feedback-form ul li {
     1374                        margin: 0;
     1375                        overflow: visible;
     1376                }
    13681377        }
    13691378
    13701379        &.single-post {
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

     
    15141514  opacity: 1;
    15151515}
    15161516
    1517 .devhub-wrap .single-wp-parser-function .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-method .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-hook .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-class .comment-awaiting-moderation {
     1517.devhub-wrap .single-wp-parser-function .comment-awaiting-moderation,
     1518.devhub-wrap .single-wp-parser-function .comment-edited, .devhub-wrap .single-wp-parser-method .comment-awaiting-moderation,
     1519.devhub-wrap .single-wp-parser-method .comment-edited, .devhub-wrap .single-wp-parser-hook .comment-awaiting-moderation,
     1520.devhub-wrap .single-wp-parser-hook .comment-edited, .devhub-wrap .single-wp-parser-class .comment-awaiting-moderation,
     1521.devhub-wrap .single-wp-parser-class .comment-edited {
    15181522  background-color: #fff8e5;
    15191523  padding: .2em .5em;
     1524  margin-right: .5em;
    15201525  border-radius: 3px;
    15211526  border: 1px solid #ffb900;
    15221527}
    15231528
    1524 .devhub-wrap .single-wp-parser-function .depth-2 .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-method .depth-2 .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-hook .depth-2 .comment-awaiting-moderation, .devhub-wrap .single-wp-parser-class .depth-2 .comment-awaiting-moderation {
     1529.devhub-wrap .single-wp-parser-function .depth-2 .comment-awaiting-moderation,
     1530.devhub-wrap .single-wp-parser-function .depth-2 .comment-edited, .devhub-wrap .single-wp-parser-method .depth-2 .comment-awaiting-moderation,
     1531.devhub-wrap .single-wp-parser-method .depth-2 .comment-edited, .devhub-wrap .single-wp-parser-hook .depth-2 .comment-awaiting-moderation,
     1532.devhub-wrap .single-wp-parser-hook .depth-2 .comment-edited, .devhub-wrap .single-wp-parser-class .depth-2 .comment-awaiting-moderation,
     1533.devhub-wrap .single-wp-parser-class .depth-2 .comment-edited {
    15251534  display: inline-block;
    15261535  margin: 2px 0;
    15271536}
     
    15611570.devhub-wrap .single-wp-parser-class #comment-preview {
    15621571  border: 1px solid #dfdfdf;
    15631572  border-radius: 2px;
     1573  width: 100%;
    15641574}
    15651575
    15661576.devhub-wrap .single-wp-parser-function .comment-list li.depth-2, .devhub-wrap .single-wp-parser-method .comment-list li.depth-2, .devhub-wrap .single-wp-parser-hook .comment-list li.depth-2, .devhub-wrap .single-wp-parser-class .comment-list li.depth-2 {
     
    17351745  padding: 0 5px;
    17361746}
    17371747
    1738 .devhub-wrap .single-wp-parser-function .comment-form ul, .devhub-wrap .single-wp-parser-method .comment-form ul, .devhub-wrap .single-wp-parser-hook .comment-form ul, .devhub-wrap .single-wp-parser-class .comment-form ul {
     1748.devhub-wrap .single-wp-parser-function .comment-form ul, .devhub-wrap .single-wp-parser-function .feedback-form ul, .devhub-wrap .single-wp-parser-method .comment-form ul, .devhub-wrap .single-wp-parser-method .feedback-form ul, .devhub-wrap .single-wp-parser-hook .comment-form ul, .devhub-wrap .single-wp-parser-hook .feedback-form ul, .devhub-wrap .single-wp-parser-class .comment-form ul, .devhub-wrap .single-wp-parser-class .feedback-form ul {
    17391749  margin-left: 1.5em;
    17401750}
    17411751
     1752.devhub-wrap .single-wp-parser-function .feedback-form ul li, .devhub-wrap .single-wp-parser-method .feedback-form ul li, .devhub-wrap .single-wp-parser-hook .feedback-form ul li, .devhub-wrap .single-wp-parser-class .feedback-form ul li {
     1753  margin: 0;
     1754  overflow: visible;
     1755}
     1756
    17421757.devhub-wrap.single-post .comment-list,
    17431758.devhub-wrap.single-post .comment-list ol {
    17441759  list-style: none;