Beispiel #1
0
" title="<?php 
printf(__('Permalink to %s', 'startbox'), esc_html(get_the_title(), 1));
?>
" rel="bookmark"><?php 
the_title();
?>
</a></h2>
		<div class="entry-meta">
			By <?php 
the_author_posts_link();
?>
 | <i class="fa fa-graduation-cap"></i> <?php 
echo count($class->getStudents()) . " " . _n("Student", "Students", count($class->getStudents()));
?>
			<?php 
if ($class->isTeacher()) {
    ?>
 | <a href="/start-a-class/?edit=<?php 
    echo $class->id;
    ?>
">Edit</a><?php 
}
?>
		</div><!-- .entry-meta -->
	</div><!-- .entry-header -->

	<?php 
do_action('sb_before_post_content');
?>

	<div class="entry-content">
Beispiel #2
0
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

/**
 * 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