Making WordPress.org

Changeset 3840


Ignore:
Timestamp:
08/23/2016 06:22:11 AM (9 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Show deprecated version in the changelog table.

Also changes get_deprecated() to add optional $formatted argument to indicate if the message should be formatted for display.

Props DrewAPicture.
Fixes #1926.

File:
1 edited

Legend:

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

    r3819 r3840  
    766766        $since_meta = get_post_meta( $post_id, '_wp-parser_tags', true );
    767767
     768        $since_tags = wp_filter_object_list( $since_meta, array( 'name' => 'since' ) );
     769        $deprecated = wp_filter_object_list( $since_meta, array( 'name' => 'deprecated' ) );
     770
     771        // If deprecated, add the since version to the term and meta lists.
     772        if ( $deprecated ) {
     773            $deprecated = array_shift( $deprecated );
     774
     775            if ( $term = get_term_by( 'name', $deprecated['content'], 'wp-parser-since' ) ) {
     776                // Terms.
     777                $since_terms[] = $term;
     778
     779                // Meta.
     780                $since_tags[] = $deprecated;
     781            }
     782        }
     783
    768784        $data = array();
    769785
    770786        // Pair the term data with meta data.
    771787        foreach ( $since_terms as $since_term ) {
    772             foreach ( $since_meta as $meta ) {
     788            foreach ( $since_tags as $meta ) {
    773789                if ( is_array( $meta ) && $since_term->name == $meta['content'] ) {
    774                     $description = empty( $meta['description'] ) ? '' : '<span class="since-description">' . \DevHub_Formatting::format_param_description( $meta['description'] ) . '</span>';
     790                    // Handle deprecation notice if deprecated.
     791                    if ( empty( $meta['description'] ) ) {
     792                        if ( $deprecated ) {
     793                            $description = get_deprecated( $post_id, false );
     794                        } else {
     795                            $description = '';
     796                        }
     797                    } else {
     798                        $description = '<span class="since-description">' . \DevHub_Formatting::format_param_description( $meta['description'] ) . '</span>';
     799                    }
    775800
    776801                    $data[ $since_term->name ] = array(
     
    782807            }
    783808        }
     809
    784810        return $data;
    785811    }
     
    820846     * Retrieve deprecated notice.
    821847     *
    822      * @param int $post_id
    823      *
    824      * @return string
    825      */
    826     function get_deprecated( $post_id = null ) {
     848     * @param int  $post_id   Optional. Post ID. Default is the ID of the global `$post`.
     849     * @param bool $formatted Optional. Whether to format the deprecation message. Default true.
     850     * @return string Deprecated notice. If `$formatted` is true, will be output in markup
     851     *                for a callout box.
     852     */
     853    function get_deprecated( $post_id = null, $formatted = true ) {
    827854        if ( ! $post_id ) {
    828855            $post_id = get_the_ID();
     
    876903        );
    877904
    878         // Use the 'warning' callout box if it's available. Otherwise, fall back to a theme-supported div class.
    879         if ( class_exists( 'WPorg_Handbook_Callout_Boxes' ) ) {
    880             $callout = new \WPorg_Handbook_Callout_Boxes();
    881             $message = $callout->warning_shortcode( array(), $contents );
     905        if ( true === $formatted ) {
     906            // Use the 'warning' callout box if it's available. Otherwise, fall back to a theme-supported div class.
     907            if ( class_exists( 'WPorg_Handbook_Callout_Boxes' ) ) {
     908                $callout = new \WPorg_Handbook_Callout_Boxes();
     909                $message = $callout->warning_shortcode( array(), $contents );
     910            } else {
     911                $message  = '<div class="deprecated">';
     912                /** This filter is documented in wp-includes/post-template.php */
     913                $message .= apply_filters( 'the_content', $contents );
     914                $message .= '</div>';
     915            }
    882916        } else {
    883             $message  = '<div class="deprecated">';
    884             /** This filter is documented in wp-includes/post-template.php */
    885             $message .= apply_filters( 'the_content', $contents );
    886             $message .= '</div>';
     917            $message = $contents;
    887918        }
    888919
Note: See TracChangeset for help on using the changeset viewer.