我在wordpress中有一个插件,根据我输入的日期更改了woocommerce订阅中的免费试用天数。它工作,现在它不是。完成所有常规安装,重新安装,deacivate,主题切换的东西,它仍然无法正常工作。
通过在某些陈述之后放置die;
并使用if ( !isset( $_POST['product-type'] ) || 'subscription' != $_POST['product-type'] ) return $post_id;
所以我删除了|| 'subscription' != $_POST['product-type']
它的工作和死亡。
当我var_dump($_POST);
时,product_type明确说明["product-type"]=> string(12) "subscription"
那么为什么||
无法正常工作
以下是该功能的代码:
function save_post( $post_id ) {
global $post;
if ( isset( $_POST ) ) {
//var_dump($_POST);
if ( !isset( $_POST['product-type'] ) || 'subscription' != $_POST['product-type'] ) return $post_id;
echo 'break'; die;
if ( is_int( wp_is_post_revision( $post_id ) ) ) return $post_id;
if( is_int( wp_is_post_autosave( $post_id ) ) ) return $post_id;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
if ( $post->post_type != 'product' ) return $post_id;
update_post_meta( $post_id, '_subscription_sync_day', absint( $_POST[ '_subscription_sync_day' ] ) );
if ( isset( $_POST['_subscription_sync'] ) )
update_post_meta( $post_id, '_subscription_sync', $_POST[ '_subscription_sync' ] );
else
delete_post_meta( $post_id, '_subscription_sync' );
$this->set_subscription_trial_length( $post_id );
$period = get_post_meta( $post_id, '_subscription_trial_period', true );
$length = get_post_meta( $post_id, '_subscription_trial_length', true );
if ( !$length )
$length = 0;
$sync = get_post_meta( $post_id, '_subscription_sync', true );
if ( 'yes' == $sync && ( ( 'day' != $period || absint( $length ) > 60 ) || ( absint( $_POST[ '_subscription_sync_day' ] ) > 28 ) ) ) {
$msg = '
<div class="form-field error" style="clear:both; background-color: #FFEBE8; border: 3px solid #CC0000; color: #cf0000;">
<p><strong>' .
__( 'WARNING: To synchronize payments the trial period must be "days", length must be set to 0 or greater, and the sync day must be 28 or less', 'sub_sync_settings' ) . '</strong></p>
</div>';
set_transient( 'ignitewoo_sub_sync', $msg, 300 );
}
}
return $post_id;
}
当然应该有效!
答案 0 :(得分:1)
根据您提供的信息,它应该失败。让我们做一点替代:
!isset( $_POST['product-type'] )
评估为!TRUE
评估为FALSE
'subscription' != $_POST['product-type']
评估为'subscription' != 'subscription'
评估为FALSE
总的来说,您的测试评估为if (FALSE || FALSE)
因此两个条件都是假的,整个事情都是假的,程序执行继续进行。
如果你想进入die语句,你需要发送一个$_POST
变量,product-type
元素为空,或者它等于&#39; subscription&#39;