diff --git content-reference.php content-reference.php
index 02cb0b5..b8e256a 100644
|
|
if ( ! empty( $since ) ) : ?> |
114 | 114 | <?php endif; |
115 | 115 | endif; ?> |
116 | 116 | |
| 117 | <?php if ( 'wp-parser-function' === get_post_type() ) : ?> |
| 118 | <hr /> |
| 119 | <section class="source-content"> |
| 120 | <h2><?php _e( 'Source', 'wporg' ); ?></h2> |
| 121 | <pre><?php echo esc_html( get_source_code() ); ?></pre> |
| 122 | </section> |
| 123 | <?php endif; ?> |
| 124 | |
117 | 125 | <?php endif; ?> |
118 | 126 | |
119 | 127 | </article> |
diff --git inc/template-tags.php inc/template-tags.php
index 28f3199..a0bc383 100755
|
|
namespace DevHub { |
564 | 564 | return strcmp( $a->post_name, $b->post_name ); |
565 | 565 | } |
566 | 566 | |
| 567 | /** |
| 568 | * Retrieve source code for a function |
| 569 | * |
| 570 | * @param int $post_id |
| 571 | * |
| 572 | * @return string The sourc |
| 573 | */ |
| 574 | function get_source_code( $post_id = null ) { |
| 575 | |
| 576 | if ( empty( $post_id ) ) { |
| 577 | $post_id = get_the_ID(); |
| 578 | } |
| 579 | |
| 580 | // Get the total file sourcecode. |
| 581 | $source_file = get_source_file( $post_id ); |
| 582 | |
| 583 | // Put the total source code in an array. |
| 584 | $total_source_code = file_get_contents( ABSPATH . $source_file ); |
| 585 | $total_source_code = explode( "\n", $total_source_code ); |
| 586 | |
| 587 | // Get the start and end lines. |
| 588 | $start_line = get_post_meta( $post_id, '_wp-parser_line_num', true ) - 1; |
| 589 | $end_line = get_post_meta( $post_id, '_wp-parser_end_line_num', true ); |
| 590 | |
| 591 | // Get the correct source code. |
| 592 | $source_code = array_slice( $total_source_code, $start_line, $end_line - $start_line ); |
| 593 | |
| 594 | return implode( "\n", $source_code ); |
| 595 | } |
| 596 | |
567 | 597 | } |
| 598 | No newline at end of file |