PHP包括Isn';t包括电子商务
简而言之,我让php向我证明文件存在并且可读,但是一旦命中include语句,脚本似乎就会停止运行 另外,您会注意到,在这个问题中,从后面的数据输出中,我使用的是绝对路径 我在解决此问题时尝试的一些值得注意的事情是:PHP包括Isn';t包括电子商务,php,wordpress,woocommerce,php-include,Php,Wordpress,Woocommerce,Php Include,简而言之,我让php向我证明文件存在并且可读,但是一旦命中include语句,脚本似乎就会停止运行 另外,您会注意到,在这个问题中,从后面的数据输出中,我使用的是绝对路径 我在解决此问题时尝试的一些值得注意的事情是: 将包含替换为需要和需要一次 用硬编码字符串替换$include var 使用require将硬编码字符串替换到无效位置 在每种情况下,都会发生相同的事情,除了include或require语句之外,不会执行任何脚本,也不会抛出任何错误 我正在研究一个Woocommerce(这可能是
/**
* Output the cart shortcode.
*/
public static function output() {
var_dump("Hello");
// Constants
if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
define( 'WOOCOMMERCE_CART', true );
}
var_dump("After Constants");
// Update Shipping
if ( ! empty( $_POST['calc_shipping'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-cart' ) ) {
self::calculate_shipping();
}
var_dump("After Shipping Calc");
// Check cart items are valid
do_action( 'woocommerce_check_cart_items' );
var_dump("After cart items check");
// Calc totals
WC()->cart->calculate_totals();
var_dump("After Calc Totals");
var_dump(WC()->cart->get_cart());
var_dump(sizeof( WC()->cart->get_cart() ));
if ( 0 === sizeof( WC()->cart->get_cart() ) ) {
var_dump("Size = 0 , Empty");
wc_get_template( 'cart/cart-empty.php' );
} else {
var_dump("Size != 0 , Not Empty");
wc_get_template( 'cart/cart.php' );
}
}
调用wc_get_template()函数:
/**
* Get other templates (e.g. product attributes) passing attributes and including the file.
*
* @access public
* @param string $template_name
* @param array $args (default: array())
* @param string $template_path (default: '')
* @param string $default_path (default: '')
* @return void
*/
function wc_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
var_dump("wc_get_template fired. Template name = " . $template_name);
if ( $args && is_array( $args ) ) {
extract( $args );
}
$located = wc_locate_template( $template_name, $template_path, $default_path );
var_dump($located);
if ( ! file_exists( $located ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
return;
}
var_dump(file_exists( $located ), "File exists");
var_dump(file_get_contents($located));
// Allow 3rd party plugin filter template file from their plugin
$located = apply_filters( 'wc_get_template', $located, $template_name, $args, $template_path, $default_path );
do_action( 'woocommerce_before_template_part', $template_name, $template_path, $located, $args );
var_dump("After do_action function");
include $located;
var_dump("After the file is included");
do_action( 'woocommerce_after_template_part', $template_name, $template_path, $located, $args );
}
输出:
string 'Hello' (length=5)
string 'After Constants' (length=15)
string 'After Shipping Calc' (length=19)
string 'After cart items check' (length=22)
string 'After Calc Totals' (length=17)
array (size=2)
'e82c4b19b8151ddc25d4d93baf7b908f' =>
array (size=10)
'product_id' => int 2468
'variation_id' => string '' (length=0)
'variation' =>
array (size=0)
empty
'quantity' => int 1
'line_total' => float 27.06
'line_tax' => float 5.412
'line_subtotal' => float 27.06
'line_subtotal_tax' => float 5.412
'line_tax_data' =>
array (size=2)
'total' =>
array (size=1)
...
'subtotal' =>
array (size=1)
...
'data' =>
object(WC_Product_Simple)[101]
public 'id' => int 2468
public 'post' =>
object(WP_Post)[103]
...
public 'product_type' => string 'simple' (length=6)
protected 'dimensions' => string '' (length=0)
protected 'shipping_class' => string '' (length=0)
protected 'shipping_class_id' => int 0
public 'price' => string '27.06' (length=5)
public 'manage_stock' => string 'no' (length=2)
public 'stock_status' => string 'instock' (length=7)
public 'tax_status' => string 'taxable' (length=7)
public 'virtual' => string 'no' (length=2)
'1843e35d41ccf6e63273495ba42df3c1' =>
array (size=10)
'product_id' => int 2463
'variation_id' => string '' (length=0)
'variation' =>
array (size=0)
empty
'quantity' => int 1
'line_total' => float 29.7
'line_tax' => float 5.94
'line_subtotal' => float 29.7
'line_subtotal_tax' => float 5.94
'line_tax_data' =>
array (size=2)
'total' =>
array (size=1)
...
'subtotal' =>
array (size=1)
...
'data' =>
object(WC_Product_Simple)[69]
public 'id' => int 2463
public 'post' =>
object(WP_Post)[67]
...
public 'product_type' => string 'simple' (length=6)
protected 'dimensions' => string '' (length=0)
protected 'shipping_class' => string '' (length=0)
protected 'shipping_class_id' => int 0
public 'price' => string '29.70' (length=5)
public 'manage_stock' => string 'no' (length=2)
public 'stock_status' => string 'instock' (length=7)
public 'virtual' => string 'no' (length=2)
public 'tax_status' => string 'taxable' (length=7)
int 2
string 'Size != 0 , Not Empty' (length=21)
string 'wc_get_template fired. Template name = cart/cart.php' (length=52)
string '/var/www/public/natural-choice/wp-content/themes/theme524401/woocommerce/cart/cart.php' (length=86)
boolean true
string 'File exists' (length=11)
string '<?php
/**
* Cart Page
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.8
*/
var_dump("Fired");
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
wc_print_notices();
do_action( 'woocommerce_before_cart' ); ?>
<form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post">
<?php do_action( 'woocommerce_before_cart_table' ); ?>
<table class="shop_table cart" cellspacing="0">
<thead>
<tr>
<th class="product-remove"> </th>
<t'... (length=6908)
string 'After do_action function' (length=24)
字符串“Hello”(长度=5)
常量之后的字符串(长度=15)
“装运计算后”字符串(长度=19)
“购物车项目检查后”字符串(长度=22)
计算总计后的字符串(长度=17)
数组(大小=2)
‘E82C4B19B8151DDC25D4D93BAF70908F’=>
阵列(大小=10)
“产品标识”=>int 2468
'variation_id'=>字符串“”(长度=0)
“变体”=>
数组(大小=0)
空的
“数量”=>int 1
“行总数”=>浮动27.06
“行税”=>浮动5.412
“行_小计”=>浮动27.06
“行小计税”=>浮动5.412
“行税数据”=>
数组(大小=2)
“总计”=>
数组(大小=1)
...
“小计”=>
数组(大小=1)
...
“数据”=>
对象(WC_产品_简单)[101]
公共“id”=>int 2468
公共“帖子”=>
对象(WP_Post)[103]
...
公共“产品类型”=>字符串“简单”(长度=6)
受保护的“维度”=>字符串“”(长度=0)
受保护的“装运类别”=>字符串“”(长度=0)
受保护的“装运类别id”=>int 0
公共“价格”=>字符串“27.06”(长度=5)
公共“管理股票”=>字符串“否”(长度=2)
公共“库存状态”=>字符串“库存”(长度=7)
公共“税务”状态=>字符串“应纳税”(长度=7)
公共“虚拟”=>字符串“否”(长度=2)
“1843E35D41CCF6E6327349495BA42DF3C1”=>
阵列(大小=10)
“产品标识”=>int 2463
'variation_id'=>字符串“”(长度=0)
“变体”=>
数组(大小=0)
空的
“数量”=>int 1
“行总数”=>浮动29.7
“行税”=>浮动5.94
“行_小计”=>浮动29.7
“行小计税”=>浮动5.94
“行税数据”=>
数组(大小=2)
“总计”=>
数组(大小=1)
...
“小计”=>
数组(大小=1)
...
“数据”=>
对象(WC_产品_简单)[69]
公共“id”=>int 2463
公共“帖子”=>
对象(WP_Post)[67]
...
公共“产品类型”=>字符串“简单”(长度=6)
受保护的“维度”=>字符串“”(长度=0)
受保护的“装运类别”=>字符串“”(长度=0)
受保护的“装运类别id”=>int 0
公共“价格”=>字符串“29.70”(长度=5)
公共“管理股票”=>字符串“否”(长度=2)
公共“库存状态”=>字符串“库存”(长度=7)
公共“虚拟”=>字符串“否”(长度=2)
公共“税务”状态=>字符串“应纳税”(长度=7)
int 2
字符串大小!=0,不为空(长度=21)
字符串“wc\u get\u模板被激发”。模板名称=cart/cart.php(长度=52)
字符串'/var/www/public/natural choice/wp content/themes/theme524401/woocommerce/cart/cart.php'(长度=86)
布尔真
字符串“文件存在”(长度=11)
字符串'
您应该能够通过查看调试日志来调试此类问题。它们可能在您的安装中被停用
您可以尝试将这两行添加到PHP文件的顶部以启用它们。它应该可以帮助您识别问题
error_reporting(E_ALL);
ini_set("display_errors", 1);
您应该能够通过查看调试日志来调试此类问题。它们可能在您的安装中被停用
您可以尝试将这两行添加到PHP文件的顶部以启用它们。它应该可以帮助您识别问题
error_reporting(E_ALL);
ini_set("display_errors", 1);
啊,与WordPress合作的乐趣。事实证明,include和require简单地停止脚本执行的原因是,我不知道有许多第三方插件正在停用和抑制所有错误
在@jason pate的建议()之后,我找到了这个问题的根源
include和required给出了错误,他们只是没有显示错误,也不是无缘无故地停止脚本,手动激活错误,突出显示正在引用的模板中存在语法问题。啊,使用WordPress的乐趣。事实证明,include和require简单地停止脚本执行的原因是,我不知道有许多第三方插件正在停用和抑制所有错误
在@jason pate的建议()之后,我找到了这个问题的根源
include和required给出了错误,他们只是没有显示错误,也不是无缘无故地停止脚本,手动激活错误突出显示所引用的模板中存在语法问题。一个很好的建议/评论…但这不是问题的答案。啊,谢谢。也许是因为我在WooCommerce工作