当我将此插件安装到我的一个使用Themify Builder的站点时,它显示以下错误。
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wp_gallery_custom_links’ not found or invalid function name in /home/content/xxxxx/wp-includes/class-wp-hook.php on line 298
您或任何人以前是否遇到过此错误?有什么快速的解决方案吗?
此外,我检查了Themify,发现他们在兼容文件中添加了插件代码,如下所示。
// WP Gallery Custom Links
if( $this->is_plugin_active( \'wp-gallery-custom-links/wp-gallery-custom-links.php\' ) ) {
add_filter( \'themify_builder_image_link_before\', \'wp_gallery_custom_links\', 10, 3 );
}
function wp_gallery_custom_links( $link_before, $image, $settings ) {
$attachment_meta = get_post_meta( $image->ID, \'_gallery_link_url\', true );
if( $attachment_meta ) {
$link_before = preg_replace( \'/href="(.*)"/\', \'href="\' . $attachment_meta . \'"\', $link_before );
}
$attachment_meta = get_post_meta( $image->ID, \'_gallery_link_target\', true );
if( $attachment_meta ) {
$link_before = str_replace( \'>\', \' target="\' . $attachment_meta . \'">\', $link_before );
}
return $link_before;
}
请对此进行调查,并尽快让我知道解决方案。
谢谢
SO网友:Tejas Dixit
通过直接在“/wp-content/themes/themify-ultra/themify/themify-builder/templates/template-gallery-grid.php”中进行更改,我最终解决了这个问题。
尝试查找下面的行。
$link_before = \'\' != $link ? sprintf( \'\', esc_attr( $image->post_title ), esc_url( $link ) ) : \'\';
$link_before = apply_filters( \'themify_builder_image_link_before\', $link_before, $image, $settings );
并替换为,
$custom_link = get_post_meta( $image->ID, \'_gallery_link_url\', true );
$custom_link_target = get_post_meta( $image->ID, \'_gallery_link_target\', true );
if($custom_link){
$link = $custom_link;
}
$link_before = \'\' != $link ? sprintf( \'\', esc_attr( $image->post_title ), esc_url( $link ), $custom_link_target ) : \'\';
//$link_before = apply_filters( \'themify_builder_image_link_before\', $link_before, $image, $settings );
谢谢