//自动改图片名 function custom_upload_filter( $file ){ $info = pathinfo($file['name']); $ext = $info['extension']; $filedate = date('YmdHis').rand(10,99);//为了避免时间重复,再加一段2位的随机数 $file['name'] = $filedate.'.'.$ext; return $file; } add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' ); //开启编辑器--用这个 function bbp_enable_visual_editor( $args = array() ) { $args['tinymce'] = true; $args['quicktags'] = false; $args['teeny'] = false; return $args; } add_filter( 'bbp_after_get_the_content_parse_args', 'bbp_enable_visual_editor' ); //所有用户隐藏工具栏 add_filter( 'show_admin_bar', '__return_false' ); //禁止访问后台 add_action('init', 'qzl_redirect_wp_admin'); function qzl_redirect_wp_admin() { if (is_admin() && is_user_logged_in() && !current_user_can('manage_options') && (!defined('DOING_AJAX') || !DOING_AJAX)) { wp_safe_redirect(home_url()); exit; } } //bbPress 添加新话题帖子标签 function rk_new_topics() { $offset = 30*30*1; if ( get_post_time() > date('U') - $offset ) echo '<span class="label label-new"><font color="#088A29"><strong>[新帖]</strong></font></span>'; } add_action( 'bbp_theme_before_topic_title', 'rk_new_topics' ); //bbPress 添加置顶标签 function rk_sticky_topics() { if ( bbp_is_topic_sticky() && !bbp_is_topic_closed() ) echo '<span class="sticky"><font color="#FF6347"><strong>[置顶]</strong></font></span>'; } add_action( 'bbp_theme_before_topic_title', 'rk_sticky_topics' ); //bbPress 回复超过25个为显示热帖 function rk_hot_topics() { $reply_count = bbp_get_topic_reply_count(); if ( $reply_count > 25 ) echo '<span class="hot"><font color="#FF1493"><strong>[热贴]</strong></font></span>'; } add_action( 'bbp_theme_before_topic_title', 'rk_hot_topics' ); //删除IP function vvd_no_view_ip( $author_ip, $r, $args ){ return __return_empty_string(); } add_filter('bbp_get_author_ip','vvd_no_view_ip', 10, 3 ); //删除IP add_filter('bbp_get_author_ip', '__return_empty_string'); //登陆页跳转 function redirect_logged_user() { if(is_user_logged_in() && (empty($_GET['action']) || $_GET['action'] == 'login')) { wp_redirect('https://sexfollowers.com/membership-account/'); exit; } } add_action( 'login_init', 'redirect_logged_user' ); //禁用后台语言切换 add_filter( 'login_display_language_dropdown', '__return_false' ); //禁用灯箱更新 function remove_update_notifications( $value ) { if ( isset( $value ) && is_object( $value ) ) { unset( $value->response[ 'meow-lightbox-pro/meow-lightbox-pro.php' ] ); } return $value; } add_filter( 'site_transient_update_plugins', 'remove_update_notifications' ); //禁用xmlrpc add_filter('xmlrpc_enabled', '__return_false'); // 在文章内添加搜索功能 开始 function wpbsearchform( $form ) { $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" > <div> <input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="请输入你要搜索的关键词回车即可,限论坛以外内容。论坛搜索请使用论坛顶部搜索框。"/> </div> </form>'; echo "<style> #searchform{background:rgba(255,255,255,0);padding:10px 5px;width:100%;} #s{width:99%} </style>"; return $form; } add_shortcode('wpbsearch', 'wpbsearchform'); // 在文章内添加搜索功能 结束
原文链接:https://c.larjie.com/wordpress-functions-php/,转载请注明出处。