duanqiang9212 2017-10-27 18:21
浏览 28
已采纳

从函数中替换变量的值

I'm trying to modify the output of a function from a WordPress plugin (Modern Tribe's The Events Calendar). I'm attempting to use apply_filter to accomplish this, but to no avail. Here is the function I want to interact with:

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 );
}

I basically just want to manipulate the output value for $tooltip. I'm not sure if I need to utilize str_replace or parse_str, but neither have worked in the functions I've tried. If someone can help with getting $tooltip emptied out, I should be able to take it from there.

  • 写回答

1条回答 默认 最新

  • duanjiao6711 2017-10-30 13:41
    关注

    Was using apply_filter when I should've been using add_filter to hook into the function (I'm new to this). Here's how I was able to modify the function so that the value was blank and I could then insert whatever I wanted to as the value:

    add_filter( 'tribe_events_recurrence_tooltip', 
    'my_function');
    
    function my_function($tooltip) {
      $tooltip = null;
    
      return $tooltip;
    }
    

    Figured someone else might search this and find the answer helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘