[wp-hackers] Re: Improving Plugin (and Theme) metadata

Lionel Elie Mamane lionel at mamane.lu
Tue Mar 4 18:19:41 GMT 2008

On Tue, Mar 04, 2008 at 05:36:40PM +0100, Lionel Elie Mamane wrote:
> Nikolay Bachiyski wrote:

>> Although westi's method of explicitly defining the metadata in php
>> code is cleanest and is easier to deal with on our side, it will
>> have two side effects, which are not desirable:

>> 2.  Harder to parse, without including the php file.

>> Again, we can't make all plugin developers to start offering their
>> plugin in a directory with a special, metadata php file.

> Hmm... I don't know PHP intimately, but if we can put PHP code in
> specially-tagged comments, easily parse it and run it, we avoid the
> "directory and extra metadata php file" problem.

Yes, we can! Here's code. Run the get-metadata script with
/path/to/other/attached/file/foo as first command-line argument for an


-------------- next part --------------
#! /usr/bin/php

if (!defined('T_ML_COMMENT')) {
  define('T_ML_COMMENT', T_COMMENT);

$source = file_get_contents($argv[1]);
$tokens = token_get_all($source);

foreach ($tokens as $token) {
  if (is_string($token)) {
    // simple 1-character token
  } else {
    // token array
    list($id, $text) = $token;

    switch ($id) {
    case T_COMMENT:
    case T_ML_COMMENT:
      if ( substr($text,0,13) == "/*WP_METADATA" ) {
	echo substr($text,13,-2);
	echo "$argv[1] defined \$description to be: $description";

echo "\n";

-------------- next part --------------
  $description = "Change all colors to a random shade of pink";

More information about the wp-hackers mailing list