Esempio n. 1
0
 /**
  * Install.
  *
  * @param bool $inc_post_types
  * @param bool $inc_endpoints
  */
 public function activate($inc_post_types = true, $inc_endpoints = true)
 {
     // Setup the database tables.
     $this->setup_tables();
     // Setup the user roles and capabilities.
     $this->setup_roles();
     // Post types and taxonomies.
     if ($inc_post_types || $inc_endpoints) {
         if ($inc_post_types) {
             Edr_PostTypes::register_post_types();
             Edr_PostTypes::register_taxonomies();
         }
         if ($inc_endpoints) {
             IB_Educator_Main::add_rewrite_endpoints();
         }
         flush_rewrite_rules();
     }
     // Setup email templates.
     $this->setup_email_templates();
     // Schedule cron events.
     $this->schedule_events();
     // Setup tax settings.
     $this->setup_taxes();
     // Do version specific updates.
     $current_version = get_option('ib_educator_version');
     if ($current_version) {
         if (version_compare($current_version, '1.4.3', '<=')) {
             $this->update_1_4_4();
         }
         if (version_compare($current_version, '1.5', '<=')) {
             $this->update_1_6();
         }
     }
     /**
      * Plugin activation hook.
      */
     do_action('ib_educator_activation');
     // Update the plugin version in database.
     update_option('ib_educator_version', IBEDUCATOR_VERSION);
 }
Esempio n. 2
0
								<!-- Payment Method -->
								<div class="ib-edu-field edu-block">
									<div class="ib-edu-label">
										<label for="ib-edu-amount"><?php 
_e('Payment Method', 'ibeducator');
?>
</label>
									</div>
									<div class="ib-edu-control">
										<select name="payment_gateway">
											<option value="">&mdash; <?php 
_e('Select', 'ibeducator');
?>
 &mdash;</option>
											<?php 
$gateways = IB_Educator_Main::get_gateways();
foreach ($gateways as $gateway) {
    echo '<option value="' . esc_attr($gateway->get_id()) . '" ' . selected($payment->payment_gateway, $gateway->get_id()) . '>' . esc_html($gateway->get_title()) . '</option>';
}
?>
										</select>
									</div>
								</div>

								<!-- Transaction ID -->
								<div class="ib-edu-field edu-block">
									<div class="ib-edu-label">
										<label for="ib-edu-txn_id"><?php 
_e('Transaction ID', 'ibeducator');
?>
</label>
Esempio n. 3
0
 /**
  * Edit payment gateway action.
  */
 public static function edit_payment_gateway()
 {
     if (!isset($_POST['gateway_id'])) {
         return;
     }
     $gateway_id = sanitize_title($_POST['gateway_id']);
     // Verify nonce.
     check_admin_referer('ib_educator_payments_settings');
     // Get available gateways.
     $gateways = IB_Educator_Main::get_gateways();
     // Does the requested gateway exist?
     if (!isset($gateways[$gateway_id])) {
         return;
     }
     // Capability check.
     if (!current_user_can('manage_educator')) {
         return;
     }
     $saved = $gateways[$gateway_id]->save_admin_options();
     $message = '';
     if (true === $saved) {
         $message = 'saved';
     } else {
         $message = 'not_saved';
     }
     wp_redirect(admin_url('admin.php?page=ib_educator_admin&tab=payment&gateway_id=' . $gateway_id . '&edu-message=' . $message));
 }
Esempio n. 4
0
 /**
  * Pay for a course.
  */
 public static function payment()
 {
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ibedu_submit_payment')) {
         return;
     }
     do_action('ib_educator_before_payment');
     // Get post id and payment type (course or membership).
     $post_id = 0;
     // either course id or membership id
     $payment_type = 'course';
     if (isset($_POST['course_id'])) {
         $post_id = absint($_POST['course_id']);
     } elseif (isset($_POST['membership_id'])) {
         $post_id = absint($_POST['membership_id']);
         $payment_type = 'membership';
     }
     $post = get_post($post_id);
     if (!$post) {
         return;
     }
     $user_id = get_current_user_id();
     $errors = new WP_Error();
     // Check the course prerequisites.
     if ('course' == $payment_type) {
         // Registration allowed?
         if ('closed' == ib_edu_registration($post_id)) {
             return;
         }
         // Check prerequisites.
         $api = IB_Educator::get_instance();
         if (!$api->check_prerequisites($post_id, $user_id)) {
             $prerequisites_html = '';
             $prerequisites = $api->get_prerequisites($post_id);
             $courses = get_posts(array('post_type' => 'ib_educator_course', 'post_status' => 'publish', 'include' => $prerequisites));
             if (!empty($courses)) {
                 foreach ($courses as $course) {
                     $prerequisites_html .= '<br><a href="' . esc_url(get_permalink($course->ID)) . '">' . esc_html($course->post_title) . '</a>';
                 }
             }
             $errors->add('prerequisites', sprintf(__('You have to complete the prerequisites for this course: %s', 'ibeducator'), $prerequisites_html));
             ib_edu_message('payment_errors', $errors);
             return;
         }
     }
     // Get the payment method.
     $payment_method = '';
     $gateways = IB_Educator_Main::get_gateways();
     if (!isset($_POST['payment_method']) || !array_key_exists($_POST['payment_method'], $gateways)) {
         $errors->add('empty_payment_method', __('Please select a payment method.', 'ibeducator'));
     } else {
         $payment_method = $_POST['payment_method'];
     }
     /**
      * Filter the validation of the payment form.
      *
      * @param WP_Error $errors
      */
     $errors = apply_filters('ib_educator_register_form_validate', $errors, $post);
     // Attempt to register the user.
     if ($errors->get_error_code()) {
         ib_edu_message('payment_errors', $errors);
         return;
     } elseif (!$user_id) {
         $user_data = apply_filters('ib_educator_register_user_data', array('role' => 'student'), $post);
         $user_id = wp_insert_user($user_data);
         if (is_wp_error($user_id)) {
             ib_edu_message('payment_errors', $user_id);
             return;
         } else {
             // Setup the password change nag.
             update_user_option($user_id, 'default_password_nag', true, true);
             // Send the new user notifications.
             wp_new_user_notification($user_id, $user_data['user_pass']);
             do_action('ib_educator_new_student', $user_id, $post);
             // Log the user in.
             wp_set_auth_cookie($user_id);
         }
     } else {
         do_action('ib_educator_update_student', $user_id, $post);
     }
     $can_pay = true;
     if ('course' == $payment_type) {
         $access_status = IB_Educator::get_instance()->get_access_status($post_id, $user_id);
         // Student can pay for a course only if he/she completed this course or didn't register for it yet.
         $can_pay = in_array($access_status, array('course_complete', 'forbidden'));
     }
     if ($can_pay) {
         // Process payment.
         $atts = array();
         if (ib_edu_get_option('payment_ip', 'settings')) {
             $atts['ip'] = $_SERVER['REMOTE_ADDR'];
         }
         $result = $gateways[$payment_method]->process_payment($post_id, $user_id, $payment_type, $atts);
         /**
          * Fires when the payment record has been created.
          *
          * The payment may not be confirmed yet.
          *
          * @param null|IB_Educator_Payment
          */
         do_action('ib_educator_payment_processed', isset($result['payment']) ? $result['payment'] : null);
         // Go to the next step(e.g. thank you page).
         wp_safe_redirect($result['redirect']);
         exit;
     }
 }
Esempio n. 5
0
require IBEDUCATOR_PLUGIN_DIR . 'includes/functions.php';
require IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-main.php';
require IBEDUCATOR_PLUGIN_DIR . 'includes/shortcodes.php';
require IBEDUCATOR_PLUGIN_DIR . 'includes/filters.php';
// Register the quizzes service.
function edr_get_quizzes_service()
{
    return new Edr_Quizzes();
}
Edr_Manager::add('edr_quizzes', 'edr_get_quizzes_service');
// Setup the memberships feature.
Edr_MembershipsRun::init();
// Setup the post types and taxonomies.
Edr_PostTypes::init();
// Setup Educator.
IB_Educator_Main::init();
// Ajax actions.
Edr_AjaxActions::init();
// Setup account processing (e.g. payment form).
Edr_StudentAccount::init();
// Parse incoming requests (e.g. PayPal IPN).
Edr_RequestDispatcher::init();
if (is_admin()) {
    // Setup the Educator's admin.
    Edr_Admin::init();
    // Check whether to run the update script or not.
    function ib_edu_update_check()
    {
        if (get_option('ib_educator_version') != IBEDUCATOR_VERSION) {
            $install = new Edr_Install();
            $install->activate(false, false);