• Resolved Kim Bydlon

    (@kbydlon)


    I am creating an internal/private Employee Directory for my company using this plugin (Circled template), and we would like to incorporate birthdays, e.g., use the related Widget Pack features and list it on individual profiles. However, as most people do not like to disclose their age, we want to exclude the year from showing up in the birthday dates. I could just remove it from the date format in Connections: Settings, but we also want to include (Work) Anniversary dates which do require the year, so it shouldn’t be hidden from ALL dates. Is there a way to target hiding the year portion of a certain type of date and leave the others unaffected?

    • This topic was modified 5 months, 2 weeks ago by Kim Bydlon.
    • This topic was modified 5 months, 2 weeks ago by Kim Bydlon.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Steven

    (@shazahm1hotmailcom)

    Apologies for the delay in my reply! I had to create a working code snippet that you can add using the Code Snippets plugin.

    Here’s the code snippet.

    add_filter(
    'cn_output_date',
    static function ( $html, $date, $entry, $atts ) {

    if ( 'birthday' !== $date->type ) {

    return $html;
    }

    $atts['date_format'] = 'F j';

    $search = array( '%label%', '%date%', '%separator%' );
    $replace = array();

    $classNames = array(
    'vevent',
    'cn-date',
    );

    if ( $date->preferred ) {

    $classNames[] = 'cn-preferred';
    $classNames[] = 'cn-date-preferred';
    }

    $row = '<span class="' . Connections_Directory\Utility\_escape::classNames( $classNames ) . '">';

    // Hidden elements are to maintain hCalendar spec compatibility.
    $replace[] = empty( $date->name ) ? '' : '<span class="date-name">' . esc_html( $date->name ) . '</span>';
    $replace[] = empty( $date->date ) ? '' : '<abbr class="dtstart" title="' . esc_attr( $date->date->format( 'Ymd' ) ) . '">' . date_i18n( $atts['date_format'], $date->date->getTimestamp(), false ) . '</abbr>
    <span class="summary" style="display:none">' . esc_html( $date->name ) . ' - ' . $entry->getName( array( 'format' => $atts['name_format'] ) ) . '</span>
    <span class="uid" style="display:none">' . esc_html( $date->date->format( 'YmdHis' ) ) . '</span>';
    $replace[] = '<span class="cn-separator">' . esc_html( $atts['separator'] ) . '</span>';

    $row .= str_ireplace(
    $search,
    $replace,
    empty( $atts['format'] ) ? ( empty( $defaults['format'] ) ? '%label%%separator% %date%' : $defaults['format'] ) : $atts['format']
    );

    return $row .= '</span>';
    },
    10,
    4
    );

    I hope this helps; please let me know.

    Thread Starter Kim Bydlon

    (@kbydlon)

    Worked like a charm! Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.