
很多朋友都在问,如果把WordPress作者存档链接中的用户名改成用户ID,好吧,一起来看看前端博客的方法吧。
作者存档页面链接是什么?
wordpress中的所有注册用WordPress教程户都有一个专属链接,称为作者存档页面链接,网站制作通常如下:
- //url重写
- http://qianduanblog.com/author=1
- //url重写
- http://qianduanblog.com/author/admin
没有url重写的参数网站制作软件值是用户id,而url重写,而url重写后的参数值是用户名。一般情况下,我们都使用url重写,而作者存档页面链接暴露了用户名,可能会对wordpress的安全性有点倾斜(而作wordpress教程菜鸟教程者的想法是,作者的参数值统一为用户id,例如:author/123,用户页面链接的参数值统一为用户id,例如:user/123,关于用户页面链接比作者存档页面链接复杂,后续文章再说),因此我们需要修改参数网站制作步骤流程图值为用户id。
修改作者存档页面链接
首先要做的是修改存档页面链接,
- //修改前
- http://qianduanblog.com/author/admin
- //修改后网站制作哪个好一些
- httwordpressp://qianduwordpress主题anblog.com/author网站制作哪个好一些/123
在wordpres网站制作品牌有哪些s中内置关于作者存档页面链接的钩子。原始作者存档页面链接是这样获得的:
- /**
- &nwordpressbsp; *Retr网站制作步骤流程图ie网站制作的相关介绍ve-the-the-twordpress官网入口he-the-author-page-the-use-with-the-wordpressid-provided。wordpress是什么意思
- *
- [email ;protected]
- [email ;protected]$wp_rewritewp_Rewrite
- [email ;protected]’;shpage网站制作流程图
- */
- function get_authowordpress是什么意思r_posts_url($author_id,$author_nicename=”){
- globall$wp_rewrit;
- $auth_ID =(int)$author_id网站制作步骤流程图;
- $link=$wp_rewritwordpress主题->;get_author_permaswordpress教程菜鸟教程truct();
- if(WordPress教程emptyempty($link)){
- $file =homewordpress建站详细过程_url(h‘;/’;
- $link=$file wordpress是什么意思 .#8216;wordpress插件author=’;$auth_ID;
- }else{
- if(”==$author_nicename){
- $user =get_userdata($author_id);
- if(!emptyempty($user->;user_niWordPress教程cenamwordpress模板e)
- $author网站制作流程图_ni网站制作软件cename=$user->;user_nicename;
- }
- $link=str_replace(‘;%author%WordPress教程217;$author_nicename,$link);
- $li网站制作软件制作效果nk =home_url(user_traiwordpress教程菜鸟教程lingslashit($link));
- }
- $link网站制作软件 &wordpress官网入口nbsp; wordpress建站详细过程=apply_filters(‘;author_link’;$link,$autwordpress插件hor_id,$author_nicename);
- return$link;
- }
参考源文档,生成用户id的作者存档页面链接:
- /**
- *修改url重写后作者存档页网站制作公司哪家好面的链接变量
- [email ;protected]
- *2013年10月8日23:23:49
- */
- add_filter(*‘;author_网站制作教程link’;,*‘;ywordpressundanran_authorwordpress是什么意思_link’;,*1网站制作流程与发布0,*2);
- function yundanran_author_lin网站制作步骤流程图k($link,$author_id){
- globall$wpwordpress插件_rewrit;
- $auth网站制作or_id =(int)$author_id;
- $link=$wp_rewrit->;get_author_permastruct网站制作哪个好一些();
- if(emptyempty($link)){
- $file =home_url(h‘;/’;
- $link=$file .#8216;author=网站制作&#WordPress教程8217;$author_id;
- }elwordpress手机版下载se{
- $link=str_replace(&#网站制作步骤流程图8216;%author%’;$author_id,$link);
- $link =home_url(user_trailingslashit($lin网站制作软件制作效果k)wordpress教程菜鸟教程);
- }
- return$link;
- }
修改后,在前台输出作者存档页面的链接:
- get_author_posts_url(1);
- //*wordpress教程菜鸟教程=>;http://qiandua网站制作软件nblog.cwordpress插件om/author/1
说明钩子是正确使用的,但是当我们打开这个链接的时候,出现了404。这是因为原作者存档页面网站制作品牌有哪些链接的url重写规则是基于用户名,现在修改为用户id,重写规则不匹配,出现了404。
修改作者存档页面查询变量
为避免出现404,我们需要修改作者存档页面的url重写规则。
- /**
- *替换作者存档页面的用户名,防止其他用途
- *作者存档页面链接有两个查询变量。
- *一个是author(作者用户id),用于未重写url
- *另一个是author_name(作者用户名),用于url重写
- *这里做的是在url重写后,用author_name代替autwordpress教程菜鸟教程hor
- [email ;protected]
- [email ;protected]
- *2013年10月8日23:19:13
- [email ;protected]://www.xhswordpressay.com/use-nickname-for-author-slug.htm网站制作步骤流程图l
- */
- add_filter(*‘;request’;,*‘;yundanrWordPress教程an_author_link_request’wordpress是什么意思;
- function &网站制作流程与发布nbsp; yundanran_author_link_request($query_varss){
- if(array_key_exists(#8216;author_name’;$query_varss)){
- gwordpressloball$wpdb;
- $author_id=$query_varss[‘;author_name’;]
- if($author_id){
- $query_网站制作的相关介绍varss[‘;author’;]$author_id;
-  wordpress插件; &网站制作教程nbsp; &nbwordpress是什么意思sp; &nwordpress教程菜鸟教程bsp; &nwordpress狮子歌歌bsp; wordpress官网入口  wordpress狮子歌歌;unset($query_varss[‘;author_name’;]
- }
- }
- return$query_varss;
- }
巧合的是,作者存档页面有两个查询变量,wordpress是什么意思前wordpress狮子歌歌面说过,一个是url未重写的用户id(author
另一个是url重写的用户名(author_name
),现在用户id直接传输,只需要参数名称author_name
修改为author
即可。
再次打开刚才的链接(http://qianduanblog.com/author/1),出现正确的页面。如果打开原始链接(http://qianduanblwordpressogwordpress教程菜鸟教程.com/author/admin),就会出现4wordpress模板04页,说明我们的修改是正确的。
请登录后发表评论
注册
社交帐号登录