本文最后更新于 2022-10-14,已超过 365 天未更新,内容可能已失效。
[tip_success]自己抽空写了给代码,适合ripro-v2【ripro转v2】,有点代码基础的可以举一反三,其他主题页适用! 支持,百度,蓝奏,123网盘,微云,189网盘,坚果等,原则上网盘都支持。可参考本网站[/tip_success]
第一步添加下面到function.php文件
[rihide]
//链接状态
function pan_check_link($url)
{
$link = $url;
if ($link == "链接为空") {
return array("status" => "1", "msg" => "存在空链接");
}
$response = wp_remote_get($link);//WordPress远程获取内容
if (is_array($response) && !is_wp_error($response) && $response["response"]["code"] == "200") {
$header = $response["headers"];
$body = $response["body"];
if (strpos($body, "页面不存在") !== false) {
return array("status" => "1", "msg" => "页面不存在,请联系客服处理!");
}
if (strpos($body, "链接不存在") !== false) {
return array("status" => "1", "msg" => "链接不存在,请联系客服处理!");
}
return array("status" => "1", "msg" => "链接正常请放心购买/下载");
}
return array("status" => "0", "msg" => "链接失效,请联系客服处理!");
}
function check_url_state()
{
$post_id = !empty($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
if(get_post_meta($post_id, "cao_downurl", true) ){
$c_link=get_post_meta($post_id, "cao_downurl", true);
}else{
$arr=get_post_meta($post_id, "cao_downurl_new", true)?get_post_meta($post_id, "cao_downurl_new", true):"";
foreach ($arr as $key => $item) {
$c_link=$item['url'];
}
}
$state = pan_check_link($c_link);
echo json_encode($state);exit;
}
[/rihide]
第二步:添加JS文件
[rihide]
function zp_check_pan_url(e) {
'use strict';
$('.zptheme-check-url').on('click', function () {
var t = $(this);
t.html();
rizhuti_v2_ajax(
{
action: 'check_url_state',
post_id: t.data("id")
},
function (e) {
t.html(iconspin+'正在检测中');
},
function (e) {
1 == e.status
? (t.toggleClass("ok"), t.attr("disabled", "true").html(e.msg))
: t.attr("disabled", "true").html(e.msg);
}
);
})
}
jQuery(function () {
zp_check_pan_url()
})
[/rihide]
第三步:添加检测按钮
在文件shop-widget.php //按钮组件 异步模式前添加以下代码
[rihide]
echo'<button type="button" class="btn btn-block btn-info mb-2 zptheme-check-url" data-id="'.$post_id.'">检测链接状态</button>';
[/rihide]
除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。



登录后即可发表评论
全部评论 (0)