您可以使用parse_request
hook. 例如:
add_action( \'parse_request\', function ( $wp ) {
// Run your actions only if the current request path is exactly \'image-generator\'
// as in https://example.com/image-generator if the site URL is https://example.com
if ( \'image-generator\' === $wp->request ) {
$a = $_GET[\'a\'];
$b = $_GET[\'b\'];
$etc = \'etc\';
// ... your code here.
// And then send the HTTP status and also the Content-Type headers.
status_header( 200 );
header( \'Content-Type: image/jpeg\' );
// ... echo your image.
exit;
}
} );
请注意
status_header()
是用于发送HTTP状态标头的WordPress函数。请参见
documentation 了解更多详细信息。