Changeset 676 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
- Timestamp:
- 06/05/2014 09:42:29 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
r640 r676 639 639 } 640 640 641 /** 642 * Retrieve source code for a function 643 * 644 * @param int $post_id 645 * 646 * @return string The sourc 647 */ 648 function get_source_code( $post_id = null ) { 649 650 if ( empty( $post_id ) ) { 651 $post_id = get_the_ID(); 652 } 653 654 // Get the total file sourcecode. 655 $source_file = get_source_file( $post_id ); 656 657 // Put the total source code in an array. 658 $total_source_code = file_get_contents( ABSPATH . $source_file ); 659 $total_source_code = explode( "\n", $total_source_code ); 660 661 // Get the start and end lines. 662 $start_line = get_post_meta( $post_id, '_wp-parser_line_num', true ) - 1; 663 $end_line = get_post_meta( $post_id, '_wp-parser_end_line_num', true ); 664 665 // Get the correct source code. 666 $source_code = array_slice( $total_source_code, $start_line, $end_line - $start_line ); 667 668 return implode( "\n", $source_code ); 669 } 670 641 671 }
Note: See TracChangeset
for help on using the changeset viewer.