gpt4 book ai didi

php - Wordpress 主题错误 "Fatal error: Cannot re-assign auto-global variable _POST"

转载 作者:行者123 更新时间:2023-12-04 14:30:57 25 4
gpt4 key购买 nike

这个主题有错误, http://www.mafiashare.net/download/sound-rock-music-band-wordpress-theme/当我尝试激活它时,出现了

( ! ) 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 中,我删除了这段代码,然后主题就可以工作了,但我想知道为什么它会抛出错误?

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 或您喜欢的任何其他名称

原因,如其他答案所写:

You cannot use $_POST as a function / method argument

.这样做会尝试重新分配符号表中的变量。将此视为语言的保存关键字。将它放在函数签名中就像使用语言的关键字作为变量名来定义新变量。

关于php - Wordpress 主题错误 "Fatal error: Cannot re-assign auto-global variable _POST",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com