为什么不|| 工作? [关闭]

I have a plugin in wordpress that changes the free trial days in woocommerce subscriptions based on a date I input. It was working and now it isn't. Done all the usual install, reinstall, deacivate, theme switching stuff and it still doesn't work. So gone through the code using my limited knowledge by putting die; after certain statements and I discover that this code doesn't die after if ( !isset( $_POST['product-type'] ) || 'subscription' != $_POST['product-type'] ) return $post_id;

So I remove || 'subscription' != $_POST['product-type'] it works and dies.

When I var_dump($_POST); the product_type clearly says ["product-type"]=> string(12) "subscription"

So why wouldn't || be working is this situation

Below is the code for the function:

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;

}

Surely it should work!

Based on the information you give, it SHOULD fail. Let's do a little substitution:

!isset( $_POST['product-type'] ) evaluates to !TRUE evaluates to FALSE

'subscription' != $_POST['product-type'] evaluates to 'subscription' != 'subscription' evaluates to FALSE

So as a whole, your test evaluates to if (FALSE || FALSE)

So both conditions are false and the whole thing is false and program execution moves on.

If you want to get to the die statement, you need to either send it a $_POST variable where the product-type element is empty or it equals something other than 'subscription'.