我已经创建了一些自定义的帖子表单,我现在使用这些表单来代替一个名为WP User Frontend 它允许您从前端发布和编辑。这些帖子表单我们工作得很好,但当我停用插件时,我现在在帖子完成上传时收到一条警告。。
警告:无法修改标题信息-标题已由(输出开始于/home/######/public\\u html/#####/wp content/themes/####/header default.php:2)在/home/#######/public\\u html/####\\\\\\\\/wp包括/可插拔。php在线881。
现在我检查了空格,老实说,我在页眉、页面模板或页脚中没有看到任何空格,我认为这与此无关,因为插件激活后,帖子表单工作正常。我也在使用buddypress,它有一个为头像提交的表单,在没有激活插件的情况下可以正常工作,所以我想我的表单缺少了插件提供的东西。我不会粘贴包括html表单在内的整个代码,而是将显示模板中完成工作的php部分。
<?php// Template Name: Album Post Form ?>
<?php get_header(); ?>
<?php if( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] && !empty( $_POST[\'action\'] ) && $_POST[\'action\'] == "new_post") {
if ( ! function_exists( \'wp_handle_upload\' )) {
require_once(ABSPATH . "wp-admin" . \'/includes/image.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/file.php\');
require_once(ABSPATH . "wp-admin" . \'/includes/media.php\');
}
$file=$_FILES;
// Do some minor form validation to make sure there is content
if (isset ($_POST[\'title\'])) {
$title = $_POST[\'title\'];
} else {
echo \'Please enter a game title\';
}
if (isset ($_POST[\'description\'])) {
$description = $_POST[\'description\'];
} else {
echo \'Please enter the content\';
}
$tags = $_POST[\'post_tags\'];
// Add the content of the form to $post as an array
$new_post = array(
\'post_title\' => $title,
\'post_content\' => $description,
\'tags_input\' => array($tags),
\'post_status\' => \'publish\', // Choose: publish, preview, future, draft, etc.
\'post_type\' => fod_albums // Use a custom post type if you want to
);
//save the new post and return its ID
$pid = wp_insert_post($new_post);
if (!($file[\'album_image\'][\'name\'] == "")) {
$cover_art_id = media_handle_sideload( $file[\'album_image\'], $pid );
if ( is_wp_error($cover_art_id) ) {
@unlink($file_array[\'tmp_name\']);
return $cover_art_id;
}
if(!is_wp_error($cover_art_id)){
wp_set_object_terms( $cover_art_id, \'cover_art\', \'category\');
}
update_post_meta($pid,\'album_cover\',$cover_art_id);
} elseif ($file[\'album_image\'][\'name\'] == "" && !($_POST[\'cover_radio\'] == \'\')) {
update_post_meta($pid,\'music_art\',$_POST[\'cover_radio\']);
}
wp_redirect( get_permalink($pid));
exit();
}
do_action(\'wp_insert_post\', \'wp_insert_post\');
?>
有什么想法吗?