Filter
uncanny-automator
uap_option_get_all_code_suffix
Filters the suffix of all Uncanny Codes option items, allowing modification before retrieval.
add_filter( 'uap_option_get_all_code_suffix', $callback, 10, 1 );
Description
Fires when Uncanny Codes options are being retrieved, allowing developers to modify the suffix used for generated codes. This filter is ideal for customizing code naming conventions or adding dynamic elements to suffixes before they are applied within Uncanny Automator.
Usage
add_filter( 'uap_option_get_all_code_suffix', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is intended to hold the previously filtered suffix option, but it is not used in the current implementation of the function.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to hook into the 'uap_option_get_all_code_suffix' filter.
* This example adds a custom suffix option to a specific code.
*
* @param array $option The array containing the option details.
* @return array Modified option array.
*/
add_filter( 'uap_option_get_all_code_suffix', function( $option ) {
// Check if this is the specific option code we want to modify.
// Replace 'YOUR_SPECIFIC_OPTION_CODE' with the actual option code you are targeting.
if ( isset( $option['option_code'] ) && 'YOUR_SPECIFIC_OPTION_CODE' === $option['option_code'] ) {
// Add a new custom suffix option to the 'options' array.
// In a real scenario, you might fetch these options dynamically
// based on user roles, settings, or other criteria.
$custom_suffixes = array(
'custom_suffix_1' => __( 'Custom Suffix One', 'uncanny-automator' ),
'custom_suffix_2' => __( 'Custom Suffix Two', 'uncanny-automator' ),
);
// Merge the new custom suffixes with existing ones, prioritizing new ones if they conflict.
// Ensure 'options' is always an array before merging.
if ( ! is_array( $option['options'] ) ) {
$option['options'] = array();
}
$option['options'] = array_merge( $option['options'], $custom_suffixes );
// Optionally, you could also add a new relevant token if this suffix implies a specific token.
// $option['relevant_tokens']['your_new_token_key'] = esc_attr__( 'New Suffix Token Label', 'uncanny-automator' );
}
// Always return the modified (or unmodified) option array.
return $option;
}, 10, 1 ); // Priority 10, accepting 1 argument.
?>
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:154
public function get_all_code_suffix( $label = null, $option_code = 'UCSUFFIX' ) {
if ( ! $label ) {
$label = esc_attr__( 'Suffix', 'uncanny-automator' );
}
global $wpdb;
$options = array();
$all_codes = $wpdb->get_results( 'SELECT DISTINCT suffix 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['suffix'] ) ) {
$suffix = Automator()->utilities->automator_sanitize( $code['suffix'] );
$options[ $suffix ] = $code['suffix'];
}
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Suffix', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_get_all_code_suffix', $option );
}