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 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?