这可能是个奇怪的问题,但我需要访问admin-ajax.php
使用PHP。
我的一个插件创建了一个仅在中显示的PDFadmin-ajax.php
, 我想用一段PHP代码下载这个PDF。现在我已经想出了如何下载PDF并将其放在正确的文件夹中,但是当我尝试访问admin-ajax.php
在我的代码中,它只返回;0英寸;。
我认为这是因为PDF只能由登录用户访问。所以我的问题是,我是否可以访问admin-ajax.php
使用PHP?
以下是我目前的代码:
add_action( \'woocommerce_payment_complete\', \'so_payment_complete\' );
function so_payment_complete( $order_id ){
// Static data for debugging
$url = \'https://example.com/wp-admin/admin-ajax.php?action=wcpn_export&request=get_labels&shipment_ids=124687111&_wpnonce=2da91e54ad\';
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
)
);
// Get the pdf data
$pdf_data = file_get_contents($url, false, stream_context_create($arrContextOptions));
if($pdf_data) :
//Save PDF on server
$pdf = file_put_contents(__DIR__."/labels/$order_id.pdf", $pdf_data);
else :
print_r("Error!");
endif;
}