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.

Admin_Menu::enqueue_global_assets()

Enqueues global assets in the Automator pages


Source

File: src/core/admin/class-admin-menu.php

	private function enqueue_global_assets() {
		// List of page where we have to add the assets
		$this->backend_enqueue_in = array(
			'post.php', // Has filter, check callback
			'uncanny-automator-dashboard',
			'uncanny-automator-integrations',
			'uncanny-automator-config',
			'uncanny-automator-tools',
			'edit.php',
		);

		// Enqueue admin scripts
		add_action(
			'admin_enqueue_scripts',
			function ( $hook ) {
				// Add exception for the "post.php" hook
				if ( 'post.php' === $hook || 'edit.php' === $hook ) {
					if ( 'uo-recipe' !== (string) get_post_type() ) {
						return;
					}
				}

				// Check if the current page is one of the target pages
				if ( in_array( str_replace( 'uo-recipe_page_', '', $hook ), $this->backend_enqueue_in, true ) ) {
					// Enqueue main CSS
					wp_enqueue_style(
						'uap-admin',
						Utilities::automator_get_asset( 'backend/dist/bundle.min.css' ),
						array(),
						Utilities::automator_get_version()
					);

					// Register main JS
					wp_register_script(
						'uap-admin',
						Utilities::automator_get_asset( 'backend/dist/bundle.min.js' ),
						array(),
						Utilities::automator_get_version(),
						true
					);

					// Get data for the main script
					wp_localize_script(
						'uap-admin',
						'UncannyAutomatorBackend',
						$this->get_js_backend_inline_data( $hook )
					);

					// Enqueue main JS
					wp_enqueue_script( 'uap-admin' );
				}
			}
		);
	}