WordPress.org

Making WordPress.org

Changeset 938


Ignore:
Timestamp:
10/26/2014 11:40:46 PM (5 years ago)
Author:
coffee2code
Message:

Code Reference: add changelog support (aka multi-@since)

fixes #653.
props DrewAPicture.

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

Legend:

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

    r874 r938  
    1515    </section>
    1616    <section class="return"><p><strong>Return:</strong> <?php echo get_return(); ?></p></section>
    17 
    18     <?php
    19     $since = get_since();
    20 if ( ! empty( $since ) ) : ?>
    21     <section class="since">
    22         <p><strong>Since:</strong> WordPress <a href="<?php echo get_since_link( $since ); ?>"><?php echo esc_html( $since ); ?></a></p>
    23     </section>
    24 <?php endif; ?>
    2517
    2618    <?php
     
    150142    <?php endif; ?>
    151143
     144    <?php
     145    $changelog_data = get_changelog_data();
     146    if ( ! empty( $changelog_data ) ) :
     147        ?>
     148        <hr/>
     149        <section class="changelog">
     150            <h2><?php _e( 'Changelog', 'wporg' ); ?></h2>
     151            <ul>
     152                <?php foreach ( $changelog_data as $version => $data ) : ?>
     153                    <li><?php _e( '<strong>Since:</strong> WordPress', 'wporg' ); ?> <a href="<?php echo esc_url( $data['since_url'] ); ?>"><?php echo esc_html( $version ); ?></a> <?php echo $data['description']; // escaped in get_changelog_data() ?></li>
     154                <?php endforeach; ?>
     155            </ul>
     156        </section>
     157    <?php endif; ?>
     158
    152159    <?php if ( comments_open() || '0' != get_comments_number() ) : ?>
    153160    <hr/>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r936 r938  
    671671
    672672    /**
    673      * Retrieve URL to since version archive
    674      *
    675      * @param string $name
    676      *
    677      * @return string
     673     * Retrieve changelog data for the current post.
     674     *
     675     * @param null $post_id Post ID, defaults to the ID of the global $post.
     676     *
     677     * @return array Associative array of changelog data.
     678     */
     679    function get_changelog_data( $post_id = null ) {
     680        $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
     681
     682        // Since terms assigned to the post.
     683        $since_terms = wp_get_post_terms( $post_id, 'wp-parser-since' );
     684
     685        // Since data stored in meta.
     686        $since_meta = get_post_meta( $post_id, '_wp-parser_tags', true );
     687
     688        $data = array();
     689
     690        // Pair the term data with meta data.
     691        foreach ( $since_terms as $since_term ) {
     692            foreach ( $since_meta as $meta ) {
     693                if ( $since_term->name == $meta['content'] ) {
     694                    $description = empty( $meta['description'] ) ? '' : '<span class="since-description">' . esc_html( $meta['description'] ) . '</span>';
     695
     696                    $data[ $since_term->name ] = array(
     697                        'version'     => $since_term->name,
     698                        'description' => $description,
     699                        'since_url'   => get_term_link( $since_term )
     700                    );
     701                }
     702            }
     703        }
     704        return $data;
     705    }
     706
     707    /**
     708     * Retrieve URL to a since version archive.
     709     *
     710     * @param string $name Since version, e.g. 'x.x.x'.
     711     *
     712     * @return string Since term archive URL.
    678713     */
    679714    function get_since_link( $name = null ) {
     
    682717
    683718        return empty( $since_object ) ? '' : esc_url( get_term_link( $since_object ) );
    684     }
    685 
    686     /**
    687      * Retrieve name of since version
    688      *
    689      * @param int $post_id
    690      *
    691      * @return string
    692      */
    693     function get_since( $post_id = null ) {
    694 
    695         $since_object = wp_get_post_terms( empty( $post_id ) ? get_the_ID() : $post_id, 'wp-parser-since', array( 'fields' => 'names' ) );
    696 
    697         return empty( $since_object ) ? '' : esc_html( $since_object[0] );
    698719    }
    699720
Note: See TracChangeset for help on using the changeset viewer.