Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions inc/Helpers/Formatting/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ function get_acf_link( array $attributes, array $settings = [] ): string {
return '';
}

$content = $attributes['field']['title'];

$attributes = wp_parse_args(
$attributes,
[
'href' => $attributes['field']['url'],
'title' => $attributes['field']['title'],
'target' => $attributes['field']['target'],
]
);
Expand All @@ -51,7 +52,7 @@ function get_acf_link( array $attributes, array $settings = [] ): string {
$settings = wp_parse_args(
$settings,
[
'content' => $attributes['title'],
'content' => $content,
]
);

Expand Down Expand Up @@ -213,3 +214,40 @@ function get_the_link( array $attributes, array $settings = [] ): string {
function the_link( array $attributes, array $settings = [] ): void {
echo get_the_link( $attributes, $settings );
}
/**
* @usage BEA\Theme\Framework\Helpers\Formatting\Link\get_acf_link_classes( ['url' => ...], [ 'menu-item'] );
*
* @param array|null $field{
* @type string $url
* @type string $title
* @type string $target
* }
*
* @param array $classes {
*
* @type string $current
* @type string $external
* }
*
* @return string Echo of the link classes
*/
function get_acf_link_classes( $field, array $classes ): string {

if ( empty( $field['url'] ) ) {
return implode( ' ', $classes );
}
// chek if current is the current url marches with the url of the field
if ( trailingslashit( $field['url'] ) === trailingslashit( home_url( add_query_arg( null, null ) ) ) ) {
Comment thread
ptesei marked this conversation as resolved.
$classes ['current'] = 'current-menu-item';
}

$components = wp_parse_url( $field['url'] );
$base = wp_parse_url( home_url( '/' ) );

if ( ! empty( $components['host'] ) && ! empty( $base['host'] ) && strcasecmp( $components['host'], $base['host'] ) ) {
Comment thread
ptesei marked this conversation as resolved.
$classes ['external'] = 'external-menu-item';
}

return implode( ' ', $classes );

}