public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/admin/functions.php
/**
 * Method called whenever a post is saved, which will check that any course units
 * save their meta data.
 *
 * @since 1.0.0
 *
 * @param integer $post_id The ID of the post being saved.
 */
Method called whenever a post is saved, which will check that any course units
save their meta data.



@param integer $post_id The ID of the post being saved.
Method called whenever a post is saved which will check that any course units save their meta data . @param integer $post_id The ID of the post being saved .
function WPCW_units_saveUnitPostMetaData( $post_id, $post ) {
	if ( 'course_unit' != $post->post_type ) {
		return;
	}
	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		return;
	}
	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
		return;
	}
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	$current_user = wp_get_current_user();
	$SQL = $wpdb->prepare( "
		SELECT *
		FROM $wpcwdb->units_meta
		WHERE unit_id = %d
	", $post_id );
	if ( ! $unitDetails = $wpdb->get_row( $SQL ) ) {
		$SQL = $wpdb->prepare( "
			INSERT INTO $wpcwdb->units_meta (unit_id, parent_module_id, unit_author)
			VALUES (%d, 0, %d)
		", $post_id, $current_user->ID );
		$wpdb->query( $SQL );
	}
	if ( $template = WPCW_arrays_getValue( $_POST, 'wpcw_units_choose_template_list' ) ) {
		update_post_meta( $post_id, WPCW_TEMPLATE_META_ID, $template );
	}
	$convertedTimestamp = absint( WPCW_arrays_getValue( $_POST, 'wpcw_units_drip_interval' ) );
	$interval_type      = WPCW_arrays_getValue( $_POST, 'wpcw_units_drip_interval_type' );
	switch ( $interval_type ) {
		case 'interval_hours':
			$convertedTimestamp = $convertedTimestamp * WPCW_TIME_HR_IN_SECS;
			break;
		case 'interval_days':
			$convertedTimestamp = $convertedTimestamp * WPCW_TIME_DAY_IN_SECS;
			break;
		case 'interval_weeks':
			$convertedTimestamp = $convertedTimestamp * WPCW_TIME_WEEK_IN_SECS;
			break;
		case 'interval_months':
			$convertedTimestamp = $convertedTimestamp * WPCW_TIME_MONTH_IN_SECS;
			break;
		case 'interval_years':
			$convertedTimestamp = $convertedTimestamp * WPCW_TIME_YEAR_IN_SECS;
			break;
	}
	$metaTableUpdate = array(
		'unit_id'                 => $post_id,
		'unit_drip_type'          => WPCW_arrays_getValue( $_POST, 'wpcw_units_drip_type' ),
		'unit_drip_interval'      => $convertedTimestamp,
		'unit_drip_interval_type' => $interval_type,
		'unit_drip_date'          => date( 'Y-m-d H:i:s', strtotime( WPCW_arrays_getValue( $_POST, 'wpcw_units_drip_date' ) ) ),
		'unit_teaser'             => WPCW_arrays_getValue( $_POST, 'wpcw_unit_teaser' ) ?: 0
	);
	$wpdb->query( arrayToSQLUpdate( $wpcwdb->units_meta, $metaTableUpdate, 'unit_id' ) );
	if ( $unitDetails && $unitDetails->parent_course_id > 0 ) {
		wpcw()->courses->invalidate_builder_cache( $unitDetails->parent_course_id );
	}
	WPCW_queue_dripfeed::updateQueueItems_unitUpdated( $post_id );
}
function WPCW_units_saveUnitPostMetaData ( $ post_id , $ post ) { if ( 'course_unit' != $ post -> post_type ) { return ; } if ( ! current_user_can ( 'edit_post' , $ post_id ) ) { return ; } if ( defined ( 'DOING_AJAX' ) && DOING_AJAX ) { return ; } global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ current_user = wp_get_current_user ( ) ; $ SQL = $ wpdb -> prepare ( " 
		SELECT *
		FROM  $ wpcwdb -> units_meta 
		WHERE unit_id = %d
	 " , $ post_id ) ; if ( ! $ unitDetails = $ wpdb -> get_row ( $ SQL ) ) { $ SQL = $ wpdb -> prepare ( " 
			INSERT INTO  $ wpcwdb -> units_meta  (unit_id, parent_module_id, unit_author)
			VALUES (%d, 0, %d)
		 " , $ post_id , $ current_user -> ID ) ; $ wpdb -> query ( $ SQL ) ; } if ( $ template = WPCW_arrays_getValue ( $ _POST , 'wpcw_units_choose_template_list' ) ) { update_post_meta ( $ post_id , WPCW_TEMPLATE_META_ID , $ template ) ; } $ convertedTimestamp = absint ( WPCW_arrays_getValue ( $ _POST , 'wpcw_units_drip_interval' ) ) ; $ interval_type = WPCW_arrays_getValue ( $ _POST , 'wpcw_units_drip_interval_type' ) ; switch ( $ interval_type ) { case 'interval_hours' : $ convertedTimestamp = $ convertedTimestamp * WPCW_TIME_HR_IN_SECS ; break ; case 'interval_days' : $ convertedTimestamp = $ convertedTimestamp * WPCW_TIME_DAY_IN_SECS ; break ; case 'interval_weeks' : $ convertedTimestamp = $ convertedTimestamp * WPCW_TIME_WEEK_IN_SECS ; break ; case 'interval_months' : $ convertedTimestamp = $ convertedTimestamp * WPCW_TIME_MONTH_IN_SECS ; break ; case 'interval_years' : $ convertedTimestamp = $ convertedTimestamp * WPCW_TIME_YEAR_IN_SECS ; break ; } $ metaTableUpdate = array ( 'unit_id' => $ post_id , 'unit_drip_type' => WPCW_arrays_getValue ( $ _POST , 'wpcw_units_drip_type' ) , 'unit_drip_interval' => $ convertedTimestamp , 'unit_drip_interval_type' => $ interval_type , 'unit_drip_date' => date ( 'Y-m-d H:i:s' , strtotime ( WPCW_arrays_getValue ( $ _POST , 'wpcw_units_drip_date' ) ) ) , 'unit_teaser' => WPCW_arrays_getValue ( $ _POST , 'wpcw_unit_teaser' ) ? : 0 ) ; $ wpdb -> query ( arrayToSQLUpdate ( $ wpcwdb -> units_meta , $ metaTableUpdate , 'unit_id' ) ) ; if ( $ unitDetails && $ unitDetails -> parent_course_id > 0 ) { wpcw ( ) -> courses -> invalidate_builder_cache ( $ unitDetails -> parent_course_id ) ; } WPCW_queue_dripfeed :: updateQueueItems_unitUpdated ( $ post_id ) ; }
Method called whenever a post is saved, which will check that any course units
 save their meta data.
Method called whenever a post is saved which will check that any course units save their meta data .
// Check we have a course unit, not any other type (including revisions). // Check user is allowed to edit the post. // Current User // See if there's an entry in the courseware table // Ensure there's a blank entry in the database for this post. // Update the selection for the unit template to standard WP meta table // For the drip-feed interval, we need to add to the post meta table. // Actual date is converted using the hidden field that has a reverse-date notation // to bypass the translation aspects. // Let the queuing system know that a change has happened.