doupingmao1903 2019-02-03 18:04
浏览 43

将Span和类添加到PHP数组

The Wordpress plugin I am using calls the invoice due date using the php:

<p><?php wpi_invoice_due_date2(); ?></p>

this then displays as one column

<p>Due Date: 10 May 2019</p>

I am looking to keep this in line with the rest of the template and to do this, I need to add a style to the date but am unsure how to achieve this.

I have created an override to the plugin to allow me to style things.

As you will see below, I have added a '' to the Due Date text. however, this is not consistent with the rest of the page, and what makes it more difficult is that this row and the rows above are all wrapped in the same element.

I could probably ammend the to make things work, however, I am keen to find out if there is a work around for this.

if ( !function_exists('wpi_invoice_due_date') ) {
function wpi_invoice_due_date2( $args = "" ) {
  global $invoice;

  $defaults = array(
      'return' => false,
      'text'   => __('<span class="duebold">Due Date:</span> ', ud_get_wp_invoice()->domain),
      'format' => 'd F Y'
  );

  extract( wp_parse_args($args, $defaults) );

  if ( empty( $invoice['due_date_year'] )
       || empty( $invoice['due_date_month'] )
       || empty( $invoice['due_date_day'] ) )  return;

  if ( !$return ) {
    echo $text.date($format, strtotime( $invoice['due_date_day'].'-'.$invoice['due_date_month'].'-'.$invoice['due_date_year'] ));
    return;
  }

  return $text.date($format, strtotime( $invoice['due_date_day'].'-'.$invoice['due_date_month'].'-'.$invoice['due_date_year'] ));
}

I have added the span in this line:

'text'   => __('<span class="duebold">Due Date:</span> ', ud_get_wp_invoice()->domain),

However, it is what comes after Due date that I would like to change

Currently I have

Invoice Number: 1111111

Invoice Amount: £120.00

Due Date: 01 March 2019

Ideally, I would like

Invoice Number: 1111111

Invoice Amount: £120.00

Due Date: 01 March 2019

  • 写回答

1条回答 默认 最新

  • dongzhankou2090 2019-02-03 18:33
    关注

    Remove the <span> tag from the text, and add it around the date using sprintf:

    if ( !function_exists('wpi_invoice_due_date') ) {
    function wpi_invoice_due_date2( $args = "" ) {
      global $invoice;
    
      $defaults = array(
          'return' => false,
          'text'   => __('Due Date: ', ud_get_wp_invoice()->domain),
          'format' => 'd F Y'
      );
    
      extract( wp_parse_args($args, $defaults) );
    
      if ( empty( $invoice['due_date_year'] )
           || empty( $invoice['due_date_month'] )
           || empty( $invoice['due_date_day'] ) )  return;
    
      $text.= sprintf(
        "<span class='duebold'>%s</span>",
        date($format, strtotime( $invoice['due_date_day'].'-'.$invoice['due_date_month'].'-'.$invoice['due_date_year'] )));
    
      if ( !$return ) {
        echo $text;
        return;
      }
    
      return $text;
    }
    

    sprintf Documentation

    Personal note:

    Please, never pass HTML to the __() function, you can always find a way to insert the HTML tags inside the string and use __() to only retrieve the needed text. HTML inside text strings makes translating them harder and prone to errors. If you don't need translations, just use plain text.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程