Making WordPress.org

Changeset 11311


Ignore:
Timestamp:
11/04/2021 03:25:50 AM (5 years ago)
Author:
dd32
Message:

Code Reference: Include a link to view the source on GitHub.

Props stuartshields, netweb, dd32.
Fixes #5942.

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/inc/template-tags.php

    r10000 r11311  
    11591159         *
    11601160         * @param null $post_id     Post ID.
    1161          * @param bool $line_number Whether to append the line number to the URL.
    1162          *                          Default true.
    11631161         * @return string Source file URL with or without line number.
    11641162         */
    1165         function get_source_file_link( $post_id = null, $line_number = true ) {
     1163        function get_source_file_link( $post_id = null ) {
    11661164
    11671165                $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
     
    11751173                        if ( $line_number = get_post_meta( get_the_ID(), '_wp-parser_line_num', true ) ) {
    11761174                                $url .= "#L{$line_number}";
     1175                        }
     1176                }
     1177
     1178                return esc_url( $url );
     1179        }
     1180
     1181        /**
     1182         * Retrieve the URL to the GitHub source file and line.
     1183         *
     1184         * @param null $post_id     Post ID.
     1185         * @return string Source file URL with or without line number.
     1186         */
     1187        function get_github_source_file_link( $post_id = null ) {
     1188
     1189                $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
     1190                $url     = '';
     1191
     1192                // Source file.
     1193                $source_file = get_source_file( $post_id );
     1194                if ( ! empty( $source_file ) ) {
     1195                        $url = 'https://github.com/WordPress/wordpress-develop/blob/' . get_current_version() . '/src/' . $source_file;
     1196                        // Line number.
     1197                        if ( $line_number = get_post_meta( get_the_ID(), '_wp-parser_line_num', true ) ) {
     1198                                $url .= "#L{$line_number}";
     1199                                if ( $end_line_number = get_post_meta( get_the_ID(), '_wp-parser_end_line_num', true ) ) {
     1200                                        $url .= "-L{$end_line_number}";
     1201                                }
    11771202                        }
    11781203                }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/reference/template-source.php

    r9822 r11311  
    3131                                </span>
    3232                                <span><a href="<?php echo get_source_file_link(); ?>"><?php _e( 'View on Trac', 'wporg' ); ?></a></span>
     33                                <span><a href="<?php echo get_github_source_file_link(); ?>"><?php _e( 'View on GitHub', 'wporg' ); ?></a></span>
    3334                        </p>
    3435                <?php else : ?>
Note: See TracChangeset for help on using the changeset viewer.