我在插件的PHP上声明一个函数。插件在每个帖子的顶部加载代码(帖子布局是插件的名称)。
无法在/home/content/08/10290908/html/wp-content/plugins/post-layout/plugin.php(181):eval()\'d code:4)中重新声明vote\\u-up()(之前在/home/content/08/102908/html/wp-content/plugins/post-layout/plugin.php中声明)。php(181):第36行的eval()\'d代码
这是显示的错误消息,不是因为函数已经在函数中声明了。php(我知道,因为我通过将其重命名为各种名称对其进行了测试)它说它已经在我用来加载代码的插件中声明了。
代码如下:
<?php
function vote_up(){
if($post_vote == "9"){
}
elseif($post_vote == "8"){
update_post_meta( get_the_ID(), \'post_vote\', \'9\', \'8\');
}
elseif($post_vote == "7"){
update_post_meta( get_the_ID(), \'post_vote\', \'8\', \'7\');
}
elseif($post_vote == "6"){
update_post_meta( get_the_ID(), \'post_vote\', \'7\', \'6\');
}
elseif($post_vote == "5"){
update_post_meta( get_the_ID(), \'post_vote\', \'6\', \'5\');
}
elseif($post_vote == "4"){
update_post_meta( get_the_ID(), \'post_vote\', \'5\', \'4\');
}
elseif($post_vote == "3"){
update_post_meta( get_the_ID(), \'post_vote\', \'4\', \'3\');
}
elseif($post_vote == "2"){
update_post_meta( get_the_ID(), \'post_vote\', \'3\', \'2\');
}
elseif($post_vote == "1"){
update_post_meta( get_the_ID(), \'post_vote\', \'2\', \'1\');
}
elseif($post_vote == "0"){
update_post_meta( get_the_ID(), \'post_vote\', \'1\', \'0\');
}
else{//do nothing
};
}
//if the post is pending show
if(get_post_status() == \'pending\') {
//if the user is logged in show
if ( is_user_logged_in() ) {
add_post_meta( get_the_ID(), \'post_vote\', \'0\', true );
$post_vote = get_post_meta( get_the_ID(), \'post_vote\', true );
echo \'Votes: \' . $post_vote;
echo \' <form action="xxx" method="post" onclick="return vote_up()">\';
echo \' <input type="button" value="Vote Up" />\';
echo \'</form>\';
} else {
echo\'Please Sign in to Vote\';
}
} else {
// do nothing
}
?>
上面的代码基本上是在尝试这样做,当您单击按钮时,投票meta\\u键将上升1。这是为了投票,所以一旦有10个用户投票,它就会发布。
这个愚蠢的纽扣真是麻烦事,我不能继续下去,直到我把它修好了,甚至还想付钱给人修纽扣,但他一点线索都没有