这是代码,如果文件不是图像,我想停止后期发布。这可能吗?
case "window-image":
$format = \'image\';
$title = esc_html($_POST[\'title_image\']);
$tags = $_POST[\'tags_image\'];
$comments = isset($_POST[\'comments_image\']) ? 1 : 0;
$anonymous = isset($_POST[\'anonymous_image\']) ? 1 : 0;
$comment_status = $comments == 1 ? \'open\' : \'closed\';
$user_id = $id;
if(($_FILES[\'image_imagepost\'][\'error\'] != 0 && $image == \'\') || $title == \'\') {
wp_redirect(home_url(\'/\') . \'?posterror=1\');
exit;
}
$post = array(
\'comment_status\' => $comment_status,
\'ping_status\' => \'open\',
\'post_author\' => $user_id,
\'post_content\' => \'\',
\'post_status\' => $status,
\'post_title\' => $title,
\'post_type\' => \'post\',
);
$post_id = wp_insert_post($post);
#Create attachment
if (!function_exists(\'wp_generate_attachment_metadata\')){
require_once(ABSPATH . "wp-admin" . \'/includes/image.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/file.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/media.php\');
}
$upload = wp_upload_bits( $_FILES[\'file\'][\'name\'], null, file_get_contents( $_FILES[\'file\'][\'tmp_name\'] ) );
$wp_filetype = wp_check_filetype( basename( $upload[\'file\'] ), null );
$wp_upload_dir = wp_upload_dir();
$attachment = array(
\'guid\' => $wp_upload_dir[\'baseurl\'] . _wp_relative_upload_path( $upload[\'file\'] ),
\'post_mime_type\' => $wp_filetype[\'type\'],
\'post_title\' => preg_replace(\'/\\.[^.]+$/\', \'\', basename( $upload[\'file\'] )),
\'post_content\' => \'\',
\'post_author\' => $user_id,
\'post_status\' => \'inherit\'
);
$attach_id = wp_insert_attachment( $attachment, $upload[\'file\'], $post_id );
require_once(ABSPATH . \'wp-admin/includes/image.php\');
$attach_data = wp_generate_attachment_metadata( $attach_id, $upload[\'file\'] );
wp_update_attachment_metadata( $attach_id, $attach_data );
#Create attachment
#Use attachment
update_post_meta( $post_id, \'_thumbnail_id\', $attach_id );
#Use attachment
$nsfw = isset($_POST[\'nsfw_image\']) ? 1 : 2;
add_post_meta($post_id, \'_standard_nsfw\', $nsfw);
add_post_meta($post_id, \'_anonymous\', $anonymous);
break;