Making WordPress.org

Changeset 768


Ignore:
Timestamp:
07/29/2014 06:57:54 PM (11 years ago)
Author:
coffee2code
Message:

Code Reference: fix so that approved examples are publicly viewable

  • Make examples publicly viewable, if present
  • Hook 'comments_open' to only enable submitting examples by site members
  • Add hook 'wporg_devhub-can_user_post_example' to allow overriding default post commenting status
  • Temporarily disable any non-example commenting
  • Rename wporg_developer_comment() to more appropriate wporg_developer_example()
  • Remove unnecessary code-example template
Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
1 deleted
5 edited

Legend:

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

    r724 r768  
    4040                 * See wporg_developer_comment() in inc/template-tags.php for more.
    4141                 */
    42                 wp_list_comments( array( 'callback' => 'wporg_developer_comment' ) );
     42                wp_list_comments( array( 'callback' => 'wporg_developer_example' ) );
    4343            ?>
    4444        </ol><!-- .comment-list -->
     
    5353
    5454    <?php endif; // have_comments() ?>
     55
     56    <?php if ( DevHub\can_user_post_example( false, get_the_ID() ) ) : ?>
    5557
    5658    <p id="add-example" style="display:none;"><a href=""><?php _e( 'Have an example to add?', 'wporg' ); ?></a></p>
     
    6870    ) ); ?>
    6971
     72    <?php endif; ?>
     73
    7074</div><!-- #comments -->
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php

    r725 r768  
    141141    <?php endif; ?>
    142142
    143     <?php if ( have_comments() || ( comments_open() && is_user_member_of_blog() ) ) : ?>
     143    <?php if ( comments_open() || '0' != get_comments_number() ) : ?>
    144144    <hr/>
    145145    <section class="examples">
    146146        <h2><?php _e( 'Examples', 'wporg' ); ?></h2>
    147         <?php get_template_part( 'code-example' ); ?>
     147        <?php comments_template(); /* TODO: add '/examples.php' */ ?>
    148148    </section>
    149149    <?php endif; ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-wp-parser-hook.php

    r724 r768  
    8484        */ ?>
    8585
    86         <?php if ( have_comments() || ( comments_open() && is_user_member_of_blog() ) ) : ?>
     86        <?php if ( comments_open() || '0' != get_comments_number() ) : ?>
    8787        <hr/>
    8888        <section class="examples">
    8989            <h2><?php _e( 'Examples', 'wporg' ); ?></h2>
    90             <?php get_template_part( 'code-example' ); ?>
     90            <?php comments_template(); /* TODO: add '/examples.php' */ ?>
    9191        </section>
    9292        <?php endif; ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

    r752 r768  
    5757    add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' );
    5858    add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 );
     59    add_filter( 'comments_open', __NAMESPACE__ . '\\can_user_post_example', 10, 2 );
    5960
    6061    // Temporarily disable comments
     
    350351    wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
    351352
    352     if ( is_singular() && comments_open() ) {
     353    if ( is_singular() && ( '0' != get_comments_number() || post_type_has_source_code() ) ) {
    353354        wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true );
    354355        wp_enqueue_style( 'syntaxhighlighter-core' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r751 r768  
    7373    endif;
    7474
    75     if ( ! function_exists( 'wporg_developer_comment' ) ) :
     75    if ( ! function_exists( 'wporg_developer_example' ) ) :
    7676        /**
    77          * Template for comments and pingbacks.
     77         * Template for examples.
    7878         *
    79          * Used as a callback by wp_list_comments() for displaying the comments.
     79         * Used as a callback by wp_list_comments() for displaying the examples.
    8080         */
    81         function wporg_developer_comment( $comment, $args, $depth ) {
     81        function wporg_developer_example( $comment, $args, $depth ) {
    8282            $GLOBALS['comment'] = $comment;
    8383
     
    753753    }
    754754
     755    /**
     756     * Indicates if the current user can post an example.
     757     *
     758     * This only affects post types wp-parser-* as they are the only things
     759     * that can have examples.
     760     *
     761     * A custom check can be performed by hooking the filter
     762     * 'wporg_devhub-can_user_post_example' and returning a
     763     * value other than null.
     764     *
     765     * By default, the ability to post examples is restricted to members of the
     766     * blog.
     767     *
     768     * @param  int  $post_id The post ID.
     769     *
     770     * @return bool True if the user can post an example.
     771     */
     772    function can_user_post_example( $open, $post_id ) {
     773
     774        // Only proceed if the post type is one that has examples.
     775        if ( 0 !== strpos( get_post_type( (int) $post_id ), 'wp-parser-' ) ) {
     776            // Temporarily disable commenting that isn't for an example since various
     777            // changes need to take place to enable regular commenting.
     778            return false; //$open;
     779        }
     780
     781        // Permit default logic to be overridden via filter that returns value other than null.
     782        if ( null !== ( $can = apply_filters( 'wporg_devhub-can_user_post_example', null, $post_id ) ) ) {
     783            return $can;
     784        }
     785
     786        // Default to limiting ability to post examples to members of the blog.
     787        return is_user_member_of_blog();
     788    }
     789
    755790}
Note: See TracChangeset for help on using the changeset viewer.