Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't hardcode file name
  • Loading branch information
szk11001 committed Sep 2, 2015
1 parent 6f706ff commit 85e70c9
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions uc-people.php
Expand Up @@ -112,20 +112,20 @@ function processCSV($file){
return $data;
}

function importFile(){
function importFile( $filename ){
if( isset( $_POST['_wpnonce_ucp_import_people_nonce'] ) ){
check_admin_referer( 'ucp_import_people_nonce', '_wpnonce_ucp_import_people_nonce' );

if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}

if( $_FILES['csv_file']['type'] !== 'text/csv' ){
if( $_FILES[$filename]['type'] !== 'text/csv' ){
echo '<div class="error notice is-dismissible below-h2" id="message"><p>Please upload a CSV file</p><button class="notice-dismiss" type="button"><span class="screen-reader-text">Dismiss this notice.</span></button></div>';
return;
}

$uploadedFile = wp_handle_upload( $_FILES['csv_file'], array( 'test_form' => false ) );
$uploadedFile = wp_handle_upload( $_FILES[$filename], array( 'test_form' => false ) );

if( $uploadedFile && !isset($uploadedFile['error']) ){
$data = processCSV( $uploadedFile['file'] );
Expand All @@ -134,7 +134,6 @@ function importFile(){
'first_name' => 'First Name',
'last_name' => 'Last Name',
'title' => 'Title',
//'about' => 'Biographical Info',
'email' => 'Email Address',
'phone' => 'Phone 1',
'phone_(alternate)' => 'Phone 2',
Expand Down Expand Up @@ -169,8 +168,6 @@ function importFile(){
}
}



function uc_people_settings_page_menu(){
add_submenu_page('tools.php', 'Import People', 'Import People', 'manage_options', 'uc-import-people', 'uc_people_settings_page' );
}
Expand All @@ -195,7 +192,7 @@ function uc_people_settings_page(){
?>
<input type="file" name="csv_file" />
<?php
importFile();
importFile( 'csv_file' );
submit_button( 'Import People' );
?>
</form>
Expand Down

0 comments on commit 85e70c9

Please sign in to comment.