Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Does Wordpress Read Comment Title?

I'm working on my own little back end framework for future clients and I'm making a folder named "Forms" to store all of my forms for CMS interaction. Inside the forms folder I'd like to store .php files similar to wordpress style plugins that I can title in the comments code like wp does... ie

/*
Plugin Name: Name Of The Plugin
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
*/

I'm wondering how WP reads that data as it is commented out... do they use file_get_contents('plugin.php'); and parse it as well as include the plugin? Is there a php function to actually read comments?

Thoughts?

like image 646
Howard Zoopaloopa Avatar asked Nov 20 '25 21:11

Howard Zoopaloopa


2 Answers

  1. Read the file by FTP or file_Get_contents()`
  2. explode each line by : and get result in array
  3. array[0] makes the key and array[1] makes the value.
like image 113
shamittomar Avatar answered Nov 22 '25 13:11

shamittomar


Wordpress has created its own function to handle file headers. I used this in my new Total Widget Control Plugin. Here's the function name and help docs on how to use it.

get_file_data( $file_path, $headers, $context)

  • http://codex.wordpress.org/File_Header

string $file: Path to the file

array $default_headers: List of headers, in the format array('HeaderKey' => 'Header Name')

string $context: If specified adds filter hook "extra_{$context}_headers"

like image 22
Marketing Consultant Avatar answered Nov 22 '25 12:11

Marketing Consultant