Ejemplo n.º 1
0
 /**
  * Register post types.
  */
 public static function register_post_types()
 {
     $permalink_settings = get_option('ib_educator_permalinks');
     // Courses.
     $course_slug = $permalink_settings && !empty($permalink_settings['course_base']) ? $permalink_settings['course_base'] : _x('courses', 'course slug', 'ibeducator');
     $courses_archive_slug = $permalink_settings && !empty($permalink_settings['courses_archive_base']) ? $permalink_settings['courses_archive_base'] : _x('courses', 'courses archive slug', 'ibeducator');
     register_post_type('ib_educator_course', apply_filters('ib_educator_cpt_course', array('labels' => array('name' => __('Courses', 'ibeducator'), 'singular_name' => __('Course', 'ibeducator')), 'public' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'capability_type' => 'ib_educator_course', 'map_meta_cap' => true, 'hierarchical' => false, 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'page-attributes'), 'has_archive' => $courses_archive_slug, 'rewrite' => array('slug' => $course_slug), 'query_var' => 'course', 'can_export' => true)));
     // Lessons.
     $supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'page-attributes');
     if (1 == ib_edu_get_option('lesson_comments', 'learning')) {
         $supports[] = 'comments';
     }
     register_post_type('ib_educator_lesson', apply_filters('ib_educator_cpt_lesson', array('labels' => array('name' => __('Lessons', 'ibeducator'), 'singular_name' => __('Lesson', 'ibeducator')), 'public' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_nav_menus' => false, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'capability_type' => 'ib_educator_lesson', 'map_meta_cap' => true, 'hierarchical' => false, 'supports' => $supports, 'has_archive' => !empty($permalink_settings['lessons_archive_base']) ? $permalink_settings['lessons_archive_base'] : _x('lessons', 'lesson slug', 'ibeducator'), 'rewrite' => array('slug' => !empty($permalink_settings['lesson_base']) ? $permalink_settings['lesson_base'] : _x('lessons', 'lessons archive slug', 'ibeducator')), 'query_var' => 'lesson', 'can_export' => true)));
     // Memberships.
     register_post_type('ib_edu_membership', apply_filters('ib_educator_cpt_membership', array('label' => __('Membership Levels', 'ibeducator'), 'labels' => array('name' => __('Membership Levels', 'ibeducator'), 'singular_name' => __('Membership Level', 'ibeducator'), 'add_new_item' => __('Add New Membership Level', 'ibeducator'), 'edit_item' => __('Edit Membership Level', 'ibeducator'), 'new_item' => __('New Membership Level', 'ibeducator'), 'view_item' => __('View Membership Level', 'ibeducator'), 'search_items' => __('Search Membership Levels', 'ibeducator'), 'not_found' => __('No membership levels found', 'ibeducator'), 'not_found_in_trash' => __('No membership levels found in Trash', 'ibeducator')), 'public' => true, 'show_ui' => true, 'show_in_menu' => 'ib_educator_admin', 'exclude_from_search' => true, 'capability_type' => 'ib_edu_membership', 'map_meta_cap' => true, 'hierarchical' => false, 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'page-attributes'), 'has_archive' => false, 'rewrite' => array('slug' => 'membership'), 'query_var' => 'membership', 'can_export' => true)));
 }
Ejemplo n.º 2
0
    /**
     * Send the membership expiration emails to users.
     */
    public static function send_expiration_notifications()
    {
        global $wpdb;
        $days_notify = ib_edu_get_option('days_notify', 'memberships');
        if (null === $days_notify) {
            $days_notify = 5;
        } else {
            $days_notify = absint($days_notify);
        }
        $expires_date = date('Y-m-d', strtotime('+ ' . $days_notify . ' days'));
        $tables = ib_edu_table_names();
        $users = $wpdb->get_results($wpdb->prepare('SELECT u.ID, u.user_email, u.display_name, m.expiration, m.membership_id
			FROM ' . $tables['members'] . ' m
			INNER JOIN ' . $wpdb->users . ' u ON u.ID = m.user_id
			WHERE m.`expiration` LIKE %s AND m.`status` = %s', $expires_date . '%', 'active'));
        if (empty($users)) {
            return;
        }
        // Get memberships.
        $membership_ids = array();
        foreach ($users as $user) {
            if (!in_array($user->membership_id, $membership_ids)) {
                $membership_ids[] = $user->membership_id;
            }
        }
        $memberships = get_posts(array('post_type' => 'ib_edu_membership', 'include' => $membership_ids, 'post_status' => 'publish', 'posts_per_page' => -1));
        if ($memberships) {
            foreach ($memberships as $key => $membership) {
                $memberships[$membership->ID] = $membership;
                unset($memberships[$key]);
            }
            foreach ($users as $user) {
                ib_edu_send_notification($user->user_email, 'membership_renew', array(), array('student_name' => $user->display_name, 'membership' => isset($memberships[$user->membership_id]) ? $memberships[$user->membership_id]->post_title : '', 'expiration' => date_i18n(get_option('date_format'), strtotime($user->expiration)), 'membership_payment_url' => ib_edu_get_endpoint_url('edu-membership', $user->membership_id, get_permalink(ib_edu_page_id('payment')))));
            }
        }
    }
Ejemplo n.º 3
0
 /**
  * Get payment info table.
  *
  * @param WP_Post $object
  * @param array $args
  * @return string
  */
 public static function payment_info($object, $args = array())
 {
     // Get price.
     if (!isset($args['price'])) {
         if ('ib_educator_course' == $object->post_type) {
             $args['price'] = ib_edu_get_course_price($object->ID);
         } elseif ('ib_edu_membership' == $object->post_type) {
             $args['price'] = IB_Educator_Memberships::get_instance()->get_price($object->ID);
         }
     }
     // Get tax data.
     $tax_enabled = ib_edu_get_option('enable', 'taxes');
     if ($tax_enabled) {
         $edu_tax = IB_Educator_Tax::get_instance();
         $tax_data = $edu_tax->calculate_tax($edu_tax->get_tax_class_for($object->ID), $args['price'], $args['country'], $args['state']);
     } else {
         $tax_data = array('taxes' => array(), 'subtotal' => $args['price'], 'tax' => 0.0, 'total' => $args['price']);
     }
     // Items list.
     $output = '<table class="edu-payment-table">';
     $output .= '<thead><tr><th>' . __('Item', 'ibeducator') . '</th><th>' . __('Price', 'ibeducator') . '</th></tr></thead>';
     if ('ib_educator_course' == $object->post_type) {
         $output .= '<tbody><tr><td>';
         if (ib_edu_get_option('payment_lecturer', 'settings')) {
             $output .= sprintf(__('%s with %s', 'ibeducator'), '<a href="' . esc_url(get_permalink($object->ID)) . '" target="_blank">' . esc_html($object->post_title) . '</a>', esc_html(get_the_author_meta('display_name', $object->post_author)));
         } else {
             $output .= '<a href="' . esc_url(get_permalink($object->ID)) . '" target="_blank">' . esc_html($object->post_title) . '</a>';
         }
         $output .= '<input type="hidden" id="payment-object-id" name="course_id" value="' . intval($object->ID) . '"></td>';
         $output .= '<td>' . ib_edu_format_price($tax_data['subtotal'], false) . '</td></tr></tbody>';
     } elseif ('ib_edu_membership' == $object->post_type) {
         $output .= '<tbody><tr><td>' . esc_html($object->post_title);
         $output .= '<input type="hidden" id="payment-object-id" name="membership_id" value="' . intval($object->ID) . '"></td>';
         $ms = IB_Educator_Memberships::get_instance();
         $membership_meta = $ms->get_membership_meta($object->ID);
         $output .= '<td>' . $ms->format_price($tax_data['subtotal'], $membership_meta['duration'], $membership_meta['period']) . '</td></tr></tbody>';
     }
     $output .= '</table>';
     // Summary.
     $output .= '<dl class="edu-payment-summary edu-dl">';
     if ($tax_data['tax'] > 0.0) {
         $output .= '<dt class="payment-subtotal">' . __('Subtotal', 'ibeducator') . '</dt><dd>' . ib_edu_format_price($tax_data['subtotal'], false) . '</dd>';
         foreach ($tax_data['taxes'] as $tax) {
             $output .= '<dt class="payment-tax">' . esc_html($tax->name) . '</dt><dd>' . ib_edu_format_price($tax->amount, false) . '</dd>';
         }
     }
     $output .= '<dt class="payment-total">' . __('Total', 'ibeducator') . '</dt><dd>' . ib_edu_format_price($tax_data['total'], false) . '</dd>';
     $output .= '</dl>';
     return $output;
 }
Ejemplo n.º 4
0
				<tr>
					<th><?php 
        _e('Status', 'ibeducator');
        ?>
</th>
					<td>
						<?php 
        $statuses = $ms->get_statuses();
        if (!empty($user_membership['status']) && array_key_exists($user_membership['status'], $statuses)) {
            echo esc_html($statuses[$user_membership['status']]);
        }
        ?>

						<div>
						<?php 
        if (1 == ib_edu_get_option('pause_memberships', 'memberships')) {
            if ('active' == $user_membership['status']) {
                $pause_url = ib_edu_get_endpoint_url('edu-action', 'pause-membership', get_permalink());
                $pause_url = add_query_arg('_wpnonce', wp_create_nonce('ib_educator_pause_membership'), $pause_url);
                echo ' <span class="pause-membership"><a class="ib-edu-button" href="' . esc_url($pause_url) . '">' . __('Pause', 'ibeducator') . '</a></span>';
            } elseif ('paused' == $user_membership['status']) {
                $resume_url = ib_edu_get_endpoint_url('edu-action', 'resume-membership', get_permalink());
                $resume_url = add_query_arg('_wpnonce', wp_create_nonce('ib_educator_resume_membership'), $resume_url);
                echo ' <span class="pause-membership"><a class="ib-edu-button" href="' . esc_url($resume_url) . '">' . __('Resume', 'ibeducator') . '</a></span>';
            }
        }
        ?>
						</div>
					</td>
				</tr>
Ejemplo n.º 5
0
/**
 * Get the business location.
 *
 * @param string $part
 * @return mixed
 */
function ib_edu_get_location($part = null)
{
    $result = array('', '');
    if ($location = ib_edu_get_option('location', 'settings')) {
        $delimiter = strpos($location, ';');
        if (false === $delimiter) {
            $result[0] = $location;
        } else {
            $result[0] = substr($location, 0, $delimiter);
            $result[1] = substr($location, $delimiter + 1);
        }
    }
    if ('country' == $part) {
        return $result[0];
    } elseif ('state' == $part) {
        return $result[1];
    }
    return $result;
}
Ejemplo n.º 6
0
 /**
  * Calculate tax.
  *
  * @param string $tax_class
  * @param float $price
  * @param string $country
  * @param string $state
  * @return array Tax data (tax, subtotal, total).
  */
 public function calculate_tax($tax_class, $price, $country, $state)
 {
     // Are prices entered with tax?
     $inclusive = ib_edu_get_option('tax_inclusive', 'taxes');
     if (!$inclusive) {
         $inclusive = 'y';
     }
     // Get rates.
     $rates_data = $this->get_tax_rate($tax_class, $country, $state);
     // Calculate tax.
     $tax_data = array('taxes' => array(), 'tax' => 0.0);
     if ('y' == $inclusive) {
         $tax_data['subtotal'] = round($price / (1 + $rates_data['inclusive'] / 100), 2);
         $tax_data['total'] = $tax_data['subtotal'];
     } else {
         $tax_data['subtotal'] = $price;
         $tax_data['total'] = $price;
     }
     foreach ($rates_data['rates'] as $rate) {
         // Calculate tax amount.
         $tax = round($tax_data['subtotal'] * $rate->rate / 100, 2);
         // Setup tax object.
         $tmp = new stdClass();
         $tmp->ID = $rate->ID;
         $tmp->name = $rate->name;
         $tmp->rate = $rate->rate;
         $tmp->amount = $tax;
         $tax_data['taxes'][] = $tmp;
         // Totals.
         $tax_data['tax'] += $tax;
         $tax_data['total'] += $tax;
     }
     return $tax_data;
 }
Ejemplo n.º 7
0
 /**
  * Resume the user's membership.
  */
 public static function resume_membership()
 {
     if (1 != ib_edu_get_option('pause_memberships', 'memberships')) {
         return;
     }
     if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'ib_educator_resume_membership')) {
         return;
     }
     // Get the current user id.
     $user_id = get_current_user_id();
     if (!$user_id) {
         return;
     }
     $ms = IB_Educator_Memberships::get_instance();
     $user_membership = $ms->get_user_membership($user_id);
     if ($user_membership && 'paused' == $user_membership['status']) {
         $ms->resume_membership($user_id);
     }
 }
Ejemplo n.º 8
0
	<div id="ib-edu-breadcrumbs"><?php 
ib_edu_breadcrumbs();
?>
</div>

	<div class="lesson-content entry-content">
		<?php 
if ($student_can_study) {
    the_content();
    Edr_View::template_part('quiz');
} else {
    echo '<p>';
    printf(__('Please register for the %s to view this lesson.', 'ibeducator'), '<a href="' . esc_url(get_permalink(ib_edu_get_course_id())) . '">' . __('course', 'ibeducator') . '</a>');
    echo '</p>';
}
?>
	</div>

	<nav class="ib-edu-lesson-nav">
		<?php 
echo ib_edu_get_adjacent_lesson_link('previous', '<div class="nav-previous">&laquo; %link</div>', __('Previous Lesson', 'ibeducator'));
echo ib_edu_get_adjacent_lesson_link('next', '<div class="nav-next">%link &raquo;</div>', __('Next Lesson', 'ibeducator'));
?>
	</nav>
</article>

<?php 
// Comments.
if ($student_can_study && 1 == ib_edu_get_option('lesson_comments', 'learning') && (comments_open() || get_comments_number())) {
    comments_template();
}