public
Created

BuddyPress - Group Extension API - delete button

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
//within the plugin and within the Extension class
 
function edit_screen() {
...
<?php if ( is_user_logged_in() && function_exists( 'bp_delete_test_page_link' ) ) : ?>
<a class="button confirm" href="<?php bp_delete_test_page_link(); ?>">Delete Test Page</a>
<?php endif; ?>
...
}
 
//within the plugin and after the Extension class
 
// create the delete test page button
function bp_delete_test_page_link() {
echo bp_get_delete_test_page_link();
}
function bp_get_delete_test_page_link() {
global $bp;
$delete_url = bp_get_group_permalink( $bp->groups->current_group ) . 'admin/test-page/delete-test-page/';
return apply_filters( 'bp_get_delete_test_page_link', wp_nonce_url( $delete_url, 'test_page_delete_check') );
}
 
 
// listens for clicks on Delete Test Page button
function bp_delete_test_page() {
 
if ( bp_is_groups_component() && bp_is_action_variable( 'test-page', 0 ) && bp_is_action_variable( 'delete-test-page', 1 ) ) {
 
if ( !$bp->is_item_admin && !is_super_admin() )
return false;
if ( !check_admin_referer( 'test_page_delete_check' ) )
return false;
 
bp_core_add_message( __( 'Test Page was deleted. -not really, just testing', 'buddypress' ) );
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
}
}
add_action( 'wp', 'bp_delete_test_page', 3 );
 
 
// the button is created with the expected href + nonce
// but when clicked, the result is being redirected to
groups/my-group/admin/test-page/delete-test-page/?_wpnonce=a9f5440346
 
 
 
FIX: add_action( 'wp', 'bp_delete_test_page', 1 );
.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.