Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How WordPress reading comment lines

Tags:

php

wordpress

In WordPress, comment lines are used to find theme summary, plugin summary, template name and so on.

for example:-

<?php
/*
Template Name: Snarfer
*/
?>

How WordPress doing this? What code is used to read comment lines.

like image 678
Gowri Avatar asked Aug 19 '11 07:08

Gowri


People also ask

How do I show comments on WordPress posts?

Navigate to the Posts/Pages screen. In the list of pages or posts, find the one you want and hover your cursor over the title of the post. You will see several links appear underneath the title. Click “Quick Edit” and check “Allow Comments.” Click “Update” to turn comments on for that post.

How do I get comments on WordPress?

By default WordPress shows the newest comment at the bottom of the comments list. Now if you have lots of comments on a post, then users will be seeing the oldest comments on top. This can be easily changed in WordPress. Simply go to Settings » Discussion and scroll down to other comments settings section.

How do I change the comment section in WordPress?

To modify your comment, you need to click on the Click to Edit link. This will allow you to make changes to your comment. However, you'll not be allowed to change your name, email, or website URL. Once you're done, you need to click on the Save button to update the comment.


1 Answers

This is done in the function get_file_data in wp-includes/functions.php with the key code section being this:

    foreach ( $all_headers as $field => $regex ) {
            preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
            if ( !empty( ${$field} ) )
                    ${$field} = _cleanup_header_comment( ${$field}[1] );
            else
                    ${$field} = '';
    }

For example for a plugin it is referenced in wp-admin/includes/plugin.php in the function get_plugin_data:

$plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );
like image 153
akirk Avatar answered Sep 25 '22 19:09

akirk