Skip to content

Commit bce2b1d

Browse files
committed
fix: fix db prefix
1 parent 83f787e commit bce2b1d

File tree

7 files changed

+65
-58
lines changed

7 files changed

+65
-58
lines changed

model/blog/category.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public function getCategory( $category_id ) {
1111
tt.`parent`,
1212
tt.`description`
1313
FROM
14-
`wp_terms` t
15-
LEFT JOIN `wp_term_taxonomy` tt
14+
`".$wpdb->prefix."terms` t
15+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
1616
ON tt.`term_id` = t.`term_id`
1717
WHERE tt.`taxonomy` = 'category' and t.`term_id` = '" . (int) $category_id . "'";
1818

@@ -32,8 +32,8 @@ public function getCategories( $data = array() ) {
3232
tt.`parent`,
3333
tt.`description`
3434
FROM
35-
`wp_terms` t
36-
LEFT JOIN `wp_term_taxonomy` tt
35+
`".$wpdb->prefix."terms` t
36+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
3737
ON tt.`term_id` = t.`term_id`
3838
WHERE tt.`taxonomy` = 'category'";
3939

@@ -87,8 +87,8 @@ public function getTotalCategories( $data = array() ) {
8787

8888
$sql = "SELECT count(*) as total
8989
FROM
90-
`wp_terms` t
91-
LEFT JOIN `wp_term_taxonomy` tt
90+
`".$wpdb->prefix."terms` t
91+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
9292
ON tt.`term_id` = t.`term_id`
9393
WHERE tt.`taxonomy` = 'category'";
9494

model/blog/post.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public function getPost($post_id)
1313
p.`post_content` AS description,
1414
p.`post_excerpt` AS shortDescription,
1515
p.`post_date` AS dateAdded,
16-
(SELECT `meta_value` FROM `wp_postmeta` WHERE `post_id` = p.`ID` AND `meta_key` = '_thumbnail_id') AS image_id
16+
(SELECT `meta_value` FROM `".$wpdb->prefix."postmeta` WHERE `post_id` = p.`ID` AND `meta_key` = '_thumbnail_id') AS image_id
1717
FROM
18-
`wp_posts` p
18+
`".$wpdb->prefix."posts` p
1919
WHERE p.`post_type` = 'post'
2020
AND p.`post_status` = 'publish' and p.`ID` = '" . (int) $post_id . "'";
2121

@@ -33,7 +33,7 @@ public function getPosts($data = array())
3333
$sql = "SELECT
3434
p.ID
3535
FROM
36-
`wp_posts` p
36+
`".$wpdb->prefix."posts` p
3737
WHERE p.`post_type` = 'post'
3838
AND p.`post_status` = 'publish'";
3939

@@ -43,8 +43,8 @@ public function getPosts($data = array())
4343
$implode[] = "'" . (int) $data['filter_category_id'] . "' IN (SELECT
4444
tt.`term_id`
4545
FROM
46-
`wp_term_relationships` tr
47-
LEFT JOIN `wp_term_taxonomy` tt
46+
`".$wpdb->prefix."term_relationships` tr
47+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
4848
ON tr.`term_taxonomy_id` = tt.`term_taxonomy_id`
4949
WHERE tt.`taxonomy` = 'category'
5050
AND tr.`object_id` = p.`ID`)";
@@ -95,7 +95,7 @@ public function getTotalPosts($data = array())
9595

9696
$sql = "SELECT count(*) as total
9797
FROM
98-
`wp_posts` p
98+
`".$wpdb->prefix."posts` p
9999
WHERE p.`post_type` = 'post'
100100
AND p.`post_status` = 'publish'";
101101

@@ -105,8 +105,8 @@ public function getTotalPosts($data = array())
105105
$implode[] = "'" . (int) $data['filter_category_id'] . "' IN (SELECT
106106
tt.`term_id`
107107
FROM
108-
`wp_term_relationships` tr
109-
LEFT JOIN `wp_term_taxonomy` tt
108+
`".$wpdb->prefix."term_relationships` tr
109+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
110110
ON tr.`term_taxonomy_id` = tt.`term_taxonomy_id`
111111
WHERE tt.`taxonomy` = 'category'
112112
AND tr.`object_id` = p.`ID`)";
@@ -128,8 +128,8 @@ public function getCategoriesByPost($post_id)
128128
$sql = "SELECT
129129
tt.`term_id`
130130
FROM
131-
`wp_term_relationships` tr
132-
LEFT JOIN `wp_term_taxonomy` tt
131+
`".$wpdb->prefix."term_relationships` tr
132+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
133133
ON tr.`term_taxonomy_id` = tt.`term_taxonomy_id`
134134
WHERE tt.`taxonomy` = 'category'
135135
AND tr.`object_id` = '" . $post_id . "'";

model/common/page.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public function getPage($page_id)
66
{
77
global $wpdb;
88

9-
$sql = "SELECT p.ID, p.post_title AS title, p.`post_content` AS description, p.`menu_order` AS sort_order FROM wp_posts p WHERE p.`post_type` = 'page' AND p.`ID` = '".(int)$page_id."'";
9+
$sql = "SELECT p.ID, p.post_title AS title, p.`post_content` AS description, p.`menu_order` AS sort_order FROM ".$wpdb->prefix."posts p WHERE p.`post_type` = 'page' AND p.`ID` = '".(int)$page_id."'";
1010

1111
$result = $wpdb->get_row($sql);
1212

@@ -17,7 +17,7 @@ public function getPages($data = array())
1717
{
1818
global $wpdb;
1919

20-
$sql = "SELECT p.ID, p.post_title AS title, p.`post_content` AS description, p.`menu_order` AS sort_order FROM wp_posts p WHERE p.`post_type` = 'page' AND p.post_status = 'publish'";
20+
$sql = "SELECT p.ID, p.post_title AS title, p.`post_content` AS description, p.`menu_order` AS sort_order FROM ".$wpdb->prefix."posts p WHERE p.`post_type` = 'page' AND p.post_status = 'publish'";
2121

2222
$implode = array();
2323

@@ -71,7 +71,7 @@ public function getTotalPages($data = array())
7171
{
7272
global $wpdb;
7373

74-
$sql = "SELECT count(*) as total FROM wp_posts p WHERE p.`post_type` = 'page' AND p.post_status = 'publish'";
74+
$sql = "SELECT count(*) as total FROM ".$wpdb->prefix."posts p WHERE p.`post_type` = 'page' AND p.post_status = 'publish'";
7575

7676
$implode = array();
7777

model/store/category.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ public function getCategory( $category_id ) {
1313
(SELECT
1414
`meta_value`
1515
FROM
16-
`wp_termmeta`
16+
`".$wpdb->prefix."termmeta`
1717
WHERE `term_id` = t.`term_id`
1818
AND meta_key = 'thumbnail_id') AS 'image_id',
1919
(SELECT
2020
`meta_value`
2121
FROM
22-
`wp_termmeta`
22+
`".$wpdb->prefix."termmeta`
2323
WHERE `term_id` = t.`term_id`
2424
AND meta_key = 'order') AS 'sort_order'
2525
FROM
26-
`wp_terms` t
27-
LEFT JOIN `wp_term_taxonomy` tt
26+
`".$wpdb->prefix."terms` t
27+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
2828
ON tt.`term_id` = t.`term_id`
2929
WHERE tt.`taxonomy` = 'product_cat' and t.`term_id` = '" . (int) $category_id . "'";
3030

@@ -46,18 +46,18 @@ public function getCategories( $data = array() ) {
4646
(SELECT
4747
`meta_value`
4848
FROM
49-
`wp_termmeta`
49+
`".$wpdb->prefix."termmeta`
5050
WHERE `term_id` = t.`term_id`
5151
AND meta_key = 'thumbnail_id') AS 'image_id',
5252
(SELECT
5353
`meta_value`
5454
FROM
55-
`wp_termmeta`
55+
`".$wpdb->prefix."termmeta`
5656
WHERE `term_id` = t.`term_id`
5757
AND meta_key = 'order') AS 'sort_order'
5858
FROM
59-
`wp_terms` t
60-
LEFT JOIN `wp_term_taxonomy` tt
59+
`".$wpdb->prefix."terms` t
60+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
6161
ON tt.`term_id` = t.`term_id`
6262
WHERE tt.`taxonomy` = 'product_cat'";
6363

@@ -112,8 +112,8 @@ public function getTotalCategories( $data = array() ) {
112112

113113
$sql = "SELECT count(*) as total
114114
FROM
115-
`wp_terms` t
116-
LEFT JOIN `wp_term_taxonomy` tt
115+
`".$wpdb->prefix."terms` t
116+
LEFT JOIN `".$wpdb->prefix."term_taxonomy` tt
117117
ON tt.`term_id` = t.`term_id`
118118
WHERE tt.`taxonomy` = 'product_cat'";
119119

model/store/option.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class VFA_ModelStoreOption extends VFA_Model
55
public function getOptionLabel($name) {
66
global $wpdb;
77

8-
$result = $wpdb->get_row("SELECT wat.`attribute_label` AS label FROM `wp_woocommerce_attribute_taxonomies` wat WHERE wat.`attribute_name` = '".str_replace('pa_', '', $name)."'");
8+
$result = $wpdb->get_row("SELECT wat.`attribute_label` AS label FROM `".$wpdb->prefix."woocommerce_attribute_taxonomies` wat WHERE wat.`attribute_name` = '".str_replace('pa_', '', $name)."'");
99

1010
return $result->label;
1111
}

model/store/product.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public function getProductRelated($product_id)
66
{
77
global $wpdb;
88

9-
$result = $wpdb->get_row("SELECT pm.`meta_value` AS related FROM `wp_postmeta` pm WHERE pm.`post_id` = '".(int)$product_id."' AND pm.`meta_key` = '_upsell_ids'");
9+
$result = $wpdb->get_row("SELECT pm.`meta_value` AS related FROM `".$wpdb->prefix."postmeta` pm WHERE pm.`post_id` = '".(int)$product_id."' AND pm.`meta_key` = '_upsell_ids'");
1010

1111
$product_data = unserialize($result->related);
1212

@@ -17,7 +17,7 @@ public function getProductImages($product_id)
1717
{
1818
global $wpdb;
1919

20-
$result = $wpdb->get_row("SELECT pm.`meta_value` AS images FROM `wp_postmeta` pm WHERE pm.`post_id` = '".(int)$product_id."' AND pm.`meta_key` = '_product_image_gallery'");
20+
$result = $wpdb->get_row("SELECT pm.`meta_value` AS images FROM `".$wpdb->prefix."postmeta` pm WHERE pm.`post_id` = '".(int)$product_id."' AND pm.`meta_key` = '_product_image_gallery'");
2121

2222
$product_data = !empty($result->images) ? explode(',', $result->images) : array();
2323

@@ -28,7 +28,7 @@ public function getProductAttributes($product_id)
2828
{
2929
global $wpdb;
3030

31-
$result = $wpdb->get_row("SELECT pm.`meta_value` AS attributes FROM `wp_postmeta` pm WHERE pm.`post_id` = '".(int)$product_id."' AND pm.`meta_key` = '_product_attributes'");
31+
$result = $wpdb->get_row("SELECT pm.`meta_value` AS attributes FROM `".$wpdb->prefix."postmeta` pm WHERE pm.`post_id` = '".(int)$product_id."' AND pm.`meta_key` = '_product_attributes'");
3232

3333
$attribute_data = unserialize($result->attributes);
3434

@@ -42,8 +42,8 @@ public function getOptionValues($taxonomy) {
4242
t.`name`,
4343
t.`slug`
4444
FROM
45-
`wp_term_taxonomy` tt
46-
LEFT JOIN `wp_terms` t ON t.`term_id` = tt.`term_id`
45+
`".$wpdb->prefix."term_taxonomy` tt
46+
LEFT JOIN `".$wpdb->prefix."terms` t ON t.`term_id` = tt.`term_id`
4747
WHERE tt.taxonomy = '".$taxonomy."' ");
4848

4949
return $result;

plugin.php

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function VFA_RestApi( WP_REST_Request $request ) {
103103
$headers = headers_list();
104104
$cookies = array();
105105

106+
106107

107108

108109
foreach($headers as $header) {
@@ -114,15 +115,17 @@ function VFA_RestApi( WP_REST_Request $request ) {
114115
}
115116

116117
}
117-
}
118-
119-
for ($i=0; $i < count($cookies); $i++) {
120-
if($i == 0) {
121-
header($cookies[$i]);
122-
} else {
123-
header($cookies[$i], false);
124-
}
125-
}
118+
}
119+
120+
if (!headers_sent()) {
121+
for ($i=0; $i < count($cookies); $i++) {
122+
if ($i == 0) {
123+
header($cookies[$i]);
124+
} else {
125+
header($cookies[$i], false);
126+
}
127+
}
128+
}
126129
},99);
127130
add_action('woocommerce_add_to_cart', function() {
128131
$headers = headers_list();
@@ -142,13 +145,15 @@ function VFA_RestApi( WP_REST_Request $request ) {
142145
}
143146

144147

145-
for ($i=0; $i < count($cookies); $i++) {
146-
if($i == 0) {
147-
header($cookies[$i]);
148-
} else {
149-
header($cookies[$i], false);
150-
}
151-
}
148+
if (!headers_sent()) {
149+
for ($i=0; $i < count($cookies); $i++) {
150+
if ($i == 0) {
151+
header($cookies[$i]);
152+
} else {
153+
header($cookies[$i], false);
154+
}
155+
}
156+
}
152157
},99);
153158

154159
add_action('shutdown', function() {
@@ -168,11 +173,13 @@ function VFA_RestApi( WP_REST_Request $request ) {
168173
}
169174
}
170175

171-
for ($i=0; $i < count($cookies); $i++) {
172-
if($i == 0) {
173-
header($cookies[$i]);
174-
} else {
175-
header($cookies[$i], false);
176-
}
177-
}
176+
if (!headers_sent()) {
177+
for ($i=0; $i < count($cookies); $i++) {
178+
if ($i == 0) {
179+
header($cookies[$i]);
180+
} else {
181+
header($cookies[$i], false);
182+
}
183+
}
184+
}
178185
}, 1);

0 commit comments

Comments
 (0)