diff --git a/includes/base/element-base.php b/includes/base/element-base.php index 1fe849c1565b..fd2857a76316 100644 --- a/includes/base/element-base.php +++ b/includes/base/element-base.php @@ -516,6 +516,43 @@ public function add_render_attribute( $element, $key = null, $value = null, $ove return $this; } + /** + * Get Render Attributes + * + * Used to retrieve render attribute. + * + * The returned array is either all elements and their attributes if no `$element` is specified, an array of all + * attributes of a specific element or a specific attribute properties if `$key` is specified. + * + * Returns null if one of the requested parameters isn't set. + * + * @param string $element + * @param string $key + * + * @return array + */ + public function get_render_attributes( $element = '', $key = '' ) { + $attributes = $this->render_attributes; + + if ( $element ) { + if ( ! isset( $attributes[ $element ] ) ) { + return null; + } + + $attributes = $attributes[ $element ]; + + if ( $key ) { + if ( ! isset( $attributes[ $key ] ) ) { + return null; + } + + $attributes = $attributes[ $key ]; + } + } + + return $attributes; + } + /** * Set render attribute. *