[ Index ]

MailPress 7.0.1

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

title

Body

[close]

/mp-content/add-ons/ -> MailPress_autoresponder.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_autoresponder' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_autoresponder
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/autoresponder/
   7  Description: Autoresponders ( based on wp-cron )
   8  Version: 7.0
   9  */
  10  
  11  // 3.
  12  
  13  /** for admin plugin pages */
  14  define ( 'MailPress_page_autoresponders',     'mailpress_autoresponders' );
  15  
  16  /** for admin plugin urls */
  17  $mp_file = 'admin.php';
  18  define ( 'MailPress_autoresponders',    add_query_arg( 'page', MailPress_page_autoresponders, $mp_file ) );
  19  
  20  class MailPress_autoresponder
  21  {
  22      const taxonomy = 'MailPress_autoresponder';
  23      const log_name = 'autoresponder';
  24  
  25      const bt = 100;
  26  
  27  	function __construct()
  28      {
  29  // for taxonomy
  30          add_action( 'init',             array( __CLASS__, 'init' ), 1 );
  31  
  32  // for plugin
  33          add_action( 'MailPress_addons_loaded',             array( __CLASS__, 'addons_loaded' ) );
  34  
  35  // for autoresponder ( from older mailpress versions )
  36          add_action( 'mp_autoresponder_process',             array( __CLASS__, 'process' ) );
  37          add_action( 'mp_process_autoresponder',             array( __CLASS__, 'process' ) );
  38  
  39  // for wp admin
  40          if ( is_admin() )
  41          {
  42          // for install
  43              register_activation_hook( plugin_basename( __FILE__ ),     array( __CLASS__, 'install' ) );
  44          // for link on plugin page
  45              add_filter( 'plugin_action_links',             array( __CLASS__, 'plugin_action_links' ), 10, 2 );
  46          // for role & capabilities
  47              add_filter( 'MailPress_capabilities',         array( __CLASS__, 'capabilities' ), 1, 1 );
  48          // for settings
  49              add_action( 'MailPress_settings_logs_form',         array( __CLASS__, 'settings_logs_form' ), 10 );
  50          // for load admin page
  51              add_filter( 'MailPress_load_admin_page',         array( __CLASS__, 'load_admin_page' ), 10, 1 );
  52          // for mails list
  53              add_filter( 'MailPress_get_icon_mails',         array( __CLASS__, 'get_icon_mails' ), 8, 2 );
  54          // for meta box in write page
  55              add_action( 'MailPress_add_help_tab_write',    array( __CLASS__, 'add_help_tab_write' ), 8 );
  56              add_action( 'MailPress_update_meta_boxes_write',array( __CLASS__, 'update_meta_boxes_write' ) );
  57              add_filter( 'MailPress_styles',             array( __CLASS__, 'styles' ), 8, 2 );
  58              add_filter( 'MailPress_scripts',             array( __CLASS__, 'scripts' ), 8, 2 );
  59              add_action( 'MailPress_add_meta_boxes_write',    array( __CLASS__, 'add_meta_boxes_write' ), 8, 2 );
  60          }
  61  
  62  // for ajax
  63          add_action( 'mp_action_add_atrspndr',             array( __CLASS__, 'mp_action_add_atrspndr' ) );
  64          add_action( 'mp_action_delete_atrspndr',             array( __CLASS__, 'mp_action_delete_atrspndr' ) );
  65          add_action( 'mp_action_add_wa',                 array( __CLASS__, 'mp_action_add_wa' ) );
  66          add_action( 'mp_action_delete_wa',                 array( __CLASS__, 'mp_action_delete_wa' ) );
  67      }
  68  
  69  //// Taxonomy ////
  70  
  71  	public static function init() 
  72      {
  73          register_taxonomy( self::taxonomy, 'MailPress_autoresponder', array( 'update_count_callback' => array( __CLASS__, 'update_count_callback' ) ) );
  74      }
  75  
  76  	public static function update_count_callback( $autoresponders )
  77      {
  78          return 0;
  79      }
  80  
  81  //// Plugin ////
  82  
  83  	public static function addons_loaded()
  84      {
  85          new MP_Autoresponder_events();
  86      }
  87  
  88  ////  Autoresponder  ////
  89  
  90  	public static function process( $args )
  91      {
  92          MP_::no_abort_limit();
  93  
  94          extract( $args );        // $umeta_id, $mail_order
  95          $meta_id = ( isset( $umeta_id ) ) ? $umeta_id : $meta_id;
  96  
  97          $meta = MP_User_meta::get_by_id( $meta_id );
  98          $term_id     = ( !$meta ) ? false : str_replace( '_MailPress_autoresponder_', '', $meta->meta_key );
  99          if ( !$term_id ) return;
 100          
 101          $autoresponder = MP_Autoresponder::get( $term_id );
 102  
 103          do_action( 'mp_process_autoresponder_' . $autoresponder->description['event'], $args );
 104      }
 105  
 106  ////  ADMIN  ////
 107  ////  ADMIN  ////
 108  ////  ADMIN  ////
 109  ////  ADMIN  ////
 110  
 111  // install
 112  	public static function install() 
 113      {
 114          MP_Log::set_option( self::log_name );
 115      }
 116  
 117  // for link on plugin page
 118  	public static function plugin_action_links( $links, $file )
 119      {
 120          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'logs' );
 121      }
 122  
 123  // for role & capabilities
 124  	public static function capabilities( $capabilities )
 125      {
 126          $capabilities['MailPress_manage_autoresponders'] = array(     'name'    => __( 'Autoresponders', 'MailPress' ),
 127                                                  'group'    => 'mails',
 128                                                  'menu'    => 15,
 129  
 130                                                  'parent'    => false,
 131                                                  'page_title'=> __( 'MailPress Autoresponders', 'MailPress' ),
 132                                                  'menu_title'=> '&#160;' . __( 'Autoresponders', 'MailPress' ),
 133                                                  'page'    => MailPress_page_autoresponders,
 134                                                  'func'    => array( 'MP_AdminPage', 'body' )
 135                                       );
 136          return $capabilities;
 137      }
 138  
 139  // for settings
 140  	public static function settings_logs_form( $logs )
 141      {
 142          MP_AdminPage::logs_sub_form( self::log_name, $logs, __( 'Autoresponder', 'MailPress' ) );
 143      }
 144  
 145  // for load admin page
 146  	public static function load_admin_page( $hub )
 147      {
 148          $hub[MailPress_page_autoresponders] = 'autoresponders';
 149          return $hub;
 150      }
 151  
 152  // for ajax
 153  	public static function mp_action_add_atrspndr() 
 154      {
 155          if ( !current_user_can( 'MailPress_manage_autoresponders' ) ) die( '-1' );
 156  
 157          if ( '' === trim( MP_WP_Ajax::$pst_['name'] ) ) 
 158          {
 159              $x = new WP_Ajax_Response( array(     'what' => 'autoresponder', 
 160                                      'id' => new WP_Error( 'autoresponder_name', __( 'You did not enter a valid autoresponder name.', 'MailPress' ) )
 161                                     ) );
 162              $x->send();
 163          }
 164  
 165          if ( MP_Autoresponder::exists( trim( MP_WP_Ajax::$pst_['name'] ) ) ) 
 166          {
 167              $x = new WP_Ajax_Response( array(     'what' => 'autoresponder', 
 168                                      'id' => new WP_Error( __CLASS__ . '::exists', __( 'The autoresponder you are trying to create already exists.', 'MailPress' ), array( 'form-field' => 'name' ) ), 
 169                                    ) );
 170              $x->send();
 171          }
 172      
 173          $autoresponder = MP_Autoresponder::insert( MP_WP_Ajax::$pst_, true );
 174  
 175          if ( is_wp_error( $autoresponder ) ) 
 176          {
 177              $x = new WP_Ajax_Response( array(     'what' => 'autoresponder', 
 178                                      'id' => $autoresponder
 179                                    ) );
 180              $x->send();
 181          }
 182  
 183          if ( !$autoresponder || ( !$autoresponder = MP_Autoresponder::get( $autoresponder ) ) )     MP_::mp_die( '0' );
 184  
 185          $autoresponder_full_name     = $autoresponder->name;
 186  
 187          include  ( MP_ABSPATH . 'mp-admin/autoresponders.php' );
 188          $x = new WP_Ajax_Response( array(     'what' => 'autoresponder', 
 189                                  'id' => $autoresponder->term_id, 
 190                                  'data' => MP_AdminPage::get_row( $autoresponder, array() ), 
 191                                  'supplemental' => array( 'name' => $autoresponder_full_name, 'show-link' => sprintf( __( 'Autoresponder <a href="#%s">%s</a> added' , 'MailPress' ), "autoresponder-$autoresponder->term_id", $autoresponder_full_name ) )
 192                                ) );
 193          $x->send();
 194      }
 195  
 196  	public static function mp_action_delete_atrspndr() 
 197      {
 198          $id = isset( MP_WP_Ajax::$pst_['id'] )? ( int ) MP_WP_Ajax::$pst_['id'] : 0;
 199          MP_::mp_die( MP_Autoresponder::delete( $id ) ? '1' : '0' );
 200      }
 201  
 202  // for mails list
 203  	public static function get_icon_mails( $out, $mail_id )
 204      {
 205          if ( MP_Autoresponder::object_have_relations( $mail_id ) ) $out .= '<span class="mp_icon mp_icon_autoresponder" title="' . __( 'Autoresponder', 'MailPress' ) . '"></span>';
 206          return $out;
 207      }
 208          
 209  // for meta box in write page
 210  	public static function add_help_tab_write()
 211      {
 212          global $current_screen;
 213  
 214          $content = '';
 215          $content .= '<p><strong>' . __( 'Autoresponders :', 'MailPress' ) . '</strong></p>';
 216          $content .= '<p>' . __( 'When scheduling an autoresponder, do as follow:', 'MailPress' ) . '</p>';
 217          $content .= '<ul>';
 218          $content .= '<li>' . sprintf( __( 'Create a new %s and use the appropriate box, link it to the MailPress autoresponder by specifying the delay between the triggered event and the mail release. For a set of mails, you will need to create as many as mails required, linked to the same autoresponder with different delays.', 'MailPress' ), sprintf( '<a href="' . MailPress_write . '" target="_blank">%s</a>', __( 'Mail', 'MailPress' ) ) ) . '</li>';
 219          $content .= '<li>' . __( 'When saving the mail, a recipient mail is required but will be replaced on time by the right recipient&#8217;s mail.', 'MailPress' ) . '</li>';
 220          $content .= '<li>' . sprintf( __( 'Autoresponder draft mail can be quickly identified in %1$s with a little clock icon : %2$s', 'MailPress' ), sprintf( '<a href="' . MailPress_mails . '" target="_blank">%s</a>', __( 'Mails list', 'MailPress' ) ) , '<span class="mp_icon mp_icon_autoresponder" title="' . __('Autoresponder', 'MailPress' ) . '"></span>' ) . '</li>';
 221          $content .= '</ul>';
 222  
 223          $current_screen->add_help_tab( array(     'id'        => 'autoresponders',
 224                                          'title'    => __( 'Autoresponders', 'MailPress' ),
 225                                          'content'    => $content )
 226          );
 227      }
 228  
 229  	public static function meta_box_write_parms()
 230      {
 231          $x['table_body_id'] = 'wa-list';                // the-list
 232          $x['ajax_response'] = 'wa-response';             // ajar-response
 233          $x['table_list_id'] = 'wa-list-table';            // list-table
 234  
 235          $x['tr_prefix_id']  = 'wa';
 236  
 237          return $x;
 238      }
 239  
 240  	public static function update_meta_boxes_write()
 241      {
 242      }
 243  
 244  	public static function styles( $styles, $screen ) 
 245      {
 246          if ( $screen != MailPress_page_write ) return $styles;
 247  
 248          wp_register_style( MailPress_page_autoresponders, '/' . MP_PATH . 'mp-admin/css/write_autoresponders.css' );
 249  
 250          $styles[] = MailPress_page_autoresponders;
 251  
 252          return $styles;
 253      }
 254  
 255  	public static function scripts( $scripts, $screen ) 
 256      {
 257          if ( $screen != MailPress_page_write ) return $scripts;
 258  
 259          wp_register_script( MailPress_page_autoresponders, '/' . MP_PATH . 'mp-admin/js/write_autoresponders.js', array( 'mp-lists' ), false, 1 );
 260          wp_localize_script( MailPress_page_autoresponders,     'adminautorespondersL10n',    array_merge(     array( 'pending' => __( '%i% pending' ), 'screen' => MP_AdminPage::screen ),
 261                                                                              self::meta_box_write_parms(),
 262                                                                              array( 'l10n_print_after' => 'try{convertEntities( adminautorespondersL10n );}catch( e ){};' )
 263                                                                   )
 264           );
 265          $scripts[] = MailPress_page_autoresponders;
 266  
 267          return $scripts;
 268      }
 269  
 270  	public static function add_meta_boxes_write( $mail_id, $mp_screen )
 271      {
 272          if ( !current_user_can( 'MailPress_manage_autoresponders' ) )    return;
 273          add_meta_box( 'write_autoresponder', __( 'Autoresponders', 'MailPress' ), array( __CLASS__, 'meta_box' ), MP_AdminPage::screen, 'normal', 'core' );
 274      }
 275  /**/
 276  	public static function meta_box( $mail )
 277      {
 278          $parms = self::meta_box_write_parms();
 279  
 280              $id = ( isset( $mail->id ) ) ? $mail->id : 0;
 281          $metadata = MP_Autoresponder::get_object_terms( $id );
 282          $count = 0;
 283  
 284          $out = '';
 285          $out .= '<div id="mailautoresponderstuff">' . "\r\n";
 286          $out .= '<div id="' . $parms['ajax_response'] . '"></div>' . "\r\n";
 287  
 288          if ( !$metadata )
 289          {
 290              $metadata = array(); 
 291  
 292              $out .= '<table id="' . $parms['table_list_id'] . '" class="hidden">' . "\r\n";
 293              $out .= '<thead><tr><th class="left">' . __( 'Autoresponder', 'MailPress' ) . '</th><th>' . __( 'Schedule', 'MailPress' ) . '</th></tr></thead>' . "\r\n";
 294              $out .= '<tbody id="' . $parms['table_body_id'] . '" class="list:' . $parms['tr_prefix_id'] . '"><tr><td></td><td></td></tr></tbody>' . "\r\n";
 295              $out .= '</table>' . "\r\n";
 296          }
 297          else
 298          {
 299              $out .= '<table id="' . $parms['table_list_id'] . '">' . "\r\n";
 300              $out .= '<thead><tr><th class="left">' . __( 'Autoresponder', 'MailPress' ) . '</th><th>' . __( 'Schedule', 'MailPress' ) . '</th></tr></thead>' . "\r\n";
 301              $out .= '<tbody id="' . $parms['table_body_id'] . '" class="list:' . $parms['tr_prefix_id'] . '">' . "\r\n";
 302              foreach ( $metadata as $entry ) $out .= self::meta_box_autoresponder_row( $entry, $count ) . "\r\n";
 303              $out .= '</tbody>' . "\r\n";
 304              $out .= '</table>' . "\r\n";
 305          }
 306  
 307          $autoresponders = MP_Autoresponder::get_all();
 308          foreach( $autoresponders as $autoresponder )
 309          {
 310              $_autoresponders[$autoresponder->term_id] = $autoresponder->name;
 311          }
 312  
 313          if ( empty( $_autoresponders ) )
 314          {
 315              $out .= '<p><strong>' . __( 'No autoresponder', 'MailPress' ) . '</strong></p>' . "\r\n";
 316          }
 317          else
 318          {
 319              $periods = array( 'Y' => __( 'Year', 'MailPress' ), 'M' => __( 'Month', 'MailPress' ), 'W' => __( 'Week', 'MailPress' ), 'D' => __( 'Day', 'MailPress' ), 'H' => __( 'Hour', 'MailPress' ) );
 320  
 321              $out .= '<p><strong>' . __( 'Link to :', 'MailPress' ) . '</strong></p>' . "\r\n";
 322  
 323              $out .= '<table id="add_' . $parms['tr_prefix_id'] . '">' . "\r\n";
 324              $out .= '<thead>'
 325                      . '<tr><th class="left"><label for="autoresponderselect">' . __( 'Autoresponder', 'MailPress' ) . '</label></th>'
 326                      . '<th><label for="metavalue">' . __( 'Schedule', 'MailPress' ) . '</label></th>'
 327                      . '</tr>'
 328                      . '</thead>' . "\r\n";
 329              $out .= '<tbody>' . "\r\n";
 330              $out .= '<tr>' . "\r\n";
 331              $out .= '<td id="newarleft" class="left">' . "\r\n";
 332              $out .= '<select name="autoresponderselect" id="autoresponderselect" tabindex="7">' . MP_AdminPage::select_option( $_autoresponders, false, false ) . '</select>' . "\r\n";
 333              $out .= '</td>';
 334              $out .= '<td style="vertical-align:top;">' . "\r\n";
 335  
 336              $out .= '<table style="border:none;margin:8px 0 8px 8px;width:95%;">' . "\r\n";
 337              $out .= '<tbody>' . "\r\n";
 338              $out .= '<tr>' . "\r\n";
 339              foreach( $periods as $k => $v )
 340              {
 341                  $out .= '<td class="arschedule">' . $v . '<br /><select name="autoresponder[schedule][' . $k . ']" >' . MP_AdminPage::select_number( 0, 99, 0, 1, false ) . '</select></td>' . "\r\n";
 342              }
 343              $out .= '</tr>' . "\r\n";
 344              $out .= '</tbody>' . "\r\n";
 345              $out .= '</table>' . "\r\n";
 346  
 347              $out .= '</td>' . "\r\n";
 348              $out .= '</tr>' . "\r\n";
 349              $out .= '<tr>' . "\r\n";
 350              $out .= '<td>' . "\r\n";
 351              $out .= '<div class="submit" style="border: 0 none;float: none;padding: 0 8px 8px;">' . "\r\n";
 352              $out .= '<input type="submit" name="addwrite_autoresponder" id="addmetasub2" class="add:' . $parms['table_body_id'] . ':add_' . $parms['tr_prefix_id'] . ' button" tabindex="9" value="' . __( 'Add', 'MailPress' ) . '" />' . "\r\n";
 353              $out .= '</div>' . "\r\n";
 354              $out .= '</td>' . "\r\n";
 355              $out .= '<td>' . "\r\n";
 356              $out .= '<p class="description">' . __( 'Not more than one year between two scheduled mails.', 'MailPress' ) . '</p>' . "\r\n";
 357              $out .= wp_nonce_field( 'add-write-autoresponder', '_ajax_nonce', false, false ) . "\r\n";
 358              $out .= '</td>' . "\r\n";
 359              $out .= '</tr>' . "\r\n";
 360              $out .= '</tbody>' . "\r\n";
 361              $out .= '</table>' . "\r\n";
 362          }
 363          $out .= '</div>' . "\r\n";
 364  
 365          echo $out;
 366      }
 367      // for ajax
 368  	public static function meta_box_autoresponder_row( $entry, &$count ) 
 369      {
 370          $parms = self::meta_box_write_parms();
 371  
 372          static $update_nonce = false;
 373          if ( !$update_nonce ) $update_nonce = wp_create_nonce( 'add-write-autoresponder' );
 374  
 375          $r = '';
 376          ++ $count;
 377  
 378          if ( $count % 2 )    $style = 'alternate';
 379          else                $style = '';
 380  
 381          $entry['meta_id']     = ( int ) $entry['meta_id'];
 382  
 383          $delete_nonce         = wp_create_nonce( 'delete-write-autoresponder_' . $entry['meta_id'] );
 384  
 385          $autoresponders = MP_Autoresponder::get_all();
 386          foreach( $autoresponders as $autoresponder )
 387          {
 388              $_autoresponders[$autoresponder->term_id] = $autoresponder->name;
 389          }
 390  
 391          $periods = array( 'Y' => __( 'Year', 'MailPress' ), 'M' => __( 'Month', 'MailPress' ), 'W' => __( 'Week', 'MailPress' ), 'D' => __( 'Day', 'MailPress' ), 'H' => __( 'Hour', 'MailPress' ) );
 392  
 393          $out = '';
 394          $out .= '<tr id="' . $parms['tr_prefix_id'] . '-' . $entry['meta_id'] . '" class="' . $style . '">';
 395          $out .= '<td class="left">';
 396          $out .= '<select name="write_autoresponder[' . $entry['meta_id'] . '][key]" id="write_autoresponder_' . $entry['meta_id'] . '_key" tabindex="7">';
 397          $out .= MP_::select_option( $_autoresponders, $entry['term_id'], false );
 398          $out .= '</select>';
 399          $out .= '<div class="submit">';
 400          $out .= '<input type="submit" name="delete_wa-' . $entry['meta_id'] . '" value="' . esc_attr( __( 'Delete' ) ) . '" class="delete:' . $parms['table_body_id'] . ':' . $parms['tr_prefix_id'] . '-' . $entry['meta_id'] . '::_ajax_nonce=' . $delete_nonce . ' delete_wa button" tabindex="6" />';
 401          $out .= '<input type="submit" name="update_wa-' . $entry['meta_id'] . '" value="' . esc_attr( __( 'Update' ) ) . '" class="add:'    . $parms['table_body_id'] . ':' . $parms['tr_prefix_id'] . '-' . $entry['meta_id'] . '::_ajax_nonce=' . $update_nonce . ' update_wa button" tabindex="6" />';
 402          $out .= wp_nonce_field( 'change-write_autoresponder', '_ajax_nonce', false, false );
 403          $out .= '</div>';
 404          $out .= '</td>';
 405          $out .= '<td style="vertical-align:top;">';
 406          $out .= '<table style="border:none;margin:8px 0 8px 8px;width:95%;">';
 407          $out .= '<tbody>';
 408          $out .= '<tr>';
 409          foreach( $periods as $k => $v )
 410          {
 411              $out .= '<td class="arschedule">';
 412              $out .= $v . '<br />';
 413              $out .= '<select name="write_autoresponder[' . $entry['meta_id'] . '][value][' . $k . ']">';
 414              $out .= MP_::select_number( 0, 99, $entry['schedule'][$k], 1, false );
 415              $out .= '</select>';
 416              $out .= '</td>';
 417          }
 418          $out .= '</tr>';
 419          $out .= '</tbody>';
 420          $out .= '</table>';
 421          $out .= '</td>';
 422          $out .= '</tr>';
 423          $out .= "\n";
 424  
 425          return $out;
 426      }
 427  
 428  // for ajax    
 429  
 430  	public static function mp_action_add_wa()
 431      {
 432          if ( !current_user_can( 'MailPress_manage_autoresponders' ) )    die( '-1' );
 433  
 434          $c = 0;
 435          $object_id = ( int ) MP_WP_Ajax::$pst_['mail_id'];
 436          if ( $object_id === 0 ) MP_::mp_die();
 437  
 438          if ( isset( MP_WP_Ajax::$pst_['autoresponderselect'] ) || isset( MP_WP_Ajax::$pst_['autoresponder']['schedule'] ) ) 
 439          {
 440              if ( !$meta_id = self::add_meta( $object_id ) ) MP_::mp_die();
 441  
 442              $response = array( 'position'     => 1 );
 443          }
 444          else
 445          {
 446              $_ak = array_keys( MP_WP_Ajax::$pst_['write_autoresponder'] );
 447              $meta_id   = ( int ) array_pop( $_ak );
 448              $key   = '_MailPress_autoresponder_' . MP_WP_Ajax::$pst_['write_autoresponder'][$meta_id]['key'];
 449              $value = MP_WP_Ajax::$pst_['write_autoresponder'][$meta_id]['value'];
 450  
 451              if ( !$meta = MP_Mail_meta::get_by_id( $meta_id ) )        MP_::mp_die();
 452              if ( !MP_Mail_meta::update_by_id( $meta_id , $key, $value ) )    MP_::mp_die( 1 );
 453  
 454              $response = array( 'old_id'     => $meta_id, 'position'     => 0 );
 455          }
 456  
 457          $meta = MP_Mail_meta::get_by_id( $meta_id );
 458          $object_id = ( int ) $meta->mp_mail_id;
 459          $meta = get_object_vars( $meta );
 460  
 461          $response = array_merge( $response, array( 'what' => 'write-autoresponder', 'id' => $meta_id, 'data' => self::meta_box_autoresponder_row( MP_Autoresponder::get_term_meta_id( $meta_id ), $c ), 'supplemental' => array( 'mail_id' => $object_id ) ) );
 462  
 463          $x = new WP_Ajax_Response( $response );
 464  
 465          $x->send();
 466  
 467      }
 468  
 469  	public static function add_meta( $mail_id )
 470      {
 471          $post_ = filter_input_array( INPUT_POST );
 472  
 473          $mail_id = ( int ) $mail_id;
 474          if ( isset( $post_['autoresponder']['schedule'] ) ) foreach ( $post_['autoresponder']['schedule'] as $k => $v ) if ( $v <10 ) $post_['autoresponder']['schedule'][$k] = '0' . $v;
 475  
 476          $meta_key     = isset( $post_['autoresponderselect'] ) ? '_MailPress_autoresponder_' . trim( $post_['autoresponderselect'] ) : '';
 477          $meta_value= isset( $post_['autoresponder']['schedule'] ) ? $post_['autoresponder']['schedule'] : array();
 478  
 479          if ( empty( $meta_value ) || empty ( $meta_key ) ) return false;
 480  
 481          return MP_Mail_meta::add( $mail_id, $meta_key, $meta_value );
 482      }
 483  
 484  	public static function mp_action_delete_wa()
 485      {
 486          if ( !current_user_can( 'MailPress_manage_autoresponders' ) )    MP_::mp_die( '-1' );
 487  
 488          $id = isset( MP_WP_Ajax::$pst_['id'] )? ( int ) MP_WP_Ajax::$pst_['id'] : 0;
 489  
 490          if ( !$meta = MP_Mail_meta::get_by_id( $id ) )                 MP_::mp_die( '1' );
 491          if ( MP_Mail_meta::delete_by_id( $meta->meta_id ) )            MP_::mp_die( '1' );
 492          MP_::mp_die( '0' );
 493      }
 494  }
 495  new MailPress_autoresponder();
 496  }


Generated: Mon Jan 28 00:07:10 2019 Cross-referenced by PHPXref 0.7.1