Making WordPress.org

Changeset 813


Ignore:
Timestamp:
08/26/2014 08:04:21 AM (10 years ago)
Author:
coffee2code
Message:

Code Reference: allow for mixed text and code in examples

  • Enable shortcode support in comments
  • Allow for mixed code and text in examples
  • Move functions and handling related to user submitted content into inc/user-content.php
  • Add padding around comments
Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

    r806 r813  
    3030    require __DIR__ . '/inc/breadcrumb-trail.php';
    3131}
     32
     33/**
     34 * User-submitted content (comments, examples, etc).
     35 */
     36require __DIR__ . '/inc/user-content.php';
    3237
    3338/**
     
    5863    add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' );
    5964    add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 );
    60     add_filter( 'comments_open', __NAMESPACE__ . '\\can_user_post_example', 10, 2 );
    6165
    6266    // Add the handbook's 'Watch' action link.
     
    6569    }
    6670
    67     // Temporarily disable comments
    68     //add_filter( 'comments_open', '__return_false' );
    69 
    7071    add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 );
    7172
    72     treat_comments_as_examples();
    7373}
    7474
     
    356356    wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
    357357    wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
    358 
    359     if ( is_singular() && ( '0' != get_comments_number() || post_type_has_source_code() ) ) {
    360         wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true );
    361         wp_enqueue_style( 'syntaxhighlighter-core' );
    362         wp_enqueue_style( 'syntaxhighlighter-theme-default' );
    363 
    364         wp_enqueue_script( 'wporg-developer-code-examples', get_template_directory_uri() . '/js/code-example.js', array(), '20140423', true );
    365         if ( get_option( 'thread_comments' ) ) {
    366             wp_enqueue_script( 'comment-reply' );
    367         }
    368     }
    369 }
    370 
    371 /**
    372  * Handles adding/removing hooks to enable comments as examples.
    373  *
    374  * Mostly gives users greater permissions in terms of comment content.
    375  *
    376  * In order to submit code examples, users must be able to post with less restrictions.
    377  */
    378 function treat_comments_as_examples() {
    379     // Restricts commenting to logged in users.
    380     add_filter( 'comments_open', __NAMESPACE__ . '\\prevent_invalid_comment_submissions', 10, 2 );
    381 
    382     if ( ! current_user_can( 'unfiltered_html' ) ) {
    383         remove_filter( 'pre_comment_content', 'wp_filter_kses'      );
    384         add_filter(    'pre_comment_content', 'wp_filter_post_kses' );
    385     }
    386 
    387     // Force comment registration to be true
    388     add_filter( 'pre_option_comment_registration', '__return_true' );
    389 
    390     // Force comment moderation to be true
    391     add_filter( 'pre_option_comment_moderation',   '__return_true' );
    392 
    393     // Remove reply to link
    394     add_filter( 'comment_reply_link',              '__return_empty_string' );
    395 
    396 /*  foreach ( array( 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
    397         add_filter( $filter, 'balanceTags', 50 );
    398     }*/
    399 
    400     remove_filter( 'comment_text',        'capital_P_dangit',   31 );
    401 
    402     remove_filter( 'comment_text',        'wptexturize'            );
    403     remove_filter( 'comment_text',        'convert_chars'          );
    404     remove_filter( 'comment_text',        'make_clickable',      9 );
    405     remove_filter( 'comment_text',        'force_balance_tags', 25 );
    406     remove_filter( 'comment_text',        'convert_smilies',    20 );
    407     remove_filter( 'comment_text',        'wpautop',            30 );
    408 
    409     remove_filter( 'pre_comment_content', 'wp_rel_nofollow',    15 );
    410 
    411     // Be more permissive with content of examples.
    412     // Note: the content gets fully escaped via 'get_comment_text'.
    413     if ( post_type_supports_examples() ) {
    414         if ( current_user_can( 'unfiltered_html' ) ) {
    415             remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
    416         } else {
    417             remove_filter( 'pre_comment_content', 'wp_filter_kses' );
    418         }
    419     }
    420 
    421     add_filter( 'get_comment_text',  __NAMESPACE__ . '\\escape_example_content' );
    422 }
    423 
    424 /**
    425  * Escapes the entirety of the content for examples.
    426  *
    427  * @param  string $text The comment/example content.
    428  * @return string
    429  */
    430 function escape_example_content( $text ) {
    431     // Only proceed if the post type is one that has examples.
    432     if ( ! post_type_supports_examples() ) {
    433         return $text;
    434     }
    435 
    436     return htmlentities( $text );
    437 }
    438 
    439 /**
    440  * Disables commenting to invalid or non-users.
    441  *
    442  * @param bool  $status Default commenting status for post.
    443  * @return bool False if commenter isn't a user, otherwise the passed in status.
    444  */
    445 function prevent_invalid_comment_submissions( $status, $post_id ) {
    446     if ( $_POST && ( ! is_user_logged_in() || ! is_user_member_of_blog() ) ) {
    447         return false;
    448     }
    449 
    450     return $status;
    451358}
    452359
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r785 r813  
    9393                <li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
    9494                <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
    95                     <div class="comment-content code-example-container">
    96                         <pre class="brush: php; toolbar: false;"><?php comment_text(); /* Fully escaped via filter */ ?></pre>
     95                    <div class="comment-content">
     96                        <?php comment_text(); ?>
    9797                    </div>
    9898                    <!-- .comment-content -->
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

    r803 r813  
    973973
    974974    .comment-list li {
    975         padding: 24px 24px 0 24px;
    976         padding: 1.5rem 1.5rem 0 1.5rem;
     975        padding: 2rem 1.5rem 1rem;
    977976        border: 0 solid #eee;
    978977        border-bottom-width: 1px;
    979978        background: #fff;
    980     }
    981 
    982     .comment-list li:first-child {
    983         padding-top: 0;
     979
     980        &:first-child {
     981            padding-top: 1rem;
     982        }
    984983    }
    985984
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

    r803 r813  
    11621162}
    11631163.devhub-wrap .comment-list li {
    1164   padding: 24px 24px 0 24px;
    1165   padding: 1.5rem 1.5rem 0 1.5rem;
     1164  padding: 2rem 1.5rem 1rem;
    11661165  border: 0 solid #eee;
    11671166  border-bottom-width: 1px;
    11681167  background: #fff;
    11691168}
    1170 .devhub-wrap .comment-list li {
    1171   padding-top: 0;
     1169.devhub-wrap .comment-list li:first-child {
     1170  padding-top: 1rem;
    11721171}
    11731172.devhub-wrap .comment-list .avatar {
Note: See TracChangeset for help on using the changeset viewer.