Wordpress 主题错误“致命错误:无法重新分配自动全局变量 _POST" [英] Wordpress theme Error "Fatal error: Cannot re-assign auto-global variable _POST"
问题描述
这个主题有错误,http://www.mafiashare.net/download/sound-摇滚音乐乐队wordpress主题/当我尝试激活它时,它出现
there's a error in this theme, http://www.mafiashare.net/download/sound-rock-music-band-wordpress-theme/ when I try to activate it, this show up
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Cannot re-assign auto-global variable _POST in C:\wamp\www\web\wp-content\themes\soundrock\functions.php on line 48
Call Stack
# Time Memory Function Location
1 0.0014 364560 {main}( ) ..\themes.php:0
2 0.0043 433520 require_once( 'C:\wamp\www\web\wp-admin\admin.php' ) ..\themes.php:10
3 0.0048 451648 require_once( 'C:\wamp\www\web\wp-load.php' ) ..\admin.php:30
4 0.0052 463256 require_once( 'C:\wamp\www\web\wp-config.php' ) ..\wp-load.php:29
5 0.0061 553312 require_once( 'C:\wamp\www\web\wp-settings.php' ) ..\wp-config.php:90
所以在第 48 行的functions.php 中,我删除了这段代码,然后主题就可以工作了,但是我想知道为什么它会抛出错误?
so in functions.php on line 48, I removed this code, then the theme is working, but I want to why it's throwing an error?
function events_meta_save($_POST, $post_id) {
global $wpdb;
if ( empty($_POST["event_social_sharing"]) ) $_POST["event_social_sharing"] = "";
if ( empty($_POST["event_start_time"]) ) $_POST["event_start_time"] = "";
if ( empty($_POST["event_end_time"]) ) $_POST["event_end_time"] = "";
if ( empty($_POST["event_all_day"]) ) $_POST["event_all_day"] = "";
if ( empty($_POST["event_booking_url"]) ) $_POST["event_booking_url"] = "";
if ( empty($_POST["event_address"]) ) $_POST["event_address"] = "";
$sxe = new SimpleXMLElement("<event></event>");
$sxe->addChild('event_social_sharing', $_POST["event_social_sharing"] );
$sxe->addChild('event_start_time', $_POST["event_start_time"] );
$sxe->addChild('event_end_time', $_POST["event_end_time"] );
$sxe->addChild('event_all_day', $_POST["event_all_day"] );
$sxe->addChild('event_booking_url', $_POST["event_booking_url"] );
$sxe->addChild('event_address', $_POST["event_address"] );
$sxe = save_layout_xml($sxe);
update_post_meta( $post_id, 'cs_event_meta', $sxe->asXML() );
}
推荐答案
替换
function events_meta_save($_POST, $post_id) {
global $wpdb;
if ( empty($_POST["event_social_sharing"]) ) $_POST["event_social_sharing"] = "";
....
....
与
function events_meta_save($_my_post, $post_id) {
global $wpdb;
if ( empty($_my_post["event_social_sharing"]) ) $_POST["event_social_sharing"] = "";
....
....
不要忘记将条件内的所有 $_POST
替换为 $_my_post
或您喜欢的任何其他名称
Do not forget to replace ALL $_POST
inside the condition with $_my_post
or any other name u like
原因,如其他答案所写:
Reason, as written in other answers:
您不能将 $_POST 用作函数/方法参数
You cannot use $_POST as a function / method argument
.这样做会尝试重新分配符号表中的变量.将此视为该语言的已保存关键字.把它放在函数签名中就像使用语言的关键字作为变量名定义一个新的变量.
. Doing so attempts to re-assign the variable in the symbol table. Regard this as a saved keyword of the language. Putting it in a function signature is like defining new variable using a keyword of the language as the variable name.
这篇关于Wordpress 主题错误“致命错误:无法重新分配自动全局变量 _POST"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!