Errant quote character showing up in an admin form added by a plugin in wrote

Hi all,

I am posting this question here because I am a beginner at plugin writing. So please understand that the code i am including is that of a beginner.

The Problem:
I create a plugin that ads a text field on to the new post admin screen. (see attached photo) for the life of me i can't figure out why when there is a close quote showing up in the text box.

the problem only shows up with a empty new post, once data has been saved the field properly displays the correct information (in this case an email address).

`function a3_notify_meta_box(){
$values = get_post_custom( $post->ID );
$text = isset( $values['a3_email_address'] ) ? esc_attr( $values['a3_email_address'][0] ) : ”;

//$text = $values['a3_email_address'] ? esc_attr( $values['a3_email_address'][0] ) : ”;
$issent = isset( $values['a3_notify_status'] ) ? esc_attr( $values['a3_notify_status'][0] ) : ”;

// We'll use this nonce field later on when saving.
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
if ($issent == '1':wink:{
$advised_text = 'Advised';}
$a3_debug_status = get_option('_a3_debug_mode':wink:;

if ($a3_debug_status==1){
$debug_text = '<strong style=\'color:red\'>DEBUG ON';}
echo $debug_text . $advised_text
?>
<label for="a3_email_address">Email Address: <?php if (get_option('a3_email_required':wink:==1){echo 'Required';}?></label>
<input type="text" size="30" name="a3_email_address" id="a3_email_address"
value="<?php echo $text ; ?>" <?php if (get_option('a3_email_required':wink:==1){echo 'required';} ?>/>
Separate addresses with commas

<?php if (get_option('a3_email_required':wink:==1){ ?>
<script type="text/javascript">
jQuery(document).ready( function($) {
jQuery('[id^=a3_email_address]':wink:.closest('form':wink:.validate({ignore:[]});
jQuery('[name="a3_email_address"]':wink:.rules('add', { messages: {required: 'An Email Address is Required', regex: 'Please enter a valid email address' } });
jQuery('[name="a3_email_address"]':wink:.rules('add', { required: true, regex: /^([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4},*[\W]*)+$/ } );
});
</script>
<?php ; };} '

  • Ash

    Hello @graham_stroh

    Please try the following code:

    function a3_notify_meta_box(){
    $values = get_post_custom( $post->ID );
    $text = isset( $values['a3_email_address'] ) ? esc_attr( $values['a3_email_address'][0] ) : "";
    
    //$text = $values['a3_email_address'] ? esc_attr( $values['a3_email_address'][0] ) : ”;
    $issent = isset( $values['a3_notify_status'] ) ? esc_attr( $values['a3_notify_status'][0] ) : "";
    
    // We'll use this nonce field later on when saving.
    wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
    if ($issent == '1'){
    $advised_text = 'Advised';}
    $a3_debug_status = get_option('_a3_debug_mode');
    
    if ($a3_debug_status==1){
    $debug_text = '<strong style=\'color:red\'>DEBUG ON';}
    echo $debug_text . $advised_text
    ?>
    <label for="a3_email_address">Email Address: <?php if (get_option('a3_email_required')==1){echo 'Required';}?></label>
    <input type="text" size="30" name="a3_email_address" id="a3_email_address"
    value="<?php echo $text ; ?>" <?php if (get_option('a3_email_required')==1){echo 'required';} ?>/>
    Separate addresses with commas
    
    <?php if (get_option('a3_email_required')==1){ ?>
    <script type="text/javascript">
    jQuery(document).ready( function($) {
    jQuery('[id^=a3_email_address]').closest('form').validate({ignore:[]});
    jQuery('[name="a3_email_address"]').rules('add', { messages: {required: 'An Email Address is Required', regex: 'Please enter a valid email address' } });
    jQuery('[name="a3_email_address"]').rules('add', { required: true, regex: /^([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4},*[\W]*)+$/ } );
    });
    </script>
    <?php ; };}

    I didn't run it though, but I wonder why you have <?php ; };} at the last line, it should show an error.

    Please let us know. If it doesn't work, please give me full plugin code using http://pastebin.com

    Cheers
    Ash

  • Predrag Dubajic

    Hey @graham_stroh,

    Hope you're doing well today :slight_smile:

    Ok, let's try this, on lines 5 and 8 at the end of lines replace double quotes with double single quotes.
    So the line 5 looks like this:
    $text = isset( $values['a3_email_address'] ) ? esc_attr( $values['a3_email_address'][0] ) : '';
    And line 8 like this:
    $issent = isset( $values['a3_notify_status'] ) ? esc_attr( $values['a3_notify_status'][0] ) : '';

    Let me know if this was the issue.

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.