Use touch_time() on front-end form via plugin

I’m working on a plug-in that let people create posts from front-end form. I want to add date&time fields in the form using touch_time() but don’t know how to use it on front-end.

I have <div id="timestampdiv" class="hide-if-js"><?php touch_time(0, 0, 5); ?></div> on the front-end form which giving me an error message Fatal error: Call to undefined function touch_time().

Is it possible to access touch_time function(wp-admin/includes/template.php) from my plugin?

Solutions Collecting From Web of "Use touch_time() on front-end form via plugin"

You might try to include the the template.php file:

<?php 
if( ! function_exists( 'touch_time' ) )
{
    require_once( ABSPATH . '/wp-admin/includes/template.php' );
    touch_time( 0, 0, 5 ); 
}
?>

but I think it might be better to just copy the code from the touch_time() function into your own function and modify accordingly.

Friday part of the answer:

“A Big Mess” and “Black Magic”

According to the inline documentation, that file is a Big Mess 😉

/**
 * Template WordPress Administration API.
 *
 * A Big Mess. Also some neat functions that are nicely written.
 *

and watch out for the Black Magic in the /wp-includes/rewrite.php file:

 /**
  * Generate rewrite rules from a permalink structure.
  *
  * The main WP_Rewrite function for building the rewrite rule list. The
  * contents of the function is a mix of black magic and regular expressions,
  * so best just ignore the contents and move to the parameters.
  *

so be aware what you include in your plugin 😉