mirror of
https://github.com/yunluo/gdk.git
synced 2024-05-12 03:06:54 +02:00
增加一键更新安装插件功能
This commit is contained in:
parent
3168271cfe
commit
ffbd3af441
|
@ -50,7 +50,7 @@ function gdk_options_page()
|
|||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h2>GDK选项 <input type="button" class="add-new-h2 get_new_version" value="检测更新"></h2>
|
||||
<h2>GDK选项 <input type="button" class="add-new-h2 get_new_version" value="检测更新"><input type="button" data-url="" class="add-new-h2 install_new_version" value="安装更新"></h2>
|
||||
<hr/>
|
||||
<?php
|
||||
if (isset($_GET['update'])) {
|
||||
|
@ -298,7 +298,7 @@ break;
|
|||
border-radius: 50%;
|
||||
box-shadow: inset 0 0 0 2px #e14d43, 0 0 0 2px #e14d43;
|
||||
}
|
||||
|
||||
.install_new_version,
|
||||
.wrap.searching .nav-tab-wrapper a,
|
||||
.wrap.searching .panel tr,
|
||||
body.show-filters .wrap form {
|
||||
|
@ -321,6 +321,17 @@ body.show-filters .wrap form {
|
|||
padding: 5px;
|
||||
font-size: medium;
|
||||
}
|
||||
.g-load{
|
||||
background: url(images/spinner.gif) no-repeat;
|
||||
background-size: 20px 20px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
opacity: .7;
|
||||
filter: alpha(opacity=70);
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: 4px 10px 0;
|
||||
}
|
||||
</style>
|
||||
<style id="theme-options-filter"></style>
|
||||
<script>
|
||||
|
@ -377,20 +388,35 @@ jQuery(function ($) {
|
|||
});
|
||||
|
||||
$(".get_new_version").click(function () {
|
||||
$(".get_new_version").after("<span class='g-load'></span>");
|
||||
var ajax_data = { action: 'get_new_version' };
|
||||
$.get(ajaxurl, ajax_data,
|
||||
function(a) {
|
||||
a = $.trim(a);
|
||||
$(".g-load").hide();
|
||||
if (a !== '400') {
|
||||
if ($(".get_update_res").length > 0) return;
|
||||
$(".get_new_version").after(a);
|
||||
$(".install_new_version").show();
|
||||
|
||||
}else{
|
||||
$(".get_new_version").after("检测失败,网络错误");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".install_new_version").click(function () {
|
||||
$(".install_new_version").after("<span class='g-load'></span>");
|
||||
var ajax_data = { action: 'install_new_version' };
|
||||
$.get(ajaxurl, ajax_data,
|
||||
function() {
|
||||
$(".g-load").hide();
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$(".feedback-btn").click(function() {
|
||||
$(".feedback-btn").after(" <span class='feedback-load'>正在努力加载中.....</span>");
|
||||
$(".feedback-btn").after("<span class='g-load'></span>");
|
||||
$("<link>").attr({
|
||||
rel: "stylesheet",
|
||||
type: "text/css",
|
||||
|
@ -399,7 +425,7 @@ $(".feedback-btn").click(function() {
|
|||
|
||||
$.getScript("https://cdn.bootcss.com/fancybox/3.0.39/jquery.fancybox.min.js",
|
||||
function() {
|
||||
$(".feedback-load").hide();
|
||||
$(".g-load").hide();
|
||||
$.fancybox.open({
|
||||
src: 'https://support.qq.com/products/51158/',
|
||||
type: 'iframe',
|
||||
|
|
|
@ -33,7 +33,7 @@ function gdk_ajax_get_update()
|
|||
$version = $plugin_info['version'];
|
||||
|
||||
if (version_compare($version, GDK_PLUGIN_VER, '>')) {
|
||||
exit('<span class="get_update_res">插件有更新,新版本:<span class="key_word">' . $version . '</span> <a class="feedback add-new-h2" href="' . $plugin_info['details_url'] . '" target="_blank">查看更新内容</a> <a class="feedback add-new-h2" href="' . $plugin_info['download_url'] . '" target="_blank">请点击下载</a></span>');
|
||||
exit('<span class="get_update_res">插件有更新,新版本:<span class="key_word">' . $version . '</span> <a class="feedback add-new-h2" href="' . $plugin_info['details_url'] . '" target="_blank">查看更新内容</a></span>');
|
||||
} else {
|
||||
exit('<span class="get_update_res">你的插件目前已经是最新版了!</span>');
|
||||
}
|
||||
|
@ -41,6 +41,17 @@ function gdk_ajax_get_update()
|
|||
add_action('wp_ajax_nopriv_get_new_version', 'gdk_ajax_get_update');
|
||||
add_action('wp_ajax_get_new_version', 'gdk_ajax_get_update');
|
||||
|
||||
//Ajax安装插件更新
|
||||
function gdk_ajax_install_update()
|
||||
{
|
||||
$url = 'http://a.gitcafe.net/Git-alpha.zip';
|
||||
unzip_url($url, ABSPATH . 'wp-content/plugins');
|
||||
exit(1);
|
||||
|
||||
}
|
||||
add_action('wp_ajax_nopriv_install_new_version', 'gdk_ajax_install_update');
|
||||
add_action('wp_ajax_install_new_version', 'gdk_ajax_install_update');
|
||||
|
||||
//粘贴上传图片
|
||||
function gdk_pasteup_imag()
|
||||
{
|
||||
|
|
|
@ -1297,3 +1297,20 @@ function getQrcode($url)
|
|||
header("content-type:application/json; charset=utf-8");
|
||||
return 'data:image/jpeg;base64,' . $imageString;
|
||||
}
|
||||
|
||||
function unzip_url($url, $where)
|
||||
{
|
||||
$zippath = $where . '/' . (basename($url)) . '.zip';
|
||||
wp_remote_get($url,
|
||||
[
|
||||
'timeout' => 300,
|
||||
'stream' => true,
|
||||
'filename' => $zippath,
|
||||
]
|
||||
);
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
\WP_Filesystem();
|
||||
\unzip_file($zippath, $where);
|
||||
usleep(300000);
|
||||
@unlink($zippath);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue