Authorize a domain for wordpress theme

In Server: $domain = $_GET['domain']; //Get domain $Array = array('127.0.0.1','localhost','www.ikxin.com','www.keepmins.com'); //Authorized domain list echo in_array($domain, $Array) ? 'true' : 'false'; //return the resule In Client: $shouname = trim($_SERVER['SERVER_NAME']); //get domain $shouurl = file_get_contents('http://119.27.180.212/auth.php?domain='.$shouname); //get authorized domain form server if($shouurl=='true'){ echo "authorized"; //Authorized }else{ die("unauthorized"); //Unauthorized }

2019-07-17 · 1 min · Duke Yin

Mobile app

Basics <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-title" content="KeepMins" /> <meta name="theme-color" content="#fffff" /> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" /> <link rel="apple-touch-icon-precomposed" href="/i/iosicon.png" /> <link rel="manifest" href="/static/manifest.json" /> iOS Status Bar <meta name="apple-mobile-web-app-status-bar-style" content="取值"> default black-translucent black White manifest.json { "name": "Keep Minutes", "short_name": "KeeMins", "theme_color": "#53c5e7", "background_color": "#53c5e7", "display": "fullscreen", "orientation": "portrait", "Scope": "/", "start_url": "/", "icons": [ { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-72x72.png", "sizes": "72x72", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-96x96.png", "sizes": "96x96", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-144x144.png", "sizes": "144x144", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-152x152.png", "sizes": "152x152", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-192x192.png", "sizes": "192x192", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-384x384.png", "sizes": "384x384", "type": "image/png" }, { "src": "wp-content/themes/keep-minutes-2/i/icons/icon-512x512.png", "sizes": "512x512", "type": "image/png" } ], "splash_pages": null } <meta name="msapplication-navbutton-color" content="#3f51b5"> <meta name="msapplication-starturl" content="/?utm_source=homescreen"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="application-name" content="Add To Home"> <meta name="apple-mobile-web-app-title" content="ADH"> <meta name="apple-mobile-web-app-status-bar-style" content="#3f51b5"> <link rel="manifest" href="manifest.json"> <link rel="apple-touch-icon" sizes="192x192" href="icons/android-chrome-192x192.png" /> <link rel="apple-touch-icon" sizes="144x144" href="icons/android-chrome-144x144.png" /> <link rel="apple-touch-icon" sizes="114x114" href="icons/android-chrome-114x114.png" /> <link rel="apple-touch-icon" sizes="72x72" href="icons/android-chrome-72x72.png" /> <link rel="apple-touch-icon" sizes="57x57" href="icons/android-chrome-57x57.png" /> <link rel="apple-touch-icon" sizes="48x48" href="icons/android-chrome-48x48.png" /> <link rel="apple-touch-icon" sizes="36x36" href="icons/android-chrome-36x36.png" /> <link rel="icon" sizes="192x192" href="/icons/android-chrome-192x192.png" /> <link rel="icon" sizes="144x144" href="icons/android-chrome-144x144.png" /> <link rel="icon" sizes="114x114" href="icons/android-chrome-114x114.png" /> <link rel="icon" sizes="72x72" href="icons/android-chrome-72x72.png" /> <link rel="icon" sizes="57x57" href="icons/android-chrome-57x57.png" /> <link rel="icon" sizes="48x48" href="icons/android-chrome-48x48.png" /> <link rel="icon" sizes="36x36" href="icons/android-chrome-36x36.png" /> <link rel="icon" type="image/x-icon" href="icons/favicon.ico" /> <meta name="msapplication-TileColor" content="#3f51b5"> <meta name="theme-color" content="#3f51b5">

2019-07-14 · 2 min · Duke Yin

Wordpress中简单的社交媒体meta SEO

<meta property="og:site_name" content="<?php bloginfo( 'name' ); ?>" /> <meta property="og:title" content="<?php if(!is_home()){the_title();echo '-';} bloginfo( 'name' ); ?>" /> <meta property="og:url" content="<?php if(is_home()){echo esc_url( home_url( '/' ) ); }else{echo esc_url( the_permalink() ); }; ?>" /> <meta property="og:type" content="website" /> <meta name="twitter:site" content="@<?php echo $dukeyin_options['acc_tw']; ?>" />   社交媒体meta是一种针对各种社交媒体的的信息提示,当网站被分享到社交媒体时,会作为标题、URL以及图像优先摘取,有利于网站的SEO,在不借助第三方插件的情况下,将这些meta信息放置在header中,有利于网站的seo。

2018-09-11 · 1 min · Duke Yin

Wordpress useful functions

1 全局添加图像链接参数 有时候调用Lightbox插件,需要在图片链接上加某些参数,已发布的文章也是,用以下代码添加data-lightbox=“lightbox”(或其他需要的参数) 来实现。 /** *Lightbox to image link globally */ add_filter('the_content', 'dukeyin_addlightbox'); function dukeyin_addlightbox($content) { global $post; $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; $replacement = '<a$1href=$2$3.$4$5 data-lightbox="lightbox" title="'.$post->post_title.'"$6>'; $content = preg_replace($pattern, $replacement, $content); return $content; } 另一种方式,修改单张图片,也修改相册的链接 <?php /** * Add data attributes for Fancybox */ // Gallery images function ccd_fancybox_gallery_attribute( $content, $id ) { // Restore title attribute $title = get_the_title( $id ); return str_replace('<a', '<a data-type="image" data-fancybox="gallery" title="' . esc_attr( $title ) . '" ', $content); } add_filter( 'wp_get_attachment_link', 'ccd_fancybox_gallery_attribute', 10, 4 ); // Single images function ccd_fancybox_image_attribute( $content ) { global $post; $pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; $replace = '<a$1href=$2$3.$4$5 data-type="image" data-fancybox="image">'; $content = preg_replace( $pattern, $replace, $content ); return $content; } add_filter( 'the_content', 'ccd_fancybox_image_attribute' ); ?>   ...

2018-08-14 · 4 min · Duke Yin

Social media share url

新浪地址接口 http://service.weibo.com/share/share.php?url={url}&appkey=&title={titledes}&pic={pic}&ralateUid=&language=&searchPic=false qq微博 http://share.v.t.qq.com/index.php?c=share&a=index&cs=1&bm=110&url={url}&pic={pic}&title={titledes} qzone http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}&title={title} qq好友 http://connect.qq.com/widget/shareqq/index.html?url={url}&showcount=0&title={title}&summary={des}&site=jiathis&pics={pic} renren http://widget.renren.com/dialog/share?resourceUrl={url}&title={title}&images={pic}&description={des} facebook https://www.facebook.com/dialog/share?app_id={app-id}&display=popup&href={link-to-share}&redirect_uri={redirect-uri} Twitter https://twitter.com/intent/tweet?text={text}&url={url}&original_referer={url}  

2018-08-08 · 1 min · Duke Yin

获取特色图像如果为空则获取第一张图

Wordpress主题制作过程中经常要获得特色图像的URL以用来裁切或者呈现,但是有时候日志中不包含特色图像,比较好的方法是建立一个方程获得文章内容的第一张特色图像。 获得第一张图的方程在网上有很多,但是缺点是每次必须要用if去判断,有特色图像如何,没有特色图像如何。 所以为何我们不将判断的工作直接放进方程里,让这个方程去获取特色图像,没有的话就调用第一张图呢? /** Get First image */ function get_first_image() { global $post, $posts; $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); if(empty($featured_img_url)){ $first_img = ''; ob_start(); ob_end_clean(); if($output = preg_match_all(’//i’, $post->post_content, $matches)){ $first_img = $matches [1] [0]; }else{ $first_img = ‘’; }; }else{ $first_img= $featured_img_url; } ...

2018-08-05 · 1 min · Duke Yin

Wordpress 主题提醒用户安装一个插件

in functions.php: /* check required plugins */ add_action( 'admin_notices', 'dukeyin_theme_dependencies' ); function dukeyin_theme_dependencies() { if( ! function_exists('new_cmb2_box') ) echo '<div class="notice notice-error"><p>' . __( '<h4>Warning: Plugin Missing: CMB2</h4>The DukeYin theme needs Plugin <a href="https://wordpress.org/plugins/cmb2/" target="_blank">CMB2</a> to function. Search "CMB2" in wordpress plugin panel, install and activit it.', 'dukeyin' ) . '</p></div>'; if(!function_exists('simpleYearlyArchive')) echo '<div class="notice notice-warning"><p>' . __( '<h4>Notice: Plugin Missing: Simple Yearly Archive</h4>The DukeYin theme needs Plugin <a href="https://wordpress.org/plugins/simple-yearly-archive/" target="_blank">Simple Yearly Archive</a> to display the archive page. Search "Simple Yearly Archive" in wordpress plugin panel, install and activit it to make your site better.', 'dukeyin' ) . '</p></div>'; }   ...

2018-07-30 · 1 min · Duke Yin

Linux宝塔面板性能优化

前期准备:安装宝塔Linux面板 4.2.x,安装Linux工具箱,安装LNMP或LAMP环境 具体优化设置步骤 1、添加计划任务,定期释放内存,建议设置每天释放一次,执行时机为半夜,如:3:30 2、打开Linux工具箱添加Swap Swap推荐值: 物理内存 Swap 512M 1024M 1GB 1500M 2GB 2048M 4GB 4096M 6GB+ 4096M 3、安装PHP缓存扩展,根据即将部署的站点需求,尽量使用更高的PHP版本,另外缓存安装建议如下: 脚本缓存:xcache、opcache 任选一项安装,PHP5.2-5.4建议使用xcache,PHP5.5以上建议使用opcache 内容缓存:若程序支持,建议优先顺序如下: redis > apc > memcached > memcache 注意:内容缓存和脚本缓存,都各只安装一个,不要安装多个! 4、若程序支持,尽量使用imagemagick代替PHP自带GD,以提升性能 5、若程序支持,尽量安装fileinfo、exif扩展,以提升站点性能和安全性 6、若确定您的程序不需要,尽量不要安装ZendGuardLoader,ioncube解密扩展 7、若您的程序不需要PATH_INFO,请把它关闭 8、PHP并发调整建议: CPU/内存 单站点 多站点 1H/512M 20-30 10-20 1H/1G 30-50 20-30 2H/2G 50-80 30-50 2H/4G 60-100 30-50 4H/4G 100-150 30-80 4H/8G 100-200 30-80 6H/6G 100-200 30-80 8H/8G 100-300 50-100 8H/16G 100-300 100-150 16H/16G 100-300 100-150 注1:容易受到CC攻击的站点使用的PHP版本,尽量不要设置过高的并发,以免服务器被打死 注2:VPS性能参差不齐,以上建议仅供参考,请根据实际使用效果自行调整 注3:不建议设置超过300并发上限,哪怕您的服务器性能足够好;若发现并发不够用,请尝试优化站点数据库缓存可能更有效 ...

2018-04-03 · 1 min · Duke Yin

全站改https的方法

如今个人ssl证书已经很便宜,很多商家甚至提供免费的ssl证书,如何让我们的网站获得全站ssl证书? 网站配置文件中开放443端口 填写获得的ssl密钥文件地址 Wordpress设置中修改主站地址为https 在数据库中替换所有图片以及其他附件地址为https UPDATE wp_posts SET post_content = replace(post_content, 'http://www.domain.com/wp-content/uploads','https://www.domain.com/wp-content/uploads'); 如果你不太会使用mysql命令,还可以在主题的functions.php中添加如下代码以达到附件地址替换为https /* 替换图片链接为 https */ function my_content_manipulator($content){ if( is_ssl() ){ $content = str_replace('http://www.domain.com/wp-content/uploads', 'https://www.domain.com/wp-content/uploads', $content); } return $content; } add_filter('the_content', 'my_content_manipulator'); 强制后台使用https 在wp-cofig 文件中加入如下条目 /* 强制后台和登录使用 SSL */ define('FORCE_SSL_LOGIN', true); define('FORCE_SSL_ADMIN', true); 由于https要求全部外链文件都必须是https,所有如果之前主题引用了http的资源,比如logo图片地址,jQ文件或者其他js,记得要替换引用的地址为https,尽量放本地加载。 ...

2017-06-15 · 1 min · Duke Yin

Wordpress常用变量函数

获取主题目录路径 get_template_directory_uri() 范例 获取首页地址 home_url() 或者 get_home_url() 范例 home_url();或者 get_home_url(); Output: http://www.example.com home_url( '/' ); Output: http://www.example.com/ home_url( $path = '/', $scheme = https ); Output: https://www.example.com/ home_url( $path = 'example', $scheme = relative ); Output: /example 获取样式表所在目录 get_stylesheet_uri() 获取当前文章的作者名称 the_author(); get_the_author(); ...

2017-06-04 · 2 min · Duke Yin