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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么