Subscribe2 widget with choosing categories?

Is it possible to specify the category people can choose to subscribe to in the Subscribe2 (WordPress Plugin) widget?

Related posts

Leave a Reply

3 comments

  1. From quick look at plugin’s description and code there doesn’t seem to be such option. Category management mostly refers to controlling them in admin area.

    Also see Plugin’s FAQ – it lists its’ community support page at GetSatisfaction and option to receive paid support from developer.

  2. just been looking into this, hope this helps.
    It’s early dev, so not fully gone through it and tested, but seems to work, so hopefully it may help you in the right direction (well, one direction anyway)..

    How it works: it basically strips the cat entries from the user_meta, then re-adds them based on the selections. It hooks into the user registration process so this may screw up any other user registrations! (my site is only for registering through Subscribe2 so i haven’t bothered isolating it to this)

    in the register_form.php in your theme (copy the one from the template dir in plugins into your theme)

    add in a cat list:

    <?php
    // preselect categories
    
    echo '<p>Select Categories</p>';
    $categories=get_categories();
    foreach($categories as $category) {
        echo "<input type='checkbox' name='cats[]' value='$category->term_id' />";
        echo $category->cat_name;
        echo '<br>';
    }
    
    ?>
    

    then in your functions, add:

    ///////////////////////////////////////////////////////////////////
    // allow preselection of categories on signup through Subscribe2 //
    ///////////////////////////////////////////////////////////////////
    
    add_action( 'user_register', 'subscribe2_registration_save', 10, 1 );
    
    function subscribe2_registration_save( $user_id ) {
    
    global $wpdb;
    
    // delete the cats to start with
    $wpdb->query("DELETE FROM wp_apb_usermeta WHERE user_id = '".$user_id."' AND meta_key LIKE 's2_cat%'");
    
    // add new cats
    if(isset($_POST['cats'])){
        $cats = $_POST['cats'];
        $str = '';
        foreach($cats as $cat){
            $str .= $cat.',';
            $query = "INSERT INTO wp_apb_usermeta (user_id,meta_key,meta_value) VALUES ('".$user_id."','s2_cat".$cat."','".$cat."')";
            //echo ('<pre>' . print_r($query,true) . '</pre>');
            $wpdb->query($query);
        }
        $str = rtrim($str, ",");
    }
    
    // update the subscribed list
    $query = "UPDATE wp_apb_usermeta SET meta_value = '".$str."' WHERE meta_key = 's2_subscribed' AND user_id = '".$user_id."'";
    //echo ('<pre>' . print_r($query,true) . '</pre>');
    $wpdb->query($query);
    
    
    //echo('<hr>');
    //echo ('<pre>' . print_r($results,true) . '</pre>');
    //echo('<hr>');
    //echo ('<pre>' . print_r($_POST,true) . '</pre>');
    //echo('<hr>');
    //die ('<pre>' . print_r($user_id,true) . '</pre>');
    
    }