更改 WP 函数以显示为 HTML

Change WP Function to Display as HTML

提问人:John 提问时间:10/4/2023 更新时间:10/4/2023 访问量:19

问:

如何更改此WordPress功能,使其将链接显示为html而不是纯文本?

function filter_image_pre_upload($file) {   

        $mimes = array( 'image/jpeg', 'image/png', 'image/gif' );

        if( !in_array( $file['type'], $mimes ) )
        return $file;

        $img = getimagesize( $file['tmp_name'] );
        $maximum = array( 'width' => 1200, 'height' => 1500 );
        
        if ( $img[0] > $maximum['width'] )
        $file['error'] = 
            'The image you are attempting to upload is too large. Your image is width is ' 
            . $img[0] . 'px. The maximum allowed sized is 1200px wide by 1500px high. Please visit <a href="https://example.com">https://example.com</a> to crop and resize your image or contact <a href="mailto:[email protected]">[email protected]</a> for assistance.';
    

        elseif ( $img[1] > $maximum['height'] )
        $file['error'] = 
            'The image you are attempting to upload is too large. Your image is height is ' 
            . $img[1] . 'px. The maximum allowed sized is 1200px wide by 1500px high. Please visit <a href="https://example.com">https://example.com</a> to crop and resize your image or contact <a href="mailto:[email protected]">[email protected]</a> for assistance.';
    return $file; 
    } 


add_filter('wp_handle_upload_prefilter', 'filter_image_pre_upload', 20);

如果在错误消息之前添加了print_r,则消息将显示为 html,但文本显示在 WP 错误警告框和图像名称上方。

(https://i.stack.imgur.com/s5zed.png)

wordpress 函数

评论


答: 暂无答案