function sp_edit_class_preheader() { if (!is_admin()) { global $post, $current_user; if (!empty($post->post_content) && strpos($post->post_content, "[sp_edit_class]") !== false) { /* Preheader operations here. */ //make sure user is logged in and a Teacher if (!pmpro_hasMembershipLevel(array(2, 3))) { wp_redirect('http://schoolpress.me/membership/'); exit; } //adding a class? if (!empty($_POST['edit'])) { $edit = intval($_POST['edit']); //get values $class_name = $_REQUEST['class_name']; $class_description = $_REQUEST['class_description']; $class_department = $_REQUEST['class_department']; $class_semester = $_REQUEST['class_semester']; if (!empty($_REQUEST['class_enrollment'])) { $class_enrollment = $_REQUEST['class_enrollment']; } else { $class_enrollment = ""; } //check values if (empty($class_name) || empty($class_description) || empty($class_department) || empty($class_semester)) { sp_setMessage("Please complete all fields.", "error"); } else { //adding or updating? if ($edit == -1) { //woah, let's make sure they are a teacher if (!pmpro_hasMembershipLevel(array(2, 3))) { die("You do not have permission to do this."); } //add class $class = new SPCLass(array('name' => $class_name, 'description' => $class_description, 'department' => $class_department, 'semester' => $class_semester, 'enrollment' => $class_enrollment)); if (!empty($class)) { //redirect to the class page wp_redirect(get_permalink($class->id)); exit; } else { sp_setMessage("Error adding class.", "error"); } } else { //update class $class = new SPClass($edit); //let's make sure they can edit this class if (!$class->isTeacher() && !current_user_can("manage_options")) { die("You do not have permission to do this."); } //okay update if (!empty($class) && $class->editClass($class_name, $class_description, $class_department, $class_semester, $class_enrollment)) { sp_setMessage("Class updated successfully.", "success"); } else { sp_setMessage("Error updating class.", "error"); } } } } //deleting a class? if (!empty($_REQUEST['delete'])) { $class_id = intval($_REQUEST['delete']); $class = new SPClass($class_id); //only teachers and admins can delete classes if ($class->isTeacher() || current_user_can("manage_options")) { $r = wp_delete_post($class->post->ID); wp_redirect(home_url("/my-classes/")); exit; } } } } }
<?php do_action('sb_before_post'); ?> <?php $class = new SPClass($post->ID); ?> <div id="post-<?php the_ID(); ?> " <?php post_class(); ?> > <div class="entry-header"> <?php if (has_post_thumbnail()) { ?> <a class="entry-photo" href="<?php the_permalink(); ?> " rel="bookmark" title="<?php echo esc_attr(get_the_title()); ?> "> <?php echo get_the_post_thumbnail($post->ID, 'class-thumb'); ?> </a>
<?php //process invites if (!empty($_REQUEST['invite_emails'])) { $invite_emails = $_REQUEST['invite_emails']; } else { $invite_emails = ""; } if (!empty($invite_emails)) { global $post; $class = new SPClass($post->ID); $invites = $class->addInvites($invite_emails); //return array(worked?, emails) //check for errors if (is_array($invites)) { //errror $invite_emails = implode("\n", $invites); sp_showMessage("There was an error adding the inviting the following emails: " . implode(", ", $invites), "error"); } else { $invite_emails = ""; sp_showMessage("Invites sent. <a href=\"" . get_permalink($post->ID) . "\">Return to Class</a>", "success"); } } //form ?> <form class="form" action="" method="post"> <input type="hidden" name="invite" value="1" /> <p class="pmpro_message pmpro_alert">Enter one email address per line to invite students to your class.</p> <div class="form-group"> <textarea class="form-control" rows="3" name="invite_emails" rows="5" cols="50"><?php echo esc_textarea($invite_emails);
static function template_redirect() { if (!function_exists('bbp_get_forum_id')) { return; } $forum_id = bbp_get_forum_id(); // Is this even a forum page at all? if (!bbp_is_forum_archive() && !empty($forum_id) && pmpro_bbp_is_forum()) { //is there a class for this forum? $class = new SPClass(); $class->getClassByForumID($forum_id); //class? make sure the current user is a member if (!empty($class->id) && !$class->isMember()) { wp_redirect(get_permalink($class->id)); exit; } } }
<?php /** * Template for displaying all single class posts **/ //get some vars global $post; $class = new SPClass($post->ID); $class->getStudents(); //inviting? if (!empty($_REQUEST['invite']) && !$class->isTeacher()) { //non-teacher trying to invite, redirect them back to class wp_redirect(get_permalink($post->ID)); exit; } //enrolling? if (!empty($_REQUEST['enroll'])) { //check for open enrollment if ($class->enrollment) { //enroll the current user $class->joinClass(); //redirect to this page to reset somet things wp_redirect(get_permalink($post->ID)); exit; } else { wp_die("This class does not have open enrollment."); } } get_header(); ?> <?php