Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. /**
  2. * Add Disable Drip-Feed (LearnDash) Metabox on user profile
  3. * @description Disable drip-feed metabox for each users.
  4. *
  5. * @author HarunRRayhan
  6. */
  7.  
  8. add_action( 'show_user_profile', 'hrx_user_disable_dripfeed' );
  9. add_action( 'edit_user_profile', 'hrx_user_disable_dripfeed' );
  10.  
  11. function hrx_user_disable_dripfeed($user) {
  12. // Check if user is Admin
  13. if( !current_user_can('manage_options', $user->ID) ) {
  14. return;
  15. }
  16. // Get Already saved disabled drip courses ID
  17. $disabled_drip_courses_id = get_the_author_meta( 'disabled_drip_courses', $user->ID );
  18. ?>
  19. <h3><?php _e("Disable Drip-Feed for Courses", "divi"); ?></h3>
  20.  
  21. <table class="form-table">
  22. <tr>
  23. <!-- <th>
  24. <label for="disabled-drip-courses"><?php _e("Course List"); ?></label>
  25. </th> -->
  26. <td>
  27. <!-- <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br /> -->
  28. <?php
  29.  
  30. // Check if LearnDash exists
  31. if ( post_type_exists( 'sfwd-courses' ) ) {
  32.  
  33. // Course Query
  34. $course_args = array(
  35. 'posts_per_page' => -1,
  36. 'orderby' => 'date',
  37. 'order' => 'DESC',
  38. 'post_type' => 'sfwd-courses',
  39. 'post_status' => 'publish',
  40. 'suppress_filters' => true
  41. );
  42. $courses_array = get_posts( $course_args );
  43.  
  44. // Check if there any course available
  45. if($courses_array ):
  46. foreach ($courses_array as $course ) {
  47. setup_postdata( $course );
  48. // echo "<pre>";
  49. // print_r($course);
  50. // echo "</pre>";
  51. echo '<input type="checkbox" name="disabled-drip-courses[]" value="' . $course->ID . '" id="course-' . $course->ID . '" ' . ((in_array($course->ID, $disabled_drip_courses_id)) ? 'checked' : '') . '> <label for="course-' . $course->ID . '">' . $course->post_title . '</label><br>';
  52. }
  53. wp_reset_postdata();
  54. ?>
  55.  
  56.  
  57. <span class="description"><?php _e("Please select course which you want to disable for driping. Multiple courses allowed."); ?></span>
  58. <?php
  59.  
  60. else:
  61. // If no couse
  62. ?>
  63. <p>
  64. <span class="description"><?php _e("There is no course in LearnDash. Please add a course first."); ?></span>
  65. </p>
  66. <?php
  67. endif;
  68. } ?>
  69. </td>
  70. </tr>
  71. </table>
  72.  
  73. <?php
  74. }
  75.  
  76. /**
  77. * Saving disabled courses ID
  78. *
  79. * @author HarunRRayhan
  80. */
  81. add_action( 'personal_options_update', 'save_disabled_drip_courses_id' );
  82. add_action( 'edit_user_profile_update', 'save_disabled_drip_courses_id' );
  83. function save_disabled_drip_courses_id( $user_id ) {
  84.  
  85. if ( !current_user_can('manage_options', $user_id ) ) { return false; }
  86. update_user_meta( $user_id, 'disabled_drip_courses', $_POST['disabled-drip-courses'] );
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement