Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for deprecated hooks #178

Merged
merged 5 commits into from Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/class-file-reflector.php
Expand Up @@ -204,8 +204,10 @@ protected function isFilter( \PHPParser_Node $node ) {
$functions = array(
'apply_filters',
'apply_filters_ref_array',
'apply_filters_deprecated',
'do_action',
'do_action_ref_array',
'do_action_deprecated',
);

return in_array( $calling, $functions );
Expand Down
6 changes: 6 additions & 0 deletions lib/class-hook-reflector.php
Expand Up @@ -67,9 +67,15 @@ public function getType() {
case 'do_action_ref_array':
$type = 'action_reference';
break;
case 'do_action_deprecated':
$type = 'action_deprecated';
break;
case 'apply_filters_ref_array':
$type = 'filter_reference';
break;
case 'apply_filters_deprecated';
$type = 'filter_deprecated';
break;
}

return $type;
Expand Down
6 changes: 5 additions & 1 deletion lib/runner.php
Expand Up @@ -335,7 +335,11 @@ function export_uses( array $uses ) {
'end_line' => $element->getNode()->getAttribute( 'endLine' ),
);

if ( '_deprecated_file' === $name || '_deprecated_function' === $name || '_deprecated_argument' === $name ) {
if ( '_deprecated_file' === $name
|| '_deprecated_function' === $name
|| '_deprecated_argument' === $name
|| '_deprecated_hook' === $name
) {
$arguments = $element->getNode()->args;

$out[ $type ][0]['deprecation_version'] = $arguments[1]->value->value;
Expand Down
29 changes: 27 additions & 2 deletions lib/template.php
Expand Up @@ -123,9 +123,34 @@ function arguments_have_default_values() {
* @return bool
*/
function is_function_deprecated() {
$return = wp_list_filter( get_post_meta( get_the_ID(), '_wp-parser_tags', true ), array( 'name' => 'deprecated' ) );
/**
* Filters whether the current function is considered deprecated.
*
* @param bool Whether the current function should be considered deprecated.
*/
return apply_filters( 'wp_parser_is_function_deprecated', is_deprecated() );
}

return apply_filters( 'wp_parser_is_function_deprecated', ! empty( $return ) );
/**
* Determines if the current element is deprecated.
*
* Works for conceivably any parsed post type that stores DocBlock tag values in meta.
*
* @return bool Whether the current element is considered deprecated.
*/
function is_deprecated() {
$tags = get_post_meta( get_the_ID(), '_wp-parser_tags', true );
$deprecated = wp_list_filter( $tags, array( 'name' => 'deprecated' ) );

$post_type = get_post_type( get_the_ID() );

/**
* Filters whether the current element is deprecated.
*
* @param bool $deprecated Whether the current element should be considered deprecated.
* @param string $post_type Post type for the current element.
*/
return apply_filters( 'wp_parser_is_deprecated', ! empty( $deprecated ), $post_type );
}

/**
Expand Down