您必须使用如下“process\\u bulk\\u action”功能:
public function process_bulk_action() {
//nonce validations,etc
$action = $this->current_action();
switch ( $action ) {
case \'export_action\':
// Do whatever you want
wp_redirect( esc_url( add_query_arg() ) );
break;
default:
// do nothing or something else
return;
break;
}
return;
}
}
如果您需要完整的示例,这是我用于插件的代码:
public function process_bulk_action() {
if ( isset( $_POST[\'_wpnonce\'] ) && ! empty( $_POST[\'_wpnonce\'] ) ) {
echo \'<pre>\';
print_r($_POST);
echo \'</pre>\';
$nonce = filter_input( INPUT_POST, \'_wpnonce\', FILTER_SANITIZE_STRING );
$action = \'bulk-\' . $this->_args[\'plural\'];
if ( ! wp_verify_nonce( $nonce, $action ) )
wp_die( \'Nope! Security check failed!\' );
}
$action = $this->current_action();
switch ( $action ) {
case \'delete\':
self::delete_activity( absint( $_GET[\'activity\'] ) );
wp_redirect( esc_url( add_query_arg() ) );
break;
case \'bulk-delete\':
$ids = esc_sql( $_POST[\'bulk-selected\'] );
foreach ( $ids as $id ) {
self::delete_activity( $id );
}
wp_redirect( esc_url( add_query_arg() ) );
break;
case \'bulk-export\':
$ids = esc_sql( $_POST[\'bulk-selected\'] );
self::export_activities( $ids );
wp_redirect( esc_url( add_query_arg() ) );
break;
default:
// do nothing or something else
return;
break;
}
return;
}
我希望这对您有所帮助;)