PageRenderTime 48ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/learnpress/inc/admin/class-lp-profile.php

https://gitlab.com/gregtyka/lfmawordpress
PHP | 139 lines | 97 code | 12 blank | 30 comment | 8 complexity | a8b0354ff4750ce5be6e13c2ef18011d MD5 | raw file
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'LP_Profile' ) ) {
  6. /**
  7. * Class LP_Profile
  8. */
  9. class LP_Profile {
  10. /**
  11. * Constructor
  12. */
  13. public function __construct() {
  14. add_filter( 'learn_press_profile_methods', array( $this, 'learn_press_profile_method' ) );
  15. // add_action( 'wp_loaded', array( $this, 'learn_press_process_profile' ) );
  16. add_action( 'learn_press_before_profile_content', array( $this, 'learn_press_add_tabs_scripts' ) );
  17. add_action( 'learn_press_add_profile_tab', array( $this, 'learn_press_add_profile_tab' ) );
  18. add_filter( 'learn_press_user_info_tab_content', array( $this, 'learn_press_user_info_tab_content' ), 10, 2 );
  19. add_filter( 'learn_press_user_courses_tab_content', array( $this, 'learn_press_user_courses_tab_content' ), 10, 2 );
  20. add_filter( 'learn_press_user_quizzes_tab_content', array( $this, 'learn_press_user_quizzes_tab_content' ), 10, 2 );
  21. add_action( 'learn_press_enrolled_course_after_title', array( $this, 'end_title_content' ), 10, 2 );
  22. }
  23. /**
  24. * Process profile
  25. */
  26. public function learn_press_process_profile() {
  27. if ( learn_press_has_profile_method() ) {
  28. if ( learn_press_get_profile_page_id() == 0 ) {
  29. $profile = array(
  30. 'post_title' => 'Profile',
  31. 'post_content' => '[learn_press_profile]',
  32. 'post_type' => 'page',
  33. 'post_status' => 'publish',
  34. );
  35. $profile_page_id = wp_insert_post( $profile );
  36. update_post_meta( $profile_page_id, '_lpr_is_profile_page', 1 );
  37. }
  38. } else {
  39. wp_delete_post( learn_press_get_profile_page_id(), true );
  40. }
  41. }
  42. /*
  43. * Profile methods
  44. */
  45. public function learn_press_profile_method( $methods ) {
  46. $methods['lpr_profile'] = __( 'LearnPress Profile', 'learnpress' );
  47. return $methods;
  48. }
  49. /*
  50. * Enqueue jquery ui scripts
  51. */
  52. public function learn_press_add_tabs_scripts() {
  53. /*wp_enqueue_style( 'lpr-jquery-ui-css', LP_CSS_URL . 'jquery-ui.css' );
  54. wp_enqueue_script( 'lpr-jquery-ui-js', LP_JS_URL . 'jquery-ui.js', array( 'jquery' ), '', false );*/
  55. }
  56. /*
  57. * Add profile tab
  58. */
  59. public function learn_press_add_profile_tab( $user ) {
  60. $content = '';
  61. $tabs = apply_filters(
  62. 'learn_press_profile_tabs',
  63. array(
  64. 10 => array(
  65. 'tab_id' => 'user_info',
  66. 'tab_name' => __( 'User Information', 'learnpress' ),
  67. 'tab_content' => apply_filters( 'learn_press_user_info_tab_content', $content, $user )
  68. ),
  69. 20 => array(
  70. 'tab_id' => 'user_courses',
  71. 'tab_name' => __( 'Courses', 'learnpress' ),
  72. 'tab_content' => apply_filters( 'learn_press_user_courses_tab_content', $content, $user )
  73. ),
  74. 30 => array(
  75. 'tab_id' => 'user_quizzes',
  76. 'tab_name' => __( 'Quiz Results', 'learnpress' ),
  77. 'tab_content' => apply_filters( 'learn_press_user_quizzes_tab_content', $content, $user )
  78. )
  79. ),
  80. $user
  81. );
  82. ksort( $tabs );
  83. echo '<ul>';
  84. foreach ( $tabs as $tab ) {
  85. echo '<li><a href="#' . $tab['tab_id'] . '">' . $tab['tab_name'] . '</a></li>';
  86. }
  87. echo '</ul>';
  88. foreach ( $tabs as $tab ) {
  89. echo '<div id="' . $tab['tab_id'] . '">' . $tab['tab_content'] . '</div>';
  90. }
  91. }
  92. /*
  93. * Add content for user information tab
  94. */
  95. public function learn_press_user_info_tab_content( $content, $user ) {
  96. ob_start();
  97. learn_press_get_template( 'profile/user-info.php', array( 'user' => $user ) );
  98. $content .= ob_get_clean();
  99. return $content;
  100. }
  101. /*
  102. * Add content for user courses tab
  103. */
  104. public function learn_press_user_courses_tab_content( $content, $user ) {
  105. ob_start();
  106. learn_press_get_template( 'profile/user-courses.php', array( 'user' => $user ) );
  107. $content .= ob_get_clean();
  108. return $content;
  109. }
  110. /*
  111. * Add content for user quiz results tab
  112. */
  113. public function learn_press_user_quizzes_tab_content( $content, $user ) {
  114. ob_start();
  115. learn_press_get_template( 'profile/user-quizzes.php', array( 'content' => $content, 'user' => $user ) );
  116. $content .= ob_get_clean();
  117. return $content;
  118. }
  119. public function end_title_content( $course, $user ) {
  120. if ( learn_press_user_has_passed_course( $course->ID, $user->ID ) ) {
  121. _e( '<span class="course-status passed">Passed</span>', 'learnpress' );
  122. } else {
  123. }
  124. }
  125. }
  126. new LP_Profile;
  127. }