From 62d1dec6b820bb0a504cfbd56fe99e88fcbd764b Mon Sep 17 00:00:00 2001 From: DrewAPicture Date: Sat, 11 Jun 2016 13:24:15 -0600 Subject: [PATCH 1/4] Allow the parser to recognize the two new functions. --- lib/class-file-reflector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/class-file-reflector.php b/lib/class-file-reflector.php index 5e1b59f..5b01e8d 100644 --- a/lib/class-file-reflector.php +++ b/lib/class-file-reflector.php @@ -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 ); From 51fedcc1785224308f27a6f74abd0aa7938f1dd6 Mon Sep 17 00:00:00 2001 From: DrewAPicture Date: Sat, 11 Jun 2016 13:24:56 -0600 Subject: [PATCH 2/4] Assign new hook types for apply_filters|do_action_deprecated() (usable by themes). --- lib/class-hook-reflector.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/class-hook-reflector.php b/lib/class-hook-reflector.php index 5120def..50075e0 100644 --- a/lib/class-hook-reflector.php +++ b/lib/class-hook-reflector.php @@ -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; From bd5a9e21f9436af65e99f79fcc0f0cf11d117b7c Mon Sep 17 00:00:00 2001 From: DrewAPicture Date: Sat, 11 Jun 2016 13:25:48 -0600 Subject: [PATCH 3/4] Handle deriving and storing a deprecated version for hooks. --- lib/runner.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/runner.php b/lib/runner.php index 89d45bb..e542787 100644 --- a/lib/runner.php +++ b/lib/runner.php @@ -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; From 50e2af79861554ba8181ec324484c8b86e125380 Mon Sep 17 00:00:00 2001 From: DrewAPicture Date: Sat, 11 Jun 2016 13:26:21 -0600 Subject: [PATCH 4/4] Introduce a generic is_deprecated() function for determining if the current element is deprecated. Also converts is_function_deprecated() into a wrapper for the new function and introduces a new generic 'wp_parser_is_deprecated' hook. The 'wp_parser_is_function_deprecated' hook is retained for back-compat on the return of is_function_deprecated(). --- lib/template.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/template.php b/lib/template.php index 8bab9f2..e2a5c0b 100644 --- a/lib/template.php +++ b/lib/template.php @@ -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 ); } /**