function render($args = null) { $answered = !empty($args['answered']) ? $args['answered'] : array(); $view = learn_press_locate_template('question/types/single-choice.php'); include $view; }
/** * redirect to plugin's template if needed * * @author TuNN * @return void */ function learn_press_template_include($template) { global $post_type; do_action('learn_press_before_template_redirect', $post_type); if (!empty($post_type)) { if (false !== strpos($post_type, 'lpr_')) { $lpr_post_type = str_replace('lpr_', '', $post_type); $template = ''; if (is_archive()) { $template = learn_press_locate_template('archive', $lpr_post_type); } else { $template = learn_press_locate_template('single', $lpr_post_type); } // ensure the template loaded otherwise load default template //if ( $template && file_exists( $template ) ) exit(); } } return $template; }
if ($title) { ?> <h3><?php echo $title; ?> </h3> <?php } ?> <?php do_action('learn_press_quiz_questions_before_questions_loop'); ?> <ul> <?php $index = 0; $question_loop_template = learn_press_locate_template('quiz/loop.php'); $current_question = learn_press_get_current_question(); $quiz_completed = learn_press_user_has_completed_quiz(); if (!empty($question_list)) { foreach ($question_list as $question_id => $question_options) { $index++; $question_title = get_the_title($question_id); $question = get_post($question_id); if ($current_question && $current_question == $question_id && !$quiz_completed) { $current = true; } else { $current = false; } // include to ensure that sub-template can be load all variables from here require $question_loop_template; }
/** * Display a form let the user can be join as a teacher */ static function become_teacher_form($atts) { global $current_user; $user = new WP_User($current_user->ID); if (in_array(LP()->teacher_role, $user->roles)) { return __("You are a teacher now", 'learn_press'); } if (!is_user_logged_in()) { return __("Please login to fill out this form", 'learn_press'); } if (!empty($_REQUEST['become-a-teacher-send'])) { return __('Your request has been sent! We will get in touch with you soon!', 'learn_press'); } get_currentuserinfo(); $atts = shortcode_atts(array('method' => 'post', 'action' => '', 'title' => __('Become a Teacher', 'learn_press'), 'description' => __('Fill out your information and send to us to become a teacher', 'learn_press'), 'submit_button_text' => __('Submit', 'learn_press')), $atts); $fields = array('bat_name' => array('title' => __('Name', 'learn_press'), 'type' => 'text', 'placeholder' => __('Your name', 'learn_press'), 'def' => $current_user->display_name), 'bat_email' => array('title' => __('Email', 'learn_press'), 'type' => 'email', 'placeholder' => __('Your email address', 'learn_press'), 'def' => $current_user->user_email), 'bat_phone' => array('title' => __('Phone', 'learn_press'), 'type' => 'text', 'placeholder' => __('Your phone number', 'learn_press'))); $fields = apply_filters('learn_press_become_teacher_form_fields', $fields); ob_start(); $form_template = learn_press_locate_template('global/become-teacher-form.php'); if (file_exists($form_template)) { require $form_template; } $html = ob_get_clean(); ob_start(); ?> <script> $('form[name="become_teacher_form"]').submit(function () { var $form = $(this); $form.siblings('.error-message').fadeOut('fast', function () { $(this).remove() }); if ($form.triggerHandler('become_teacher_send') !== false) { $.ajax({ url : $form.attr('action'), data : $form.serialize(), dataType: 'html', type : 'post', success : function (code) { if (code.indexOf('<!-- LP_AJAX_START -->') >= 0) code = code.split('<!-- LP_AJAX_START -->')[1]; if (code.indexOf('<!-- LP_AJAX_END -->') >= 0) code = code.split('<!-- LP_AJAX_END -->')[0]; var result = $.parseJSON(code); return; if (!result.error.length) { var url = window.location.href; if (url.indexOf('?') != -1) url += '&' else url += '?'; url += 'become-a-teacher-send=1'; window.location.href = url; } else { $.each(result.error, function () { $('<p class="error-message">' + this + '</p>').insertBefore($form); }) } } }); } return false; }); </script> <?php $js = preg_replace('!</?script>!', '', ob_get_clean()); //$js = preg_replace( '!\s+|\t+!', ' ', $js ); learn_press_enqueue_script($js); return $html; }
/** * Get other templates passing attributes and including the file. * * @param string $template_name * @param array $args (default: array()) * @param string $template_path (default: '') * @param string $default_path (default: '') * * @return void */ function learn_press_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { if ($args && is_array($args)) { extract($args); } $located = learn_press_locate_template($template_name, $template_path, $default_path); if (!file_exists($located)) { _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); return; } // Allow 3rd party plugin filter template file from their plugin $located = apply_filters('learn_press_get_template', $located, $template_name, $args, $template_path, $default_path); do_action('learn_press_before_template_part', $template_name, $template_path, $located, $args); include $located; do_action('learn_press_after_template_part', $template_name, $template_path, $located, $args); }
/** * Display course curriculum */ function learn_press_course_curriculum() { $curriculum = learn_press_get_course_curriculum(); if ($tpl = learn_press_locate_template('course/curriculum.php')) { require $tpl; } }