function get_request_url($order_id) { $user = learn_press_get_current_user(); $nonce = wp_create_nonce('learn-press-paypal-nonce'); $order = LP_Order::instance($order_id); $custom = array('order_id' => $order_id, 'order_key' => $order->order_key); $query = array('cmd' => '_xclick', 'amount' => learn_press_get_cart_total(), 'quantity' => '1', 'business' => $this->paypal_email, 'item_name' => learn_press_get_cart_description(), 'return' => add_query_arg(array('learn-press-transaction-method' => 'paypal-standard', 'paypal-nonce' => $nonce), learn_press_get_cart_course_url()), 'currency_code' => learn_press_get_currency(), 'notify_url' => get_site_url() . '/?' . learn_press_get_web_hook('paypal-standard') . '=1', 'no_note' => '1', 'shipping' => '0', 'email' => $user->user_email, 'rm' => '2', 'cancel_return' => learn_press_get_cart_course_url(), 'custom' => json_encode($custom), 'no_shipping' => '1'); $query = apply_filters('learn_press_paypal_standard_query', $query); $paypal_payment_url = $this->paypal_url . '?' . http_build_query($query); return $paypal_payment_url; }
/** * Get all prerequisite courses that user need to pass before take a course * * @param bool $user_id * @param $course_id -=90a4 * * @return array|bool */ function learn_press_user_prerequisite_courses($user_id = false, $course_id) { if (!$user_id) { $user = learn_press_get_current_user(); $user_id = $user->ID; } $prerequisite = (array) get_post_meta($course_id, '_lpr_course_prerequisite', true); $courses = false; if ($prerequisite) { $course_completed = get_user_meta($user_id, '_lpr_course_completed', true); foreach ($prerequisite as $course) { if ($course && $course_completed) { if (!array_key_exists($course, $course_completed)) { if (!$courses) { $courses = array(); } $courses[] = $course; } } } } return $courses; }
* Template for displaying the enroll button * * @author ThimPress * @package LearnPress/Templates * @version 1.0 */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } global $course; if (!$course->is_required_enroll()) { return; } $course_status = learn_press_get_user_course_status(); $user = learn_press_get_current_user(); // only show enroll button if user had not enrolled $purchase_button_text = apply_filters('learn_press_purchase_button_text', __('Buy this course', 'learn_press')); $enroll_button_text = apply_filters('learn_press_enroll_button_loading_text', __('Enroll', 'learn_press')); if ($user->has('enrolled-course', $course->id)) { ?> <?php learn_press_display_message(__('You have already enrolled this course', 'learn_press')); ?> <?php } else { ?> <?php if ($user->has('purchased-course', $course->id)) {
/** * Log the messages between admin and instructor */ function post_review_message_box() { global $post; if (!learn_press_course_is_required_review($post->ID, get_current_user_id())) { //return; } $user = learn_press_get_current_user(); if ($user->is_instructor()) { ?> <div id="learn-press-review-message"> <h4><?php _e('Your message to Reviewer', 'learn_press'); ?> </h4> <textarea name="review_message" resize="none" placeholder="<?php _e('Enter some information here for reviewer', 'learn_press'); ?> "></textarea> <p> <label> <input type="checkbox" /> <?php _e('Notice to the admin for reviews', 'learn_press'); ?> </label> </p> <p class="description submitdelete"> <?php _e('Warning! Your course will become to Pending Review for admin reviews before it can be published when you update'); ?> </p> </div> <?php ob_start(); ?> <script type="text/javascript"> $('#post').submit(function (e) { var $review = $('textarea[name="review_message"]'); if (!($review.val() + '').length) { alert('<?php _e('Please write your message to Reviewer', 'learn_press'); ?> '); $review.focus(); return false; } }); </script> <?php learn_press_enqueue_script(strip_tags(ob_get_clean())); ?> <?php } else { if ($user->is_admin()) { ?> <div id="learn-press-review-message"> <h4><?php _e('Your message to Instructor', 'learn_press'); ?> </h4> <textarea name="review_message" resize="none" placeholder="<?php _e('Enter some information here for instructor. E.g: for reason why the course is rejected etc...', 'learn_press'); ?> "></textarea> <p> <label> <input type="checkbox" /> <?php _e('Notice to the instructor for changes', 'learn_press'); ?> </label> </p> </div> <?php ob_start(); ?> <script type="text/javascript"> $('#post').submit(function (e) { var $review = $('textarea[name="review_message"]', this), $status = $('select#post_status', this), clicked = $(':focus', this).attr('name'); if (clicked == 'save' && $status.val() != 'publish' && !($review.val() + '').length) { alert('<?php _e('Please write your message to Reviewer', 'learn_press'); ?> '); $review.focus(); return false; } }); </script> <?php learn_press_enqueue_script(strip_tags(ob_get_clean())); ?> <?php } } }
/** * Action when user press the "Take this course" button * * @param $course_id * @param string $payment_method */ function learn_press_take_course($course_id, $payment_method = '') { $user = learn_press_get_current_user(); $can_take_course = apply_filters('learn_press_before_take_course', true, $user->ID, $course_id, $payment_method); if ($can_take_course) { if (learn_press_is_free_course($course_id)) { if ($order_id = learn_press_add_transaction(array('method' => 'free', 'method_id' => '', 'status' => '', 'user_id' => $user->ID, 'transaction_object' => learn_press_generate_transaction_object()))) { learn_press_update_order_status($order_id, 'Completed'); learn_press_add_message('message', __('Congratulations! You have enrolled this course')); $json = array('result' => 'success', 'redirect' => ($confirm_page_id = learn_press_get_page_id('taken_course_confirm')) && get_post($confirm_page_id) ? learn_press_get_order_confirm_url($order_id) : get_permalink($course_id)); learn_press_send_json($json); } } else { if (has_filter('learn_press_take_course_' . $payment_method)) { $order = null; $result = apply_filters('learn_press_take_course_' . $payment_method, $order); $result = apply_filters('learn_press_payment_result', $result, $order); if (is_ajax()) { learn_press_send_json($result); exit; } else { wp_redirect($result['redirect']); exit; } } else { wp_die(__('Invalid payment method.', 'learn_press')); } } } else { learn_press_add_message('error', __('Sorry! You can not enroll to this course')); $json = array('result' => 'error', 'redirect' => get_permalink($course_id)); echo '<!--LPR_START-->' . json_encode($json) . '<!--LPR_END-->'; } }
/** * @param null $args * * @return mixed */ function learn_press_add_order($args = null) { //$method, $method_id, $status = 'Pending', $customer_id = false, $transaction_object = false, $args = array() $default_args = array('method' => '', 'method_id' => '', 'status' => '', 'user_id' => null, 'order_id' => 0, 'parent' => 0, 'transaction_object' => false); $args = wp_parse_args($args, $default_args); $order_data = array(); if ($args['order_id'] > 0 && get_post($args['order_id'])) { $updating = true; $order_data['ID'] = $args['order_id']; } else { $updating = false; $order_data['post_type'] = LP()->order_post_type; $order_data['post_status'] = !empty($args['status']) ? 'publish' : 'lpr-draft'; $order_data['ping_status'] = 'closed'; $order_data['post_author'] = ($order_owner_id = learn_press_cart_order_instructor()) ? $order_owner_id : 1; // always is administrator $order_data['post_parent'] = absint($args['parent']); } $order_title = array(); if ($args['method']) { $order_title[] = $args['method']; } if ($args['method_id']) { $order_title[] = $args['method_id']; } $order_title[] = date_i18n('Y-m-d-H:i:s'); $order_data['post_title'] = join('-', $order_title); if (empty($args['user_id'])) { $user = learn_press_get_current_user(); $args['user_id'] = $user->ID; } if (!$args['transaction_object']) { $args['transaction_object'] = learn_press_generate_transaction_object(); } if (!$updating) { if ($transaction_id = wp_insert_post($order_data)) { update_post_meta($transaction_id, '_learn_press_transaction_method', $args['method']); //update_post_meta( $transaction_id, '_learn_press_transaction_status', $status ); update_post_meta($transaction_id, '_learn_press_customer_id', $args['user_id']); update_post_meta($transaction_id, '_learn_press_customer_ip', learn_press_get_ip()); update_post_meta($transaction_id, '_learn_press_order_items', $args['transaction_object']); add_user_meta($args['user_id'], '_lpr_order_id', $transaction_id); } } else { $transaction_id = wp_update_post($order_data); } if ($transaction_id) { if (!empty($args['status'])) { learn_press_update_order_status($transaction_id, $args['status']); } update_post_meta($transaction_id, '_learn_press_transaction_method_id', $args['method_id']); if ($args['transaction_object']) { update_post_meta($transaction_id, '_learn_press_order_items', $args['transaction_object']); } if (!empty($args['status'])) { if ($updating) { return apply_filters('learn_press_update_transaction_success', $transaction_id, $args); } else { return apply_filters('learn_press_add_transaction_success', $transaction_id, $args); } } return $transaction_id; } return false; //do_action( 'learn_press_add_transaction_fail', $args );// $method, $method_id, $status, $customer_id, $transaction_object, $args ); }
/** * Redirect to question if user access to a quiz that user has started * * @param string * * @return string */ function learn_press_redirect_to_question($template) { global $post_type; if (is_single() && $post_type == LP()->quiz_post_type) { $user = learn_press_get_current_user(); $quiz_id = get_the_ID(); $quiz_status = $user->get_quiz_status($quiz_id); if ($quiz_status == 'started' && learn_press_get_quiz_time_remaining($user->id, $quiz_id) == 0 && get_post_meta($quiz_id, '_lpr_duration', true)) { $user->finish_quiz($quiz_id); $quiz_status = 'completed'; } if (learn_press_get_request('question') && $quiz_status == '') { wp_redirect(get_the_permalink($quiz_id)); } elseif ($quiz_status == 'started') { if (learn_press_get_request('question')) { } else { wp_redirect(learn_press_get_user_question_url($quiz_id)); die; } } elseif ($quiz_status == 'completed' && learn_press_get_request('question')) { wp_redirect(get_the_permalink($quiz_id)); die; } } return $template; }
<?php if (learn_press_get_current_user()->is('guest')) { return; } $course_id = learn_press_get_course_by_quiz(get_the_ID()); $passed = learn_press_user_has_passed_course($course_id); $result = learn_press_get_quiz_result(); ?> <div class="clearfix"></div> <?php if ($passed) { ?> <?php learn_press_message(sprintf(__('You have passed this course with %.2f%% of total', 'learn_press'), $result['mark_percent'] * 100)); } else { ?> <?php $passing_condition = learn_press_get_course_passing_condition($course_id); ?> <?php learn_press_message(sprintf(__('Sorry, you have not passed this course. This course required you pass %.2f%% but your result is only %.2f%%', 'learn_press'), $passing_condition, $result['mark_percent'] * 100), 'error'); }
function save_user_answer($answer, $quiz_id, $user_id = null) { if ($user_id) { $user = LP_User::get_user($user_id); } else { $user = learn_press_get_current_user(); } if ($progress = $user->get_quiz_progress($quiz_id)) { if (!isset($progress->question_answers)) { $question_answers = array(); } else { $question_answers = $progress->question_answers; } $question_answers[$this->id] = $answer; $question_answers = apply_filters('learn_press_update_user_question_answers', $question_answers, $progress->history_id, $user_id, $this, $quiz_id); learn_press_update_user_quiz_meta($progress->history_id, 'question_answers', $question_answers); } //do_action( 'learn_press_update_user_answer', $progress, $user_id, $this, $quiz_id ); }
static function search_questions() { global $wpdb; $quiz_id = learn_press_get_request('quiz_id'); $user = learn_press_get_current_user(); if (!$user->is_admin() && get_post_field('post_author', $quiz_id) != get_current_user_id()) { wp_die(__('You have not permission to access this section', 'learn_press')); } $term = (string) stripslashes(learn_press_get_request('term')); $exclude = array(); if (!empty($_GET['exclude'])) { $exclude = array_map('intval', $_GET['exclude']); } $added = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT question_id\n\t\t\t\t\tFROM {$wpdb->prefix}learnpress_quiz_questions\n\t\t\t\t\tWHERE %d\n\t\t\t\t", 1)); if ($added) { $exclude = array_merge($exclude, $added); $exclude = array_unique($exclude); } $args = array('post_type' => array('lp_question'), 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'parent title', 'exclude' => $exclude); if (!$user->is_admin()) { $args['author'] = $user->id; } if ($term) { $args['s'] = $term; } $posts = get_posts($args); $found_questions = array(); if (!empty($posts)) { foreach ($posts as $post) { $found_questions[$post->ID] = !empty($post->post_title) ? $post->post_title : sprintf('(%s)', __('Untitled', 'learn_press')); } } ob_start(); if ($found_questions) { foreach ($found_questions as $id => $question) { printf(' <li class="" data-id="%1$d" data-type="" data-text="%2$s"> <label> <input type="checkbox" value="%1$d"> <span class="lp-item-text">%2$s</span> </label> </li> ', $id, $question); } } else { echo '<li>' . __('No question found', 'learn_press') . '</li>'; } $response = array('html' => ob_get_clean(), 'data' => $found_questions, 'args' => $args); learn_press_send_json($response); }
function start_quiz() { $quiz_id = !empty($_REQUEST['quiz_id']) ? absint($_REQUEST['quiz_id']) : 0; if (!$quiz_id) { learn_press_send_json(array('result' => 'error', 'message' => __('The quiz ID is empty', 'learn_press'))); } $quiz = LP_Quiz::get_quiz($quiz_id); if (!$quiz->id || $quiz->id != $quiz_id) { learn_press_send_json(array('result' => 'error', 'message' => __('Something is wrong! Please try again', 'learn_press'))); } $user = learn_press_get_current_user(); if ($quiz->is_require_enrollment() && $user->is('guest')) { learn_press_send_json(array('result' => 'error', 'message' => __('Please login to do this quiz', 'learn_press'))); } $user->set_quiz($quiz); switch (strtolower($user->get_quiz_status())) { case 'completed': learn_press_send_json(array('result' => 'error', 'message' => __('You have completed this quiz', 'learn_press'), 'data' => $user->get_quiz_result())); break; case 'started': learn_press_send_json(array('result' => 'error', 'message' => __('You have started this quiz', 'learn_press'), 'data' => array('status' => $user->get_quiz_status()))); break; default: $result = $user->start_quiz(); learn_press_send_json(array('result' => 'success', 'data' => $result, 'question_url' => learn_press_get_user_question_url($quiz_id), 'question_content' => $user->get_current_question($quiz_id, 'html'))); } die; }
function get_paypal_basic_request_url($order) { $settings = get_option('_lpr_settings_payment'); if (empty($settings['paypal'])) { return; } $paypal_settings = $settings['paypal']; $user = learn_press_get_current_user(); $paypal_args = array('cmd' => '_xclick', 'amount' => learn_press_get_cart_total(), 'quantity' => '1'); $transaction = learn_press_generate_transaction_object(); $temp_id = learn_press_uniqid(); $xxx = @file_get_contents(LPR_PLUGIN_PATH . '/temp.txt'); learn_press_set_transient_transaction('lpps', $temp_id, $user->ID, $transaction); file_put_contents(LPR_PLUGIN_PATH . '/temp.txt', $xxx . "=" . $temp_id); /*$order_id = LearnPress()->session->get( 'learn_press_user_order' ); $order_id = learn_press_add_transaction( array( 'method' => $this->method, 'method_id' => '', 'status' => '', 'user_id' => null, 'order_id' => $order_id, 'parent' => 0, 'transaction_object' => $transaction ) ); //LearnPress()->session->set( 'learn_press_user_order', $order_id ); $order = new LPR_Order( $order_id );*/ $nonce = wp_create_nonce('learn-press-paypal-nonce'); $paypal_email = $paypal_settings['sandbox'] ? $paypal_settings['paypal_sandbox_email'] : $paypal_settings['paypal_email']; $query = array('business' => $paypal_email, 'item_name' => learn_press_get_cart_description(), 'return' => add_query_arg(array('learn-press-transaction-method' => 'paypal-standard', 'paypal-nonce' => $nonce), learn_press_get_cart_course_url()), 'currency_code' => learn_press_get_currency(), 'notify_url' => get_site_url() . '/?' . learn_press_get_web_hook('paypal-standard') . '=1', 'no_note' => '1', 'shipping' => '0', 'email' => $user->user_email, 'rm' => '2', 'cancel_return' => learn_press_get_cart_course_url(), 'custom' => $temp_id, 'no_shipping' => '1'); $query = array_merge($paypal_args, $query); $query = apply_filters('it_exchange_paypal_standard_query', $query); $paypal_payment_url = ($paypal_settings['sandbox'] ? $this->paypal_payment_sandbox_url : $this->paypal_payment_live_url) . '?' . http_build_query($query); return $paypal_payment_url; }
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); }
/** * @param $user_id * * @return WP_Query */ function learn_press_get_passed_courses($user_id) { $user = learn_press_get_current_user(); return $user->get_finished_courses(); $pid = get_user_meta($user_id, '_lpr_course_finished', true); if (!$pid) { $pid = array(0); } $arr_query = array('post_type' => LP()->course_post_type, 'post__in' => $pid, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'posts_per_page' => -1); $my_query = new WP_Query($arr_query); return $my_query; }
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); }
/** * Finish a course by ID of an user * When a course marked is finished then also mark all lessons, quizzes as completed * * @param int $course_id * @param int $user_id * * @return array */ function learn_press_finish_course($course_id = null, $user_id = null) { $course_id = learn_press_get_course_id($course_id); if (!$user_id) { $user_id = get_current_user_id(); } $can_finish = !learn_press_get_current_user()->is('guest'); if (!apply_filters('lp_before_finish_course', $can_finish, $course_id, $user_id)) { return; } $course_finished = get_user_meta($user_id, '_lpr_course_finished', true); if (!$course_finished) { $course_finished = array(); } $course_finished[] = $course_id; $course_finished = array_unique($course_finished); update_user_meta($user_id, '_lpr_course_finished', $course_finished); $course_time = get_user_meta($user_id, '_lpr_course_time', true); if (!$course_time) { $course_time = array(); } if (!empty($course_time[$course_id])) { $course_time[$course_id]['end'] = current_time('timestamp'); } update_user_meta($user_id, '_lpr_course_time', $course_time); //learn_press_output_file( $course_time, 'finish_course.txt' ); $user_finished = get_post_meta($course_id, '_lpr_user_finished', true); if (!$user_finished) { $user_finished = array(); } $user_finished[] = $user_id; update_post_meta($course_id, '_lpr_user_finished', $user_finished); $lesson_quiz = learn_press_get_lessons_quizzes($course_id, false); if ($lesson_quiz) { foreach ($lesson_quiz as $post) { if ('lpr_lesson' == $post->post_type) { learn_press_mark_lesson_complete($post->ID); } else { learn_press_mark_quiz_complete($post->ID); } } } do_action('learn_press_user_finished_course', $course_id, $user_id); return array('finish' => true, 'message' => ''); }
?> "><?php _e('Add to section', 'learn_press'); ?> </button> <button class="lp-close-lightbox button" onclick="LearnPress.MessageBox.hide();"><?php _e('Close', 'learn_press'); ?> </button> </div> </script> <script type="text/html" id="tmpl-lp-modal-search-quiz"> <div id="lp-modal-search-quiz" class="lp-modal-search"> <?php $exclude_quizzes = $curriculum_items['quizzes']; $quizzes = learn_press_get_current_user()->get_quizzes(array('orderby' => 'name', 'order' => 'ASC', 'posts_per_page' => -1)); ?> <div class="lp-search-items"> <input type="text" name="lp-item-name" placeholder="<?php _e('Type here to search the quiz', 'learn_press'); ?> " /> <!--<button type="button" class="button lp-add-new-item"><?php _e('Add New', 'learn_press'); ?> </button>--> </div> <ul> <?php if ($quizzes) { foreach ($quizzes as $quiz) {
function get_buttons() { $user = learn_press_get_current_user(); $buttons = array(); if (!$user->has('started-quiz', $this->id)) { $buttons['start'] = sprintf('<button class="button-start-quiz" data-id="%d">%s</button>', $this->id, apply_filters('learn_press_start_quiz_button_text', __("Start Quiz", "learn_press"))); $buttons['start'] .= wp_nonce_field('start-quiz', 'start-quiz-nonce'); } $buttons['finish'] = sprintf('<button class="button-finish-quiz" data-id="%d">%s</button>', $this->id, apply_filters('learn_press_finish_quiz_button_text', __("Finish Quiz", "learn_press"))); $buttons['finish'] .= wp_nonce_field('finish-quiz', 'finish-quiz-nonce'); if ($remain = $user->can('retake-quiz', $this->id)) { $buttons['retake'] = sprintf('<button class="button-retake-quiz" data-id="%d">%s (+%d)</button>', $this->id, apply_filters('learn_press_retake_quiz_button_text', __('Retake', 'learn_press')), $remain); $buttons['retake'] .= wp_nonce_field('retake-quiz', 'retake-quiz-nonce'); } return apply_filters('learn_press_single_quiz_buttons', $buttons, $this, $user); }
function get_user() { if (!$this->user) { $this->user = learn_press_get_current_user(); } return $this->user; }
function get_request_url($order_id) { $user = learn_press_get_current_user(); $sandbox = LP()->settings->get('paypal_sandbox') == 'yes'; $payment_form = ''; $paypal_api_url = $sandbox ? $this->paypal_nvp_api_sandbox_url : $this->paypal_nvp_api_live_url; // PAYPAL_NVP_API_SANDBOX_URL : PAYPAL_NVP_API_LIVE_URL; $paypal_payment_url = $sandbox ? $this->paypal_payment_sandbox_url : $this->paypal_payment_sandbox_url; //'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; $paypal_email = $sandbox ? LP()->settings->get('paypal_sandbox_email') : LP()->settings->get('paypal_email'); $paypal_api_username = $sandbox ? LP()->settings->get('paypal_sandbox_api_username') : LP()->settings->get('paypal_api_username'); $paypal_api_password = $sandbox ? LP()->settings->get('paypal_sandbox_api_password') : LP()->settings->get('paypal_api_password'); $paypal_api_signature = $sandbox ? LP()->settings->get('paypal_sandbox_api_signature') : LP()->settings->get('paypal_api_signature'); if (!empty($paypal_email) && !empty($paypal_api_username) && !empty($paypal_api_password) && !empty($paypal_api_signature)) { remove_filter('the_title', 'wptexturize'); // remove this because it screws up the product titles in PayPal $temp_id = learn_press_uniqid(); $button_request = array('USER' => trim($paypal_api_username), 'PWD' => trim($paypal_api_password), 'SIGNATURE' => trim($paypal_api_signature), 'VERSION' => '96.0', 'METHOD' => 'BMCreateButton', 'BUTTONCODE' => 'ENCRYPTED', 'BUTTONIMAGE' => 'REG', 'BUYNOWTEXT' => 'PAYNOW'); $button_request['BUTTONTYPE'] = 'BUYNOW'; //$L_BUTTONVARS[] = 'amount=' . learn_press_get_cart_total(); //$L_BUTTONVARS[] = 'quantity=1'; $nonce = wp_create_nonce('learn-press-paypal-nonce'); $L_BUTTONVARS[] = 'business=' . $paypal_email; //$L_BUTTONVARS[] = 'item_name=' . learn_press_get_cart_description(); $L_BUTTONVARS[] = 'return=' . add_query_arg(array('learn-press-transaction-method' => 'paypal-standard-secure', 'paypal-nonce' => $nonce), learn_press_get_cart_course_url()); $L_BUTTONVARS[] = 'currency_code=' . learn_press_get_currency(); //$general_settings['default-currency']; $L_BUTTONVARS[] = 'notify_url=' . learn_press_get_web_hook('paypal-standard-secure'); //http://lessbugs.com/paypal/paypal_ipn.php';// . get_site_url() . '/?paypal-stardard-secure=1' ; $L_BUTTONVARS[] = 'no_note=1'; $L_BUTTONVARS[] = 'shipping=0'; $L_BUTTONVARS[] = 'email=' . $user->user_email; $L_BUTTONVARS[] = 'rm=2'; //Return Method - https://developer.paypal.com/webapps/developer/docs/classic/button-manager/integration-guide/ButtonManagerHTMLVariables/ $L_BUTTONVARS[] = 'cancel_return=' . learn_press_get_cart_course_url(); $L_BUTTONVARS[] = 'custom=' . $temp_id; $L_BUTTONVARS[] = 'no_shipping=1'; foreach ($this->get_item_lines() as $k => $v) { $L_BUTTONVARS[] = "{$k}={$v}"; } $L_BUTTONVARS = apply_filters('learn_press_paypal_standard_secure_button_vars', $L_BUTTONVARS); $count = 0; foreach ($L_BUTTONVARS as $L_BUTTONVAR) { $button_request['L_BUTTONVAR' . $count] = $L_BUTTONVAR; $count++; } //print_r($button_request);die(); $button_request = apply_filters('learn_press_paypal_standard_secure_button_request', $button_request); $response = wp_remote_post($paypal_api_url, array('body' => $button_request)); if (!is_wp_error($response)) { parse_str(wp_remote_retrieve_body($response), $response_array); if (!empty($response_array['ACK']) && 'Success' === $response_array['ACK']) { if (!empty($response_array['WEBSITECODE'])) { $payment_form = str_replace(array("\r\n", "\r", "\n"), '', stripslashes($response_array['WEBSITECODE'])); } } } else { print_r($response); } if (preg_match('/-----BEGIN PKCS7-----.*-----END PKCS7-----/i', $payment_form, $matches)) { $query = array('cmd' => '_s-xclick', 'encrypted' => $matches[0]); $paypal_payment_url = $paypal_payment_url . '?' . http_build_query($query); return $paypal_payment_url; } else { echo $payment_form; } } return false; }
function review_log($new_status, $old_status, $course_id) { global $wpdb, $post; $required_review = LP()->settings->get('required_review') == 'yes'; $enable_edit_published = LP()->settings->get('enable_edit_published') == 'yes'; if (!$required_review || $required_review && $enable_edit_published) { return; } $user = learn_press_get_current_user(); $message = learn_press_get_request('review_message'); if (LP()->user->is_instructor() && $required_review && !$enable_edit_published) { remove_action('rwmb_course_curriculum_before_save_post', array($this, 'before_save_curriculum')); wp_update_post(array('ID' => $post->ID, 'post_status' => 'pending'), array('%d', '%s')); add_action('rwmb_course_curriculum_before_save_post', array($this, 'before_save_curriculum')); } if (!$message && !$user->is_instructor() && get_post_status($post->ID) == 'publish') { $message = __('Your course has published', 'learn_press'); } if (apply_filters('learn_press_review_log_message', $message, $post->ID, $user->id)) { $query = $wpdb->prepare("\n\t\t\t\t\tINSERT INTO {$wpdb->learnpress_review_logs}(`course_id`, `user_id`, `message`, `date`, `status`, `user_type`)\n\t\t\t\t\tVALUES(%d, %d, %s, %s, %s, %s)\n\t\t\t\t", $post->ID, $user->id, $message, current_time('mysql'), get_post_status($post->ID), $user->is_instructor() ? 'instructor' : 'reviewer'); $wpdb->query($query); do_action('learn_press_update_review_log', $wpdb->insert_id, $post->ID, $user->id); } }