Your <?php
/?>
tags are aligned such that none of your actual PHP code is being interpreted as PHP code (except the is_page ('1150')
conditional) – it’s actually just printing it all into your markup, including the <script>
element. So since it’s not running the logic to check the user or the user meta-data, the script element is always there.
I’d simplify it all like this:
<?php
if( is_page( '1150' ) ) {
$current_user_id = get_current_user_id();
if( $current_user_id > 0 ) {
$permission = get_user_meta( $current_user_id, 'pro_status_confirmed_true' , true );
if( empty( $permission ) ) {
?>
<script type="text/javascript">jQuery(document).ready(function(){ jQuery('form#gform_190').trigger('submit');});</script>
<?php
}
}
}
?>
If all submitting this form does is instantly redirect “non-pro” status users however, you may want to read up on performing the redirect using wp_redirect()
. This is more efficient than printing a script element, and also more secure – in printing a script element to redirect “unauthorized” users, they still load the page body – if the script is meant to keep them off that page, a user could still find the page in their browser cache, prevent the redirect, or simply disable JavaScript in order to circumvent the check. Redirecting using wp_redirect()
before content is sent to the client will also be somewhat faster.