Skip to content

Instantly share code, notes, and snippets.

@shanebp
Created August 14, 2012 21:48
Show Gist options
  • Save shanebp/3353337 to your computer and use it in GitHub Desktop.
Save shanebp/3353337 to your computer and use it in GitHub Desktop.
BuddyPress - Group Extension API - delete button
//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 );
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment