本文是《wordpress(共168篇)》专题的第 68 篇。阅读本文前,建议先阅读前面的文章:
相信有很多朋友开始写自己的原创WordPress主题,在这个时候通常很多都是借助于插件或是直接手动推送给用户,无论您是不会写还是没时间折腾更新,或是怕在线更新功能会被盗版也提供更新了今天要讲的方法很不错哟。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
//主题更新功能 add_filter(‘pre_set_site_transient_update_themes’, ‘theme_update’); add_action(‘delete_site_transient_update_themes’, ‘deleteStoredData’) function get_current_theme( $name=false ){ $theme = wp_get_theme(); if($theme->get(‘Template’)){ return $name ? $theme->parent()->get(‘Name’) : $theme->template; }else{ return $name ? $theme->get(‘Name’) : $theme->stylesheet; } } function theme_update($value){ $new_version=‘2.9.6’;//新版 $new_url=‘https://www.xxxx.com/chameleons/’;//介绍页 $new_package=‘https://www.xxxx.com/chameleons/xxx.zip’;//下载包 //以上数据可以定义为post接受参数来赋予,这样可以很好的保护我们主题下载包,你可以加授权验证账号网站等 //注意下方修改变量 $version=‘2.9.5’;//旧版 $state = get_option(‘update_chameleonS’); if ( empty($state) ){ $state = new StdClass; $state->lastCheck = time(); $state->checkedVersion = $version; $state->update = null; } if(version_compare($version, $new_version)<0) { $state->update = new StdClass; $state->update->version = $new_version; $state->update->url = urldecode($new_url); $state->update->package = urldecode($new_package); update_option(‘update_chameleonS’, $state); } global $theme_update_state; if(!isset($theme_update_state)) $theme_update_state = get_option(‘update_chameleonS’); if ( !empty($theme_update_state) && isset($theme_update_state->update) && !empty($theme_update_state->update) ){ |
当你添加搞定好就拥有了和WordPress默认主题更新功能啦,是否很简单呢,好了今天的将更新功能添加到你自己的WordPress主题中教程就写到这里了
您已阅读完《wordpress(共168篇)》专题的第 68 篇。请继续阅读该专题下面的文章:
本站模板没有任何后门,也不会和我们服务器有任何通信,请您放心使用。
本源码一次性买断,没有二次费用,并享受免费更新。
在使用本站模板时,请不要使用我们的产品从事违反中华人民共和国法律、违反公序良俗的活动,否则我们有权拒绝服务,并配合有关单位予以处置。如果您不符合条件,请勿购买。
售后是指通过QQ与客服联系处理问题,售后过期不影响您对主题的使用和更新。免费三个月售后服务。售后服务时间为工作日早9点到晚5点。如果不在线可以QQ留言,我们会尽快给您答复。
售后服务包括程序的使用、BUG的处理、意见建议等。不包括技术服务、网站优化、二次开发、环境配置、服务器运维等。
代码类商品属于数字化商品,具有可复制性,不支持退款,详见《网络交易管理办法》第二章 第16条 第三类。
请仔细阅读我们的用户协议:用户协议



