
不再盲目铺货!拼多多一件代发矩阵落地攻略,提供优质货源店铺运营全流程,零基础可直接复制
感谢您的来访,获取更多精彩文章请收藏本站。
[gcdb_paid_delivery]
format(‘Y-m-d’) === $date ? $date : ’’; }
function gcdb_existing($source_id, $source_url, $title) { global $wpdb;
keys = array(); if(source_id !== ’‘) { $keys[’_gcdb_source_id’] =
$source_id; }
if ($source_url !==’‘) { $keys[’_gcdb_source_url’] = $source_url; }
fingerprint = gcdb_(t)itle_(k)ey(title); if ($fingerprint) {
$keys[’_gcdb_title_key’] = $fingerprint; }
foreach ($keys as $meta_key => $meta_value) { $found =
wpdb− > get_(v)ar(wpdb->prepare( “SELECT p.ID FROM
{$wpdb->posts} p JOIN {$wpdb->postmeta} m ON p.ID=m.post_id WHERE
p.post_type=‘gc_resource’ AND m.meta_key=%s AND m.meta_value=%s LIMIT
1”, $meta_key, meta_(v)alue)); if(found) { return (int) $found; }
}
// 与旧版发布插件共用去重字段,避免同一项目被两套插件重复导入。
if ($source_id !==’‘) { $found = wpdb− > get_(v)ar(wpdb->prepare(
“SELECT p.ID FROM {$wpdb->posts} p JOIN {$wpdb->postmeta} m ON
p.ID=m.post_id WHERE p.post_type=’gc_resource’ AND
m.meta_key=’_gc_resource_remote_id’ AND m.meta_value=%s LIMIT 1”,
source_(i)d)); if(found) { return (int) $found; }
}
if ($fingerprint) { $found = wpdb− > get_(v)ar(wpdb->prepare(
“SELECT p.ID FROM {$wpdb->posts} p JOIN {$wpdb->postmeta} m ON
p.ID=m.post_id WHERE p.post_type=‘gc_resource’ AND
m.meta_key=’_gc_resource_dedupe_title_key’ AND m.meta_value=%s LIMIT 1”,
fingerprint)); if(found) { return (int) $found; } } //
老文章可能未保存指纹,仍以严格相同标题拦截。
found = get_(p)age_(b)y_(t)itle(title, OBJECT, ‘gc_resource’); return
$found ? (int) $found->ID : 0; }
/** *
只从素材中生成有限的公开简介,不能把课程目录/视频/网盘地址写入公开正文。 *
失败时宁可仅显示待编辑提示,也不公开原始全文。 */ function
gcdb_public_intro($raw_html, $title = ’‘) { $html = (string) $raw_html;
// 选择第一张非 data: 图片用于预览;不会复制视频或含下载入口的链接。
$cover =’‘; if
(preg_match(’_(](?:data-src|src)=(https?://[^"\']+)[“'][^>]>)iu’,
$html, $m)) { url = esc_(u)rl_(r)aw(html_(e)ntity_(d)ecode(m[1],
ENT_QUOTES | ENT_HTML5, ‘UTF-8’)); if
($url && preg_match('~\.(?:png|jpe?g|webp|gif)(?:[?#]|$)~i’, $url)) {
$cover = '
请在完成购买并获得权限后查看。 不再盲目铺货!拼多多一件代发矩阵落地攻略,提供优质货源店铺运营全流程,零基础可直接复制 [gcdb_paid_delivery]8,
‘redirection’=>3)); if (!is_wp_error($head)) {
length = (int)wp_(r)emote_(r)etrieve_(h)eader(head, ‘content-length’);
if ($length > 6 * 1024 * 1024) { return ‘封面超过6MB,待人工设置’; }
mime = (string)wp_(r)emote_(r)etrieve_(h)eader(head, ‘content-type’); if
($mime && !preg_match('~^image/(?:jpe?g|png|webp)(?:\s*;|\s*$)~i’,
$mime)) { return ‘图片响应类型不合格’; } } if
(!function_exists(‘media_sideload_image’)) { require_once
ABSPATH.’wp-admin/includes/media.php’; } if
(!function_exists(‘download_url’)) { require_once
ABSPATH.’wp-admin/includes/file.php’; } if
(!function_exists(‘wp_generate_attachment_metadata’)) { require_once
ABSPATH.’wp-admin/includes/image.php’; } // media_sideload_image 会按
WordPress 支持的图片 MIME 规则验证并生成媒体附件。
attachment = media_(s)ideload_(i)mage(url,
post_(i)d, get_(t)he_(t)itle(post_id), ‘id’); if
(is_wp_error($attachment)) { return '封面下载失败:'.$attachment->get_error_message();
} path = get_(a)ttached_(f)ile(attachment); if ($path && is_file($path)
&& filesize($path) > 6 * 1024 * 1024) {
wp_delete_attachment($attachment, true); return
‘下载封面超过6MB,待人工设置’; } if
(!set_post_thumbnail(post_(i)d, (int)attachment)) { return
‘媒体附件已创建但特色图片设置失败’; } return ‘已设置特色图片’; }
/** 补全只操作本插件导入的未发布草稿,保持现有分类和封面不变。 */
function gcdb_enrich_drafts($limit = 10) { $posts =
get_posts(array(‘post_type’=>‘gc_resource’,‘post_status’=>‘draft’,
‘meta_key’=>’_gcdb_source_url’,‘meta_compare’=>‘EXISTS’,
‘posts_per_page’=>200,
‘orderby’=>‘ID’,‘order’=>‘DESC’,‘no_found_rows’=>true));
results = array(); foreach(posts as $post) {
if (count($results) >= min(10, max(1,(int)$limit))) { break; }
$taxonomy = gcdb_category_taxonomy(); $existing_terms =
taxonomy?wp_(g)et_(o)bject_(t)erms(post->ID, $taxonomy,
array(‘fields’=>‘ids’)) : array();
category_(o)k = \!is_(w)p_(e)rror(existing_terms) &&
!empty($existing_terms);
excerpt_(n)eeds_(f)ix = strpos((string)post->post_excerpt,
‘[gcdb_paid_delivery]’) !== false; if (has_post_thumbnail($post->ID) &&
$category_ok && !$excerpt_needs_fix) { continue; }
raw = (string)get_(p)ost_(m)eta(post->ID, ’_gcdb_private_delivery_html’,
true); cover = has_(p)ost_(t)humbnail(post->ID) ? ‘已有特色图片’ :
gcdb_attach_featured($post->ID, $raw ?: $post->post_content);
category = gcdb_(a)ssign_(c)ategory(post->ID);
update_post_meta($post->ID, ’_gcdb_cover_last_result’,
cover); update_(p)ost_(m)eta(post->ID, ’_gcdb_category_last_result’,
category); if(excerpt_needs_fix) {
clean_(e)xcerpt = trim(str_(r)eplace(′[gcdb_(p)aid_(d)elivery]′, ″, (string)post->post_excerpt));
wp_update_post(array(‘ID’=>post− > ID, ′post_(e)xcerpt′ = > wp_(t)rim_(w)ords(wp_(s)trip_(a)ll_(t)ags(clean_excerpt),
80, ‘…’))); }
results[] = array(′id′ = > (int)post->ID,‘title’=>post− > post_(t)itle, ′cover′ = >cover,‘category’=>$category);
} return $results; }
// 必须和共创社现有 single-gc_resource 模板使用同样的权限过滤器。 //
不接收前端传来的资源 ID,防止借其他页面读取未购买的项目。 function
gcdb_can_view_delivery($post_id) { if
(current_user_can(‘manage_options’)) { return true; }
uid = get_(c)urrent_(u)ser_(i)d(); if(!uid) { return false; }
mode = function_(e)xists(′gchuang_(g)et_(a)ccess_(m)ode′)?gchuang_(g)et_(a)ccess_(m)ode(post_id)
: get_post_meta($post_id, ’_gc_resource_access’, true); $is_member =
(bool) apply_filters(‘gchuang_user_is_member’, false, $uid); $purchased
= (bool) apply_filters(‘gchuang_resource_user_has_purchase’, false,
$uid, $post_id); // 此模块一律不因意外设为“免费”而公开交付内容。
allowed = (mode === ‘purchase’ && purchased)||(mode === ‘member’ &&
is_(m)ember)||(mode === ‘member_purchase’ && ($purchased ||
$is_member)); return (bool)
apply_filters(‘gchuang_resource_user_can_download’, $allowed, $uid,
$post_id, $mode); } /** *
仅取得本站当前存在的结算入口。订单与支付由现有主题和支付插件完成, *
草稿对接插件绝不自行写订单、不处理收款、不更改购买权限。 */ function
gcdb_checkout_status() {
page = get_(p)age_(b)y_(p)ath(′checkout′, OBJECT, ′page′); if(!page ||
$page->post_status !== ‘publish’) { return ‘结算页面不存在或尚未发布’; }
$file = ‘page-checkout.php’;
theme_(h)as_(t)emplate = file_(e)xists(trailingslashit(get_(s)tylesheet_(d)irectory()).file)
||
file_exists(trailingslashit(get_template_directory()).file); if(!theme_has_template)
{ return ‘结算模板 page-checkout.php 未部署’; } if
(!function_exists(‘gchuang_get_or_create_resource_order’)) { return
‘订单创建函数未加载’; } return ’‘; } function
gcdb_checkout_link($post_id) { if (gcdb_checkout_status() !==’‘) {
return’‘; } $checkout = get_page_by_path(’checkout’, OBJECT, ‘page’);
url = add_(q)uery_(a)rg(′resource_(i)d′, absint(post_id),
get_permalink($checkout)); $url = (string)
apply_filters(‘gchuang_resource_purchase_url’, url, absint(post_id),
get_current_user_id()); url = esc_(u)rl_(r)aw(url); if (!$url ||
!preg_match(‘_(^https?://)i’, $url)) { return ’‘; } if
(!is_user_logged_in()) { url = wp_(l)ogin_(u)rl(url); } return
esc_url($url);
}
function gcdb_has_private_delivery($post_id) { return (bool)
get_post_meta(absint($post_id), '_gcdb_private_delivery_html', true);
}
add_shortcode('gcdb_paid_delivery', function ($atts = array()) {
post = get_(p)ost(); if(!post || $post->post_type !== ’gc_resource’) {
return ’‘; } $id = (int) $post->ID;
html = (string)get_(p)ost_(m)eta(id,’_gcdb_private_delivery_html’,
true); if ($html === ’‘) { return’‘; } //
旧主题若有原生下载区域,其锚点继续由原模板创建,避免重复 ID。
anchor = get_(p)ost_(m)eta(id,’_gc_resource_download_url’, true) ? ’’ :
’ id=“gc-resource-download”‘; // 同旧主题的 #gc-resource-download
锚点相兼容。 // 不在 HTML
中输出原始交付内容,未授权时只渲染说明和购买链接。 if
(!gcdb_can_view_delivery($id)) { url = gcdb_(c)heckout_(l)ink(id); $buy
= $url
? ''
.'
视频课程及交付资料
'
.'已解锁:视频课程与交付资料
'.wp_kses_post($html).’
’; });
/** * 原主题顶部“立即购买”链接指向 #gc-resource-download; *
但新采集资源没有旧的下载字段,导致该锚点此前不存在。 *
本修复仅针对本插件导入、且保存了私密交付内容的项目。 * JS
若加载失败,顶部按钮仍可跳到上面的新锚点,不再失效。 */
add_action(‘wp_footer’, function () { if (!is_singular(‘gc_resource’)) {
return; } post = get_(q)ueried_(o)bject(); if(!post ||
!gcdb_has_private_delivery($post->ID)) { return; }
unlocked = gcdb_(c)an_(v)iew_(d)elivery(post->ID); $checkout_url =
unlocked?″ : gcdb_(c)heckout_(l)ink(post->ID);
url_(j)son = wp_(j)son_(e)ncode(checkout_url, JSON_HEX_TAG |
JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); $unlock_json =
$unlocked ? 'true' : 'false';
echo '
资源内容

感谢您的来访,获取更多精彩文章请收藏本站。