Não há script ou plug-in que eu saiba para fazer o que você quer. Como você afirmou, existem scripts ( mesmo variáveis globais ) que você pode usar para imprimir filtros e ações que estão sendo usadas atualmente.
Quanto a filtros e ações dormentes, escrevi duas funções muito básicas ( com alguma ajuda aqui e ali ) que encontra todas as instâncias de apply_filters
e do_action
em um arquivo e depois imprime fora
BASICS
-
Usaremos as classes
RecursiveDirectoryIterator
,RecursiveIteratorIterator
eRegexIterator
PHP para obter todos os arquivos PHP em um diretório. Como exemplo, no meu localhost, useiE:\xammp\htdocs\wordpress\wp-includes
-
Em seguida, percorremos os arquivos, pesquisamos e retornamos (
preg_match_all
) todas as instâncias deapply_filters
edo_action
. Eu configurei-o para coincidir com instâncias aninhadas de parênteses e também para combinar possíveis espaços em branco entreapply_filters
/do_action
e o primeiro parênteses
Vamos simplificar, em seguida, criar um array com todos os filtros e ações e, em seguida, percorrer o array e gerar o nome do arquivo, filtros e ações. Vamos pular arquivos sem filtros / ações
NOTAS IMPORTANTES
-
Essas funções são muito caras. Execute-os apenas em uma instalação de teste local.
-
Modifique as funções conforme necessário. Você pode decidir gravar a saída em um arquivo, criar uma página especial de back-end para isso, as opções são ilimitadas
OPÇÃO 1
A primeira função de opções é muito simples, retornamos o conteúdo de um arquivo como uma string usando file_get_contents
, procuramos as apply_filters
/ do_action
instances e simplesmente geramos o nome do arquivo e os nomes de filtro / ação
Comentei o código para facilitar o acompanhamento
function get_all_filters_and_actions( $path = '' )
{
//Check if we have a path, if not, return false
if ( !$path )
return false;
// Validate and sanitize path
$path = filter_var( $path, FILTER_SANITIZE_URL );
/**
* If valiadtion fails, return false
*
* You can add an error message of something here to tell
* the user that the URL validation failed
*/
if ( !$path )
return false;
// Get each php file from the directory or URL
$dir = new RecursiveDirectoryIterator( $path );
$flat = new RecursiveIteratorIterator( $dir );
$files = new RegexIterator( $flat, '/\.php$/i' );
if ( $files ) {
$output = '';
foreach($files as $name=>$file) {
/**
* Match and return all instances of apply_filters(**) or do_action(**)
* The regex will match the following
* - Any depth of nesting of parentheses, so apply_filters( 'filter_name', parameter( 1,2 ) ) will be matched
* - Whitespaces that might exist between apply_filters or do_action and the first parentheses
*/
// Use file_get_contents to get contents of the php file
$get_file_content = file_get_contents( $file );
// Use htmlspecialchars() to avoid HTML in filters from rendering in page
$save_content = htmlspecialchars( $get_file_content );
preg_match_all( '/(apply_filters|do_action)\s*(\([^()]*(?:(?-1)[^()]*)*+\))/', $save_content, $matches );
// Build an array to hold the file name as key and apply_filters/do_action values as value
if ( $matches[0] )
$array[$name] = $matches[0];
}
foreach ( $array as $file_name=>$value ) {
$output .= '<ul>';
$output .= '<strong>File Path: ' . $file_name .'</strong></br>';
$output .= 'The following filters and/or actions are available';
foreach ( $value as $k=>$v ) {
$output .= '<li>' . $v . '</li>';
}
$output .= '</ul>';
}
return $output;
}
return false;
}
Você pode usar a seguir em um modelo, frontend ou backend
echo get_all_filters_and_actions( 'E:\xammp\htdocs\wordpress\wp-includes' );
Isso imprimirá
OPÇÃO2
Estaopçãoéumpoucomaiscaraparaserexecutada.Estafunçãoretornaonúmerodalinhaondeofiltro/açãopodeserencontrado.
Aquiusamosfile
paraexplodiroarquivoemumamatriz,entãoprocuramoseretornamosofiltro/açãoeonúmerodalinha
functionget_all_filters_and_actions2($path=''){//Checkifwehaveapath,ifnot,returnfalseif(!$path)returnfalse;//Validateandsanitizepath$path=filter_var($path,FILTER_SANITIZE_URL);/***Ifvaliadtionfails,returnfalse**Youcanaddanerrormessageofsomethingheretotell*theuserthattheURLvalidationfailed*/if(!$path)returnfalse;//GeteachphpfilefromthedirectoryorURL$dir=newRecursiveDirectoryIterator($path);$flat=newRecursiveIteratorIterator($dir);$files=newRegexIterator($flat,'/\.php$/i');if($files){$output='';$array=[];foreach($filesas$name=>$file){/***Matchandreturnallinstancesofapply_filters(**)ordo_action(**)*Theregexwillmatchthefollowing*-Anydepthofnestingofparentheses,soapply_filters('filter_name',parameter(1,2))willbematched*-Whitespacesthatmightexistbetweenapply_filtersordo_actionandthefirstparentheses*///Usefile_get_contentstogetcontentsofthephpfile$get_file_contents=file($file);foreach($get_file_contentsas$key=>$get_file_content){preg_match_all('/(apply_filters|do_action)\s*(\([^()]*(?:(?-1)[^()]*)*+\))/',$get_file_content,$matches);if($matches[0])$array[$name][$key+1]=$matches[0];}}if($array){foreach($arrayas$file_name=>$values){$output.='<ul>';$output.='<strong>FilePath:'.$file_name.'</strong></br>';$output.='Thefollowingfiltersand/oractionsareavailable';foreach($valuesas$line_number=>$string){$whitespaces=' ';$output.='<li>Linereference'.$line_number.$whitespaces.$string[0].'</li>';}$output.='</ul>';}}return$output;}returnfalse;}
Vocêpodeusaraseguiremummodelo,frontendoubackend
echoget_all_filters_and_actions2('E:\xammp\htdocs\wordpress\wp-includes');
Issoimprimirá
EDITAR
Isso é basicamente o que eu posso fazer sem os scripts expirarem ou ficarem sem memória. Com o código na opção 2, é tão fácil quanto ir ao dito arquivo e a dita linha no código fonte e então obter todos os valores de parâmetros válidos do filtro / ação, também, importante, obter a função e o contexto em que o filtro / ação é usado