121 lines
3.3 KiB
PHP
121 lines
3.3 KiB
PHP
<?php
|
|
/*
|
|
Plugin Name: EO import venues
|
|
Description: Import venues for event organiser...
|
|
see : https://gist.github.com/stephenharris/00a6a601b274b38a59cc82c146a95688
|
|
Add options page with ACF with file field and button.
|
|
Version: 0.1
|
|
License: GPL
|
|
Author: Richard Turner
|
|
Author URI: yoururl
|
|
*/
|
|
|
|
function pgm_enqueue_styles(){
|
|
$template_url = get_template_directory_uri();
|
|
$plugin_url = plugin_dir_url( __FILE__ );
|
|
wp_register_style( 'eoiv-style-css', $plugin_url.'css/style.css', false, NULL, 'all');
|
|
wp_enqueue_style( 'eoiv-style-css' );
|
|
wp_register_script('eoiv-custom-script', $plugin_url . 'js/custom-script.js', array('jquery'), null, true);
|
|
wp_enqueue_script('eoiv-custom-script');
|
|
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'pgm_enqueue_styles' );
|
|
|
|
add_action('acfe/fields/button/name=importer_les_venues', 'acf_import_venues_button_ajax', 10, 2);
|
|
function acf_import_venues_button_ajax($field, $post_id){
|
|
|
|
$column_map = array(
|
|
'name',
|
|
'description',
|
|
'address',
|
|
'city',
|
|
'state',
|
|
'postcode',
|
|
'country',
|
|
'latitude',
|
|
'longtitude',
|
|
);
|
|
|
|
/*
|
|
[0] => Fête Romane - Wolubilis
|
|
[1] => http://www.wolubilis.be/fr/la_saison/2013/theatre-danse-musique-cirque_12-13/ds_%E2%80%93_you_can_ne
|
|
[2] =>
|
|
[3] => Brussels
|
|
[4] => Belgiuem
|
|
[5] =>
|
|
[6] =>
|
|
[7] =>
|
|
|
|
*/
|
|
|
|
//TODO tab/semicolon delimiter!
|
|
|
|
$file_ID = $_POST['acf']['field_6231b2205f346'];
|
|
$tmp = "";
|
|
$file = get_attached_file($file_ID);
|
|
// $tmp .= print_r($file,1);
|
|
// error_log(__LINE__." ".$tmp);
|
|
if($file == ""){
|
|
wp_send_json_success("Error File is Empty file_ID:".$file_ID);
|
|
return;
|
|
}
|
|
|
|
// $csvFile = file($file);
|
|
$csvFile = fopen($file, 'r');
|
|
$i = 0;
|
|
$count_adjusted = 0;
|
|
|
|
|
|
|
|
while (($row = fgetcsv($csvFile)) !== false) {
|
|
// $tmp .= print_r($row,1);
|
|
// $tmp .= " 1st\n";
|
|
// $tmp .= print_r(utf8_encode($row),1);
|
|
// wp_send_json_success("End of Function:".$tmp."\n");
|
|
if(empty($row)){
|
|
wp_send_json_success("Error! File is empty");
|
|
return;
|
|
}
|
|
|
|
$venue['name'] = $row[0];
|
|
$venue['description'] = $row[1];
|
|
$venue['address'] = $row[2];
|
|
$venue['city'] = $row[3];
|
|
$venue['state'] = $row[4];
|
|
$venue['postcode'] = $row[5];
|
|
$venue['country'] = $row[6];
|
|
$venue['latitude'] = $row[7];
|
|
$venue['longtitude'] = $row[8];
|
|
|
|
$return = eo_insert_venue( $venue['name'], $venue );
|
|
|
|
// if(is_wp_error( $return )){
|
|
// $tmp .= print_r($return,1);
|
|
// wp_send_json_success("End of Function:".$tmp."\n");
|
|
// return;
|
|
// }else{
|
|
// $tmp .= $return."\n";
|
|
// }
|
|
$tmp .= print_r($return,1);
|
|
}
|
|
|
|
|
|
|
|
// $tmp .= print_r($return,1);
|
|
wp_send_json_success("End of Function:".$tmp);
|
|
return;
|
|
}
|
|
|
|
add_action('acf/input/admin_enqueue_scripts', 'acf_admin_enqueue_scripts');
|
|
function acf_admin_enqueue_scripts() {
|
|
$plugin_url = plugin_dir_url( __FILE__ );
|
|
// wp_enqueue_style( 'nevicata-acf-input-css', get_stylesheet_directory_uri() . '/css/nevicata-acf-input.css', false, '1.0.0' );
|
|
wp_enqueue_script( 'eoiv-acf-input-js', $plugin_url . 'js/eoiv-acf-input.js', false, '1.0.0' );
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|