diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index d4c38aaeaab..7d2530a4a8a 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -1426,31 +1426,21 @@ public static function decorate_filter_source( $value ) { * @type string $type Source type (core, plugin, mu-plugin, or theme). * @type string $name Source name. * @type string $function Normalized function name. - * @type ReflectionMethod|ReflectionFunction $reflection + * @type ReflectionMethod|ReflectionFunction $reflection Reflection. * } */ public static function get_source( $callback ) { $reflection = null; - $class_name = null; // Because ReflectionMethod::getDeclaringClass() can return a parent class. try { if ( is_string( $callback ) && is_callable( $callback ) ) { // The $callback is a function or static method. $exploded_callback = explode( '::', $callback, 2 ); if ( 2 === count( $exploded_callback ) ) { - $class_name = $exploded_callback[0]; $reflection = new ReflectionMethod( $exploded_callback[0], $exploded_callback[1] ); } else { $reflection = new ReflectionFunction( $callback ); } } elseif ( is_array( $callback ) && isset( $callback[0], $callback[1] ) && method_exists( $callback[0], $callback[1] ) ) { - // The $callback is a method. - if ( is_string( $callback[0] ) ) { - $class_name = $callback[0]; - } elseif ( is_object( $callback[0] ) ) { - $class_name = get_class( $callback[0] ); - } - - // This is needed later for AMP_Validation_Manager::has_parameters_passed_by_reference(). $reflection = new ReflectionMethod( $callback[0], $callback[1] ); // Handle the special case of the class being a widget, in which case the display_callback method should @@ -1465,6 +1455,7 @@ public static function get_source( $callback ) { return null; } + // The reflection is needed later for AMP_Validation_Manager::has_parameters_passed_by_reference(). if ( ! $reflection ) { return null; } @@ -1501,8 +1492,8 @@ public static function get_source( $callback ) { $source['line'] = $reflection->getStartLine(); } - if ( $class_name ) { - $source['function'] = $class_name . '::' . $reflection->getName(); + if ( $reflection instanceof ReflectionMethod ) { + $source['function'] = $reflection->getDeclaringClass()->getName() . '::' . $reflection->getName(); } else { $source['function'] = $reflection->getName(); }