1) Off hand, I don’t know of a way to do that. You could use the filter as you mentioned, but I think it would be better to prevent submission of invalid dates as well, and I’m not sure of a way to do that, right now – I’ll have to look into it. I’m traveling right now, so this may take a little while to look into.
2) There are no filters on the admin table to change the information in that field. It might be possible to use a core filter on the author object, but I don’t know for sure whether any such filter exists that would work for you.
Thank you very much for the tips! I’ll check it up and return with a code in case of I find an answer!
I wish you a nice trip, Joe!
I finally found out how to do it. I just wouldn’t know how to return to the plugin that the post was invalidated. So I just did a wp_die with a message for my client and it worked fine.
I would like to thank you again very much, Joe, for show me the path…
function my_calendar_30_days( $post, $action, $i ) {
if (!is_user_logged_in()){
wp_die();
}
if ( $action == 'add' || $action == 'edit' || $action == 'copy' ) {
$begin = strtotime(trim( $post['event_begin'][ $i ] ));
$end = strtotime(trim( $post['event_end'][ $i ] ));
$now = time();
$begindiff = abs($now - $begin);
$enddiff = abs($now - $end);
$beginInDays= floor($begindiff/(60*60*24));
if ($end==''){
$endInDays = 0;
} else {
$endInDays = floor($enddiff/(60*60*24));
}
if($beinInDays > 30 || $endInDays > 30){
//More than 30 days. cancel the event.
wp_die("<h3>It's not <b>alloewd</b> insert events with more than 30 days from now.</h3>");
} else {
//Everything it's ok, return to plugin for other validations
return $post;
}
} else {
//Maybe there's a 'delete' operation?
return $post;
}
}
add_filter( 'mc_pre_checkdata', 'my_calendar_30_days', 10, 3 );