Not logged in. · Lost password · Registration disabled

All posts by NasheedsNow.com (1)

topic: Auto Subscribe when new user registing  in the forum: Files & Mods / Datein & Mods
NasheedsNow.com #1
Member since Mar 2009 · 1 post
Group memberships: Mitglieder
Show profile · Link to this post
Quote by syfr12 on 2009-01-06, 17:00:
give admin an option "Auto Subscribe When New User Registing" ,Choice "yes" ,the new user will auto subscribe


change :

1 in install.php add
add_option('post_notification_auto_subscribe', 'yes','Auto Subscribe when regist new user', 'no'); 
2 in admin_settings.php
  2.1 under line  <h4> <?php  _e('Technical', 'post_notification');  ?></h4>
      add:
    <tr class="alternate">
        <th style="text-align:right;padding-right:10px;"><?php _e('Auto Subscribe When New User Registing:', 'post_notification'); ?></th>
        <td>
            <select name="auto_subscribe" >
              <option value="no"  <?php  echo $auto_subscribeN; ?> > <?php  _e('No', 'post_notification'); ?></option>
              <option value="yes" <?php  echo $auto_subscribeY; ?> > <?php  _e('Yes', 'post_notification'); ?></option>
            </select>   
        </td>
    </tr> 

   2.2 in function post_notification_admin_sub()
      add:


    update_option('post_notification_auto_subscribe', $_POST['auto_subscribe']);

    if(get_option('post_notification_auto_subscribe') == 'yes') //rather have No
        $auto_subscribeY = $selected;
    else
        $auto_subscribeN = $selected;

3 in post_notification.php
  3.1 in  function post_notification_gui_init() add:
      add_action('user_register', 'post_notification_register'); 
  3.2 add function  post_notification_register
///  Auto Subscribe for new wordpress user registion
function post_notification_register($user_id) {
    global $wpdb;     
   
    if ($user_id == 0 ) { $user_id = get_userdatabylogin($_POST['user_login']); }
  
    $auto_subscribe =  get_option('post_notification_auto_subscribe') ;
    if ($auto_subscribe == "no") { return; }
   
    if (0 == $user_id) { $user_id = (int) func_get_arg( 0 ); }
    if (0 == $user_id) { return; }      
      
        $t_emails = $wpdb->prefix . 'post_notification_emails';
        $t_cats = $wpdb->prefix . 'post_notification_cats';
       
          
        $user = get_userdata($user_id);
        $addr = $user->user_email ;
        $gets_mail = 1;
        $now = post_notification_date2mysql();
       
        $mid = $wpdb->get_var("SELECT id FROM $t_emails WHERE email_addr = '$addr'");
        if (!$mid) {
            $wpdb->query(
                    "INSERT " . $t_emails .
                    " (email_addr, gets_mail, last_modified, date_subscribed) " .
                    " VALUES ('$addr', '$gets_mail', '$now', '$now')");       
            $mid = $wpdb->get_var("SELECT id FROM $t_emails WHERE email_addr = '$addr'");        
        }
       
        $selected_cats = explode(',', get_option('post_notification_selected_cats'));
       
        foreach($selected_cats as $cat){
            if(is_numeric($cat)){ //Security
                    if(!$wpdb->get_var("SELECT id FROM $t_cats WHERE id = $mid AND cat_id = $cat")){
                        $wpdb->query("INSERT INTO $t_cats (id, cat_id) VALUES($mid, $cat)");
                    }
            }
        }
    
}

Thank you so much! This is just what I was looking for and it worked  :-D ! Cheers.

Hmm, it makes me wonder whether it is possible to autosubscribe existing registered users using a mod? Thanks again!
Close Smaller – Larger + Reply to this post:
Special characters:
Special queries
Go to forum