';
- // 正文转换
- $bilismiliestrans['{{' . $name[$i] . '}}'] = '
';
}
return $return_smiles;
}
push_bili_smilies();
-function bili_smile_filter($content) {
+function bili_smile_filter($content)
+{
global $bilismiliestrans;
- $content = str_replace(array_keys($bilismiliestrans), $bilismiliestrans, $content);
+ $content = str_replace(array_keys($bilismiliestrans), $bilismiliestrans, $content);
return $content;
}
add_filter('the_content', 'bili_smile_filter'); //替换文章关键词
-add_filter( 'comment_text', 'bili_smile_filter' );//替换评论关键词
+add_filter('comment_text', 'bili_smile_filter'); //替换评论关键词
-function featuredtoRSS($content) {
+function featuredtoRSS($content)
+{
global $post;
- if ( has_post_thumbnail( $post->ID ) ){
- $content = '
' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 15px;' ) ) . '
' . $content;
+ if (has_post_thumbnail($post->ID)) {
+ $content = '
' . get_the_post_thumbnail($post->ID, 'medium', array('style' => 'margin-bottom: 15px;')) . '
' . $content;
}
return $content;
}
@@ -1168,19 +1243,21 @@ add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
//
-function bili_smile_filter_rss($content) {
- $content = str_replace("{{",'
',$content);
- $content = str_replace('[img]', '
', $content);
+function bili_smile_filter_rss($content)
+{
+ $content = str_replace("{{", '
', $content);
+ $content = str_replace('[img]', '
', $content);
return $content;
}
-add_filter( 'comment_text_rss', 'bili_smile_filter_rss' );//替换评论rss关键词
+add_filter('comment_text_rss', 'bili_smile_filter_rss'); //替换评论rss关键词
-function toc_support($content) {
- $content = str_replace('[toc]', '
', $content); // TOC 支持
- $content = str_replace('[begin]', '
', $content); // 首字格式支持
- $content = str_replace('[/begin]', '', $content); // 首字格式支持
+function toc_support($content)
+{
+ $content = str_replace('[toc]', '
', $content); // TOC 支持
+ $content = str_replace('[begin]', '
', $content); // 首字格式支持
+ $content = str_replace('[/begin]', '', $content); // 首字格式支持
return $content;
}
add_filter('the_content', 'toc_support');
@@ -1188,44 +1265,47 @@ add_filter('the_excerpt_rss', 'toc_support');
add_filter('the_content_feed', 'toc_support');
// 显示访客当前 IP
-function get_the_user_ip() {
-if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
+function get_the_user_ip()
+{
+ if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//check ip from share internet
-$ip = $_SERVER['HTTP_CLIENT_IP'];
-} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
+ } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//to check ip is pass from proxy
-$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
-} else {
-$ip = $_SERVER['REMOTE_ADDR'];
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ } else {
+ $ip = $_SERVER['REMOTE_ADDR'];
+ }
+ return apply_filters('wpb_get_ip', $ip);
}
-return apply_filters( 'wpb_get_ip', $ip );
-}
-
+
add_shortcode('show_ip', 'get_the_user_ip');
-
/*歌词*/
-function hero_get_lyric() {
- /** These are the lyrics to Hero */
- $lyrics = "";
+function hero_get_lyric()
+{
+ /** These are the lyrics to Hero */
+ $lyrics = "";
- // Here we split it into lines
- $lyrics = explode( "\n", $lyrics );
+ // Here we split it into lines
+ $lyrics = explode("\n", $lyrics);
- // And then randomly choose a line
- return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
+ // And then randomly choose a line
+ return wptexturize($lyrics[mt_rand(0, count($lyrics) - 1)]);
}
// This just echoes the chosen line, we'll position it later
-function hello_hero() {
- $chosen = hero_get_lyric();
- echo $chosen;
+function hello_hero()
+{
+ $chosen = hero_get_lyric();
+ echo $chosen;
}
/*私密评论*/
add_action('wp_ajax_nopriv_siren_private', 'siren_private');
add_action('wp_ajax_siren_private', 'siren_private');
-function siren_private(){
+function siren_private()
+{
$comment_id = $_POST["p_id"];
$action = $_POST["p_action"];
if ($action == 'set_private') {
@@ -1241,31 +1321,42 @@ function siren_private(){
}
//时间序列
-function memory_archives_list() {
- if( true ){
- $output = '
['.__( "All expand/collapse", "sakura" )/*全部展开/收缩*/.']
';
- $the_query = new WP_Query( 'posts_per_page=-1&ignore_sticky_posts=1&post_type=post' ); //update: 加上忽略置顶文章
- $year=0; $mon=0; $i=0; $j=0;
- while ( $the_query->have_posts() ) : $the_query->the_post();
- $year_tmp = get_the_time('Y');
+function memory_archives_list()
+{
+ if (true) {
+ $output = '
[' . __("All expand/collapse", "sakura") /*全部展开/收缩*/ . ']
';
+ $the_query = new WP_Query('posts_per_page=-1&ignore_sticky_posts=1&post_type=post'); //update: 加上忽略置顶文章
+ $year = 0;
+ $mon = 0;
+ $i = 0;
+ $j = 0;
+ while ($the_query->have_posts()): $the_query->the_post();
+ $year_tmp = get_the_time('Y');
$mon_tmp = get_the_time('m');
- $y=$year; $m=$mon;
- if ($mon != $mon_tmp && $mon > 0) $output .= '';
- if ($year != $year_tmp && $year > 0) $output .= '';
+ $y = $year;
+ $m = $mon;
+ if ($mon != $mon_tmp && $mon > 0) {
+ $output .= '';
+ }
+
+ if ($year != $year_tmp && $year > 0) {
+ $output .= '';
+ }
+
if ($year != $year_tmp) {
$year = $year_tmp;
- $output .= '
'. $year . __(" ","year","sakura"). /*年*/'
'; //输出年份
+ $output .= '' . $year . __(" ", "year", "sakura") . /*年*/'
'; //输出年份
}
if ($mon != $mon_tmp) {
$mon = $mon_tmp;
- $output .= '- '.get_the_time('M').' ('.__(" post(s)","sakura") /*篇文章*/.')
'; //输出月份
+ $output .= '- ' . get_the_time('M') . ' (' . __(" post(s)", "sakura") /*篇文章*/ . ')
';
#update_option('memory_archives_list', $output);
- }
+ }
echo $output;
}
@@ -1273,27 +1364,28 @@ function memory_archives_list() {
* 隐藏 Dashboard
*/
/* Remove the "Dashboard" from the admin menu for non-admin users */
-function remove_dashboard () {
+function remove_dashboard()
+{
global $current_user, $menu, $submenu;
wp_get_current_user();
- if( ! in_array( 'administrator', $current_user->roles ) ) {
- reset( $menu );
- $page = key( $menu );
- while( ( __( 'Dashboard' ) != $menu[$page][0] ) && next( $menu ) ) {
- $page = key( $menu );
+ if (!in_array('administrator', $current_user->roles)) {
+ reset($menu);
+ $page = key($menu);
+ while ((__('Dashboard') != $menu[$page][0]) && next($menu)) {
+ $page = key($menu);
}
- if( __( 'Dashboard' ) == $menu[$page][0] ) {
- unset( $menu[$page] );
+ if (__('Dashboard') == $menu[$page][0]) {
+ unset($menu[$page]);
}
reset($menu);
$page = key($menu);
- while ( ! $current_user->has_cap( $menu[$page][1] ) && next( $menu ) ) {
- $page = key( $menu );
+ while (!$current_user->has_cap($menu[$page][1]) && next($menu)) {
+ $page = key($menu);
}
- if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI'] ) &&
- ( 'index.php' != $menu[$page][2] ) ) {
- wp_redirect( get_option( 'siteurl' ) . '/wp-admin/profile.php');
+ if (preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) &&
+ ('index.php' != $menu[$page][2])) {
+ wp_redirect(get_option('siteurl') . '/wp-admin/profile.php');
}
}
}
@@ -1306,31 +1398,33 @@ add_action('admin_menu', 'remove_dashboard');
* @return int (Maybe) modified excerpt length.
*/
-function GBsubstr($string, $start, $length) {
+function GBsubstr($string, $start, $length)
+{
if (strlen($string) > $length) {
$str = null;
$len = 0;
$i = $start;
- while ( $len < $length) {
- if (ord(substr($string, $i, 1)) > 0xc0) {
- $str .=substr($string, $i, 3);
- $i+= 3;
- }elseif (ord(substr($string, $i, 1)) > 0xa0) {
- $str .= substr($string, $i, 2);
- $i+= 2;
- }else {
- $str.=substr($string, $i, 1);
- $i++;
- }
- $len ++;
+ while ($len < $length) {
+ if (ord(substr($string, $i, 1)) > 0xc0) {
+ $str .= substr($string, $i, 3);
+ $i += 3;
+ } elseif (ord(substr($string, $i, 1)) > 0xa0) {
+ $str .= substr($string, $i, 2);
+ $i += 2;
+ } else {
+ $str .= substr($string, $i, 1);
+ $i++;
+ }
+ $len++;
}
return $str;
- }else {
+ } else {
return $string;
}
}
-
-function excerpt_length($exp) {
+
+function excerpt_length($exp)
+{
if (!function_exists('mb_substr')) {
$exp = GBsubstr($exp, 0, 80);
} else {
@@ -1339,39 +1433,40 @@ function excerpt_length($exp) {
*/
$exp = mb_substr($exp, 0, 80);
}
- return $exp;
+ return $exp;
}
-add_filter( 'the_excerpt', 'excerpt_length' );
-
+add_filter('the_excerpt', 'excerpt_length');
/*
* 后台路径
*/
/*
add_filter('site_url', 'wpadmin_filter', 10, 3);
- function wpadmin_filter( $url, $path, $orig_scheme ) {
- $old = array( "/(wp-admin)/");
- $admin_dir = WP_ADMIN_DIR;
- $new = array($admin_dir);
- return preg_replace( $old, $new, $url, 1);
- }
-*/
+function wpadmin_filter( $url, $path, $orig_scheme ) {
+$old = array( "/(wp-admin)/");
+$admin_dir = WP_ADMIN_DIR;
+$new = array($admin_dir);
+return preg_replace( $old, $new, $url, 1);
+}
+ */
-function admin_ini() {
- wp_enqueue_style('admin-styles-fix-icon', get_site_url() . '/wp-includes/css/dashicons.css');
- wp_enqueue_style('cus-styles-fit', get_template_directory_uri() . '/inc/css/dashboard-fix.css');
- wp_enqueue_script( 'lazyload', 'https://cdn.jsdelivr.net/npm/lazyload@2.0.0-beta.2/lazyload.min.js' );
+function admin_ini()
+{
+ wp_enqueue_style('admin-styles-fix-icon', get_site_url() . '/wp-includes/css/dashicons.css');
+ wp_enqueue_style('cus-styles-fit', get_template_directory_uri() . '/inc/css/dashboard-fix.css');
+ wp_enqueue_script('lazyload', 'https://cdn.jsdelivr.net/npm/lazyload@2.0.0-beta.2/lazyload.min.js');
}
add_action('admin_enqueue_scripts', 'admin_ini');
-function custom_admin_js() {
+function custom_admin_js()
+{
echo '