generated from AsianHighway/PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ut_country_plugin.php
94 lines (81 loc) · 2.6 KB
/
ut_country_plugin.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Plugin Name: UT Country Plugin
* Plugin URI: #
* Description: [ut_country id="my_id" field="correspondant_field"]
* Version: 1.0
* Author: Tourism Development
* Author URI: //7millionjobs.com/
**/
function get_country_by($id) {
global $wpdb;
//$table_name = $wpdb->prefix . "ut_country";
$table_name = "ut_countries";
$query = "SELECT * FROM $table_name WHERE country_id = $id ";
return $wpdb->get_row( $query , OBJECT );
}
function get_continent_by($id) {
global $wpdb;
//$table_name = $wpdb->prefix . "ut_country";
$table_name = "ut_continents";
$query = "SELECT * FROM $table_name WHERE continent_id = $id ";
return $wpdb->get_row( $query , OBJECT );
}
function get_president_by($id) {
global $wpdb;
//$table_name = $wpdb->prefix . "ut_country";
$table_name = "ut_president";
$query = "SELECT * FROM $table_name WHERE country_id = $id ";
return $wpdb->get_row( $query , OBJECT );
}
function get_highways_by($id) {
global $wpdb;
//$table_name = $wpdb->prefix . "ut_country";
$table_name = "ut_highways";
$query = "SELECT * FROM $table_name WHERE country_id = $id ";
return $wpdb->get_results( $query , OBJECT );
}
// [ut_country id="my_id" field="correspondant_field"]
function ut_country_func( $atts ){
$a = shortcode_atts( array(
'id' => '', // default value set
'field' => ''
), $atts );
$country = get_country_by($a['id']);
$continent = get_continent_by($country->continent_id);
$president = get_president_by($country->country_id);
$highways = get_highways_by($country->country_id);
$strHighways = '';
if ( count($highways) > 0 ) {
foreach ($highways as $k3y => $oneRow) {
$strHighways .= " " . $oneRow->highway_name . ";";
}
} else {
$strHighways = 'Nothing';
}
switch ($a['field']) {
case 'name':
$out = $country->country_name;
break;
case 'continent':
$out = $continent->continent_name;
break;
case 'image':
$out = $country->country_image;
break;
case 'playlist':
$out = $country->country_playlist;
break;
case 'highways':
$out = $strHighways;
break;
case 'president':
$out = $president->name;
break;
default:
$out = 'Nothing to display here ....';
break;
}
return $out;
}
add_shortcode( 'ut_country', 'ut_country_func' );