/** * Get an array of class name lineage * * Returns an array of class names with most distant ancenstor first, current class last (if inclusive), or parent. * * @example array( 'WP_Base', 'WP_Field_Base', 'WP_Text_Field' ) * * @todo Consider if there is a better name than 'lineage'? Open to suggestion on GitHub issues... * * @param string $class_name * @param bool $inclusive * * @return array */ function wp_get_class_lineage($class_name, $inclusive = true) { if (!($lineage = wp_cache_get($cache_key = "class_lineage[{$class_name}]"))) { $lineage = $inclusive ? array($class_name) : array(); if ($class_name = get_parent_class($class_name)) { $lineage = array_merge(wp_get_class_lineage($class_name, true), $lineage); } wp_cache_set($cache_key, $lineage); } return $lineage; }
/** * Call a named method starting with the most distant anscestor down to the current class with no return value. * * @param string $method_name * @param array $args */ private function _call_lineage($method_name, $args = array()) { $lineage = wp_get_class_lineage(get_class($this), true); foreach ($lineage as $ancestor) { if ($this->_has_own_method($ancestor, $method_name)) { $this->_invoke_method($ancestor, $this, $method_name, array($args)); } } }