Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create an array from csv files
- function ImportCSV2Array($filename){
- $row = 0;
- $col = 0;
- $handle = @fopen($filename, "r");
- if ($handle)
- {
- while (($row = fgetcsv($handle, 4096)) !== false)
- {
- if (empty($fields))
- {
- $fields = $row;
- continue;
- }
- foreach ($row as $k=>$value)
- {
- $results[$col][$fields[$k]] = $value;
- }
- $col++;
- unset($row);
- }
- if (!feof($handle))
- {
- echo "Error: unexpected fgets() failn";
- }
- fclose($handle);
- }
- return $results;
- }
- // function to update wp options
- function import_location_address_eventon() {
- $options = get_option('evo_tax_meta');
- $filename = "https://name_file.csv";
- $csvArray = ImportCSV2Array($filename);
- $agg_evotax_meta = "NO";
- foreach($csvArray as $row) {
- $term_id = $row['Term ID'];
- $tmp = $options['event_location'][$term_id]['location_address'];
- if ( empty($tmp) ) {
- // se il campo indirizzo è vuoto lo aggiorno con il valore dal file csv
- $options['event_location'][$term_id]['location_address'] = $row['Indirizzo'];
- echo $row['Term ID'] . " - " . $row['Indirizzo'] . " INDIRIZZO DA CSV " . $options['event_location'][$term_id]['location_address'] . " INDIRIZZO AGGIUNTO" . "<br><br>";
- $agg_evotax_meta = "SI";
- }
- }
- if ( $agg_evotax_meta != "SI") {
- echo "Nessuna Variazione nelle località";
- } else {
- // update_option('evo_tax_meta', $options);
- echo "Variazione nelle località!!!";
- }
- }
- // function to check from wp dashbord widget
- function gpr_wp_dashboard_setup() {
- wp_add_dashboard_widget( 'import_location_address_eventon', __( 'Notifications' ),'import_location_address_eventon');
- }
- add_action('wp_dashboard_setup', 'gpr_wp_dashboard_setup');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement