Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Post_Template::find_link_href
Return the href of the nearest ancestor <a> of the given image, or an empty string.
Method of the class: Post_Template{}
No Hooks.
Returns
string.
Usage
// private - for code of main (parent) class only $result = $this->find_link_href( $img_element ): string;
- $img_element(DOMElement) (required)
- The image element.
Post_Template::find_link_href() Post Template::find link href code WC 11.1.2
private function find_link_href( \DOMElement $img_element ): string {
$parent = $img_element->parentNode; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
while ( $parent instanceof \DOMElement ) {
if ( 'a' === $parent->tagName ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
return $parent->getAttribute( 'href' );
}
$parent = $parent->parentNode; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}
return '';
}