Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add Disable Drip-Feed (LearnDash) Metabox on user profile
- * @description Disable drip-feed metabox for each users.
- *
- * @author HarunRRayhan
- */
- add_action( 'show_user_profile', 'hrx_user_disable_dripfeed' );
- add_action( 'edit_user_profile', 'hrx_user_disable_dripfeed' );
- function hrx_user_disable_dripfeed($user) {
- // Check if user is Admin
- if( !current_user_can('manage_options', $user->ID) ) {
- return;
- }
- // Get Already saved disabled drip courses ID
- $disabled_drip_courses_id = get_the_author_meta( 'disabled_drip_courses', $user->ID );
- ?>
- <h3><?php _e("Disable Drip-Feed for Courses", "divi"); ?></h3>
- <table class="form-table">
- <tr>
- <!-- <th>
- <label for="disabled-drip-courses"><?php _e("Course List"); ?></label>
- </th> -->
- <td>
- <!-- <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br /> -->
- <?php
- // Check if LearnDash exists
- if ( post_type_exists( 'sfwd-courses' ) ) {
- // Course Query
- $course_args = array(
- 'posts_per_page' => -1,
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'post_type' => 'sfwd-courses',
- 'post_status' => 'publish',
- 'suppress_filters' => true
- );
- $courses_array = get_posts( $course_args );
- // Check if there any course available
- if($courses_array ):
- foreach ($courses_array as $course ) {
- setup_postdata( $course );
- // echo "<pre>";
- // print_r($course);
- // echo "</pre>";
- 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>';
- }
- wp_reset_postdata();
- ?>
- <span class="description"><?php _e("Please select course which you want to disable for driping. Multiple courses allowed."); ?></span>
- <?php
- else:
- // If no couse
- ?>
- <p>
- <span class="description"><?php _e("There is no course in LearnDash. Please add a course first."); ?></span>
- </p>
- <?php
- endif;
- } ?>
- </td>
- </tr>
- </table>
- <?php
- }
- /**
- * Saving disabled courses ID
- *
- * @author HarunRRayhan
- */
- add_action( 'personal_options_update', 'save_disabled_drip_courses_id' );
- add_action( 'edit_user_profile_update', 'save_disabled_drip_courses_id' );
- function save_disabled_drip_courses_id( $user_id ) {
- if ( !current_user_can('manage_options', $user_id ) ) { return false; }
- update_user_meta( $user_id, 'disabled_drip_courses', $_POST['disabled-drip-courses'] );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement