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.

Recipe_Post_Utilities::assets_get_automator_main_object()


Return Return

(mixed|void)


Source Source

File: src/core/automator-post-types/uo-recipe/class-recipe-post-utilities.php

	private function assets_get_automator_main_object() {
		global $post;

		// $post return $post->ID as a string, Our JS expects an int... change it
		$post_id = (int) $post->ID;

		// API data
		$completions_allowed     = get_post_meta( $post_id, 'recipe_completions_allowed', true );
		$max_completions_allowed = get_post_meta( $post_id, 'recipe_max_completions_allowed', true );
		$recipe_type             = get_post_meta( $post_id, 'uap_recipe_type', true );

		// Get source
		$source = get_post_meta( $post_id, 'source', true );
		// Create fields array
		$fields = array(
			'existingUser' => array(),
			'newUser'      => array(),
		);
		// Check if the user defined a valid source
		if ( in_array( $source, array( 'existingUser', 'newUser' ), false ) ) {
			// If the user did it, then add the fields
			$fields[ $source ] = get_post_meta( $post_id, 'fields', true );
		}

		$editable_roles = get_editable_roles();
		$roles          = array();
		foreach ( $editable_roles as $role_key => $role_data ) {
			$roles[ $role_key ] = $role_data['name'];
		}

		$api_setup = array(
			'wp'             => false,
			'restURL'        => esc_url_raw( rest_url() . AUTOMATOR_REST_API_END_POINT ),
			'siteURL'        => get_site_url(),
			'nonce'          => \wp_create_nonce( 'wp_rest' ),
			'dev'            => array(
				'debugMode'    => (bool) AUTOMATOR_DEBUG_MODE,
				'recipesUrl'   => admin_url( 'edit.php?post_type=uo-recipe' ),
				'debuggingURL' => 'https://automatorplugin.com/knowledge-base/troubleshooting-plugin-errors/?utm_source=uncanny_automator&utm_medium=recipe-wizard-error-modal&utm_content=learn-more-debugging',
			),
			'integrations'   => Automator()->get_integrations(),
			'triggers'       => Automator()->get_triggers(),
			'actions'        => Automator()->get_actions(),
			'closures'       => Automator()->get_closures(),
			'i18n'           => Automator()->i18n->get_all(),
			'recipes_object' => Automator()->get_recipes_data( true, $post_id ),
			'version'        => Utilities::automator_get_version(),
			'proVersion'     => defined( 'AUTOMATOR_PRO_FILE' ) ? \Uncanny_Automator_Pro\InitializePlugin::PLUGIN_VERSION : '',
			'proFeatures'    => $this->get_pro_items(),
			'recipe'         => array(
				'id'           => $post_id,
				'author'       => $post->post_author,
				'status'       => $post->post_status,
				'type'         => empty( $recipe_type ) ? null : $recipe_type,
				'isLive'       => 'publish' === $post->post_status,
				'errorMode'    => false,
				'isValid'      => false,
				'userSelector' => array(
					'source'    => $source,
					'data'      => $fields,
					'isValid'   => false,
					'resources' => array(
						'roles' => $roles,
					),
				),
				'hasLive'      => array(
					'trigger' => false,
					'action'  => false,
					'closure' => false,
				),
				'message'      => array(
					'error'   => '',
					'warning' => '',
				),
				'items'        => array(),
				'publish'      => array(
					'timesPerUser'   => empty( $completions_allowed ) ? 1 : $completions_allowed,
					'timesPerRecipe' => empty( $max_completions_allowed ) ? '-1' : $max_completions_allowed,
					'createdOn'      => date_i18n( 'M j, Y @ G:i', get_the_time( 'U', $post_id ) ),
					'moveToTrash'    => get_delete_post_link( $post_id ),
					'copyToDraft'    => sprintf( '%s?action=%s&post=%d&return_to_recipe=yes&_wpnonce=%s', admin_url( 'edit.php' ), 'copy_recipe_parts', $post_id, wp_create_nonce( 'Aut0Mat0R' ) ),
				),
			),
			'format'         => array(
				'date' => get_option( 'date_format' ),
			),
		);

		$api_setup = apply_filters_deprecated( 'uap_api_setup', array( $api_setup ), '3.0', 'automator_api_setup' ); // deprecate

		return apply_filters( 'automator_api_setup', $api_setup );
	}