Making WordPress.org


Ignore:
Timestamp:
08/26/2014 08:04:21 AM (12 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
File:
1 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
Note: See TracChangeset for help on using the changeset viewer.