This test plugin has two versions:
-
This one which uses
admin_action_{$action}
. -
And this which uses
load-{$page_hook}
.
This test plugin has two versions:
This one which uses admin_action_{$action}
.
And this which uses load-{$page_hook}
.
<?php | |
/** | |
* Plugin Name: Test Plugin | |
* Version: 20190618.1 | |
* Text Domain: test-plugin | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
add_action( 'admin_menu', 'register_admin_menu' ); | |
function register_admin_menu() { | |
add_menu_page( 'Test Plugin', 'Test Plugin', 'manage_options', 'batch-op-settings', 'render_admin_page' ); | |
} | |
function render_admin_page() { | |
?> | |
<div class="wrap"> | |
<h1>Test Plugin</h1> | |
<?php if ( ! empty( $_GET['batch_deleted'] ) ) : ?> | |
<div class="notice notice-info is-dismissible"> | |
<p>Dummy batch deletion was successful!</p> | |
</div> | |
<?php endif; ?> | |
<p><a href="<?php echo esc_url( add_query_arg( [ | |
'action' => 'batch-delete', | |
'post_id' => 5, | |
// Don't add the "page" parameter. | |
], admin_url( 'admin.php' ) ) ); ?>" class="button">Delete</a> (<i>nothing will be deleted</i>)</p> | |
</div> | |
<?php | |
} | |
add_action( 'admin_action_batch-delete', 'batch_delete_data' ); | |
function batch_delete_data() { | |
// Update/delete your data. | |
error_log( 'Yay, it works!' ); | |
// Back to the plugin page. | |
$menu_page_url = menu_page_url( 'batch-op-settings', false ); | |
wp_redirect( add_query_arg( 'batch_deleted', '1', $menu_page_url ) ); | |
exit; | |
} |
I am trying to understand the code and i have understood something and i think that wp_redirect function will not work either because due to wp_redirect the issue is coming header is already set .
@samairali In that case, try posting the full code as a gist (don't post here). And update your WPSE question so that others can check it, too.
But I'm guessing you know what could be the reasons to the issue ("headers already sent"), so you should make sure there has been no output printed before you call wp_redirect()
.
A simple space in your functions file could cause the issue, you know. So try to find the code which may be printing the output and fix that code.
@5ally issue is resolved now ... i want to know something if you have free time ?
yes exactly that was the issue , i was not printing but might be wordpress core files were doing something but i have used ob_start at the start and it is ok now ... it is redirected now but how can i print message on redirection that specific thing is deleted ?
how can i print message on redirection that specific thing is deleted
Look at the sample plugins again. You could see I printed a sample notice there.
You could also use the admin_notices
hook or add_settings_error()
.
i have used ob_start at the start and it is ok now
Ok, but you should try to disable all plugins except yours and try a default theme as well. Doing that could help you with a proper fix than a workaround.
thankyou sally for doing so much effort for me :)