WordPress作者存档链接中管理员会直接显示用户名存在安全隐患。一个不错的解决方法是将WordPress作者存档链接中的用户名改为ID,方法如下。
代码
//在functions.php中加入以下代码:
//作者存档链接中的用户名改为ID- add_filter( ‘author_link’, ‘lxtx_yundanran_author_link’, 10, 2 );
- function lxtx_yundanran_author_link( $link, $author_id) {
- global $wp_rewrite;
- $author_id = (int) $author_id;
- $link = $wp_rewrite->get_author_permastruct();
- if ( emptyempty($link) ) {
- $file = home_url( ‘/’ );
- $link = $file . ‘?author=’ . $author_id;
- } else {
- $link = str_replace(‘%author%’, $author_id, $link);
- $link = home_url( user_trailingslashit( $link ) );
- }
- return $link;
- }
- add_filter( ‘request’, ‘lxtx_yundanran_author_link_request’ );
- function lxtx_yundanran_author_link_request( $query_vars ) {
- if ( array_key_exists( ‘author_name’, $query_vars ) ) {
- global $wpdb;
- $author_id=$query_vars[‘author_name’];
- if ( $author_id ) {
- $query_vars[‘author’] = $author_id;
- unset( $query_vars[‘author_name’] );
- }
- }
- return $query_vars;
- }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系贝贝进行处理。本站默认解压密码:www.hibbba.com


评论(0)