Filter
uncanny-automator-pro
uap_option_all_mpca_corporate_accounts
Filters the data related to all MPCA corporate accounts before they are displayed or processed.
add_filter( 'uap_option_all_mpca_corporate_accounts', $callback, 10, 1 );
Description
Filters the available options for mapping corporate account fields within MemberPress integrations. Developers can use this hook to add or remove custom field mappings for corporate account usernames, first names, last names, and emails when Uncanny Automator Pro is integrated with MemberPress.
Usage
add_filter( 'uap_option_all_mpca_corporate_accounts', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the selected option or value from the dropdown for corporate accounts.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the 'uap_option_all_mpca_corporate_accounts' hook.
* This example adds a new custom field option for corporate accounts.
*
* The original hook provides an array of options for corporate accounts, typically
* including fields like username, first name, last name, and email.
*
* @param array $option The original array of options for corporate accounts.
* @return array The modified array of options.
*/
add_filter( 'uap_option_all_mpca_corporate_accounts', function( $option ) {
// Assuming $option is an array containing a key like 'corporate_account_fields'
// and that key holds another array of key-value pairs for the options.
// We need to ensure the structure exists before adding to it.
if ( is_array( $option ) && isset( $option['corporate_account_fields'] ) && is_array( $option['corporate_account_fields'] ) ) {
// Add a new custom field for a 'Company Name' to the corporate account options.
// The key format should match the existing pattern (e.g., $option_code . '_NEWFIELD').
// For realism, let's assume the original $option_code might be accessible or derivable,
// but if not, we'll create a consistent key.
// In a real scenario, you'd inspect the $option array to see the exact structure.
// For this example, let's assume the base option code is something like 'mpca'.
$base_option_code = 'mpca'; // This would ideally come from the original context if possible.
$option['corporate_account_fields'][ $base_option_code . '_SUBACCCNAME' ] = esc_attr__( 'Company Name', 'uncanny-automator-pro' );
// If there's another structure, for example, an overall option group key like 'mpca_group':
// if ( isset( $option['mpca_group']['corporate_account_fields'] ) && is_array( $option['mpca_group']['corporate_account_fields'] ) ) {
// $option['mpca_group']['corporate_account_fields'][ $base_option_code . '_SUBACCCNAME' ] = esc_attr__( 'Company Name', 'uncanny-automator-pro' );
// }
} else {
// Handle cases where the expected structure might not exist.
// Log an error or create the structure if appropriate, depending on the plugin's behavior.
// For this example, we'll just ensure we return the original option if the structure is unexpected.
}
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
uncanny-automator-pro/src/integrations/memberpress/helpers/memberpress-pro-helpers.php:208
public function all_mpca_corporate_accounts( $label = null, $option_code = 'MPCAACCOUNTS', $args = array() ) {
if ( ! $label ) {
$label = esc_attr__( 'Parent account', 'uncanny-automator-pro' );
}
$args = wp_parse_args(
$args,
array(
'uo_include_any' => false,
'uo_any_label' => esc_attr__( 'Any parent account', 'uncanny-automator-pro' ),
)
);
$options = array();
if ( $args['uo_include_any'] ) {
$options[- 1] = $args['uo_any_label'];
}
$parent_accounts = MPCA_Corporate_Account::get_all();
foreach ( $parent_accounts as $parent_account ) {
$user = get_userdata( $parent_account->user_id );
$options[ $parent_account->user_id ] = $user->user_email;
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Parent account', 'uncanny-automator-pro' ),
$option_code . '_SUBACCUNAME' => esc_attr__( 'Username', 'uncanny-automator-pro' ),
$option_code . '_SUBACCFNAME' => esc_attr__( 'First name', 'uncanny-automator-pro' ),
$option_code . '_SUBACCLNAME' => esc_attr__( 'Last name', 'uncanny-automator-pro' ),
$option_code . '_SUBACCEMAIL' => esc_attr__( 'Email', 'uncanny-automator-pro' ),
),
);
return apply_filters( 'uap_option_all_mpca_corporate_accounts', $option );
}