public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/admin/functions.php
/**
 * Function called when a post is being deleted by WordPress. Want to check
 * if this relates to a unit, and if so, remove it from our tables.
 *
 * @since 1.0.0
 *
 * @param integer $post_id The ID of the post being deleted.
 */
Function called when a post is being deleted by WordPress. Want to check
if this relates to a unit, and if so, remove it from our tables.



@param integer $post_id The ID of the post being deleted.
Function called when a post is being deleted by WordPress . Want to check if this relates to a unit and if so remove it from our tables . @param integer $post_id The ID of the post being deleted .
function WPCW_units_deleteUnitHandler( $post_id ) {
	if ( 'course_unit' != get_post_type( $post_id ) ) {
		return;
	}
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	$SQL = $wpdb->prepare( "SELECT * FROM $wpcwdb->units_meta WHERE unit_id = %d", $post_id );
	if ( $unitDetails = $wpdb->get_row( $SQL ) ) {
		$parentData = WPCW_units_getAssociatedParentData( $post_id );
		$SQL = $wpdb->prepare( "DELETE FROM $wpcwdb->units_meta WHERE unit_id = %d", $post_id );
		$wpdb->query( $SQL );
		if ( $unitDetails->parent_course_id > 0 ) {
			WPCW_courses_reorderUnitNumbers( $unitDetails->parent_course_id );
			$parentCourseDetails = WPCW_courses_getCourseDetails( $unitDetails->parent_course_id );
			do_action( 'wpcw_course_details_updated', $parentCourseDetails );
			wpcw()->courses->invalidate_builder_cache( $unitDetails->parent_course_id );
		}
	}
	$SQL = $wpdb->prepare( "DELETE FROM $wpcwdb->user_progress WHERE unit_id = %d", $post_id );
	$wpdb->query( $SQL );
	$SQL = $wpdb->prepare( "UPDATE $wpcwdb->quiz SET parent_unit_id = 0, parent_course_id = 0 WHERE parent_unit_id = %d", $post_id );
	$wpdb->query( $SQL );
	$SQL = $wpdb->prepare( "UPDATE $wpcwdb->user_progress_quiz SET unit_id = 0 WHERE unit_id = %d", $post_id );
	$wpdb->query( $SQL );
	WPCW_queue_dripfeed::updateQueueItems_unitDeleted( $post_id );
}
function WPCW_units_deleteUnitHandler ( $ post_id ) { if ( 'course_unit' != get_post_type ( $ post_id ) ) { return ; } global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ SQL = $ wpdb -> prepare ( " SELECT * FROM  $ wpcwdb -> units_meta  WHERE unit_id = %d " , $ post_id ) ; if ( $ unitDetails = $ wpdb -> get_row ( $ SQL ) ) { $ parentData = WPCW_units_getAssociatedParentData ( $ post_id ) ; $ SQL = $ wpdb -> prepare ( " DELETE FROM  $ wpcwdb -> units_meta  WHERE unit_id = %d " , $ post_id ) ; $ wpdb -> query ( $ SQL ) ; if ( $ unitDetails -> parent_course_id > 0 ) { WPCW_courses_reorderUnitNumbers ( $ unitDetails -> parent_course_id ) ; $ parentCourseDetails = WPCW_courses_getCourseDetails ( $ unitDetails -> parent_course_id ) ; do_action ( 'wpcw_course_details_updated' , $ parentCourseDetails ) ; wpcw ( ) -> courses -> invalidate_builder_cache ( $ unitDetails -> parent_course_id ) ; } } $ SQL = $ wpdb -> prepare ( " DELETE FROM  $ wpcwdb -> user_progress  WHERE unit_id = %d " , $ post_id ) ; $ wpdb -> query ( $ SQL ) ; $ SQL = $ wpdb -> prepare ( " UPDATE  $ wpcwdb -> quiz  SET parent_unit_id = 0, parent_course_id = 0 WHERE parent_unit_id = %d " , $ post_id ) ; $ wpdb -> query ( $ SQL ) ; $ SQL = $ wpdb -> prepare ( " UPDATE  $ wpcwdb -> user_progress_quiz  SET unit_id = 0 WHERE unit_id = %d " , $ post_id ) ; $ wpdb -> query ( $ SQL ) ; WPCW_queue_dripfeed :: updateQueueItems_unitDeleted ( $ post_id ) ; }
Function called when a post is being deleted by WordPress.
Function called when a post is being deleted by WordPress .
// Only process course units. // See if we've got data on this unit in the meta table // Associated with a course? Get course details // Right, it's one of our units, so need to delete the meta data // Now update the course data. // Need to update the course unit count and progresses // Delete it from the user progress too // Quiz - Unconnect it from the quiz that it's associated with. // Quiz Progress - Remove user progress for this quiz/unit // Remove any queue data so that users aren't notified about deleted items.