Submission_Manager::maybe_delete_submissions()

Deletes submissions that have been ‘progressing’ for too long, if enabled.

Description

This is executed twice daily via cron.

See also

Source

File: src/db-objects/submissions/submission-manager.php

	public function maybe_delete_submissions() {
		$settings = $this->get_parent_manager( 'forms' )->options()->get( 'general', array() );

		$delete = isset( $settings['delete_submissions'] ) ? (bool) $settings['delete_submissions'] : false;
		if ( ! $delete ) {
			return;
		}

		$delete_days = ! empty( $settings['delete_submissions_days'] ) ? (int) $settings['delete_submissions_days'] : 1;

		/**
		 * Filters the limit for the query detecting incomplete submissions to delete.
		 *
		 * This can be used to adjust the value, depending on more or less server power.
		 *
		 * @since 1.0.0
		 *
		 * @param int $limit Limit for the query. Default is 50.
		 */
		$limit = apply_filters( "{$this->get_prefix()}delete_submissions_query_limit", 50 );

		$submissions = $this->query( array(
			'number'    => $limit,
			'status'    => 'progressing',
			'timestamp' => array(
				'lower_than' => current_time( 'timestamp', true ) - $delete_days * DAY_IN_SECONDS,
			),
		) );
		foreach ( $submissions as $submission ) {
			$submission->delete();
		}
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.