Filter
uncanny-automator
uap_option_get_all_code_prefix
Filters the array of all code prefixes for Uncanny Codes options, allowing modification before they are retrieved.
add_filter( 'uap_option_get_all_code_prefix', $callback, 10, 1 );
Description
Filters the data array for the 'Prefix' option in Uncanny Codes. Developers can modify the 'required', 'options', or 'relevant_tokens' to customize how code prefixes are handled or displayed within the Uncanny Automator integration. This hook fires when the 'Prefix' option's configuration is being prepared.
Usage
add_filter( 'uap_option_get_all_code_prefix', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter holds the retrieved code prefix value from the database.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_get_all_code_prefix', 'my_custom_code_prefix', 10, 1 );
/**
* Customizes the code prefix options for Uncanny Automator.
*
* This function demonstrates how to modify the default code prefix options
* provided by Uncanny Automator. In this example, we're adding a new
* custom prefix option.
*
* @param array $option The original array of code prefix options.
*
* @return array The modified array of code prefix options.
*/
function my_custom_code_prefix( $option ) {
// Check if the current option is related to code prefixes and if we want to modify it.
// In a real-world scenario, you might inspect $option['option_code']
// or other parts of the $option array to determine if this filter
// should apply to the current context.
// For this example, we'll assume we always want to add our custom prefix.
// Add a new custom prefix option.
// The key of the array element is the actual prefix value (e.g., 'MYC').
// The value is the display label for that prefix.
$option['options']['MYC'] = esc_attr__( 'My Custom Code', 'my-text-domain' );
// Ensure the 'relevant_tokens' array is updated if necessary.
// This part depends heavily on how Uncanny Automator uses 'relevant_tokens'.
// For demonstration, we'll add our new prefix to the tokens.
$option['relevant_tokens']['MYC'] = esc_attr__( 'My Custom Prefix', 'my-text-domain' );
// Always return the modified $option array.
return $option;
}
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/integrations/uncanny-codes/helpers/uncanny-codes-helpers.php:112
public function get_all_code_prefix( $label = null, $option_code = 'UCPREFIX' ) {
if ( ! $label ) {
$label = esc_attr__( 'Prefix', 'uncanny-automator' );
}
global $wpdb;
$options = array();
$all_codes = $wpdb->get_results( 'SELECT DISTINCT prefix FROM ' . $wpdb->prefix . 'uncanny_codes_groups', ARRAY_A );
if ( ! $all_codes ) {
return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
}
foreach ( $all_codes as $code ) {
if ( ! empty( $code['prefix'] ) ) {
$prefix = Automator()->utilities->automator_sanitize( $code['prefix'] );
$options[ $prefix ] = $code['prefix'];
}
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Prefix', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_get_all_code_prefix', $option );
}