uo_create_new_group_status
Filters the status assigned to a newly created group.
add_filter( 'uo_create_new_group_status', $callback, 10, 1 );
Description
Filters the status used when creating a new group programmatically. Developers can use this hook to set a custom post status, overriding the default 'publish' for newly created groups. This allows for more granular control over group lifecycle management.
Usage
add_filter( 'uo_create_new_group_status', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of using the 'uo_create_new_group_status' filter to change the default
* post status for newly created groups.
*
* This function will change the status of a newly created group from 'publish'
* to 'draft' if the group name contains the word "pending".
*
* @param string $status The current post status.
* @return string The modified post status.
*/
function my_custom_group_creation_status( $status ) {
// Access the group name from the global scope if available,
// or assume it's passed if the hook were to provide it (though it doesn't currently).
// For realism, we'll simulate checking a variable that *might* be available.
global $group_name; // This assumes $group_name is available in the context where the filter is applied.
// If $group_name is not globally available, you might need to adjust this logic
// based on how you are passing or determining the group name in your specific use case.
// For this example, we'll proceed with the assumption.
if ( isset( $group_name ) && stripos( $group_name, 'pending' ) !== false ) {
return 'draft'; // Set status to draft if "pending" is in the group name.
}
return $status; // Otherwise, return the original status.
}
add_filter( 'uo_create_new_group_status', 'my_custom_group_creation_status', 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/classes/helpers/process-manual-group.php:104
if ( $group_leader_id ) {
$group_title = $group_name;
$ld_group_args = apply_filters(
'ulgm_insert_group',
array(
'post_type' => 'groups',
'post_status' => apply_filters( 'uo_create_new_group_status', 'publish' ),
'post_title' => $group_title,
'post_content' => '',
'post_parent' => $group_parent,
'post_author' => apply_filters( 'ulgm_custom_group_post_author', $customer_id, $group_leader_id, 'admin-created' ),
)
);