class My_Job_Manager_Custom_Alerts {
    
    /** 
     * Constructor
     */
    public function __construct() {
        add_action( 'publish_to_expired', array( $this, 'expired_post' ) );
    }
        
    /**
     * Expired post triggered by publish_to_expired hook
     * @param $post post object
     */
    public function expired_post( $post ) {
        if ( 'job_listing' == $post->post_type ) {
            $send_to = '';
            $email = get_post_meta( $post->ID, '_application', true );
            $user    = $post->post_author;
            
            if ( is_email( $email ) ) {
                $send_to = $email;
            } elseif ( $user ) {
                $user    = get_user_by( 'id', $user );
                $send_to = $user->user_email;
            }
            
            if ( ! $send_to )
                return;
    
            $message = sprintf( "Hello,\n\nThe job ā€œ%sā€ which you posted on %s has just expired and will no longer be visible.\n\nTo check your other active listings, or post a new job listing, please visit your dashboard.", esc_html( $post->post_title ), esc_html( get_bloginfo( 'name' ) ) );
        
            wp_mail( $send_to, 'Your job listing has expired', $message );
        }
    }
    
}

new My_Job_Manager_Custom_Alerts();

 

Geef een reactie 0