Filter
uncanny-automator
automator_conflictive_assets
Filters the list of assets deemed conflictive, allowing for custom exclusion or modification.
add_filter( 'automator_conflictive_assets', $callback, 10, 1 );
Description
Filters an array of assets (scripts and styles) identified as potentially conflicting during the automator recipe post type's asset loading process. Developers can modify this array to exclude specific assets or manage conflicts before they impact functionality. Ensures the array structure remains valid.
Usage
add_filter( 'automator_conflictive_assets', 'your_function_name', 10, 1 );
Parameters
-
$conflictive_assets(mixed) - This parameter contains an array of scripts and styles that are deemed conflictive and should be excluded.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to hook into the 'automator_conflictive_assets' filter.
* This example demonstrates how to programmatically remove specific script handles
* from the list of conflictive assets that the Uncanny Automator plugin might detect.
* This could be useful if you have custom scripts that you know do not conflict
* with Uncanny Automator's functionality, but are being flagged incorrectly.
*
* @param array $conflictive_assets An array containing 'scripts' and 'styles' keys,
* each holding an array of asset handles.
* @return array The modified $conflictive_assets array with unwanted scripts removed.
*/
function my_automator_remove_specific_script_conflict( $conflictive_assets ) {
// Define the script handles you want to ensure are NOT considered conflictive.
$scripts_to_remove = array(
'my-custom-plugin-script',
'another-plugin-frontend-script',
);
// Check if the 'scripts' key exists and is an array before proceeding.
if ( isset( $conflictive_assets['scripts'] ) && is_array( $conflictive_assets['scripts'] ) ) {
// Filter out the script handles that are in our $scripts_to_remove list.
$conflictive_assets['scripts'] = array_diff( $conflictive_assets['scripts'], $scripts_to_remove );
// Re-index the array to ensure clean sequential keys after removal.
$conflictive_assets['scripts'] = array_values( $conflictive_assets['scripts'] );
}
// Always return the modified array.
return $conflictive_assets;
}
// Add the filter to WordPress.
// The 'automator_conflictive_assets' hook accepts one argument.
add_filter( 'automator_conflictive_assets', 'my_automator_remove_specific_script_conflict', 10, 1 );
?>
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/automator-post-types/uo-recipe/class-recipe-post-utilities.php:390
);
$conflictive_assets = array(
'scripts' => $conflictive_scripts,
'styles' => $conflictive_styles,
);
$conflictive_assets = apply_filters( 'automator_conflictive_assets', $conflictive_assets );
// Check if the array is valid
if ( empty( $conflictive_assets ) || ! isset( $conflictive_assets['scripts'] ) || ! isset( $conflictive_assets['styles'] ) ) {
// Someone made a mess and this is empty now. Bail
return;
}
foreach ( $conflictive_assets['scripts'] as $conflictive_script ) {