WordPress.org

Plugin Directory

Changeset 609917


Ignore:
Timestamp:
10/09/12 08:14:48 (19 months ago)
Author:
picklewagon
Message:

refactor code to send approval and denial emails so that they can easily be disabled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-user-approve/trunk/new-user-approve.php

    r609906 r609917  
    6767        add_action( 'new_user_approve_deny_user', array( $this, 'delete_new_user_approve_transient' ), 11 ); 
    6868        add_action( 'deleted_user', array( $this, 'delete_new_user_approve_transient' ) ); 
     69        add_action( 'new_user_approve_user_denied', array( $this, 'send_denial_message' ) ); 
     70        add_action( 'new_user_approve_user_approved', array( $this, 'send_approval_message' ) ); 
    6971 
    7072        // Filters 
     
    291293     */ 
    292294    public function approve_user() { 
    293         global $wpdb; 
    294  
    295295        $user_id = (int) $_GET['user']; 
    296296        $user = new WP_User( $user_id ); 
    297297 
     298        // change usermeta tag in database to approved 
     299        update_user_meta( $user->ID, 'pw_user_status', 'approved' ); 
     300         
     301        do_action( 'new_user_approve_user_approved', $user ); 
     302    } 
     303 
     304    /** 
     305     * Send a message to the user upon approval 
     306     *  
     307     * @param object $user WP_User object 
     308     */ 
     309    public function send_approval_email( $user ) { 
    298310        $bypass_password_reset = apply_filters( 'new_user_approve_bypass_password_reset', false ); 
    299311         
     
    310322            $wpdb->update($wpdb->users, $data, $where, array( '%s', '%s' ), array( '%d' ) ); 
    311323        } 
    312  
     324         
    313325        wp_cache_delete( $user->ID, 'users' ); 
    314326        wp_cache_delete( $user->user_login, 'userlogins' ); 
    315  
     327         
    316328        // send email to user telling of approval 
    317329        $user_login = stripslashes( $user->user_login ); 
    318330        $user_email = stripslashes( $user->user_email ); 
    319  
     331         
    320332        // format the message 
    321333        $message  = sprintf( __( 'You have been approved to access %s', $this->plugin_id ), get_option( 'blogname' ) ) . "\r\n"; 
     
    325337        } 
    326338        $message .= get_option( 'siteurl' ) . "/wp-login.php\r\n"; 
    327  
     339         
    328340        $message = apply_filters( 'new_user_approve_approve_user_message', $message, $user ); 
    329341         
     
    332344         
    333345        // send the mail 
    334         @wp_mail( $user_email, $subject, $message ); 
    335  
    336         // change usermeta tag in database to approved 
    337         update_user_meta( $user->ID, 'pw_user_status', 'approved' ); 
    338          
    339         do_action( 'new_user_approve_user_approved', $user ); 
    340     } 
    341  
     346        wp_mail( $user_email, $subject, $message ); 
     347    } 
     348     
    342349    /** 
    343350     * Admin denial of user 
     
    347354        $user = new WP_User( $user_id ); 
    348355 
     356        // change usermeta tag in database to denied 
     357        update_user_meta( $user->ID, 'pw_user_status', 'denied' ); 
     358         
     359        do_action( 'new_user_approve_user_denied', $user ); 
     360    } 
     361 
     362    /** 
     363     * Send the denial message to the user 
     364     *  
     365     * @param object $user WP_User object 
     366     */ 
     367    public function send_denial_message( $user ) { 
    349368        // send email to user telling of denial 
    350369        $user_email = stripslashes( $user->user_email ); 
    351  
     370         
    352371        // format the message 
    353372        $message = sprintf( __( 'You have been denied access to %s', $this->plugin_id ), get_option( 'blogname' ) ); 
     
    356375        $subject = sprintf( __( '[%s] Registration Denied', $this->plugin_id ), get_option( 'blogname' ) ); 
    357376        $subject = apply_filters( 'new_user_approve_deny_user_subject', $subject ); 
    358  
     377         
    359378        // send the mail 
    360         @wp_mail( $user_email, $subject, $message ); 
    361  
    362         // change usermeta tag in database to denied 
    363         update_user_meta( $user->ID, 'pw_user_status', 'denied' ); 
    364          
    365         do_action( 'new_user_approve_user_denied', $user ); 
    366     } 
    367  
     379        wp_mail( $user_email, $subject, $message ); 
     380    } 
     381     
    368382    /** 
    369383     * Display a message to the user after they have registered 
Note: See TracChangeset for help on using the changeset viewer.