Making WordPress.org


Ignore:
Timestamp:
06/29/2014 08:41:47 AM (10 years ago)
Author:
coffee2code
Message:

Code Reference: add ability for users to submit code examples (via comments). See #180

Viewable by all, but temporarily only submittable by members of the site.

File:
1 edited

Legend:

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

    r688 r724  
    5555
    5656    // Temporarily disable comments
    57     add_filter( 'comments_open', '__return_false' );
     57    //add_filter( 'comments_open', '__return_false' );
    5858
    5959    add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 );
     60
     61    treat_comments_as_examples();
    6062}
    6163
     
    350352    }
    351353
    352     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    353         wp_enqueue_script( 'comment-reply' );
    354     }
    355 }
     354    if ( is_singular() && comments_open() ) {
     355        wp_enqueue_script( 'wporg-developer-code-examples', get_template_directory_uri() . '/js/code-example.js', array(), '20140423', true );
     356        if ( get_option( 'thread_comments' ) ) {
     357            wp_enqueue_script( 'comment-reply' );
     358        }
     359    }
     360}
     361
     362/**
     363 * Handles adding/removing hooks to enable comments as examples.
     364 *
     365 * Mostly gives users greater permissions in terms of comment content.
     366 *
     367 * In order to submit code examples, users must be able to post with less restrictions.
     368 */
     369function treat_comments_as_examples() {
     370    // Restricts commenting to logged in users.
     371    add_filter( 'comments_open', __NAMESPACE__ . '\\prevent_invalid_comment_submissions', 10, 2 );
     372
     373    if ( ! current_user_can( 'unfiltered_html' ) ) {
     374        remove_filter( 'pre_comment_content', 'wp_filter_kses'      );
     375        add_filter(    'pre_comment_content', 'wp_filter_post_kses' );
     376    }
     377
     378    // Force comment registration to be true
     379    add_filter( 'pre_option_comment_registration', '__return_true' );
     380
     381    // Force comment moderation to be true
     382    add_filter( 'pre_option_comment_moderation',   '__return_true' );
     383
     384    // Remove reply to link
     385    add_filter( 'comment_reply_link',              '__return_empty_string' );
     386
     387/*  foreach ( array( 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
     388        add_filter( $filter, 'balanceTags', 50 );
     389    }*/
     390
     391    remove_filter( 'comment_text',        'capital_P_dangit',   31 );
     392
     393    remove_filter( 'comment_text',        'wptexturize'            );
     394    remove_filter( 'comment_text',        'convert_chars'          );
     395    remove_filter( 'comment_text',        'make_clickable',      9 );
     396    remove_filter( 'comment_text',        'force_balance_tags', 25 );
     397    remove_filter( 'comment_text',        'convert_smilies',    20 );
     398    remove_filter( 'comment_text',        'wpautop',            30 );
     399
     400    remove_filter( 'pre_comment_content', 'wp_rel_nofollow',    15 );
     401}
     402
     403/**
     404 * Disables commenting to invalid or non-users.
     405 *
     406 * @param bool  $status Default commenting status for post.
     407 * @return bool False if commenter isn't a user, otherwise the passed in status.
     408 */
     409function prevent_invalid_comment_submissions( $status, $post_id ) {
     410    if ( $_POST && ( ! is_user_logged_in() || ! is_user_member_of_blog() ) ) {
     411        return false;
     412    }
     413
     414    return $status;
     415}
Note: See TracChangeset for help on using the changeset viewer.