• Resolved brunonar

    (@brunonar)


    Hi, first of all I’d like to thank you for this amazing Calendar of yours.
    I’d like to know if you could help me with two features that I need.

    1) There are any way to restrict the range of a event that a subscriber user can schedule (eg. Max 30 days from now)? I’ve think about using the ‘mc_before_save_insert’ filter, but I’m not sure how could I take the date option that the user is trying to set.

    2) I’d like to know if it’s possible to change the table “my-calendar-admin-table”. I need to change the Author column to a custom user field (apartment number). I really don’t know if I’ll have to change the plugin’s code or there are a action or filter for it.

    Since now I apologize about my poor English and thank you very much in advance.

    https://www.ads-software.com/plugins/my-calendar/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Joe Dolson

    (@joedolson)

    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.

    Thread Starter brunonar

    (@brunonar)

    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!

    Thread Starter brunonar

    (@brunonar)

    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 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Restrict event range for subscriber users’ is closed to new replies.