-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
64 lines (48 loc) · 1.24 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
function check_empty_table($tablename, &$response) {
global $wpdb;
$result = $wpdb->get_results("SELECT * FROM $tablename");
if(empty($result)){
$response = '';
return $response;
}
if(!empty($result)){
$response = $result;
return $response;
}
}
function importdata($file) {
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
// Name of the file
$plugindir = dirname( __FILE__ );
$filename = $plugindir . '/metaboxes/database/' . $file;
if(file_exists($filename)){
// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
// Perform the query
$wpdb->query($templine);
// Reset temp variable to empty
$templine = '';
}
}
echo 'Importing the data now, this page will be auto refreshed in a while ..';
echo '<META HTTP-EQUIV="REFRESH" CONTENT="8">' ;
}
else
echo "Error Importing: Cannot find SQL File ...";
}
?>