[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-admin/includes/settings/test/ -> update.php (source)

   1  <?php // test  => one sanitize here, selects and checkboxes + email is checked with email validator (RFC822,2822,5321,5322,6530,6531,6532) those RFC are not supported by Wp
   2  
   3  if ( isset( MP_AdminPage::$pst_['test'] ) )
   4  {
   5      $test     = stripslashes_deep( MP_AdminPage::$pst_['test'] );
   6  
   7      $test['toname'] = sanitize_text_field( $test['toname'] );
   8  
   9      $test['template'] = $test['th'][$test['theme']]['tm'];
  10      unset( $test['th'] );
  11  
  12      switch ( true )
  13      {
  14          case ( !MailPress::is_email( $test['toemail'] ) ) :
  15              MP_AdminPage::$err_mess['toemail'] = __( 'field should be an email', 'MailPress' );
  16          break;
  17          case ( empty( $test['toname'] ) ) :
  18              MP_AdminPage::$err_mess['toname']  = __( 'field should be a name', 'MailPress' );
  19          break;
  20          default :
  21              update_option( MailPress::option_name_test, $test );
  22              if ( isset( MP_AdminPage::$pst_['Submit'] ) )
  23              {
  24                  $message = __( 'Test settings saved', 'MailPress' );
  25              }
  26              else
  27              {
  28                  $url   = home_url();
  29                  $title = get_bloginfo( 'name' );
  30      
  31                  $mail = new stdClass();
  32                  $mail->Theme = $test['theme'];
  33                  if ( '0' != $test['template'] ) $mail->Template = $test['template'];
  34  
  35                  $mail->id        = MP_Mail::get_id( 'settings test' );
  36  
  37              // Set the from name and email
  38                  $mail->fromemail     = $mp_general['fromemail'];
  39                  $mail->fromname    = $mp_general['fromname'];
  40  
  41              // Set destination address
  42                  $mail->toemail     = $test['toemail'];
  43                  $mail->toname    = MP_Mail::display_name( $test['toname'] );
  44                  $key = MP_User::get_key_by_email( $mail->toemail );
  45                  if ( $key )
  46                  {
  47                      $mail->viewhtml     = MP_User::get_view_url( $key, $mail->id );
  48                      $mail->unsubscribe = MP_User::get_unsubscribe_url( $key );
  49                      $mail->subscribe      = MP_User::get_subscribe_url( $key );
  50                  }
  51  
  52              // Set mail's subject and body
  53                  $mail->subject    = sprintf( __( 'Connection test : %1$s - Template : %2$s', 'MailPress' ), get_bloginfo( 'name' ), isset( $mail->Template ) ? $mail->Template : __( 'none', 'MailPress' ) );
  54  
  55                  $mail->plaintext   =  "\n\n" . __( 'This is a test message of MailPress from', 'MailPress' ) . ' ' . $url . "\n\n";
  56  
  57                  $message  = '<div><br /><br />';
  58                  $message .=  sprintf( __( 'This is a <blink>test</blink> message of %1$s from %2$s. <br /><br />', 'MailPress' ), ' <b>MailPress</b> ', '<a href="' .  $url . '">' . $title . '</a>' );
  59                  $message .= '<br /><br /></div>';
  60                  $mail->html       = $message;
  61  
  62                  if ( class_exists( 'MailPress_newsletter' ) )
  63                  {
  64                      if ( isset( $mail->Template ) && in_array( $mail->Template, MP_Newsletter::get_templates() ) )
  65                      {
  66                          $posts = $wpdb->get_results( "SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY RAND() LIMIT 1;" );
  67                          if ( $posts )
  68                          {
  69                              $mail->the_title = apply_filters( 'the_title', $posts[0]->post_title );
  70                              $mail->newsletter= true;
  71                              query_posts( 'p='. $posts[0]->ID );
  72                          }
  73                      }
  74                  }
  75  
  76                  if (  isset( $test['forcelog'] ) )    $mail->forcelog = '';
  77                  if ( !isset( $test['fakeit'] ) )    $mail->nomail = '';
  78                  if ( !isset( $test['archive'] ) )    $mail->noarchive = '';
  79                  if ( !isset( $test['stats'] ) )        $mail->nostats = '';
  80  
  81                  if ( MailPress::mail( $mail ) )
  82                  {
  83                      if ( !isset( $test['fakeit'] ) )
  84                      {
  85                          $message = __( 'Test settings saved, Mail not send as required', 'MailPress' );
  86                      }
  87                      else
  88                      {
  89                          $message = __( 'Test successful, CONGRATULATIONS !', 'MailPress' );
  90                      }
  91                  }
  92                  else
  93                  {
  94                      MP_AdminPage::$err_mess['test'] = __( 'FAILED. Check your logs & settings !', 'MailPress' );
  95                  }
  96              }
  97          break;
  98      }
  99  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1