WordPress作者存档链接中管理员会直接显示用户名存在安全隐患。一个不错的解决方法是将WordPress作者存档链接中的用户名改为ID,方法如下。

代码


  1. //在functions.php中加入以下代码:
    //作者存档链接中的用户名改为ID 
  2. add_filter( ‘author_link’, ‘lxtx_yundanran_author_link’, 10, 2 );
  3. function lxtx_yundanran_author_link( $link$author_id) {
  4.     global $wp_rewrite;
  5.     $author_id = (int) $author_id;
  6.     $link = $wp_rewrite->get_author_permastruct();
  7.     if ( emptyempty($link) ) {
  8.         $file = home_url( ‘/’ );
  9.         $link = $file . ‘?author=’ . $author_id;
  10.     } else {
  11.         $link = str_replace(‘%author%’, $author_id$link);
  12.         $link = home_url( user_trailingslashit( $link ) );
  13.     }
  14.     return $link;
  15. }
  16. add_filter( ‘request’, ‘lxtx_yundanran_author_link_request’ );
  17. function lxtx_yundanran_author_link_request( $query_vars ) {
  18.     if ( array_key_exists( ‘author_name’, $query_vars ) ) {
  19.         global $wpdb;
  20.         $author_id=$query_vars[‘author_name’];
  21.         if ( $author_id ) {
  22.             $query_vars[‘author’] = $author_id;
  23.             unset( $query_vars[‘author_name’] );
  24.         }
  25.     }
  26.     return $query_vars;
  27. }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系贝贝进行处理。
本站默认解压密码:www.hibbba.com