Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save adamjacob/5172223 to your computer and use it in GitHub Desktop.

Select an option

Save adamjacob/5172223 to your computer and use it in GitHub Desktop.
<?php
/**
* Get Plugin Headers
*
* Get the header information from all plugins in
* the plugins pool for use later on.
*
* @param mixed $plugin
*/
public function get_plugin_headers($plugin)
{
if (self::$plugins_pool !== false AND !empty(self::$plugins_pool))
{
$plugin = strtolower(trim($plugin)); // Lowercase and trim the plugin name
$plugin_data = read_file($this->plugins_dir.$plugin."/".$plugin.".php"); // Load the plugin we want
preg_match ( '|Plugin Name:(.*)$|mi', $plugin_data, $name );
preg_match ( '|Plugin URI:(.*)$|mi', $plugin_data, $uri );
preg_match ( '|Version:(.*)|i', $plugin_data, $version );
preg_match ( '|Description:(.*)$|mi', $plugin_data, $description );
preg_match ( '|Author:(.*)$|mi', $plugin_data, $author_name );
preg_match ( '|Author URI:(.*)$|mi', $plugin_data, $author_uri );
if (isset($name[1]))
{
$arr['plugin_name'] = trim($name[1]);
}
if (isset($uri[1]))
{
$arr['plugin_uri'] = trim($uri[1]);
}
if (isset($version[1]))
{
$arr['plugin_version'] = trim($version[1]);
}
if (isset($description[1]))
{
$arr['plugin_description'] = trim($description[1]);
}
if (isset($author_name[1]))
{
$arr['plugin_author'] = trim($author_name[1]);
}
if (isset($author_uri[1]))
{
$arr['plugin_author_uri'] = trim($author_uri[1]);
}
// For every plugin header item
foreach ($arr AS $k => $v)
{
// If the key doesn't exist or the value is not the same, update the array
if ( !isset(self::$plugins_pool[$plugin]['plugin_info'][$k]) OR self::$plugins_pool[$plugin]['plugin_info'][$k] != $v )
{
self::$plugins_pool[$plugin]['plugin_info'][$k] = trim($v);
}
else
{
return true;
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment