| 1 |
<?php |
| 2 |
/** |
| 3 |
* Builder Plugin Compatibility Code |
| 4 |
* |
| 5 |
* @package Themify_Builder |
| 6 |
* @subpackage Themify_Builder/classes |
| 7 |
*/ |
| 8 |
|
| 9 |
class Themify_Builder_Plugin_Compat_GalleryCustomLinks { |
| 10 |
|
| 11 |
static function init() { |
| 12 |
add_filter( 'themify_builder_image_link_before', array( __CLASS__, 'wp_gallery_custom_links' ), 10, 3 ); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Compatibility with WP Gallery Custom Links plugin |
| 17 |
* @link https://wordpress.org/plugins/wp-gallery-custom-links |
| 18 |
* Apply Link and Target fields to gallery images in Grid layout |
| 19 |
* |
| 20 |
* @return string |
| 21 |
*/ |
| 22 |
public static function wp_gallery_custom_links(string $link_before, $image, $settings ):string { |
| 23 |
$attachment_meta = get_post_meta( $image->ID, '_gallery_link_url', true ); |
| 24 |
if( $attachment_meta ) { |
| 25 |
$link_before = preg_replace( '/href="(.*)"/', 'href="' . $attachment_meta . '"', $link_before ); |
| 26 |
} |
| 27 |
$attachment_meta = get_post_meta( $image->ID, '_gallery_link_target', true ); |
| 28 |
if( $attachment_meta ) { |
| 29 |
$link_before = str_replace( '>', ' target="' . $attachment_meta . '">', $link_before ); |
| 30 |
} |
| 31 |
|
| 32 |
return $link_before; |
| 33 |
} |
| 34 |
} |