Wordpress 添加post row操作以在不呈现WP Admin UI的情况下调用函数
我正在使用以下代码向post行操作添加一个新链接Wordpress 添加post row操作以在不呈现WP Admin UI的情况下调用函数,wordpress,Wordpress,我正在使用以下代码向post行操作添加一个新链接 add_filter( 'post_row_actions', 'pdf_row_actions', 10, 2 ); function pdf_row_actions( $actions, WP_Post $post ) { if ( $post->post_type == 'carte' ) { $url = admin_url('admin.php?page=generate_pdf_carte&id='.
add_filter( 'post_row_actions', 'pdf_row_actions', 10, 2 );
function pdf_row_actions( $actions, WP_Post $post ) {
if ( $post->post_type == 'carte' ) {
$url = admin_url('admin.php?page=generate_pdf_carte&id='.$post->ID);
$actions['generate-pdf'] = '<a href="'.$url.'" title="PDF generieren" rel="permalink">PDF herunterladen</a>';
}
return $actions;
}
function generate_pdf_carte(){
$options = new Options();
$options->set('tempDir', 'tmp');
$dompdf = new Dompdf($options);
$dompdf->loadHtmlFile('http://localhost/xxx/output.php');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4');
$dompdf->render();
$dompdf->stream();
}
add_filter('post_row_actions','pdf_row_actions',10,2);
函数pdf_行_操作($actions,WP_Post$Post){
如果($post->post_type=='carte'){
$url=admin\u url('admin.php?page=generate\u pdf\u carte&id='。$post->id);
$actions['generate-pdf']='';
}
返回$actions;
}
函数generate\u pdf\u carte(){
$options=新选项();
$options->set('tempDir','tmp');
$dompdf=新的dompdf($options);
$dompdf->loadHtmlFile('http://localhost/xxx/output.php');
//(可选)设置纸张大小和方向
$dompdf->setPaper('A4');
$dompdf->render();
$dompdf->stream();
}
单击此链接时,我收到以下消息:无法流式传输pdf:标题已发送
如何在不呈现管理员UI的情况下将URL添加到此generate_pdf_carte()函数?对于需要设置标题的内容,可以使用admin_init hook
add_action( 'admin_init', 'maybe_generate_pdf_carte' );
function maybe_generate_pdf_carte() {
if ( isset( $_GET['page'], $_GET['id'] ) && $_GET['page'] == 'generate_pdf_carte' && (int)$_GET['id'] )
generate_pdf_carte();
}