Making WordPress.org


Ignore:
Timestamp:
12/19/2014 09:57:26 PM (11 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.