/
thegamingplace.php
61 lines (50 loc) · 1.74 KB
/
thegamingplace.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
<style>
.tgp_product {
float: left;
width: 190px;
margin-right: 15px;
}
</style>
<?php
/*
Plugin Name: The Gaming Place
Description: A bridge plugin for TheGamingPlace store products
Author: Raz Damaschin
Version: 1.0
*/
// Add Setting Menu Item
function tgp_admin_actions() {
add_options_page("TGP Product Display", "TGP Product Display", 1, "TGP_Product_Display", "tgp_admin");
}
add_action('admin_menu', 'tgp_admin_actions');
function tgp_admin() {
include('thegamingplace_admin.php');
}
// Get and display products
function tgp_get_products() {
// Connect to the database
$db = new wpdb(get_option('db_user'),get_option('db_pass'),get_option('db_name'),get_option('db_host'));
// Get values
$store_url = get_option('store_url');
$img_folder = get_option('img_folder');
$num_products = get_option('num_products');
// Get Products
$products = $db->get_results("SELECT * FROM products LIMIT ".$num_products);
// Build Output
$output = '';
if($products) {
foreach($products as $product) {
$output .= '<div class="tgp_product">';
$output .= '<h3>'.$product->title.'</h3>';
$output .= '<img src="'.$store_url.'/'.$img_folder.'/'.$product->image.'" alt="'.$product->title.'">';
$output .= '<div class="price">'.$product->price.'</div>';
$output .= '<div class="desc">'.wp_trim_words($product->description, 10).'</div>';
$output .= '<a href="'.$store_url.'products/details/'.$product->id.'">Buy Now</a>';
}
} else {
$output .= 'No products to list';
}
return $output;
}
//Add Shortcode
add_shortcode('show_products', 'tgp_get_products');