我试图从WordPress插件(Modern Tribe的事件日历)修改函数的输出。我尝试使用apply_filter
来完成此任务,但无济于事。这是我想要与之互动的功能:
function tribe_events_recurrence_tooltip( $post_id = null ) {
if ( empty( $post_id ) ) {
$post_id = get_the_ID();
}
$tooltip = '';
if ( tribe_is_recurring_event( $post_id ) ) {
$tooltip .= '<div class="recurringinfo">';
$tooltip .= '<div class="event-is-recurring">';
$tooltip .= '<span class="tribe-events-divider">|</span>';
$tooltip .= sprintf( __( 'Recurring %s', 'tribe-events-calendar-pro' ), tribe_get_event_label_singular() );
$tooltip .= sprintf( ' <a href="%s">%s</a>',
esc_url( tribe_all_occurences_link( $post_id, false ) ),
__( '(See all)', 'tribe-events-calendar-pro' )
);
$tooltip .= '<div id="tribe-events-tooltip-'. $post_id .'" class="tribe-events-tooltip recurring-info-tooltip">';
$tooltip .= '<div class="tribe-events-event-body">';
$tooltip .= tribe_get_recurrence_text( $post_id );
$tooltip .= '</div>';
$tooltip .= '<span class="tribe-events-arrow"></span>';
$tooltip .= '</div>';
$tooltip .= '</div>';
$tooltip .= '</div>';
}
if ( has_filter( 'tribe_events_event_recurring_info_tooltip' ) ) {
_deprecated_function( "The 'tribe_get_related_events' filter", '3.9', " the 'tribe_events_recurrence_tooltip' filter" );
$tooltip = apply_filters( 'tribe_events_event_recurring_info_tooltip', $tooltip ); // for backwards-compat, will be removed
}
return apply_filters( 'tribe_events_recurrence_tooltip', $tooltip );
}
我基本上只想操纵$tooltip
的输出值。我不确定是否需要使用str_replace
或parse_str
,但我没有尝试过我曾尝试过的功能。如果有人可以帮助$tooltip
清空,我应该可以从那里拿走它。
答案 0 :(得分:0)
在我应该使用apply_filter
挂钩函数时使用add_filter
(我是新手)。以下是我能够修改函数以使值为空白然后我可以插入任何我想要的值作为值:
add_filter( 'tribe_events_recurrence_tooltip',
'my_function');
function my_function($tooltip) {
$tooltip = null;
return $tooltip;
}
想到其他人可能会搜索此内容并找到有用的答案。