wordpress 不用插件直接源码实现smtp发邮件
add_action('phpmailer_init', 'fanly_mail_smtp');
function fanly_mail_smtp( $phpmailer ) {
$phpmailer->IsSMTP();
$phpmailer->SMTPAuth = true;//启用 SMTPAuth 服务
$phpmailer->FromName = '三伏磨'; //发件人名称
$phpmailer->Port =465;//MTP 邮件发送端口,常用的端口为25和465(SSL加密端口)
$phpmailer->SMTPSecure ="ssl";//是否验证 ssl,与 MTP 邮件发送端口对应,如果不填写,则上面的端口须为 25
$phpmailer->Host ="smtp.126.com";//邮箱的 SMTP 服务器地址,目前 smtp.exmail.qq.com 为 QQ 邮箱
$phpmailer->Username = "htmonitor1@126.com";//你的邮箱地址
$phpmailer->Password ="sqxxxxx66";//你的邮箱登录密码(如果是QQ邮箱填写生成的授权码)
}
add_filter( 'wp_mail_from', 'fanly_wp_mail_from' );
function fanly_wp_mail_from() {
return 'htmonitor1@126.com'; //邮箱账户,和上面的邮箱地址一致
}
禁止复制
<script type="text/Javascript">
<!--
document.oncontextmenu=function(e){return false;};
document.onselectstart=function(e){return false;};
//-->
</script>
<style>
body{
-moz-user-select:none;
}
</style>
<SCRIPT LANGUAGE=javascript><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>
<noscript><iframe src=*.html></iframe></noscript>
复制提醒方法2
<script>
function stop(){
alert('复制成功!转载请务必保留原文链接,申明来源,谢谢合作!');
return false;
}
document.oncontextmenu=stop;
</script>
<body onselectstart="return false" onpaste="return false" oncop
y="return false;"
oncut="return false;" >
复制提醒方法1 ok
function zm_copyright_tips() {
echo '<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.css" >';
echo '<script src="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>';
echo '<script>document.body.oncopy = function() { swal("复制成功!", "转载请务必保留原文链接,申明来源,谢谢合作!!","success");};</script>';
}
add_action( 'wp_footer', 'zm_copyright_tips', 100 );
显示页面查询次数、加载时间和内存占用
//显示页面查询次数、加载时间和内存占用
function performance( $visible = false ) {
$stat = sprintf( ‘%d 次查询 耗时 %.3f seconds, 使用 %.2fMB 内存’,
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
echo $visible ? $stat : “” ;
}
后台禁用Google Open Sans字体,加速网站
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
wiz 去除
//wiz
function content_replace($data) {
// 正则字符串写法为'/reg_exp/', /需要转义成\/
$data = preg_replace("/<div><a.*http:\/\/www.wiz.cn\/.*<\/a><\/div>/", "", $data);
return $data;
}
add_filter( 'content_save_pre', 'content_replace');
移除wp-json链接 删除emoji脚本
//移除wp-json链接
add_filter(‘rest_enabled’, ‘_return_false’);
add_filter(‘rest_jsonp_enabled’, ‘_return_false’);
remove_action( ‘wp_head’, ‘rest_output_link_wp_head’, 10 );
remove_action( ‘wp_head’, ‘wp_oembed_add_discovery_links’, 10 );
//删除emoji脚本
remove_action( ‘admin_print_scripts’, ‘print_emoji_detection_script’);
remove_action( ‘admin_print_styles’, ‘print_emoji_styles’);
remove_action( ‘wp_head’, ‘print_emoji_detection_script’, 7);
remove_action( ‘wp_print_styles’, ‘print_emoji_styles’);
remove_filter( ‘the_content_feed’, ‘wp_staticize_emoji’);
remove_filter( ‘comment_text_rss’, ‘wp_staticize_emoji’);
remove_filter( ‘wp_mail’, ‘wp_staticize_emoji_for_email’);
实现部分内容评论后可见
/实现部分内容评论后可见
function reply_to_read($atts, $content=null) {
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "hnkady@126.com"; //博主 Email
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if ($wpdb->get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');
压测及磁盘快照 镜像
app-wd5.2-php7-mariadb10.1-verynginx-ok_hotday-ok_book-ls1
app-wd5.2-php7-mariadb10.1-verynginx-ok_hotday-ok_book-ls
http_load -p 120 -s 280 /usr/bin/url >> http_load.log
cpu 70% mem 70% network25M load 6 ;id 10