/**
  * Process profile
  */
 public function learn_press_process_profile()
 {
     if (learn_press_has_profile_method()) {
         if (learn_press_get_profile_page_id() == 0) {
             $profile = array('post_title' => 'Profile', 'post_content' => '[learn_press_profile]', 'post_type' => 'page', 'post_status' => 'publish');
             $profile_page_id = wp_insert_post($profile);
             update_post_meta($profile_page_id, '_lpr_is_profile_page', 1);
         }
     } else {
         wp_delete_post(learn_press_get_profile_page_id(), true);
     }
 }
function learn_press_edit_admin_bar()
{
    global $wp_admin_bar;
    $current_user = wp_get_current_user();
    if (learn_press_has_profile_method()) {
        $course_profile = array();
        $course_profile['id'] = 'course_profile';
        $course_profile['parent'] = 'user-actions';
        $course_profile['title'] = __('View Course Profile', 'learn_press');
        $course_profile['href'] = learn_press_get_current_profile_link();
        $course_profile['meta']['target'] = '_blank';
        $wp_admin_bar->add_menu($course_profile);
    }
    // add `be teacher` link
    if (in_array('lpr_teacher', $current_user->roles) || in_array('administrator', $current_user->roles)) {
        return;
    }
    if (!class_exists('LPR_Admin_Settings')) {
        return;
    }
    $settings = LPR_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);
    }
}
function learn_press_get_current_profile_link()
{
    if (!learn_press_has_profile_method()) {
        return;
    }
    global $wp_rewrite;
    if (empty($wp_rewrite->permalink_structure)) {
        return;
    }
    $current_user = wp_get_current_user();
    $link = home_url("/profile/{$current_user->user_login}");
    return $link;
}
function learn_press_edit_permalink()
{
    // Setting up notification
    $check = get_option('_lpr_ignore_setting_up');
    if (!$check && current_user_can('manage_options')) {
        echo '<div id="lpr-setting-up" class="updated"><p>';
        echo sprintf(__('<strong>LearnPress is almost ready</strong>. <a class="lpr-set-up" href="%s">Setting up</a> something right now is a good idea. That\'s better than you <a class="lpr-ignore lpr-set-up">ignore</a> the message.', 'learn_press'), esc_url(add_query_arg(array('page' => 'learn_press_settings'), admin_url('options-general.php'))));
        echo '</p></div>';
    }
    // Add notice if no rewrite rules are enabled
    global $wp_rewrite;
    if (learn_press_has_profile_method()) {
        if (empty($wp_rewrite->permalink_structure)) {
            echo '<div class="fade error"><p>';
            echo sprintf(wp_kses(__('<strong>LearnPress Profile is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'learn_press'), array('a' => array('href' => array()), 'strong' => array())), admin_url('options-permalink.php'));
            echo '</p></div>';
        }
    }
}