修复已弃用:Get_the_Author_Lastname

时间:2021-03-26 作者:antonnb

我有一个只有一个php代码的插件

<?php
/*
Plugin Name: COinS Metadata Exposer
Plugin URI: http://www.zotero.org
Description: Makes your blog readable by Zotero and other COinS interpreters.
Version: 0.5
Author: Sean Takats - Center for History and New Media
Author URI: http://chnm.gmu.edu

Copyright 2007 Sean Takats (email: [email protected])

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

add_filter(\'the_content\', \'coinsify_the_content\');

function coinsify_the_content($content)
{
    foreach((get_the_category()) as $cat) {
        $cats = $cats . "&amp;rft.subject=" . urlencode($cat->cat_name);
    } ?>
    
    <span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;rft.title=<?php echo(urlencode(get_the_title())); ?>&amp;rft.aulast=<?php echo(urlencode(get_the_author_lastname())); ?>&amp;rft.aufirst=<?php echo(urlencode(get_the_author_firstname())); echo $cats; ?>&amp;rft.source=<?php echo(urlencode(get_bloginfo(\'name\'))); ?>&amp;rft.date=<?php the_time(\'Y-m-d\'); ?>&amp;rft.type=blogPost&amp;rft.format=text&amp;rft.identifier=<?php the_permalink(); ?>&amp;rft.language=English"></span>
<?php 
    return $content;
}
?>
但是插件导致以下代码错误

<br /> Deprecated: get_the_author_lastname started <strong> deprecated </strong> since version 2.8.0! 
Use get_the_author_meta (\'last_name\'). in /home/dgrou/wp-includes/functions.php on line 4861 <br /> 
Mike, <br /> Deprecated: get_the_author_firstname started <strong> deprecated </strong> since version 
2.8.0! Use get_the_author_meta (\'first_name\'). in /home/dgrou//wp-includes/functions.php on line 4861 
<br /> 
有人能帮我替换不推荐使用的代码吗?或者完整的固定代码就好了

非常感谢。

1 个回复
最合适的回答,由SO网友:Sally CJ 整理而成

注意:我并不是简单地给您完整的固定代码,而是您需要进行更改的那一行<span class="Z3988" ...>.

所以是的,两者都有get_the_author_firstname()get_the_author_lastname() 如错误中所述,您应该使用get_the_author_meta().

coinsify_the_content() 函数,只需查找和:

更换get_the_author_firstname() 具有get_the_author_meta( \'first_name\' ).

更换get_the_author_lastname() 具有get_the_author_meta( \'last_name\' ).