Plugin Directory

Changeset 773028


Ignore:
Timestamp:
09/16/2013 02:25:10 AM (13 years ago)
Author:
codebykat
Message:

fixed option validation and detection of unconfigured/error states

Location:
post-by-email/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • post-by-email/trunk/class-post-by-email-admin.php

    r773024 r773028  
    8484        $default_options = Post_By_Email::$default_options;
    8585
    86         $mailserver_url = trim( $input['mailserver_url'] );
    87         if ( $mailserver_url != $default_options['mailserver_url'] ) {
    88             $options['mailserver_url'] = $mailserver_url;
    89         }
     86        $options['mailserver_url'] = trim( $input['mailserver_url'] );
    9087
    9188        $mailserver_protocol = trim( $input['mailserver_protocol'] );
    92         if ( in_array( $options['mailserver_protocol'], array( 'POP3', 'IMAP' ) ) ) {
     89        if ( in_array( $mailserver_protocol, array( 'POP3', 'IMAP' ) ) ) {
    9390            $options['mailserver_protocol'] = $mailserver_protocol;
    9491        }
     
    10097        }
    10198
    102         $mailserver_login = trim( $input['mailserver_login'] );
    103         if ( $mailserver_login != $default_options['mailserver_login'] ) {
    104             $options['mailserver_login'] = $mailserver_login;
    105         }
    106 
    107         $mailserver_pass = trim( $input['mailserver_pass'] );
    108         if ( '' != $mailserver_pass ) {
    109             $options['mailserver_pass'] = $mailserver_pass;
    110         }
     99        $options['mailserver_login'] = trim( $input['mailserver_login'] );
     100        $options['mailserver_pass'] = trim( $input['mailserver_pass'] );
    111101
    112102        // default email category must be the ID of a real category
     
    119109        $options['delete_messages'] = isset( $input['delete_messages'] ) && '' != $input['delete_messages'];
    120110
    121         if ( $options['mailserver_url'] && $options['mailserver_port']
    122             && $options['mailserver_login'] && $options['mailserver_pass'] ) {
    123 
    124             // clear the transient and any error conditions if options have been updated
     111        $options['pin_required'] = isset( $input['pin_required'] ) && '' != $input['pin_required'];
     112        $options['pin'] = trim( $input['pin'] );
     113
     114        // this is ridiculous
     115        if ( isset ( $input['status'] ) && in_array( $input['status'], array( 'unconfigured', 'error', '') ) ) {
     116            // maintain saved state
     117            $options['status'] = $input['status'];
     118        }
     119        elseif ( ( $options['mailserver_url'] == $default_options['mailserver_url'] )
     120            || ( '' == $options['mailserver_url'] )
     121            || ( $options['mailserver_login'] == $default_options['mailserver_login'] )
     122            || ( '' == $options['mailserver_login'] )
     123            || ( '' == $options['mailserver_pass'] )
     124            || ( '' == $options['mailserver_port'] )
     125            || ( '' == $options['mailserver_protocol' ] )
     126            ) {
     127            // detect if settings are blank or defaults
     128            $options['status'] = 'unconfigured';
     129        }
     130        else {
     131            // clear the transient and any error conditions if we have good options now
    125132            delete_transient( 'mailserver_last_checked' );
    126133            $options['status'] = '';
    127134        }
    128 
    129         $options['pin_required'] = isset( $input['pin_required'] ) && '' != $input['pin_required'];
    130         $options['pin'] = trim( $input['pin'] );
    131135
    132136        return $options;
  • post-by-email/trunk/class-post-by-email.php

    r773023 r773028  
    236236
    237237        $options = get_option( 'post_by_email_options' );
     238
     239        // if options aren't set, there's nothing to do, move along
     240        if ( 'unconfigured' == $options['status'] ) {
     241            return;
     242        }
     243
    238244        $options['last_checked'] = current_time( 'timestamp' );
    239245        $options['status'] = '';
    240246        update_option( 'post_by_email_options', $options );
    241 
    242         // if options aren't set, there's nothing to do, move along
    243         if ( 'unconfigured' == $options['status'] ) {
    244             return;
    245         }
    246247
    247248        $this->connection = $this->open_mailbox_connection( $options );
  • post-by-email/trunk/views/admin.php

    r773023 r773028  
    242242        </p>
    243243        <p>
    244             <a href="<?php echo add_query_arg( 'check_mail', true ); ?>" class="button-secondary">
     244            <a href="<?php echo add_query_arg( 'check_mail', true ); ?>" class="button-secondary"
     245                <?php if ( 'unconfigured' == $options['status'] ) { echo 'disabled'; } ?> >
    245246                <?php _e( 'Check now', 'post-by-email' ); ?>
    246247            </a>
Note: See TracChangeset for help on using the changeset viewer.