我正在尝试重新构造一个函数(在插件中),以便它应用于自定义帖子类型中的帖子,而不是普通帖子。
function saving_posts($post_id)
{
global $wpdb, $user_ID;
$this->setup_links();
if(defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE)
return;
if(\'post\' == $_POST[\'post_type\'])
{
if(!current_user_can(\'edit_post\', $post_id))
return;
}
else
return;
$mydata = ($_POST[\'mf_post_to_forum\'] == \'true\')?true:false;
if($mydata)
{
$date = $this->wpf_current_time_fixed(\'mysql\', 0);
$fid = (int)$_POST[\'mf_post_to_forum_forum\'];
$_POST[\'mf_post_to_forum\'] = \'false\'; //Eternal loop if this isn\'t set to false
$post = get_post($post_id);
$sql_thread = "INSERT INTO {$this->t_threads} (last_post, subject, parent_id, `date`, status, starter) VALUES(\'{$date}\', \'".$this->strip_single_quote($post->post_title)."\', \'{$fid}\', \'{$date}\', \'open\', \'{$user_ID}\')";
$wpdb->query($sql_thread);
$tid = $wpdb->insert_id;
$sql_post = "INSERT INTO {$this->t_posts} (text, parent_id, `date`, author_id, subject) VALUES(\'".$this->input_filter($wpdb->escape($post->post_content))."\', \'{$tid}\', \'{$date}\', \'{$user_ID}\', \'".$this->strip_single_quote($post->post_title)."\')";
$wpdb->query($sql_post);
$new = $post->post_content."\\n".\'<p><a href="\'.$this->get_threadlink($tid).\'">\'.__("Join the Forum discussion on this post", "mingleforum").\'</a></p>\';
$post->post_content = $new;
wp_update_post($post);
}
}
我想我可以改变一下
if(\'post\' == $_POST[\'post_type\'])
到
if(\'my_custom_post\' == $_POST[\'post_type\'])
其余的也一样。这个
$mydata
价值来自这里:
function send_wp_posts_to_forum()
{
add_meta_box(\'mf_posts_to_forum\', __(\'Mingle Forum Post Options\', \'mingleforum\'), array(&$this, \'show_meta_box_options\'), \'my_custom_post\');
}
function show_meta_box_options()
{
$forums = $this->get_forums();
echo \'<input type="checkbox" name="mf_post_to_forum" value="true" /> \'.__(\'Add this post to\', \'mingleforum\');
echo \' <select name="mf_post_to_forum_forum">\';
foreach($forums as $f)
echo \'<option value="\'.$f->id.\'">\'.$f->name.\'</option>\';
echo \'</select><br/><small>\'.__(\'Do not check this if this post has already been linked to the forum!\', \'mingleforum\').\'</small>\';
}
这很好,因为元框位于正确的位置。