Making WordPress.org

Changeset 639


Ignore:
Timestamp:
05/23/2014 05:58:19 AM (12 years ago)
Author:
coffee2code
Message:

Code Reference: Add link to core.trac to view code source for item. Fixes #447. props DrewAPicture

  • Change 'Source:' label to 'Source file:'
  • Add 'View source...' link that points to relevant line in core.trac when appropriate
Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
3 edited

Legend:

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

    r591 r639  
    2626        <?php
    2727        $source_file = get_source_file();
    28         if ( ! empty( $source_file ) ) : ?>
    29         <section class="source">
    30                 <p><strong><?php _e( 'Source:', 'wporg' ); ?></strong> <a href="<?php echo get_source_file_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a></p>
    31         </section>
     28        if ( ! empty( $source_file ) ) :
     29                ?>
     30                <section class="source">
     31                        <p><strong><?php _e( 'Source file:', 'wporg' ); ?> </strong><a href="<?php echo get_source_file_archive_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a></p>
     32                        <p><a href="<?php echo get_source_file_link(); ?>"><?php _e( 'View source&hellip;', 'wporg' ); ?></a></p>
     33                </section>
    3234        <?php endif; ?>
    3335
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-wp-parser-hook.php

    r561 r639  
    44
    55        <h1><a href="<?php the_permalink() ?>"><?php echo get_signature(); ?></a></h1>
    6 
    76        <section class="description">
    87                <?php the_excerpt(); ?>
    … …  
    2524        <?php
    2625        $source_file = get_source_file();
    27         if ( ! empty( $source_file ) ) : ?>
    28         <section class="source">
    29                 <p><strong><?php _e( 'Source:', 'wporg' ); ?></strong> <a href="<?php echo get_source_file_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a></p>
    30         </section>
     26        if ( ! empty( $source_file ) ) :
     27                ?>
     28                <section class="source">
     29                        <p><strong><?php _e( 'Source file:', 'wporg' ); ?> </strong><a href="<?php echo get_source_file_archive_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a></p>
     30                        <p><a href="<?php echo get_source_file_link(); ?>"><?php _e( 'View source&hellip;', 'wporg' ); ?></a></p>
     31                </section>
    3132        <?php endif; ?>
    3233
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r638 r639  
    558558
    559559        /**
    560          * Retrieve URL to source file archive
     560         * Retrieve URL to source file archive.
    561561         *
    562562         * @param string $name
    … …  
    564564         * @return string
    565565         */
    566         function get_source_file_link( $name = null ) {
     566        function get_source_file_archive_link( $name = null ) {
    567567
    568568                $source_file_object = get_term_by( 'name', empty( $name ) ? get_source_file() : $name, 'wp-parser-source-file' );
    … …  
    583583
    584584                return empty( $source_file_object ) ? '' : esc_html( $source_file_object[0] );
     585        }
     586
     587        /**
     588         * Retrieve the URL to the actual source file and line.
     589         *
     590         * @param null $post_id     Post ID.
     591         * @param bool $line_number Whether to append the line number to the URL.
     592         *                          Default true.
     593         * @return string Source file URL with or without line number.
     594         */
     595        function get_source_file_link( $post_id = null, $line_number = true ) {
     596
     597                $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
     598                $url     = '';
     599
     600                // Source file.
     601                $source_file = get_source_file( $post_id );
     602                if ( ! empty( $source_file ) ) {
     603                        $url = 'https://core.trac.wordpress.org/browser/tags/' . get_current_version() . '/src/' . $source_file;
     604                        // Line number.
     605                        if ( $line_number = get_post_meta( get_the_ID(), '_wp-parser_line_num', true ) ) {
     606                                $url .= "#L{$line_number}";
     607                        }
     608                }
     609
     610                return esc_url( $url );
    585611        }
    586612
Note: See TracChangeset for help on using the changeset viewer.