Submission_Export::get_submission_columns( awsmug\Torro_Forms\DB_Objects\Forms\Form $form )

Gets submission columns for the export.

Description

These columns deal with the submission itself, not with individual submission values.

See also

Parameters

$form

(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form for which submissions are being exported.

Return

(array) Associative array of <code>$column_slug => $column_data</code> pairs where each <code>$column_data</code> must be an array containing 'label' and 'callback' keys. The callback must accept a submission object.

Source

File: src/components/submission-export.php

	protected function get_submission_columns( $form ) {
		$submission_columns = array(
			'id'   => array(
				'label'    => __( 'ID', 'torro-forms' ),
				'callback' => function( $submission ) {
					return $submission->id;
				},
			),
			'user' => array(
				'label'    => __( 'User', 'torro-forms' ),
				'callback' => function( $submission ) {
					if ( ! $submission->user_id ) {
						return __( 'not available', 'torro-forms' );
					}

					$user = get_user_by( 'id', $submission->user_id );
					if ( ! $user || ! $user->exists() ) {
						return __( 'not available', 'torro-forms' );
					}

					return $user->display_name;
				},
			),
			'date' => array(
				'label'    => __( 'Date', 'torro-forms' ),
				'callback' => function( $submission ) {
					/* translators: 1: date format string, 2: time format string */
					$format = sprintf( _x( '%1$s %2$s', 'concatenating date and time format', 'torro-forms' ), get_option( 'date_format' ), get_option( 'time_format' ) );

					return $submission->format_datetime( $format, false );
				},
			),
		);

		/**
		 * Filters the columns to display for a submission when exporting.
		 *
		 * @since 1.0.0
		 *
		 * @param array $submission_columns Associative array of `$column_slug => $column_data` pairs
		 *                                  where `$column_data must be an array with 'label' amd 'callback'
		 *                                  keys. The callback must accept a submission object.
		 * @param Form  $form               Form object for which submissions are being exported.
		 */
		return apply_filters( "{$this->handler->get_prefix()}submission_export_columns", $submission_columns, $form );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.