php - 如何修复 class-wp-meta-query 中的“trim() 需要参数 1”-> 要选择哪个 Meta Key?
问题描述
我正在开发一个外部应用程序,该应用程序通过我的网站(使用 woocommerce)使用来自注册用户的数据来登录应用程序。
我想误用产品到期(您可以在 woocommerce 中创建的产品的产品属性)来检查该人是否仍然可以下载产品并因此也可以登录,或者如果不能,客户应该无法登录。
我在 php 方面并没有真正的经验,并且阅读了 wc 的文档,但这对我没有帮助。
我通过登录从客户那里获得凭据,然后我想使用这些数据来获取订单。从订单中我想看看我是否可以得到产品,然后检查产品到期是否仍然有效。
元键会产生一些问题,因为我将它与一个对象配对。错误信息是:
PHP Warning: trim() expects parameter 1 to be string, object given in
../wp-includes/class-wp-meta-query.php on line 599.
但是,如果我_customer_user
像在某些解决方案中看到的那样使用它,它对我不起作用:
<?php
/*
Template Name: Login
*/
?>
<?php
require_once('./wp-includes/pluggable.php');
$sEmail = $_POST['email'];
$sPassword = $_POST['password'];
$sSecret = $_POST['secret'];
$oUser = get_user_by('email', $sEmail);
$iUserID = $oUser->ID;
$sUserName = $oUser->user_login;
if(!isset($sEmail) || !isset($sPassword) || !isset($sSecret)) {
die();
}
$local_secret = 'XXXXXXXXXXXX';
// Get the last order by email, orderd by the most recent order and
//$args = array(
//'customer' => $sEmail,
//'orderby' => 'date',
//'order' => 'DESC',
//);
//$oLastOrder = wc_get_order( $args );
// Get orders by customer with email 'woocommerce@woocommerce.com'.
// Get all current customer orders
$customer_orders = wc_get_orders( $args = array(
'numberposts' => -1,
'meta_key' => $oUser,
'meta_value' => $iUserID,// for current user id
'post_status' => array_keys(wc_get_order_statuses()),
) );
// The different loops to get the downloadable products bought by this user
foreach ( $customer_orders as $customer_order )
if (!empty($customer_orders)){
foreach ( $customer_orders as $customer_order ){
if( !$customer_order->has_downloadable_item() && $customer_order->is_paid() ){
foreach( $customer_order->get_items() as $item ){
$item_id = $item[614]; // product ID
// Just the downloadable items Below
if($item->is_download_permitted()) {
//Check Credentials
if ($sSecret == $local_secret) {
if ($user && wp_check_password( $password, $user->data->user_pass, $user->ID )) {
echo json_encode(array("success" => "true"));
}else {
echo json_encode(array("success" => "false"));
}
}else {
echo json_encode(array("success" => "false"));
}
//End of Credentialscheck
} else {
echo json_encode(array("success" => "false"));
}
}
}
}
}
?>
有什么想法我可以更改才能登录吗?
解决方案
推荐阅读
- python - 将 pandas DataFrame 列拆分为 OneHot/Binary 列
- android - 调整当前宽度相等的单个线性布局子元素的宽度?
- firebase - 在 GitLab 中安装 Firebase 工具的权限被拒绝错误
- apache-nifi - Apache Nifi 1,8,0 和 CryptographicHashContent
- java - 嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法构造 `com.xyz.pqr.model.Date` 的实例
- r - fwrite.data.table 和 `yyyy-mm-dd hh:mm:ss` 格式优化,固定 UTC 偏移
- angular - Angular 项目在构建时出现 AbstractControl 错误
- javascript - Redux:在按钮的 onClick 期间道具没有改变
- php - 我可以在codeigniter的查询构建器之间添加一个IF条件吗
- c - 如何从多个静态库 .a 文件中制作单个动态库、.so 文件