
如图,火车头采集时社区发布模块已经设置了价格,但是我这个地方还是需要我用管理权限 再次点击一次“阅读权限”才能正常保存!请问各位大师怎么处理!
火车头接口文件代码:
<?php
error_reporting(E_ERROR);
ini_set("display_errors", 0);
$post_author_default = 0; // 这里强制改为 0,不使用默认管理员
$post_status = 'publish';
$time_interval = 1;
$post_next = 'now';
$post_ping = false;
$translate_slug = false;
$secretWord = '123456';
$checkTitle = true;
$postformat = false;
$new_user_role = 'author';
if (!isset($_GET['action'])) die("操作被禁止");
$hm_action = $_GET['action'];
include_once "./wp-config.php";
if ($post_ping) require_once("./wp-includes/comment.php");
function getPost($key, $default = '') {
return isset($_POST[$key]) ? trim($_POST[$key]) : $default;
}
$post_title = getPost('post_title');
$post_content = getPost('post_content');
$tag = getPost('tag');
$post_category = getPost('post_category');
$post_date = getPost('post_date');
$post_excerpt = getPost('post_excerpt');
$post_author = getPost('post_author');
$post_type = getPost('post_type');
$post_taxonomy = getPost('post_taxonomy');
$post_format = getPost('post_format');
$post_meta = $_POST['post_meta'] ?? [];
// ======================
// 火车头控制:板块ID
// ======================
$plate_id = $post_meta['plate_id'] ?? '';
// ======================
// 强制只用火车头作者,绝不回退到管理员ID1
// ======================
if (empty($post_author)) {
die("作者不能为空,请在火车头填写 post_author");
}
$final_author_id = hm_force_get_author($post_author);
// ======================
// 发布逻辑
// ======================
if ($hm_action === "list") {
$cats = get_categories(["hierarchical"=>0,"hide_empty"=>0]);
foreach($cats as $cat) echo "<<<{$cat->cat_ID}--{$cat->cat_name}>>>";
exit;
}
if ($hm_action === "save") {
if (!empty($secretWord) && ($_GET['secret'] ?? '') !== $secretWord) die("接口密码错误");
if (empty($post_title) || $post_title === '[标题]') die("标题为空");
if (empty($post_content) || $post_content === '[内容]') die("内容为空");
if (empty($plate_id) || !is_numeric($plate_id)) die("版块ID错误");
global $wpdb;
if ($checkTitle) {
$exists = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title=%s AND post_type='forum_post'", $post_title));
if ($exists) die("标题重复,发布成功");
}
$post_type = 'forum_post';
$post_taxonomy = 'category';
$post_content = fileHandle('fujian', $post_content);
fileHandle('thumb');
$post_id = hm_force_publish([
'post_title' => $post_title,
'post_content' => $post_content,
'post_category' => $post_category,
'post_excerpt' => $post_excerpt,
'post_type' => $post_type,
'post_taxonomy' => $post_taxonomy,
'tags_input' => $tag,
'post_date' => $post_date,
'post_author' => $final_author_id,
]);
if ($post_id && !is_wp_error($post_id)) {
update_post_meta($post_id, 'zib_bbs_plate_id', $plate_id);
}
echo "发布成功";
exit;
}
echo "非法操作";
// ======================
// 强制获取作者(不存在自动创建)
// ======================
function hm_force_get_author($name) {
if (ctype_digit($name)) {
$user = get_user_by('id', (int)$name);
if ($user) return $user->ID;
}
$user = get_user_by('login', $name);
if (!$user) $user = get_user_by('nickname', $name);
if (!$user) $user = get_user_by('display_name', $name);
if ($user) return $user->ID;
$pwd = wp_generate_password(16, true);
$uid = wp_insert_user([
'user_login' => sanitize_user($name),
'user_pass' => $pwd,
'display_name' => $name,
'nickname' => $name,
'role' => 'author',
'user_email' => sanitize_user($name).'@'.uniqid().'.com',
]);
if (is_wp_error($uid)) {
die("作者创建失败:" . $uid->get_error_message());
}
return $uid;
}
// ======================
// 强制发布
// ======================
function hm_force_publish($arr) {
global $thumbid, $post_status, $post_meta, $postformat, $post_format;
extract($arr);
$time_difference = absint(get_option('gmt_offset')) * 3600;
$tm = !empty($post_date) && strtotime($post_date) ? strtotime($post_date) : time() + $time_difference;
$cats = hm_fix_category($post_category, $post_taxonomy);
$id = wp_insert_post([
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => $post_status,
'post_author' => $post_author,
'post_type' => $post_type,
'post_date' => date('Y-m-d H:i:s', $tm),
'post_date_gmt'=> gmdate('Y-m-d H:i:s', $tm - $time_difference),
'post_excerpt' => $post_excerpt,
'post_category'=> $cats,
'tags_input' => str_replace('|||', ',', $tags_input),
]);
if ($id && !is_wp_error($id)) {
global $wpdb;
$wpdb->update($wpdb->posts, ['post_author' => $post_author], ['ID' => $id]);
}
if (!empty($thumbid)) set_post_thumbnail($id, $thumbid);
if (!empty($post_meta) && is_array($post_meta)) {
foreach ($post_meta as $k => $v) update_post_meta($id, $k, $v);
}
if ($postformat && !empty($post_format)) set_post_format($id, $post_format);
return $id;
}
// ======================
// 分类处理
// ======================
function hm_fix_category($str, $tax='category') {
if (empty($str)) return [];
$ids = [];
foreach(explode(',', $str) as $item) {
$item = trim($item);
if (ctype_digit($item)) $ids[] = (int)$item;
else if ($t=get_term_by('name',$item,$tax)) $ids[] = $t->term_id;
}
return array_unique($ids);
}
// ======================
// 附件上传
// ======================
function fileHandle($filesnames, $content=null) {
global $thumbid;
if (empty($_FILES[$filesnames.'0']['name'])) return $content;
require_once('./wp-load.php');
require_once('./wp-admin/includes/file.php');
require_once('./wp-admin/includes/image.php');
$i=0;
while(isset($_FILES[$filesnames.$i])) {
$f = $_FILES[$filesnames.$i];
if (empty($f['name'])) {$i++;continue;}
$ext = pathinfo($f['name'],PATHINFO_EXTENSION);
$f['name'] = uniqid().'.'.$ext;
$r = wp_handle_upload($f, ['test_form'=>false]);
if (isset($r['error'])) wp_die('上传失败');
$content = str_replace($f['name'], $r['url'], $content);
$aid = wp_insert_attachment([
'guid'=>$r['url'],'post_mime_type'=>$r['type'],'post_title'=>$f['name'],'post_status'=>'inherit'
],$r['file']);
if (strpos($f['type'],'image')!==false && empty($thumbid)) {
$thumbid = $aid;
$data = wp_generate_attachment_metadata($aid,$r['file']);
wp_update_attachment_metadata($aid,$data);
}
$i++;
}
return $content;
}
function hm_strip_slashes($str) {
return stripslashes($str);
}
发布模块和采集规则截图:


发布模块对应的表单:
表单名:post_meta[posts_zibpay][points_price] 对应的表单值:[标签:积分售价]
表单名:post_meta[posts_zibpay][vip_1_points] 对应的表单值:[标签:黄金会员积分售价]
表单名:post_meta[posts_zibpay][vip_2_points] 对应的表单值:[标签:钻石会员积分售价]
表单名:post_meta[posts_zibpay][pay_price] 对应的表单值:[标签:执行价]
表单名:post_meta[posts_zibpay][pay_original_price] 对应的表单值:[标签:原价]
表单名:post_meta[posts_zibpay][vip_1_price] 对应的表单值:[标签:黄金会员价格]
表单名:post_meta[posts_zibpay][vip_2_price] 对应的表单值:[标签:钻石会员价格]
表单名:post_meta[posts_zibpay][pay_rebate_discount]对应的表单值:[标签:推广折扣]
表单名:post_meta[posts_zibpay][pay_cuont] 对应的表单值:[标签:销量浮动]
论坛听说有大神!恳请指导一下!豆包都干冒烟了,都没办法解决问题!





