Skip to content

Instantly share code, notes, and snippets.

@lmm214
lmm214 / cloudflare-worker-proxy.js
Created March 5, 2023 15:07 — forked from noobnooc/cloudflare-worker-proxy.js
cloudflare-worker-proxy
// Website you intended to retrieve for users.
const upstream = 'api.openai.com'
// Custom pathname for the upstream website.
const upstream_path = '/'
// Website you intended to retrieve for users using mobile devices.
const upstream_mobile = upstream
// Countries and regions where you wish to suspend your service.
@lmm214
lmm214 / 24dian.sql
Last active July 7, 2016 00:55
24点题库(10以内)
insert `24dian`(`num1`,`num2`,`num3`,`num4`) values('1','1','1','8'),
('1','1','1','8'),
('1','1','2','6'),
('1','1','2','7'),
('1','1','2','8'),
('1','1','2','9'),
('1','1','2','10'),
('1','1','3','4'),
('1','1','3','5'),
('1','1','3','6'),
@lmm214
lmm214 / Anonymous Comments
Created July 15, 2015 07:54
Remove Name and Email From Comment Form
function wpb_alter_comment_form_fields($fields) {
unset($fields['author']);
unset($fields['email']);
unset($fields['url']);
return $fields;
}
add_filter('comment_form_default_fields', 'wpb_alter_comment_form_fields');
@lmm214
lmm214 / preprocess_comment
Created July 15, 2015 07:21
Limit Comment Length Using Code Snippet
add_filter( 'preprocess_comment', 'wpb_preprocess_comment' );
function wpb_preprocess_comment($comment) {
if ( strlen( $comment['comment_content'] ) > 5000 ) {
wp_die('Comment is too long. Please keep your comment under 5000 characters.');
}
if ( strlen( $comment['comment_content'] ) < 60 ) {
wp_die('Comment is too short. Please use at least 60 characters.');
}
return $comment;
@lmm214
lmm214 / gist:c404c944287e1d7d77ff
Created July 6, 2015 13:47
发布文章添加编辑器按钮
function my_add_quicktags() {
if (wp_script_is('quicktags')){ ?>
<script type="text/javascript">
//QTags.addButton( id, display, arg1, arg2, access_key, title, priority, instance );
QTags.addButton( 'pre.html4', 'HTML代码', "\n<pre lang='html4strict'>\n", "\n</pre>\n" );
QTags.addButton( 'pre.js', 'JS代码', "\n<pre lang='javascript'>\n", "\n</pre>\n" );
QTags.addButton( 'pre.php', 'PHP代码', "\n<pre lang='php'>\n", "\n</pre>\n" );
QTags.addButton( '[gallery.i2m]', '两列', '\n[gallery link="file" include="," columns="2" size="medium"]\n','' );
QTags.addButton( '[gallery.i3m]', '三列', '\n[gallery link="file" include="," size="medium"]\n','' );
</script>
@lmm214
lmm214 / gist:e6584f891b1620899919
Created July 6, 2015 13:44
禁止全英文评论
function scp_comment_post( $incoming_comment ) {
$pattern = '/[一-龥]/u';
if(!preg_match($pattern, $incoming_comment['comment_content'])) {
wp_die( "您的评论中必须包含中文!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'scp_comment_post');
@lmm214
lmm214 / allow_email_login
Last active August 29, 2015 14:24
//允许 Email 登录 WordPress 后台
//允许 Email 登录 WordPress 后台
function allow_email_login($username ) {
$user = get_user_by( 'email', $username );
if ( ! empty( $user) ) {
$username = $user-&gt;user_login;
}
return $username;
}
add_filter('sanitize_user', 'allow_email_login');
@lmm214
lmm214 / duoshuo_avatar.php
Created July 16, 2014 11:15
WordPress 调用多说 Gravatar 头像
function duoshuo_avatar($avatar) {
$avatar = str_replace(array("www.gravatar.com","0.gravatar.com","1.gravatar.com","2.gravatar.com"),"gravatar.duoshuo.com",$avatar);
return $avatar;
}
add_filter( 'get_avatar', 'duoshuo_avatar', 10, 3 );
@lmm214
lmm214 / qiniu-cache-gravatar
Last active August 29, 2015 14:03
七牛云缓存 Gravatar头像(支持头像大小参数)
// By ImMmMm.com 七牛云缓存 Gravatar头像(支持头像大小参数)
function qiniu_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="http://你的空间名称.qiniudn.com/avatar/$1-$2" class="avatar avatar-$2" height="$2" width="$2">',$avatar);
return $avatar;
}
add_filter( 'get_avatar', 'qiniu_avatar', 10, 3 );
// WordPress 4.0+ 适用
function qiniu_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*.srcset=.*/','<img src="http://你的空间名称.qiniudn.com/avatar/$1-$2" class="avatar avatar-$2" height="$2" width="$2">',$avatar);
return $avatar;
@lmm214
lmm214 / gist.php
Last active August 29, 2015 14:03 — forked from ccbikai/gist.php
WordPress 使用 iframe 嵌入Github Gist代码,使用方法单独起一行写入: https://gist.github.com/
function wp_iframe_handler_gist( $matches, $attr, $url, $rawattr ) {
$iframe = '<iframe width="100%" height="300" src="https://gist.github.com/'. esc_attr($matches[1]) .'/'. esc_attr($matches[2]) . '.pibb" frameborder=0 ></iframe>';
return apply_filters( 'iframe_gist', $iframe, $matches, $attr, $url, $rawattr );
}
wp_embed_register_handler( 'gist_iframe', '#https://gist.github.com/(.*?)/([\w]+)#i', 'wp_iframe_handler_gist' );
//七牛云缓存:新建空间,镜像源设置成“https://gist.github.com/”,然后把上面代码中的这句链接改成“https://你的空间项目.qiniudn.com/”