• Resolved ashleylyn07

    (@ashleylyn07)


    We are using this plugin for our employee directory and when you click to view the individual person’s profile, I have their date of hire and birthday both listed. I need to hide the birth year for everyone so right now I have the Date Format showing just the month and day, but I’d like to be able to show the full date (year included) for the hire date. Is this possible? Or what could I do to show this “custom” hire date?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Steven

    (@shazahm1hotmailcom)

    There is no click it and set it feature to accomplish this, but it might be possible to accomplish. I’ll see if this can be accomplished with an easy-to-implement filter and get back to your asap.

    Thread Starter ashleylyn07

    (@ashleylyn07)

    Thank you so much! I would really appreciate it!

    Plugin Author Steven

    (@shazahm1hotmailcom)

    Apologies for the delay in my reply!!!

    I’ve worked out a solution.

    First install and activate the Code Snippets plugin. Here’s the link:

    Copy-paste the following code into a new code snippet. Save it and then activate it. Here’s the code:

    add_filter(
    	'cn_output_date',
    	static function( $html, $date, $entry, $atts ) {
    		
    		$search  = array( '%label%', '%date%', '%separator%' );
    		$replace = array();
    
    		if ( false === $date->date ) {
    
    			return $html;
    		}
    
    		$classNames = array(
    			'vevent',
    			'cn-date',
    		);
    
    		if ( $date->preferred ) {
    
    			$classNames[] = 'cn-preferred';
    			$classNames[] = 'cn-date-preferred';
    		}
    		
    		if ( 'DOH' === $date->name ) {
    			$atts['date_format'] = 'F jS Y';
    		}
    
    		$html = '<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>';
    
    		$html .= str_ireplace(
    			$search,
    			$replace,
    			empty( $atts['format'] ) ? ( empty( $defaults['format'] ) ? '%label%%separator% %date%' : $defaults['format'] ) : $atts['format']
    		);
    
    		$html .= '</span>';
    		
    		return $html;
    	},
    	10,
    	4
    );

    I hope this helps; please let me know. Thanks!

    Thread Starter ashleylyn07

    (@ashleylyn07)

    That worked like a charm! Thank you so much for working on that. I’m so excited to be able to show their anniversary year in their profiles and I really appreciate your help on this!

    Plugin Author Steven

    (@shazahm1hotmailcom)

    No problem; happy to help!

    I would genuinely appreciate a review if you have a moment, as they really make a difference.

    https://ww.wp.xz.cn/plugins/connections/

    Thanks in advance for your time!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Profile Details Date Formatting’ is closed to new replies.