• Resolved creativecatapps

    (@creativecatapps)


    Hi,

    I would like to use Forminator for a monthly event of up to 16 people. I have set the submissions lifespan to 16, but will need to manually reset this each month.

    I have seen code on the WPMU website which retrieves the number of submissions for a form, but is there a filter or hook that will reset this to a provided number?

    Thanks,
    Emma

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @creativecatapps,

    I hope you are doing well today!

    This issue has been flagged to our SLS (Second Line Support) Team so that they can dig into this further. We will post an update here as soon as more information is available.

    Please keep in mind that our SLS Team deals with more complicated issues, so it may take a little longer for us to reply here.

    Thank you for your patience while we look into this further.

    Kind regards,
    Zafer

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @creativecatapps,

    Could you please try this code snippet and then check whether it helps?

    <?php
    
    add_filter( 'forminator_cform_form_is_visible', 'wpmudev_formi_form_can_show', 10, 3 );
    function wpmudev_formi_form_can_show( $can_show, $id, $form_settings ) {
    	if ( 2910 != $id ) {
    		return $can_show;
    	}
    
    	$now 				= strtotime('now');
    	$this_day 			= date( 'j', $now );
    	$days_this_month 	= date( 't', $now );
    	$month				= date( 'n', $now );
    
    	$form_meta = get_post_meta( $id, 'forminator_form_meta', true );
    	if ( ! empty( $form_meta ) ) {
    		$update_meta = false;
    		if ( ! empty( $form_meta['settings']['expire_submits'] ) ) {
    			$entries = wpmudev_get_months_entries( $id, $month );
    			if ( $this_day == 1 && ! $can_show ) {
    				if ( empty( $entries ) || count( $entries ) < 16 ) {
    					$expire_submits = $form_meta['settings']['expire_submits'] + 16;
    					$form_meta['settings']['expire_submits'] = $expire_submits;
    					$update_meta = true;
    				}
    			}
    		}
    
    		if ( $update_meta ) {
    			update_post_meta( $id, 'forminator_form_meta', $form_meta );
    			$can_show = true;
    		}
    	}
    
    	return $can_show;
    }
    
    function wpmudev_get_months_entries( $id, $month ) {
    	global $wpdb;
        $entry_table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY );
        $sql              = "SELECT <code>entry_id</code> FROM {$entry_table_name} WHERE <code>form_id</code> = %d AND MONTH(<code>date_created</code>) = %d";
        $entries          = $wpdb->get_results( $wpdb->prepare( $sql, $id, $month ) );
        if ( ! empty( $entries ) ) {
            return $entries;
        }
        return false;
    }

    You’ll have to update the following line from the above code to your forms ID, ie:

    	if ( 2910 != $id ) {
    

    Suppose your Form ID is 123, then the above will change to:

    	if ( 123 != $id ) {
    

    Please do note that the code checks if this is the first day of the month and then adds +16 to the previous value.

    The above snippet can be added as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,
    Nithin

    Thread Starter creativecatapps

    (@creativecatapps)

    Hi,

    Many thanks for the reply. I can’t test the code till next week now, but looking through, I can understand how it works and it’s far further along than I’ve got!

    Will report back.
    Thanks,
    Emma

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @creativecatapps

    Sure thing, take as much time as you need. Just let us know in case you’d need any more assistance with it. We are here all year long and can back to it whenever needed.

    Best regards,
    Adam

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @creativecatapps ,

    We haven’t heard from you for over a week now, so it looks like you don’t have any more questions for us.

    Feel free to re-open this ticket if
    needed.

    Kind regards
    Kasia

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Reset lifespan submissions via function’ is closed to new replies.