| 1 |
<?php |
| 2 |
/** |
| 3 |
* Lession function. |
| 4 |
* |
| 5 |
* @author ThimPress |
| 6 |
* @version 4.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || exit(); |
| 10 |
|
| 11 |
function learn_press_lesson_comment_form_fields( $post_id ) { |
| 12 |
if ( empty( $_REQUEST['content-item-only'] ) ) { |
| 13 |
return; |
| 14 |
} |
| 15 |
?> |
| 16 |
|
| 17 |
<input type="hidden" name="content-item-only-redirect" value="<?php echo learn_press_get_current_url(); ?>"/> |
| 18 |
<input type="hidden" name="content-item-only" value="yes"/> |
| 19 |
|
| 20 |
<?php |
| 21 |
} |
| 22 |
add_action( 'comment_form', 'learn_press_lesson_comment_form_fields' ); |
| 23 |
|
| 24 |
if ( ! function_exists( 'learn_press_get_only_content_permalink' ) ) { |
| 25 |
function learn_press_get_only_content_permalink( $redirect, $comment ) { |
| 26 |
if ( empty( $_REQUEST['content-item-only'] ) || sanitize_text_field( $_REQUEST['content-item-only'] ) !== 'yes' ) { |
| 27 |
return $redirect; |
| 28 |
} |
| 29 |
|
| 30 |
if ( empty( $_REQUEST['content-item-only-redirect'] ) ) { |
| 31 |
return $redirect; |
| 32 |
} |
| 33 |
|
| 34 |
if ( get_post_type( $comment->comment_post_ID ) != 'lp_lesson' ) { |
| 35 |
return $redirect; |
| 36 |
} |
| 37 |
|
| 38 |
return esc_url_raw( add_query_arg( 'content-item-only', 'yes', LP_Helper::sanitize_params_submitted( $_REQUEST['content-item-only-redirect'] ) ) ); |
| 39 |
} |
| 40 |
} |
| 41 |
add_filter( 'comment_post_redirect', 'learn_press_get_only_content_permalink', 10, 2 ); |
| 42 |
|
| 43 |
/*function learn_press_lesson_comment_form() { |
| 44 |
global $post; |
| 45 |
|
| 46 |
$course = learn_press_get_course(); |
| 47 |
if ( ! $course ) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
$lesson = LP_Global::course_item(); |
| 52 |
if ( ! $lesson ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
$user = learn_press_get_current_user(); |
| 57 |
|
| 58 |
if ( $lesson->setup_postdata() ) { |
| 59 |
if ( comments_open() || get_comments_number() ) { |
| 60 |
add_filter( 'deprecated_file_trigger_error', '__return_false' ); |
| 61 |
comments_template(); |
| 62 |
remove_filter( 'deprecated_file_trigger_error', '__return_false' ); |
| 63 |
} |
| 64 |
|
| 65 |
$lesson->reset_postdata(); |
| 66 |
} |
| 67 |
|
| 68 |
}*/ |
| 69 |
|
| 70 |
/** |
| 71 |
* Remove data section after remove lesson |
| 72 |
*/ |
| 73 |
function learn_press_lesson_before_delete_post( $post_id, $force = false ) { |
| 74 |
global $wpdb; |
| 75 |
|
| 76 |
if ( 'lp_lesson' === get_post_type( $post_id ) ) { |
| 77 |
$sql = 'DELETE FROM `' . $wpdb->prefix . 'learnpress_section_items` WHERE `item_id` = ' . $post_id . ' AND `item_type` = "lp_lesson"'; |
| 78 |
$wpdb->query( $sql ); |
| 79 |
} |
| 80 |
} |
| 81 |
add_action( 'delete_post', 'learn_press_lesson_before_delete_post', 10, 2 ); |
| 82 |
|