Posted by Simon Goodchild at January 23rd, 2012
This set of tutorials will cover how to use the wps_mail class (and the others) to create a custom WP Symposium mail page template. The classes can also be used to create WPS plugins and widgets.
So that I don’t need to duplicate information, I’ll assume that you’ve worked through the profile page template tutorial.
Unfortunately I may not have time to respond personally to queries on this tutorial (I’ll try!), but there is an area of the forum for questions (which would be better so answers are available to others to see and learn from).
Let’s get started
So this first part is going to use the wps_mail class to retrieve and display mail for the currently logged in user, just to make sure the basics are working. From the tutorials/mail_page_template folder in the wp-symposium plugin folder you will find the tutorial pages as they develop, start by using wps_mail_page_1.php - copy that file, and wps_mail_page.css into your theme folder, creating a page (mine is called AA Mail) and selecting the new page template you copied across.
We are going to include the wps class and the wps_mail class as follows (profile page tutorial provides more information on this, please read that tutorial for more info):
require_once(ABSPATH.'wp-content/plugins/wp-symposium/class.wps.php'); require_once(ABSPATH.'wp-content/plugins/wp-symposium/class.wps_mail.php');
$wps = new wps(); $wps_mail = new wps_mail(); // defaults to current logged in user
Telling WP Symposium about your new mail page
As in the profile page template, we need to set WPS mail page location to our new page (mine is at /aa-mail), see the profile page template tutorial if you need to remind yourself why.
$wps->set_mail_url('/aa-mail');
Finally, we will include the CSS file that should be sitting in your theme folder (your path may be different):
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/wps_mail_page.css" />
Getting the contents of the users inbox
$inbox = $wps_mail->get_inbox();
This will set $inbox to the current users inbox contents.
If you wanted to use a different user, pass their ID as a parameter.
$inbox will be an array, so we can then loop through showing the various fields passed back.
So we simply use a PHP loop to display the basic mail information for each returned.
if ($inbox) {
foreach($inbox as $mail) {
echo 'From: '.$mail['display_name'].'<br />';
echo 'Subject: '.$mail['mail_subject'].'<br />';
echo 'Date: '.$mail['mail_sent'].'<br />';
echo 'Message: '.$mail['mail_message'].'<br /><br />';
}
} else {
echo "You have no mail in your inbox.";
}
Even with basic PHP know-how you should hopefully see what’s happening – play around and you can change the format (although we will do that in part 2…).
There are other parameters you can pass:
get_inbox(count, start_from, avatar_size, search_term, order, message_length)
We will cover the other parameters as we work through the tutorial, but feel free to play around with them! For example, to return a maximum of 20 mail messages (20), starting from the first one (0), an avatar of 40×40 pixels (40), no search term (“”), most recent first (true) and the first 75 characters of the message (75):
get_inbox(20, 0, 40, "", true, 75)
Nifty! Part 2 makes it look a little nicer…
Category: Tutorials

Post Tagged with 


Saving...
Leave a Reply