Skip to content

Commit

Permalink
Add give_date_format helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk committed Aug 24, 2016
1 parent ffbdfc4 commit 4ac1fe4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,52 @@ function give_cmb_amount_field_render_row_cb( $field_args, $field ) {
</div>
</div>
<?php
}


/**
* Get date format string on basis of given context.
*
*
* @since 1.7
*
* @param string $date_context Date format context name.
*
* @return string Date format string
*/
function give_date_format ( $date_context = '' ) {
/**
* Filter the date context
*
* You can add your own date context or use already exist context.
* For example:
* add_filter( 'give_date_format_contexts', 'add_new_date_contexts' );
* function add_new_date_contexts( $date_format_contexts ) {
* // You can add single context like this $date_format_contexts['checkout'] = 'F j, Y';
* // Instead add multiple date context at once.
* $new_date_format_contexts = array(
* 'checkout' => 'F j, Y',
* 'report' => 'Y-m-d',
* 'email' => 'm/d/Y',
* );
*
* // Merge date contexts array only if you are adding multiple date contexts at once otherwise return $date_format_contexts.
* return array_merge( $new_date_format_contexts, $date_format_contexts );
*
* }
*/
$date_format_contexts = apply_filters( 'give_date_format_contexts', array() );

// Set date format to default date format.
$date_format = get_option('date_Format');


// Update date format if we have non empty date format context array and non empty date format string for that context.
if( $date_context && ! empty( $date_format_contexts ) && array_key_exists( $date_format_contexts, $date_format_contexts ) ) {
$date_format = ! empty( $date_format_contexts[ $date_context ] )
? $date_format_contexts[ $date_context ]
: $date_format;
}

return apply_filters( 'give_date_format', $date_format );
}

0 comments on commit 4ac1fe4

Please sign in to comment.