Yes, definitely helpful. Any idea how to implement the solution within the groups index page as a bulk option as oppose to having to go into the individual group?
I tried using wordpress’s bulk admin similar to the example pertaining to load-users.php, but it isn’t working.
add_filter( 'handle_bulk_actions-toplevel_page_bp-groups', 'add_bpgroups_to_bpgroup', 10, 3 );
function add_bpgroups_to_bpgroup($redirect_to, $doaction, $group_ids) {
trigger_error($doaction);
trigger_error($redirect_to);
if( bp_is_active('groups') ):
if ( $doaction !== 'assign_parent_group' ) {
return $redirect_to;
}
trigger_error(print_r($group_ids,TRUE));
$redirect_to = add_query_arg( 'groups_assigned' , implode(',', $group_ids) , $redirect_to );
endif;
return $redirect_to;
}
add_filter( 'bulk_actions-toplevel_page_bp-groups', 'register_bulk_assign_parent_action' );
function register_bulk_assign_parent_action ($bulk_actions) {
$bulk_actions['assign_parent_group'] = __( 'Assign Parent Group', 'assign_parent_group');
//form submission
add_action( 'admin_footer', function() { ?>
<script type="text/javascript" charset="utf-8">
jQuery("#doaction").click(function(e){
if(jQuery("select[name='action'] :selected").val()=="assign_parent_group") { e.preventDefault();
gid=prompt("Enter a Group ID","1");
if (gid != null) {
jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
}
}
});
</script>
<?php
});
return $bulk_actions;
}
add_action( 'admin_notices', 'bulk_assign_parent_action_admin_notice' );
function bulk_assign_parent_action_admin_notice() {
if ( ! empty( $_REQUEST['groups_assigned'] ) && ! empty( $_REQUEST['assigned_group'] ) ) {
$groups_assigned = $_REQUEST['groups_assigned'] ;
$parent_id = $_REQUEST['assigned_group'];
$parent_group = groups_get_group($parent_id);
if ($parent_group->id == 0) {
printf( '<div id="message" class="error">Unknown group ID %s</div>', $parent_id);
return;
}
$group_ids = explode(',' , $groups_assigned);
foreach ($group_ids as $group_id) {
$group = groups_get_group( $group_id );
if (false === groups_edit_group_settings($group_id, $group->enable_forum, $group->status, false, $parent_id )) {
printf( '<div id="message" class="error">Failed to add group %s to %s.</div>', $group->name, $parent_group->name);
break;
}
}
printf( '<div id="message" class="updated fade">Successfully ' .
_n( 'assigned %s group',
'assigned %s groups',
$groups_assigned,
'assign_parent_group'
) . 'to %s</div>', $groups_assigned, $group_name );
}
It fires the
add_filter( ‘bulk_actions-toplevel_page_bp-groups’, ‘register_bulk_assign_parent_action’ );
correctly but seems to completely ignore
add_filter( ‘handle_bulk_actions-toplevel_page_bp-groups’, ‘add_bpgroups_to_bpgroup’, 10, 3 );
Any ideas?