0 ) { $url = get_permalink( $post_id ); } } elseif ( ! empty( $attrs['smartLinkUrl'] ) ) { $url = (string) $attrs['smartLinkUrl']; } $url = esc_url_raw( $url ); if ( empty( $url ) ) { return $block_content; } $target = ! empty( $attrs['smartLinkNewTab'] ) ? '_blank' : ''; $rel = ! empty( $attrs['smartLinkRel'] ) ? sanitize_text_field( (string) $attrs['smartLinkRel'] ) : ''; if ( '_blank' === $target ) { $rels = preg_split( '/\s+/', strtolower( $rel ), -1, PREG_SPLIT_NO_EMPTY ); if ( ! is_array( $rels ) ) { $rels = array(); } if ( ! in_array( 'noopener', $rels, true ) ) { $rels[] = 'noopener'; } if ( ! in_array( 'noreferrer', $rels, true ) ) { $rels[] = 'noreferrer'; } $rel = implode( ' ', array_unique( $rels ) ); } $aria_label = ! empty( $attrs['smartLinkAriaLabel'] ) ? sanitize_text_field( (string) $attrs['smartLinkAriaLabel'] ) : ''; $wrapper_class = 'forwp-smart-link-wrapper forwp-smart-link-wrapper--cover'; $attributes = array( 'href="' . esc_url( $url ) . '"', 'class="' . esc_attr( $wrapper_class ) . '"', 'data-forwp-smart-link="' . esc_attr( 'cover' ) . '"', 'style="display:block;color:inherit;text-decoration:none;"', ); if ( ! empty( $target ) ) { $attributes[] = 'target="' . esc_attr( $target ) . '"'; } if ( ! empty( $rel ) ) { $attributes[] = 'rel="' . esc_attr( $rel ) . '"'; } if ( ! empty( $aria_label ) ) { $attributes[] = 'aria-label="' . esc_attr( $aria_label ) . '"'; } return sprintf( '%2$s', implode( ' ', $attributes ), $block_content ); } }