Changeset 813 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
- Timestamp:
- 08/26/2014 08:04:21 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r806 r813 30 30 require __DIR__ . '/inc/breadcrumb-trail.php'; 31 31 } 32 33 /** 34 * User-submitted content (comments, examples, etc). 35 */ 36 require __DIR__ . '/inc/user-content.php'; 32 37 33 38 /** … … 58 63 add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' ); 59 64 add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 ); 60 add_filter( 'comments_open', __NAMESPACE__ . '\\can_user_post_example', 10, 2 );61 65 62 66 // Add the handbook's 'Watch' action link. … … 65 69 } 66 70 67 // Temporarily disable comments68 //add_filter( 'comments_open', '__return_false' );69 70 71 add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 ); 71 72 72 treat_comments_as_examples();73 73 } 74 74 … … 356 356 wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true ); 357 357 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 true388 add_filter( 'pre_option_comment_registration', '__return_true' );389 390 // Force comment moderation to be true391 add_filter( 'pre_option_comment_moderation', '__return_true' );392 393 // Remove reply to link394 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 string429 */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;451 358 } 452 359
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)