Advertisement
Guest User

Untitled

a guest
Jun 30th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. // create an array from csv files
  2. function ImportCSV2Array($filename){
  3.     $row = 0;
  4.     $col = 0;
  5.    
  6.     $handle = @fopen($filename, "r");
  7.     if ($handle)
  8.     {
  9.         while (($row = fgetcsv($handle, 4096)) !== false)
  10.         {
  11.             if (empty($fields))
  12.             {
  13.                 $fields = $row;
  14.                 continue;
  15.             }
  16.            
  17.             foreach ($row as $k=>$value)
  18.             {
  19.                 $results[$col][$fields[$k]] = $value;
  20.             }
  21.             $col++;
  22.             unset($row);
  23.         }
  24.         if (!feof($handle))
  25.         {
  26.             echo "Error: unexpected fgets() failn";
  27.         }
  28.         fclose($handle);
  29.     }
  30.    
  31.     return $results;
  32. }
  33.  
  34.  
  35. // function to update wp options
  36. function import_location_address_eventon() {
  37.     $options = get_option('evo_tax_meta');
  38.     $filename = "https://name_file.csv";
  39.     $csvArray = ImportCSV2Array($filename);
  40.     $agg_evotax_meta = "NO";
  41.     foreach($csvArray as $row) {
  42.         $term_id = $row['Term ID'];
  43.         $tmp = $options['event_location'][$term_id]['location_address'];
  44.  
  45.         if ( empty($tmp) ) {
  46.             // se il campo indirizzo è vuoto lo aggiorno con il valore dal file csv
  47.             $options['event_location'][$term_id]['location_address'] = $row['Indirizzo'];
  48.             echo $row['Term ID'] . " - " . $row['Indirizzo'] . " INDIRIZZO DA CSV " . $options['event_location'][$term_id]['location_address'] . " INDIRIZZO AGGIUNTO" .  "<br><br>";
  49.             $agg_evotax_meta = "SI";
  50.         }
  51.     }
  52.     if ( $agg_evotax_meta != "SI") {
  53.         echo "Nessuna Variazione nelle località";
  54.     } else {
  55.         // update_option('evo_tax_meta', $options);
  56.         echo "Variazione nelle località!!!";
  57.     }
  58. }
  59. // function to check from wp dashbord widget
  60. function gpr_wp_dashboard_setup() {
  61.     wp_add_dashboard_widget( 'import_location_address_eventon', __( 'Notifications' ),'import_location_address_eventon');
  62. }
  63. add_action('wp_dashboard_setup', 'gpr_wp_dashboard_setup');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement