public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/admin/functions.php
/**
 * Function that generates a sample CSV file from the database using the relevant course IDs.
 *
 * @since 1.0.0
 */
Function that generates a sample CSV file from the database using the relevant course IDs.
Function that generates a sample CSV file from the database using the relevant course IDs .
function WPCW_data_export_userImportSample() {
	$current_user = wp_get_current_user();
	if ( ! user_can( $current_user, 'manage_wpcw_settings' ) ) {
		wp_die( __( 'You do not have sufficient permissions to import users.', 'wp-courseware' ) );
	}
	WPCW_data_export_sendHeaders_CSV( 'wpcw-import-users-sample.csv' );
	$out = fopen( 'php://output', 'w' );
	$headings = array( 'first_name', 'last_name', 'email_address', 'courses_to_add_to' );
	fputcsv( $out, $headings );
	$courseList    = array();
	$courseList[1] = __( 'Test Course', 'wp-courseware' ) . ' A';
	$courseList[2] = __( 'Test Course', 'wp-courseware' ) . ' B';
	$courseListOfIDs = 0;
	foreach ( $courseList as $courseID => $courseName ) {
		$data   = array();
		$data[] = 'John';
		$data[] = 'Smith';
		$data[] = get_bloginfo( 'admin_email' );
		if ( $courseListOfIDs ) {
			$courseListOfIDs .= ',' . $courseID;
		} else {
			$courseListOfIDs = $courseID;
		}
		$data[] = $courseListOfIDs;
		$data[] = false;
		fputcsv( $out, $data );
	}
	fclose( $out );
	die();
}
function WPCW_data_export_userImportSample ( ) { $ current_user = wp_get_current_user ( ) ; if ( ! user_can ( $ current_user , 'manage_wpcw_settings' ) ) { wp_die ( __ ( 'You do not have sufficient permissions to import users.' , 'wp-courseware' ) ) ; } WPCW_data_export_sendHeaders_CSV ( 'wpcw-import-users-sample.csv' ) ; $ out = fopen ( 'php://output' , 'w' ) ; $ headings = array ( 'first_name' , 'last_name' , 'email_address' , 'courses_to_add_to' ) ; fputcsv ( $ out , $ headings ) ; $ courseList = array ( ) ; $ courseList [ 1 ] = __ ( 'Test Course' , 'wp-courseware' ) . ' A' ; $ courseList [ 2 ] = __ ( 'Test Course' , 'wp-courseware' ) . ' B' ; $ courseListOfIDs = 0 ; foreach ( $ courseList as $ courseID => $ courseName ) { $ data = array ( ) ; $ data [ ] = 'John' ; $ data [ ] = 'Smith' ; $ data [ ] = get_bloginfo ( 'admin_email' ) ; if ( $ courseListOfIDs ) { $ courseListOfIDs .= ',' . $ courseID ; } else { $ courseListOfIDs = $ courseID ; } $ data [ ] = $ courseListOfIDs ; $ data [ ] = false ; fputcsv ( $ out , $ data ) ; } fclose ( $ out ) ; die ( ) ; }
Function that generates a sample CSV file from the database using the relevant course IDs.
Function that generates a sample CSV file from the database using the relevant course IDs .
// Check permissions // Start CSV // The headings // Use existing course IDs to make it more useful. If there are no courses // Create some dummy courses to add. // Sequentially add each ID to the list // Not removing any courses