コード例 #1
0
 public function get_return_url($order = null)
 {
     if ($order) {
         $return_url = $order->get_checkout_order_received_url();
     } else {
         $return_url = learn_press_get_endpoint_url('lp-order-received', '', learn_press_get_page_link('checkout'));
     }
     return apply_filters('learn_press_get_return_url', $return_url, $order);
 }
コード例 #2
0
 static function auto_shortcode($template)
 {
     if (is_page()) {
         global $post, $wp_query, $wp;
         $page_id = $wp_query->queried_object_id;
         if ($page_id == learn_press_get_page_id('checkout')) {
             if (!preg_match('/\\[learn_press_checkout\\s?(.*)\\]/', $post->post_content)) {
                 $post->post_content .= '[learn_press_checkout]';
             }
         } elseif ($page_id == learn_press_get_page_id('profile')) {
             if (empty($wp->query_vars['user'])) {
                 $current_user = wp_get_current_user();
                 if (!empty($current_user->user_login)) {
                     wp_redirect(learn_press_get_endpoint_url('', $current_user->user_login, learn_press_get_page_link('profile')));
                     die;
                 } else {
                     learn_press_404_page();
                 }
             } else {
                 $query = array();
                 parse_str($wp->matched_query, $query);
                 if ($query) {
                     $profile_endpoints = (array) LP()->settings->get('profile_endpoints');
                     $endpoints = array_keys($profile_endpoints);
                     foreach ($query as $k => $v) {
                         if ($k == 'view') {
                             if (!$v) {
                                 $v = reset($profile_endpoints);
                             }
                             if (!in_array($v, apply_filters('learn_press_profile_tab_endpoints', $profile_endpoints))) {
                                 learn_press_404_page();
                             }
                         }
                         if (!empty($v)) {
                             $wp->query_vars[$k] = $v;
                         }
                     }
                 }
             }
             if (!preg_match('/\\[learn_press_profile\\s?(.*)\\]/', $post->post_content)) {
                 $post->post_content .= '[learn_press_profile]';
             }
         } elseif ($page_id == learn_press_get_page_id('cart')) {
             if (!preg_match('/\\[learn_press_cart\\s?(.*)\\]/', $post->post_content)) {
                 $post->post_content .= '[learn_press_cart]';
             }
         }
     }
     return $template;
 }
コード例 #3
0
function learn_press_edit_admin_bar()
{
    global $wp_admin_bar;
    if (($profile = learn_press_get_page_id('profile')) && get_post_type($profile) == 'page' && LP()->settings->get('admin_bar_link') == 'yes') {
        $text = LP()->settings->get('admin_bar_link_text');
        $course_profile = array();
        $course_profile['id'] = 'course_profile';
        $course_profile['parent'] = 'user-actions';
        $course_profile['title'] = $text ? $text : get_the_title($profile);
        $course_profile['href'] = learn_press_get_page_link('profile');
        $course_profile['meta']['target'] = LP()->settings->get('admin_bar_link_target');
        $wp_admin_bar->add_menu($course_profile);
    }
    $current_user = wp_get_current_user();
    // add `be teacher` link
    if (in_array(LP()->teacher_role, $current_user->roles) || in_array('administrator', $current_user->roles)) {
        return;
    }
    //if ( !class_exists( 'LP_Admin_Settings' ) ) return;
    /**
     * $settings = LP_Admin_Settings::instance( 'general' );
     * if ( $settings->get( 'instructor_registration' ) ) {
     * $be_teacher           = array();
     * $be_teacher['id']     = 'be_teacher';
     * $be_teacher['parent'] = 'user-actions';
     * $be_teacher['title']  = __( 'Become An Instructor', 'learn_press' );
     * $be_teacher['href']   = '#';
     * $wp_admin_bar->add_menu( $be_teacher );
     * }*/
}
コード例 #4
0
            do_action('learn_press_before_purchase_button');
            ?>
				<input type="hidden" name="_wp_http_referer" value="<?php 
            echo get_the_permalink();
            ?>
" />
				<input type="hidden" name="add-course-to-cart" value="<?php 
            echo $course->id;
            ?>
" />
				<button class="button purchase-button"><?php 
            echo $purchase_button_text;
            ?>
</button>
				<a class="button view-cart-button" href="<?php 
            echo learn_press_get_page_link('cart');
            ?>
"><?php 
            esc_html_e('View cart', 'learn_press');
            ?>
</a>
				<?php 
            do_action('learn_press_after_purchase_button');
            ?>
			</form>

		<?php 
        }
        ?>

	<?php 
コード例 #5
0
 /**
  * Get checkout order success url
  *
  * @return mixed
  */
 public function get_checkout_order_received_url()
 {
     $received_url = learn_press_get_endpoint_url('order-received', $this->id, learn_press_get_page_link('checkout'));
     $received_url = add_query_arg('key', $this->order_key, $received_url);
     return apply_filters('learn_press_get_checkout_order_received_url', $received_url, $this);
 }
コード例 #6
0
 /**
  * @return mixed
  */
 public function get_checkout_url()
 {
     $checkout_url = learn_press_get_page_link('checkout');
     return apply_filters('learn_press_get_checkout_url', $checkout_url);
 }
コード例 #7
0
 /**
  * Process checkout
  *
  * @throws Exception
  */
 function process_checkout()
 {
     try {
         if (strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
             return;
         }
         // Prevent timeout
         @set_time_limit(0);
         do_action('learn_press_before_checkout_process');
         $success = true;
         if (LP()->cart->is_empty()) {
             learn_press_send_json(array('result' => 'success', 'redirect' => learn_press_get_page_link('checkout')));
         }
         if (empty($_REQUEST['payment_method'])) {
             $success = false;
             learn_press_add_notice(__('Please select a payment method', 'learn_press'), 'error');
         } else {
             $this->payment_method = $_REQUEST['payment_method'];
             if ($this->checkout_fields) {
                 foreach ($this->checkout_fields as $name => $field) {
                     if (!apply_filters('learn_press_checkout_validate_field', true, array('name' => $name, 'text' => $field), $this)) {
                         $success = false;
                     }
                 }
             }
             if (isset($this->checkout_fields['user_login']) && isset($this->checkout_fields['user_password'])) {
                 $creds = array();
                 $creds['user_login'] = $_POST['user_login'];
                 $creds['user_password'] = $_POST['user_password'];
                 $creds['remember'] = true;
                 $user = wp_signon($creds, false);
                 if (is_wp_error($user)) {
                     learn_press_add_notice($user->get_error_message(), 'error');
                     $success = false;
                 }
             }
             LP()->session->set('chosen_payment_method', $this->payment_method);
         }
         if ($success && LP()->cart->needs_payment()) {
             // Payment Method
             $available_gateways = LP_Gateways::instance()->get_available_payment_gateways();
             if (!isset($available_gateways[$this->payment_method])) {
                 $this->payment_method = '';
                 learn_press_add_notice(__('Invalid payment method.', 'learn_press'), 'error');
             } else {
                 $this->payment_method = $available_gateways[$this->payment_method];
                 $success = $this->payment_method->validate_fields();
             }
         } else {
             $available_gateways = array();
         }
         $order_id = $this->create_order();
         if ($success && $this->payment_method && $order_id) {
             LP()->session->order_awaiting_payment = $order_id;
             // Process Payment
             $result = $this->payment_method->process_payment($order_id);
             $success = !empty($result['result']) ? $result['result'] == 'success' : false;
             // Redirect to success/confirmation/payment page
             if ($success) {
                 $result = apply_filters('learn_press_payment_successful_result', $result, $order_id);
                 //LP()->cart->empty_cart();
                 if (is_ajax()) {
                     learn_press_send_json($result);
                 } else {
                     wp_redirect($result['redirect']);
                     exit;
                 }
             }
         }
     } catch (Exception $e) {
         if (!empty($e)) {
             learn_press_add_notice($e->getMessage(), 'error');
         }
         $success = false;
     }
     $error_messages = '';
     if (!$success) {
         ob_start();
         learn_press_print_notices();
         $error_messages = ob_get_clean();
     }
     $result = array('result' => $success ? 'success' : 'fail', 'messages' => $error_messages, 'redirect' => '');
     return $result;
 }
コード例 #8
0
ファイル: tabs.php プロジェクト: hernanimattos/LearnPress
        ?>
" data-slug="<?php 
        echo add_query_arg('', '', learn_press_get_page_link('profile') . $user->user_login) . '/' . $key;
        ?>
"><?php 
        echo apply_filters('learn_press_profile_' . $key . '_tab_title', esc_html($tab['title']), $key);
        ?>
</a>
			<?php 
    } else {
        ?>
			<a href="<?php 
        echo add_query_arg(array('user' => $user->user_login, 'tab' => $key), learn_press_get_page_link('profile'));
        ?>
" data-slug="<?php 
        echo add_query_arg('', '', learn_press_get_page_link('profile') . $user->user_login) . '/' . $key;
        ?>
"><?php 
        echo apply_filters('learn_press_profile_' . $key . '_tab_title', esc_html($tab['title']), $key);
        ?>
</a>
			<?php 
    }
    ?>
		</li>
	<?php 
}
?>
</ul>
<div class="user-profile-tabs learn-press-tabs-wrapper-x">
	<?php 
コード例 #9
0
 function get_paypal_args($order)
 {
     $this->prepare_line_items();
     $user = learn_press_get_current_user();
     $nonce = wp_create_nonce('learn-press-paypal-nonce');
     $custom = array('order_id' => $order->id, 'order_key' => $order->order_key);
     $args = array_merge(array('cmd' => '_cart', 'business' => $this->paypal_email, 'no_note' => 1, 'currency_code' => learn_press_get_currency(), 'charset' => 'utf-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return' => esc_url($this->get_return_url($order)), 'cancel_return' => esc_url(learn_press_is_enable_cart() ? learn_press_get_page_link('cart') : get_site_url()), 'bn' => 'LearnPress_Cart', 'custom' => json_encode($custom), 'notify_url' => get_site_url() . '/?' . learn_press_get_web_hook('paypal') . '=1', 'email' => $user->user_email), $this->get_item_lines());
     //print_r($args);die();
     return apply_filters('learn_press_paypal_args', $args);
 }
コード例 #10
0
 function get_view_order_url()
 {
     global $wp_query;
     $view_order_url = learn_press_get_endpoint_url('view-order', $this->id, learn_press_get_page_link('profile'));
     //
     $user = learn_press_get_current_user();
     $view_order_endpoint = LP()->settings->get('profile_endpoints.profile-order-details');
     if (!$view_order_endpoint) {
         $view_order_endpoint = 'order-details';
     }
     if (get_option('permalink_structure')) {
         $view_order_url = learn_press_get_page_link('profile') . $user->user_login . '/' . $view_order_endpoint . '/' . $this->id;
     } else {
         $args = array('user' => $user->user_login);
         $args['view'] = $view_order_endpoint;
         if ($view_order_endpoint) {
             $args['id'] = $this->id;
         }
         $view_order_url = add_query_arg($args, learn_press_get_page_link('profile'));
     }
     return apply_filters('learn_press_view_order_url', $view_order_url, $this);
 }
コード例 #11
0
 static function do_ajax($var)
 {
     if (!defined('DOING_AJAX')) {
         define('DOING_AJAX', true);
     }
     LP_Gateways::instance()->get_available_payment_gateways();
     $result = false;
     switch ($var) {
         case 'checkout':
             $result = LP()->checkout->process_checkout();
             break;
         case 'enroll-course':
             $course_id = learn_press_get_request('enroll-course');
             if (!$course_id) {
                 throw new Exception(__('Invalid course', 'learn_press'));
             }
             $insert_id = LP()->user->enroll($course_id);
             $response = array('result' => 'fail', 'redirect' => apply_filters('learn_press_enroll_course_failure_redirect_url', get_the_permalink($course_id)));
             if ($insert_id) {
                 $response['result'] = 'success';
                 $response['redirect'] = apply_filters('learn_press_enrolled_course_redirect_url', get_the_permalink($course_id));
                 $message = apply_filters('learn_press_enrolled_course_message', sprintf(__('Congrats! You have enrolled <strong>%s</strong>', 'learn_press'), get_the_title($course_id)), $course_id, LP()->user->id);
                 learn_press_add_notice($message);
             } else {
                 $message = apply_filters('learn_press_enroll_course_failed_message', sprintf(__('Sorry! The course <strong>%s</strong> you want to enroll has failed! Please contact site\'s administrator for more information.', 'learn_press'), get_the_title($course_id)), $course_id, LP()->user->id);
                 learn_press_add_notice($message, 'error');
             }
             if (is_ajax()) {
                 learn_press_send_json($response);
             }
             if ($response['redirect']) {
                 wp_redirect($response['redirect']);
             }
             break;
         case 'checkout-login':
             $result = array('result' => 'success');
             ob_start();
             if (empty($_REQUEST['user_login'])) {
                 $result['result'] = 'fail';
                 learn_press_add_notice(__('Please enter username', 'learn_press'), 'error');
             }
             if (empty($_REQUEST['user_password'])) {
                 $result['result'] = 'fail';
                 learn_press_add_notice(__('Please enter password', 'learn_press'), 'error');
             }
             if ($result['result'] == 'success') {
                 $creds = array();
                 $creds['user_login'] = $_REQUEST['user_login'];
                 $creds['user_password'] = $_REQUEST['user_password'];
                 $creds['remember'] = true;
                 $user = wp_signon($creds, false);
                 if (is_wp_error($user)) {
                     $result['result'] = 'fail';
                     learn_press_add_notice($user->get_error_message(), 'error');
                 } else {
                     $result['redirect'] = learn_press_get_page_link('checkout');
                 }
             }
             learn_press_print_notices();
             $messages = ob_get_clean();
             if ($result['result'] == 'fail') {
                 $result['messages'] = $messages;
             }
             break;
         case 'add-to-cart':
             $result = LP()->cart->add_to_cart(learn_press_get_request('add-course-to-cart'));
     }
     learn_press_send_json($result);
 }
コード例 #12
0
<?php

global $wp_query;
learn_press_get_template('order/order-details.php', array('order' => $order));
?>
<a href="<?php 
echo learn_press_get_page_link('profile');
?>
"><?php 
_e('My Profile', 'learn_press');
?>
</a>
コード例 #13
0
ファイル: empty-cart.php プロジェクト: thonysmith/LearnPress
<?php

/**
 * @author  ThimPress
 * @package LearnPress/Templates
 * @version 1.0
 */
if (!defined('ABSPATH')) {
    exit;
}
learn_press_add_notice(__('Your cart is currently empty.', 'learn_press'), 'error');
learn_press_print_notices();
?>
<a href="<?php 
echo learn_press_get_page_link('courses');
?>
"><?php 
_e('Back to class', 'learn_press');
?>
</a>
コード例 #14
0
ファイル: info.php プロジェクト: hernanimattos/LearnPress
 * @author  ThimPress
 * @package LearnPress/Templates
 * @version 1.0
 */
if (!defined('ABSPATH')) {
    exit;
}
global $wp_query;
$tabs = learn_press_user_profile_tabs($user);
if (!empty($wp_query->query_vars['tab'])) {
    $current = $wp_query->query_vars['tab'];
} else {
    $tab_keys = array_keys($tabs);
    $current = reset($tab_keys);
}
$profile_link = learn_press_get_page_link('profile');
if (!empty($tabs) && !empty($tabs[$current])) {
    ?>
	<div class="user-info" id="learn-press-user-info">
		<div class="user-basic-info">
			<span class="user-avatar"><?php 
    echo get_avatar($user->ID);
    ?>
</span>
			<strong class="user-nicename"><?php 
    echo $user->user_nicename;
    ?>
</strong>
			<?php 
    if ($description = get_user_meta($user->id, 'description', true)) {
        ?>