Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Logs_List_Table::format_trigger_data( array $triggers )

Format trigger log data


Parameters Parameters

$triggers

(array) (Required) list of objects


Top ↑

Return Return

(array)


Source Source

File: src/core/admin/class-logs-list-table.php

	private function format_trigger_data( $triggers ) {


		$data         = array();
		$recipes_data = Automator()->get_recipes_data( false );

		foreach ( $triggers as $trigger ) {

			$trigger_code = $this->item_code( $recipes_data, absint( $trigger->automator_trigger_id ) );

			$trigger_date_completed = $trigger->trigger_date;
			if ( ! empty( $trigger->trigger_run_time ) && '0000-00-00 00:00:00' !== (string) $trigger->trigger_run_time ) {
				$trigger_date_completed = $trigger->trigger_run_time;
			}

			$recipe_link = get_edit_post_link( absint( $trigger->automator_recipe_id ) );
			/* translators: 1: Post ID */
			$recipe_name = ! empty( $trigger->recipe_title ) ? $trigger->recipe_title : sprintf( esc_attr__( 'ID: %1$s (no title)', 'uncanny-automator' ), $trigger->automator_recipe_id );

			if ( ! empty( $recipe_link ) ) {
				$recipe_name = '<a href="' . $recipe_link . '" class="uap-log-table__recipe-name">' . $recipe_name . '</a>';
			}

			if ( 1 === absint( $trigger->recipe_completed ) ) {
				/* translators: Trigger status */
				$recipe_status = esc_attr_x( 'Completed', 'Trigger', 'uncanny-automator' );
			} elseif ( 2 === absint( $trigger->recipe_completed ) ) {
				/* translators: Trigger status */
				$recipe_status = esc_attr_x( 'Completed with errors', 'Trigger', 'uncanny-automator' );
			} elseif ( 9 === absint( $trigger->recipe_completed ) ) {
				/* translators: Trigger status */
				$recipe_status = esc_attr_x( 'Completed, do nothing', 'Trigger', 'uncanny-automator' );
			} else {
				/* translators: Trigger status */
				$recipe_status = esc_attr_x( 'In progress', 'Trigger', 'uncanny-automator' );
			}

			$recipe_date_completed = ( 1 === absint( $trigger->recipe_completed ) || 2 === absint( $trigger->recipe_completed ) || 9 === absint( $trigger->recipe_completed ) ) ? $trigger->recipe_date_time : '';
			if ( is_null( $trigger->user_id ) ) {
				/* translators: User type */
				$user_name = esc_attr_x( 'Anonymous', 'User', 'uncanny-automator' );
			} else {
				$user_link       = get_edit_user_link( absint( $trigger->user_id ) );
				$user_email_link = sprintf(
					'<a href="mailto:%1$s" title="%2$s">(%1$s)</a>',
					sanitize_email( $trigger->user_email ),
					esc_attr__( 'Send Email', 'uncanny-automator' )
				);
				$user_name       = '<a href="' . $user_link . '">' . $trigger->display_name . '</a> <br>' . $user_email_link;
			}

			/* translators: 1. Trigger ID */
			$trigger_name = sprintf( esc_attr__( 'Trigger deleted: %1$s', 'uncanny-automator' ), $trigger->automator_trigger_id );

			if ( $trigger_code ) {
				// get the trigger title
				$trigger_title = $trigger->trigger_title;
				// get the triggers completed sentence
				$trigger_sentence = $trigger->trigger_sentence;
				if ( empty( $trigger_title ) && ! defined( 'AUTOMATOR_PRO_FILE' ) ) {
					/* translators: 1. Trademarked term */
					$trigger_name = sprintf( esc_attr__( '(Reactivate %1$s to view)', 'uncanny-automator' ), 'Uncanny Automator Pro' );
				} else {
					if ( empty( $trigger_sentence ) ) {
						$trigger_name = '<div class="uap-logs-table__item-main-sentence">' . $trigger_title . '</div>';
					} else {
						$trigger_name = '<div class="uap-logs-table__item-main-sentence">' . $this->format_human_readable_sentence( $trigger_sentence ) . '</div>';
						$trigger_name .= '<div class="uap-logs-table__item-secondary-sentence">' . $trigger_title . '</div>';
					}
				}
			}

			$recipe_run_number   = absint( $trigger->recipe_run_number );
			$trigger_run_number  = ( 0 === absint( $trigger->trigger_run_number ) || empty( $trigger->trigger_run_number ) ) ? 1 : absint( $trigger->trigger_run_number );
			$trigger_total_times = ( 0 === absint( $trigger->trigger_total_times ) || empty( $trigger->trigger_total_times ) ) ? 1 : $trigger->trigger_total_times;
			$recipe_run_number   = 'anonymous' === (string) Automator()->utilities->get_recipe_type( absint( $trigger->automator_recipe_id ) ) ? 'N/A' : $recipe_run_number;

			$data[] = array(
				'trigger_id'         => $trigger->ID,
				'trigger_title'      => $trigger_name,
				'trigger_date'       => $trigger_date_completed,
				'recipe_title'       => $recipe_name,
				'recipe_completed'   => $recipe_status,
				'recipe_date_time'   => $recipe_date_completed,
				'recipe_run_number'  => $recipe_run_number,
				'trigger_run_number' => sprintf( esc_attr__( '%d of %d', 'uncanny-automator' ), $trigger_run_number, $trigger_total_times ),
				'display_name'       => $user_name,
			);
		}

		return $data;
	}