Filter uncanny-automator

automator_assets_backend_js_data

Filters the JavaScript data for the backend, allowing modification before it's loaded.

add_filter( 'automator_assets_backend_js_data', $callback, 10, 2 );

Description

Fires before backend JavaScript data is enqueued for the Automator. Allows developers to modify the data array passed to the JavaScript, enabling customization of frontend behavior and integration with other plugins. Use with caution to avoid breaking core functionality.


Usage

add_filter( 'automator_assets_backend_js_data', 'your_function_name', 10, 2 );

Parameters

$automator_backend_js (mixed)
This parameter contains an array of data that will be passed to the JavaScript for the Uncanny Automator backend, including AJAX and REST API configurations.
$hook (mixed)
This parameter contains an array of data that will be passed to the JavaScript running in the WordPress backend, including AJAX endpoints and security nonces.

Return Value

The filtered value.


Examples

<?php
/**
 * Example callback function for the 'automator_assets_backend_js_data' filter hook.
 * This function adds a new configuration option to the JavaScript data object
 * for the WordPress Automator backend.
 *
 * @param array $automator_backend_js The original array of JavaScript data.
 * @param string $hook The hook name that triggered this data generation (e.g., 'automator_menu_page').
 * @return array The modified array of JavaScript data.
 */
function my_automator_add_custom_setting( $automator_backend_js, $hook ) {
	// Check if the hook is relevant, though this filter is generally applied broadly.
	// For this example, we'll assume we want to add this setting regardless of the specific hook.

	// Add a new configuration option for a hypothetical custom feature.
	// This could be a boolean flag, a string, an array, etc.
	$automator_backend_js['customSettings'] = [
		'enableNewFeature' => true,
		'featureName'      => 'Advanced Notifications',
		'defaultLimit'     => 50,
	];

	// Optionally, you might want to conditionally modify data based on the hook,
	// for example:
	// if ( $hook === 'automator_specific_page' ) {
	//     $automator_backend_js['pageSpecificData'] = 'someValue';
	// }

	// Always return the modified data.
	return $automator_backend_js;
}
add_filter( 'automator_assets_backend_js_data', 'my_automator_add_custom_setting', 10, 2 );
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

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

public function get_js_backend_inline_data( $hook ) {
		// Set default data
		$automator_backend_js = array(
			'ajax'       => array(
				'url'   => admin_url( 'admin-ajax.php' ),
				'nonce' => wp_create_nonce( 'uncanny_automator' ),
			),
			'rest'       => array(
				'url'   => esc_url_raw( rest_url() . AUTOMATOR_REST_API_END_POINT ), // Automator URL endpoint
				'base'  => esc_url_raw( rest_url() ), // Actual URL of the /wp-json/
				'nonce' => wp_create_nonce( 'wp_rest' ),
			),
			'logs'       => array(
				'runsPerPage' => (int) apply_filters( 'automator_loop_logs_runs_per_page', Uncanny_AutomatorRestEndpointLog_EndpointResourcesLoop_Logs_Resources::DEFAULT_RUNS_PER_PAGE ),
			),
			'debugging'  => array(
				'enabled' => (bool) AUTOMATOR_DEBUG_MODE,
			),
			'components' => array(
				'icon'     => array(
					'integrations' => $this->get_integrations_for_components(),
				),
			),
			'_site'      => array(
				'automator' => array(
					'license_details'    => ( new License_Summary() )->get_license_summary(),
					'is_pro_active'      => defined( 'AUTOMATOR_PRO_PLUGIN_VERSION' ),
					'links' => array(
						'marketing_referer'  => automator_get_option( 'uncannyautomator_source', '' ),
						'external' => array(
							'url_upgrade_to_pro' => add_query_arg(
								// UTM
								array(
									'utm_source'  => 'uncanny_automator',
									'utm_medium'  => 'upgrade_to_pro',
									'utm_content' => 'upgrade_to_pro_button',
								),
								'https://automatorplugin.com/pricing/'
							),
						),
						'internal' => array(
							'all_recipes'        => admin_url( 'edit.php?post_type=uo-recipe' ),
							'tools'              => admin_url( 'edit.php?post_type=uo-recipe&page=uncanny-automator-tools' ),
							'manage_license'     => admin_url( 'edit.php?post_type=uo-recipe&page=uncanny-automator-config&tab=general&general=license' ),
						),
					),
				),
			),
		);

		// Filter data
		$automator_backend_js = apply_filters(
			'automator_assets_backend_js_data',
			$automator_backend_js,
			$hook
		);

		return $automator_backend_js;
	}

Scroll to Top