Skip to content

Instantly share code, notes, and snippets.

@kjohnson
Created January 20, 2017 17:26
Show Gist options
  • Select an option

  • Save kjohnson/6804787420b0edc110af6e34da064904 to your computer and use it in GitHub Desktop.

Select an option

Save kjohnson/6804787420b0edc110af6e34da064904 to your computer and use it in GitHub Desktop.
Converts a formatted Ninja Forms date to a timestamp for compatibility with Custom Fields (Date Type)
<?php
// Requires PHP v5.3 or higher.
add_filter( 'ninja_forms_create_post_meta_value', function( $meta_value, $post_type, $meta_key ){
// TODO: Update $post_type check.
// TODO: Update $meta_key check.
if( 'test' == $post_type && 'wpcf-test-date' == $meta_key ){
// Convert formatted date to timestamp for WP-Types compatibility.
$meta_value = DateTime::createFromFormat( 'd/m/Y', $meta_value )->getTimestamp();
}
return $meta_value;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment