1

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?

3

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 ;-)

  • Thank you for the answer! Would you mind explaining why it's better to copy the code from touch_time()? Your code brings the time form in my front-end form but it does not actually update the time in DB. – Ohsik Oct 16 '15 at 18:38
  • This function only displays the form and doesn't contain the update code. This is also specific to the back-end so it might not suit your needs on the front-end, like the OK and Cancel parts. It might also change in the future? @Ohsik – birgire Oct 16 '15 at 18:45
  • Thank you so much for the answer! that cleared lots of things for me :) Now I have to find a way to process that Date/Time values ;) – Ohsik Oct 16 '15 at 18:55
  • you're welcome and good luck with your project. @Ohsik – birgire Oct 16 '15 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.