简体   繁体   English

Wordpress插件PHP解析错误:语法错误,意外的“ {”,预期为“)”

[英]Wordpress plugin PHP Parse error: syntax error, unexpected '{', expecting ')'

I'm doing some work on a Wordpress site built by someone else. 我正在其他人建立的Wordpress网站上做一些工作。 They produced a custom plugin but are no longer with the company. 他们制作了一个自定义插件,但不再与公司合作。 The plugin loads on the live site but won't load on the test server and therefore it's very hard to work on the changes. 该插件会在实时站点上加载,但不会在测试服务器上加载,因此很难进行更改。

Loading the plugin on the test server gives the error: 在测试服务器上加载插件会出现错误:

Parse error: syntax error, unexpected '{', expecting ')' in wp-content/plugins/uni-todays-program/todays-program.php on line 221

Line 221 is: 221行是:

 $query = new WP_Query( [

The surrounding code is: 周围的代码是:

// [today]
function today_func( $atts ) {

    // Retrieve current days schedule
    $today = getdate();
    $query = new WP_Query( [
      'post_type' => 'day_entry',
      'year' => $today["year"], 
      'monthnum' => $today["mon"], 
      'day' => $today["mday"] , 
      'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash')
    ]  );
    $day_type = $query->post->day_type;
    $query = new WP_Query( ['post_type' => 'day_type','name' => $day_type] );
    return $query->post->post_content;

}
add_shortcode( 'today', 'today_func' );

I'm just a frontend guy, so I my php is very limited but I can't see the issue. 我只是一个前端人员,所以我的PHP非常有限,但看不到问题。 There isn't an opening ( that needs closing. 没有开口(需要关闭。

I did Google it and found something that suggested it was the php version but I've since had that changed so the live and test server are both 5.4. 我用Google做它,发现一些东西暗示它是php版本,但此后我做了更改,因此实时服务器和测试服务器均为5.4。

Can anyone steer me in the right direction? 谁能引导我正确的方向?

[] is the short syntax for array declaration, it should work if the test server has php 5.4 or greater. []是数组声明的简短语法,如果测试服务器的PHP 5.4或更高版本,它应该可以工作。

If the problem persists for some reason try changing the code to this: 如果由于某种原因问题仍然存在,请尝试将代码更改为此:

// [today]
function today_func( $atts ) {

    // Retrieve current days schedule
    $today = getdate();
    $query = new WP_Query( array(
      'post_type' => 'day_entry',
      'year' => $today["year"], 
      'monthnum' => $today["mon"], 
      'day' => $today["mday"] , 
      'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash')
    )  );
    $day_type = $query->post->day_type;
    $query = new WP_Query( array('post_type' => 'day_type','name' => $day_type) );
    return $query->post->post_content;

}
add_shortcode( 'today', 'today_func' );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析错误:语法错误,意外的';',期望的是')'(Wordpress functions.php) - Parse error: syntax error, unexpected ';', expecting ')' (Wordpress functions.php) 解析错误:语法错误,意外的 '[',期待 ')' php - Parse error: syntax error, unexpected '[', expecting ')' php PHP解析错误:语法错误,意外的“:”,期待“;” 或者 '{' - PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' 解析错误:语法错误,意外的'}'在Wordpress插件激活php 5.5中 - Parse error: syntax error, unexpected '}' In Wordpress plugin activation php 5.5 解析错误:语法错误,意外的'[',期望')',可能是PHP版本问题 - Parse error: syntax error, unexpected '[', expecting ')', possibly PHP version issue PHP 版本 4:: 解析错误:语法错误,意外 '=',期待 ')' - PHP version 4 :: Parse error: syntax error, unexpected '=', expecting ')' PHP解析错误:语法错误,意外的T_IS_EQUAL,预期 - PHP Parse error: syntax error, unexpected T_IS_EQUAL, expecting 的PHP-语法错误,意外的'(',期待')' - php - syntax error, unexpected '(', expecting ')' 解析错误:语法错误,意外'(',期待','或';'in - Parse error: syntax error, unexpected '(', expecting ',' or ';' in 解析错误:语法错误,意外的'{',需要'('帮助? - Parse error: syntax error, unexpected '{', expecting '(' help?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM