1

I was wondering if there is a way to interact with the Page-level DocBlocks. My question is more specifically about wordpress plugin development, but this question has arised also in a non-wordpress environments.

The reason is mainly the possibility to easily change VERSIONS and names throughout a large project with maybe a constant definition - but that will reflect also in the docblock..

The following example Docblock is from a wordpress plugin I write -

/*
Plugin Name: o99 Auxilary Functions v0.4.7
Plugin URI: http://www.myurl.com
Description: some simple description that nobody reads.
Version: 0.4.7
Author: my cool name
Author URI: http://www.ok-alsouri.com
*/

Is there a way to transform it into :

$ver = '0.4.7';
$uri = 'http://www.myurl.com';
$desc = 'some simple description that nobody reads.';
$mcn = 'my cool name';
etc.. 
etc..

    /*
    Plugin Name: o99 Auxilary Functions ($ver)
    Plugin URI: ($uri)
    Description: ($desc)
    Version: ($ver)
    Author: ($mcn)
    Author URI: ($$uri)
    */

obviously for echo to work I would need to break the docblock itself, and I can not WRITE the docblock directly into it´s own file .

In shorts : can I "generate" a docblock with php itself somehow (I would think that the answer is - "no" for the page itself.. But maybe I am wrong and someone has some neat hack :-) )

Is that even possible ?

Obmerk Kronen
  • 15,619
  • 16
  • 66
  • 105

1 Answers1

1

You could do:

$ver = '0.4.7';
$uri = 'http://www.myurl.com';
$desc = 'some simple description that nobody reads.';
$mcn = 'my cool name';
etc.. 
etc..

$docblock = <<<TEMPLATE
/*
Plugin Name: o99 Auxilary Functions ($ver)
Plugin URI: $uri
Description: $desc
Version: $ver
Author: $mcn
Author URI: $uri
*/
TEMPLATE;

$file_data = $docblock;
$file_data .= file_get_contents('yourplugin.php');
file_put_contents('yourplugin.php', $file_data);
  • thanks. I am not sure how to implement this . I believe you are suggesting to put that in an EXTERNAL file to modify this file . I was looking for a way to use it in the same file . Wordpress refers to this main plugin file (and the docblock) as a reference to activation - in other words, if a valid docblock does not exists - as far as wordpress is concerned - it is not a plugin file .. – Obmerk Kronen Jun 23 '12 at 03:52