Collabpress中出现意外的T_STRING错误

时间:2014-09-14 11:47:34

标签: php wordpress wordpress-plugin

我正在尝试为WordPress调试Collabpress插件。我对PHP的了解非常基础。

错误出现在一个名为cp-loader.php的php文件中。第88行的错误是意外的T_STRING,在下面突出显示。代码如下:

<?php
/*
Plugin Name: CollabPress
Plugin URI: http://collabpress.org/
Description: A Project Management Plugin for WordPress
Version: 1.3.1.2
Author: WebDevStudios.com
Author URI: http://webdevstudios.com/
License: GPLv2
*/

/*  Copyright 2011  WebDevStudios  (email : contact@webdevstudios.com)

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

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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

// CollabPress Define(s)
define( 'CP_VERSION', '1.3.1.2' );

if ( ! defined( 'CP_BASENAME' ) ) {
define( 'CP_BASENAME', plugin_basename(__FILE__) );
}

if ( ! defined( 'CP_PLUGIN_DIR' ) ) {
define( 'CP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}

if ( ! defined( 'CP_PLUGIN_URL' ) ) {
define( 'CP_PLUGIN_URL', plugins_url( substr( CP_BASENAME, 0, strpos( CP_BASENAME, '/' ) ) ) .           '/' );
}

define( 'CP_RSS_URL', 'http://collabpress.org/feed' );

// Before CollabPress
do_action( 'cp_before_collabpress' );

//front-end querystring support
$cp_qs_add = cp_frontend_querystrings();

// Define the dashboard link
$cp_dashboard = ( is_admin() ) ? 'admin.php?page=collabpress-dashboard' : '?' .$cp_qs_add.         'cp=front';

// If we're processing an AJAX request,
// set the dashboard link according to the origin of the request
if ( ! empty( $_REQUEST['data']['collabpress_ajax_request_origin'] ) ) {
$cp_dashboard = ( $_REQUEST['data']['collabpress_ajax_request_origin'] == 'admin' ) ? 'admin.php?        page=collabpress-dashboard' : '?' .$cp_qs_add. 'cp=front';
}

define( 'CP_DASHBOARD', $cp_dashboard );

// CollabPress Core
require_once( 'includes/cp-core.php' );

 // activation hook
 register_activation_hook( __FILE__, 'cp_activation' );


/**
* Returns the query string of CollabPress values
* e.g. task=3&task-list=4
*/
function cp_frontend_querystrings() {

// grab any query strings that exist
if (isset($_SERVER['QUERY_STRING'])) {
$cp_all_querystrings = ( $_SERVER["QUERY_STRING"] ) ? $_SERVER["QUERY_STRING"] : '';
$cp_querystrings = explode( '&', $cp_all_querystrings );
} else {
$vars = $_GET;
}

//set pattern to strip out
$pattern = "/^cp|project|task-list|task|view|activity_page/";
$cp_qs_add = '';

foreach ((array) ( '$cp_querystrings as $cp_querystring') 
     -->    preg_match ( '$pattern, $cp_querystring ' ) {  <-- line 88: unexpected T_STRING error
        $cp_qs_add .= $cp_querystring .'&';
    }
}

if ( $cp_qs_add != '&' ) :
    return $cp_qs_add;
endif;

}

我用上面的箭头突出显示了错误。第88行出现意外错误&#34;意外T_STRING错误&#34;。

我能得到的任何帮助都会很棒。由于这是Github上的一个开源项目,如果有效,我也会在Github上发布一些内容。

1 个答案:

答案 0 :(得分:0)

典型的foreach循环如下所示: foreach($some_array as $item)其中$ some_array是一个数组。 Foreach迭代数组中包含的每个项目。

但在您的代码中,您使用的是String。通过文本'$cp_querystrings as $cp_querystring'周围的引号可见。这是代码中的主要错误。 要解决此错误,您尝试将String转换为数组。这满足了Foreach循环的需求。但不幸的是,PHP对转换类型非常慷慨,所以真正的原因没有显示在您的错误消息中。

preg_match ( '$pattern, $cp_querystring ' )几乎相同的问题。

'$pattern, $cp_querystring '是一个字符串,因此preg_match只有一个参数。

下一个问题是preg_match缺少if子句。

我将解决方案纳入此修复程序:

foreach ($cp_querystrings as $cp_querystring) { if( preg_match ($pattern, $cp_querystring) > 0 ) { $cp_qs_add .= $cp_querystring .'&'; } }

您拥有的代码总体上已损坏,无法在任何PHP安装上运行。也许你已经收到了一个正在进行主动开发的版本?