Making WordPress.org

Changeset 1057


Ignore:
Timestamp:
12/19/2014 09:57:26 PM (10 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Reintroduce Explanations, with editorial flow.

  • Add explanations as an associated post type
  • Add metabox to create, unpublish, and link to edit explanation for a parsed post type
  • Add template tags: get_explanation() and get_explanation_field()
  • Re-enable display of Explanations on the frontend

props DrewAPicture.
fixes #786.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
2 added
7 edited

Legend:

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

    r1053 r1057  
    4646
    4747    <?php
    48     $explanation = '';
     48    $explanation = get_explanation_field( 'post_content', get_the_ID() );
    4949    if ( $explanation ) :
    5050        ?>
     
    5252        <section class="explanation">
    5353            <h2><?php _e( 'Explanation', 'wporg' ); ?></h2>
    54             <?php the_content(); ?>
     54            <?php echo apply_filters( 'the_content', apply_filters( 'get_the_content', $explanation ) ); ?>
    5555        </section>
    5656    <?php endif; ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-wp-parser-hook.php

    r1053 r1057  
    4444
    4545        <?php
    46         $explanation = '';
     46        $explanation = get_explanation_field( 'post_content', get_the_ID() );
    4747        if ( $explanation ) :
    4848            ?>
     
    5050            <section class="explanation">
    5151                <h2><?php _e( 'Explanation', 'wporg' ); ?></h2>
    52                 <?php the_content(); ?>
     52                <?php echo apply_filters( 'the_content', apply_filters( 'get_the_content', $explanation ) ); ?>
    5353            </section>
    5454        <?php endif; ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

    r1045 r1057  
    4545 */
    4646require __DIR__ . '/inc/user-content-voting.php';
     47
     48/**
     49 * Explanations for functions. hooks, classes, and methods.
     50 */
     51require( __DIR__ . '/inc/explanations.php' );
    4752
    4853/**
     
    8085    add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' );
    8186    add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\theme_scripts_styles' );
     87
    8288    add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 );
    8389    add_filter( 'term_link', __NAMESPACE__ . '\\taxonomy_permalink', 10, 3 );
    8490    add_filter( 'the_posts', __NAMESPACE__ . '\\rerun_empty_exact_search', 10, 2 );
     91
    8592    add_theme_support( 'automatic-feed-links' );
    8693    add_theme_support( 'post-thumbnails' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/parsed-content.php

    r942 r1057  
    7070        $ticket_label = get_post_meta( $post->ID, 'wporg_ticket_title', true );
    7171        $ticket_info  = get_post_meta( $post->ID, 'wporg_parsed_ticket_info', true );
    72         $content      = get_post_meta( $post->ID, 'wporg_parsed_content', true );
     72        $content      = $post->post_content;
    7373
    7474        if ( $ticket ) {
     
    9999                    <div class="wporg_parsed_readonly <?php echo $ticket ? 'hidden' : ''; ?>"><?php echo apply_filters( 'the_content', $content ); ?></div>
    100100                    <div class="wporg_parsed_content <?php echo $ticket ? '' : 'hidden'; ?>">
    101                         <?php wp_editor( $content, 'wporg_parsed_content_editor', array(
     101                        <?php wp_editor( $content, 'content', array(
    102102                            'media_buttons' => false,
    103103                            'tinymce'       => false,
    104104                            'quicktags'     => true,
    105105                            'textarea_rows' => 10,
    106                             'textarea_name' => 'wporg_parsed_content',
     106                            'textarea_name' => 'content',
    107107                        ) ); ?>
    108108                    </div>
     
    164164        // Only enqueue 'wporg-parsed-content' script and styles on Code Reference post type screens.
    165165        if ( in_array( get_current_screen()->id, $this->post_types ) ) {
    166             wp_enqueue_style( 'wporg-parsed-content', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20140826' );
     166            wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20140826' );
    167167            wp_enqueue_script( 'wporg-parsed-content', get_template_directory_uri() . '/js/parsed-content.js', array( 'jquery', 'utils' ), '20140826', true );
    168168
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r1054 r1057  
    11041104    }
    11051105
     1106    /**
     1107     * Retrieve an explanation for the given post.
     1108     *
     1109     * @param int|WP_Post $post      Post ID or WP_Post object.
     1110     * @param bool        $published Optional. Whether to only retrieve the explanation if it's published.
     1111     *                               Default false.
     1112     * @return WP_Post|null WP_Post object for the Explanation, null otherwise.
     1113     */
     1114    function get_explanation( $post, $published = false ) {
     1115        if ( ! $post = get_post( $post ) ) {
     1116            return null;
     1117        }
     1118
     1119        $args = array(
     1120            'post_type'      => 'wporg_explanations',
     1121            'post_parent'    => $post->ID,
     1122            'no_found_rows'  => true,
     1123            'posts_per_page' => 1,
     1124        );
     1125
     1126        if ( true === $published ) {
     1127            $args['post_status'] = 'publish';
     1128        }
     1129
     1130        $explanation = get_children( $args, OBJECT );
     1131
     1132        if ( empty( $explanation ) ) {
     1133            return null;
     1134        }
     1135
     1136        $explanation = reset( $explanation );
     1137
     1138        if ( ! $explanation ) {
     1139            return null;
     1140        }
     1141        return $explanation;
     1142    }
     1143
     1144    /**
     1145     * Retrieve data from an explanation post field.
     1146     *
     1147     * Works only for published explanations.
     1148     *
     1149     * @see get_post_field()
     1150     *
     1151     * @param string      $field   Post field name.
     1152     * @param int|WP_Post $post    Post ID or object for the function, hook, class, or method post
     1153     *                             to retrieve an explanation field for.
     1154     * @param string      $context Optional. How to filter the field. Accepts 'raw', 'edit', 'db',
     1155     *                             or 'display'. Default 'display'.
     1156     * @return string The value of the post field on success, empty string on failure.
     1157     */
     1158    function get_explanation_field( $field, $post, $context = 'display' ) {
     1159        if ( ! $explanation = get_explanation( $post, $published = true ) ) {
     1160            return '';
     1161        }
     1162        return get_post_field( $field, $explanation, $context );
     1163    }
    11061164}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/admin.scss

    r831 r1057  
    2121    display: block;
    2222}
     23
     24
     25/* Explanations */
     26
     27.post-type-wporg_explanations .add-new-h2 {
     28    display: none;
     29}
     30
     31.expl-row-actions {
     32    display: block;
     33
     34    a {
     35        display: inline-block;
     36
     37        &:first-child {
     38            padding-right: 6px;
     39            padding-left: 0;
     40        }
     41        &:nth-child(n+2) {
     42            padding-left: 8px;
     43            border-left: 1px solid #ccc;
     44        }
     45    }
     46}
     47
     48.status {
     49    font-weight: bold;
     50
     51    &.pending {
     52        color: red;
     53    }
     54
     55    &.publish {
     56        color: green;
     57    }
     58}
     59.post-type-wp-parser-function,
     60.post-type-wp-parser-class,
     61.post-type-wp-parser-method,
     62.post-type-wp-parser-hook {
     63    .form-table {
     64        th {
     65            padding-top: 10px;
     66            padding-bottom: 10px;
     67        }
     68        td {
     69            padding: 10px;
     70
     71            p {
     72                margin-top: 0;
     73            }
     74        }
     75    }
     76}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/admin.css

    r831 r1057  
    2020  display: block;
    2121}
     22
     23/* Explanations */
     24.post-type-wporg_explanations .add-new-h2 {
     25  display: none;
     26}
     27
     28.expl-row-actions {
     29  display: block;
     30}
     31.expl-row-actions a {
     32  display: inline-block;
     33}
     34.expl-row-actions a:first-child {
     35  padding-right: 6px;
     36  padding-left: 0;
     37}
     38.expl-row-actions a:nth-child(n+2) {
     39  padding-left: 8px;
     40  border-left: 1px solid #ccc;
     41}
     42
     43.status {
     44  font-weight: bold;
     45}
     46.status.pending {
     47  color: red;
     48}
     49.status.publish {
     50  color: green;
     51}
     52
     53.post-type-wp-parser-function .form-table th,
     54.post-type-wp-parser-class .form-table th,
     55.post-type-wp-parser-method .form-table th,
     56.post-type-wp-parser-hook .form-table th {
     57  padding-top: 10px;
     58  padding-bottom: 10px;
     59}
     60.post-type-wp-parser-function .form-table td,
     61.post-type-wp-parser-class .form-table td,
     62.post-type-wp-parser-method .form-table td,
     63.post-type-wp-parser-hook .form-table td {
     64  padding: 10px;
     65}
     66.post-type-wp-parser-function .form-table td p,
     67.post-type-wp-parser-class .form-table td p,
     68.post-type-wp-parser-method .form-table td p,
     69.post-type-wp-parser-hook .form-table td p {
     70  margin-top: 0;
     71}
Note: See TracChangeset for help on using the changeset viewer.