Skip to content

Instantly share code, notes, and snippets.

@aliboy08
Created February 16, 2024 01:03
Show Gist options
  • Save aliboy08/228fb6d590cebf1c15f44efdaeb85934 to your computer and use it in GitHub Desktop.
Save aliboy08/228fb6d590cebf1c15f44efdaeb85934 to your computer and use it in GitHub Desktop.
get plugin version from php file comment
<?php
function get_plugin_version($file){
$file_content = file_get_contents($file);
$tokens = token_get_all( $file_content );
$comment = array(
T_COMMENT,
T_DOC_COMMENT,
);
foreach( $tokens as $token ) {
if( !in_array($token[0], $comment) ) continue;
$comment_text = $token[1];
if( strpos( $comment_text, 'Version:' ) !== false ) {
$temp = explode('Version:', $comment_text);
$temp2 = explode(PHP_EOL, $temp[1]);
$version = trim($temp2[0]);
return $version;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment