Making WordPress.org

Ticket #1926: 1926.diff

File 1926.diff, 3.5 KB (added by DrewAPicture, 9 years ago)
  • inc/template-tags.php

     
    765765                // Since data stored in meta.
    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 ( ! empty( $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 ( ! empty( $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(
    777802                                                'version'     => $since_term->name,
     
    781806                                }
    782807                        }
    783808                }
     809
    784810                return $data;
    785811        }
    786812
     
    819845        /**
    820846         * Retrieve deprecated notice.
    821847         *
    822          * @param int $post_id
    823          *
    824          * @return string
     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.
    825852         */
    826         function get_deprecated( $post_id = null ) {
     853        function get_deprecated( $post_id = null, $formatted = true ) {
    827854                if ( ! $post_id ) {
    828855                        $post_id = get_the_ID();
    829856                }
     
    875902                        $deprecation_info
    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
    889920                return $message;