Changeset 2878617
- Timestamp:
- 03/12/2023 08:48:18 AM (3 years ago)
- Location:
- guidant/trunk
- Files:
-
- 3 edited
-
guidant.php (modified) (3 diffs)
-
includes/GuidantUtils.php (modified) (24 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
guidant/trunk/guidant.php
r2791038 r2878617 4 4 * Plugin URI: https://wpcommerz.com/guidant/ 5 5 * Description: Build Multi-step Guided Selling Process & Smart Forms to Convert 10X More Traffic Into Leads & New Customers. 6 * Version: 1.0. 86 * Version: 1.0.9 7 7 * Author: WPCommerz 8 8 * Author URI: https://wpcommerz.com/ … … 13 13 */ 14 14 15 16 15 // If this file is called directly, abort. 17 if ( ! defined( 'WPINC' )) {16 if (!defined('WPINC')) { 18 17 die; 19 18 } 20 19 21 define( 'GUIDANT_VERSION', '1.0.8' ); 22 defined( 'GUIDANT_PATH' ) or define( 'GUIDANT_PATH', plugin_dir_path( __FILE__ ) ); 23 defined( 'GUIDANT_URL' ) or define( 'GUIDANT_URL', plugin_dir_url( __FILE__ ) ); 24 defined( 'GUIDANT_BASE_PATH' ) or define( 'GUIDANT_BASE_PATH', plugin_basename(__FILE__) ); 25 defined( 'GUIDANT_IMG_DIR' ) or define( 'GUIDANT_IMG_DIR', plugin_dir_url( __FILE__ ) . 'assets/img/' ); 26 defined( 'GUIDANT_CSS_DIR' ) or define( 'GUIDANT_CSS_DIR', plugin_dir_url( __FILE__ ) . 'assets/css/' ); 27 defined( 'GUIDANT_JS_DIR' ) or define( 'GUIDANT_JS_DIR', plugin_dir_url( __FILE__ ) . 'assets/js/' ); 28 29 30 20 define('GUIDANT_VERSION', '1.0.8'); 21 defined('GUIDANT_PATH') or define('GUIDANT_PATH', plugin_dir_path(__FILE__)); 22 defined('GUIDANT_URL') or define('GUIDANT_URL', plugin_dir_url(__FILE__)); 23 defined('GUIDANT_BASE_PATH') or define('GUIDANT_BASE_PATH', plugin_basename(__FILE__)); 24 defined('GUIDANT_IMG_DIR') or define('GUIDANT_IMG_DIR', plugin_dir_url(__FILE__) . 'assets/img/'); 25 defined('GUIDANT_CSS_DIR') or define('GUIDANT_CSS_DIR', plugin_dir_url(__FILE__) . 'assets/css/'); 26 defined('GUIDANT_JS_DIR') or define('GUIDANT_JS_DIR', plugin_dir_url(__FILE__) . 'assets/js/'); 31 27 32 28 require_once GUIDANT_PATH . 'includes/GuidantSettings.php'; … … 40 36 require_once GUIDANT_PATH . 'frontend/class-guidant-shortcode.php'; 41 37 require_once GUIDANT_PATH . 'frontend/class-guidant-frontend.php'; 42 43 -
guidant/trunk/includes/GuidantUtils.php
r2747015 r2878617 1 1 <?php 2 2 3 // If this file is called directly, abort.4 if ( ! defined( 'WPINC' )) {3 // If this file is called directly, exit. 4 if (!defined('WPINC')) { 5 5 die; 6 6 } 7 7 8 if ( ! class_exists( 'GuidantUtils' )) {8 if (!class_exists('GuidantUtils')) { 9 9 class GuidantUtils 10 10 { 11 11 12 public function filterBySearch($array, $search = ""){ 13 14 if(strlen(trim($search)) == 0){ 12 public function filterBySearch($array, $search = "") 13 { 14 15 if (strlen(trim($search)) == 0) { 15 16 return $array; 16 17 } 17 18 18 19 $filteredArray = array(); 19 foreach ($array as $single_row) {20 foreach ($array as $single_row) { 20 21 if (strpos(strtolower($single_row['id']), strtolower($search)) !== false) { 21 22 $filteredArray[] = $single_row; 22 } else if (strpos(strtolower($single_row['text']), strtolower($search)) !== false) {23 } else if (strpos(strtolower($single_row['text']), strtolower($search)) !== false) { 23 24 $filteredArray[] = $single_row; 24 25 } … … 39 40 return $this->filterBySearch($postAttributes, $search); 40 41 } 41 42 42 43 43 public function getPostAttributesForResult($search) … … 91 91 $acfAttributes = array(); 92 92 if (class_exists('ACF')) { 93 $sql = $wpdb->prepare( "SELECT post_title, post_excerpt FROM {$wpdb->prefix}posts WHERE post_type = 'acf-field' AND post_status = 'publish' ORDER BY ID DESC", array());93 $sql = $wpdb->prepare("SELECT post_title, post_excerpt FROM {$wpdb->prefix}posts WHERE post_type = 'acf-field' AND post_status = 'publish' ORDER BY ID DESC", array()); 94 94 $listPosts = $wpdb->get_results($sql); 95 95 if (sizeof($listPosts) > 0) { 96 96 foreach ($listPosts as $singlePost) { 97 $acfAttributes[] = array("id" => "post_meta_" .$singlePost->post_excerpt, "text" => $singlePost->post_title);97 $acfAttributes[] = array("id" => "post_meta_" . $singlePost->post_excerpt, "text" => $singlePost->post_title); 98 98 } 99 99 } … … 105 105 { 106 106 $guidantCustomFields = array(); 107 foreach ($list_fields as $single_field) {108 $guidantCustomFields[] = array("id" => "post_meta_" .$single_field['field_id'], "text" => "[Custom Field] ".$single_field['field_label']);107 foreach ($list_fields as $single_field) { 108 $guidantCustomFields[] = array("id" => "post_meta_" . $single_field['field_id'], "text" => "[Custom Field] " . $single_field['field_label']); 109 109 } 110 110 return $this->filterBySearch($guidantCustomFields, $search); … … 116 116 global $wpdb; 117 117 $guidantAllMetaFields = array(); 118 $sql = $wpdb->prepare( "SELECT DISTINCT m.meta_key FROM {$wpdb->prefix}posts as p, {$wpdb->prefix}postmeta as m118 $sql = $wpdb->prepare("SELECT DISTINCT m.meta_key FROM {$wpdb->prefix}posts as p, {$wpdb->prefix}postmeta as m 119 119 WHERE p.post_type = %s AND p.post_status = 'publish' 120 AND m.post_id = p.ID", array( $post_type));120 AND m.post_id = p.ID", array($post_type)); 121 121 $listFields = $wpdb->get_results($sql); 122 122 123 123 if (sizeof($listFields) > 0) { 124 124 foreach ($listFields as $single_field) { 125 $guidantAllMetaFields[] = array("id" => "post_meta_" .$single_field->meta_key, "text" => $single_field->meta_key);125 $guidantAllMetaFields[] = array("id" => "post_meta_" . $single_field->meta_key, "text" => $single_field->meta_key); 126 126 } 127 127 } … … 129 129 return $this->filterBySearch($guidantAllMetaFields, $search); 130 130 } 131 132 133 131 134 132 public function getAttributeValues($attribute_name, $search = "") … … 139 137 140 138 /* *************** POST ATTRIBUTES *************** */ 141 if ($attribute_name == "post_category") {139 if ($attribute_name == "post_category") { 142 140 $listCategories = get_categories(array('hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC', 'name__like' => $search)); 143 141 if (sizeof($listCategories) > 0) { … … 148 146 } 149 147 150 151 152 if($attribute_name == "post_title") { 153 $sql = $wpdb->prepare( "SELECT DISTINCT post_title FROM {$wpdb->prefix}posts WHERE post_title LIKE %s ORDER BY ID DESC LIMIT 40", array( '%'.$search.'%' ) ); 148 if ($attribute_name == "post_title") { 149 $sql = $wpdb->prepare("SELECT DISTINCT post_title FROM {$wpdb->prefix}posts WHERE post_title LIKE %s ORDER BY ID DESC LIMIT 40", array('%' . $search . '%')); 154 150 $listPosts = $wpdb->get_results($sql); 155 151 if (sizeof($listPosts) > 0) { … … 160 156 } 161 157 162 163 164 if($attribute_name == "post_type") { 158 if ($attribute_name == "post_type") { 165 159 $listPostTypes = get_post_types(array('public' => true), 'objects'); 166 160 if (sizeof($listPostTypes) > 0) { 167 161 foreach ($listPostTypes as $singlePostType) { 168 $labels = get_post_type_labels( $singlePostType ); 169 $attributeValues[] = array("id" => $singlePostType->name, "text" => "[".$singlePostType->name."] ".$labels->name); 170 } 171 } 172 } 173 174 175 if($attribute_name == "post_date") { 176 $sql = $wpdb->prepare( "SELECT DATE_FORMAT(post_date, %s) AS p_date FROM {$wpdb->prefix}posts WHERE DATE_FORMAT(post_date, %s) LIKE %s GROUP BY DATE_FORMAT(post_date, %s) ORDER BY post_date DESC LIMIT 10" , 177 array('%Y-%m-%d', '%Y-%m-%d', '%'.$search.'%', '%Y-%m-%d') ); 162 $labels = get_post_type_labels($singlePostType); 163 $attributeValues[] = array("id" => $singlePostType->name, "text" => "[" . $singlePostType->name . "] " . $labels->name); 164 } 165 } 166 } 167 168 if ($attribute_name == "post_date") { 169 $sql = $wpdb->prepare("SELECT DATE_FORMAT(post_date, %s) AS p_date FROM {$wpdb->prefix}posts WHERE DATE_FORMAT(post_date, %s) LIKE %s GROUP BY DATE_FORMAT(post_date, %s) ORDER BY post_date DESC LIMIT 10", 170 array('%Y-%m-%d', '%Y-%m-%d', '%' . $search . '%', '%Y-%m-%d')); 178 171 $listPosts = $wpdb->get_results($sql); 179 172 if (sizeof($listPosts) > 0) { … … 184 177 } 185 178 186 if ($attribute_name == "post_modified") {187 $sql = $wpdb->prepare( "SELECT DATE_FORMAT(post_modified, %s) AS p_date FROM {$wpdb->prefix}posts WHERE DATE_FORMAT(post_modified, %s) LIKE %s GROUP BY DATE_FORMAT(post_modified, %s) ORDER BY post_modified DESC LIMIT 10",188 array('%Y-%m-%d', '%Y-%m-%d', '%' .$search.'%', '%Y-%m-%d'));179 if ($attribute_name == "post_modified") { 180 $sql = $wpdb->prepare("SELECT DATE_FORMAT(post_modified, %s) AS p_date FROM {$wpdb->prefix}posts WHERE DATE_FORMAT(post_modified, %s) LIKE %s GROUP BY DATE_FORMAT(post_modified, %s) ORDER BY post_modified DESC LIMIT 10", 181 array('%Y-%m-%d', '%Y-%m-%d', '%' . $search . '%', '%Y-%m-%d')); 189 182 $listPosts = $wpdb->get_results($sql); 190 183 if (sizeof($listPosts) > 0) { … … 195 188 } 196 189 197 198 if($attribute_name == "post_author") { 199 $listUsers = get_users(array( 'search' => '*'.$search.'*' )); 190 if ($attribute_name == "post_author") { 191 $listUsers = get_users(array('search' => '*' . $search . '*')); 200 192 if (sizeof($listUsers) > 0) { 201 193 foreach ($listUsers as $singleUser) { … … 205 197 } 206 198 207 208 if($attribute_name == "post_tags") { 199 if ($attribute_name == "post_tags") { 209 200 $listTags = get_tags(array('hide_empty' => false)); 210 201 if (sizeof($listTags) > 0) { … … 217 208 /* *************** WOOCOMMERCE ATTRIBUTES *************** */ 218 209 219 if ($attribute_name == "woocommerce_category") {210 if ($attribute_name == "woocommerce_category") { 220 211 if (class_exists('WooCommerce')) { 221 212 $listCategories = get_terms('product_cat', array('hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC', 'name__like' => $search)); … … 228 219 } 229 220 230 231 if($attribute_name == "woocommerce_tags") { 232 if (class_exists('WooCommerce')) { 233 $sql = $wpdb->prepare( "SELECT terms.name as tag FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}terms as terms, 221 if ($attribute_name == "woocommerce_tags") { 222 if (class_exists('WooCommerce')) { 223 $sql = $wpdb->prepare("SELECT terms.name as tag FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}terms as terms, 234 224 {$wpdb->prefix}term_relationships as relationship, {$wpdb->prefix}term_taxonomy as taxonomies 235 WHERE posts.post_type = 'product' AND posts.post_status = 'publish' 225 WHERE posts.post_type = 'product' AND posts.post_status = 'publish' 236 226 AND relationship.object_id = posts.ID AND taxonomies.term_taxonomy_id = relationship.term_taxonomy_id 237 AND taxonomies.taxonomy = 'product_tag' AND terms.term_id = taxonomies.term_id AND terms.name LIKE %s GROUP BY terms.name LIMIT 10", array( '%'.$search.'%' ));227 AND taxonomies.taxonomy = 'product_tag' AND terms.term_id = taxonomies.term_id AND terms.name LIKE %s GROUP BY terms.name LIMIT 10", array('%' . $search . '%')); 238 228 $listTags = $wpdb->get_results($sql); 239 229 if (sizeof($listTags) > 0) { … … 245 235 } 246 236 247 if ($attribute_name == "woocommerce_product") {248 if (class_exists('WooCommerce')) { 249 $sql = $wpdb->prepare( "SELECT ID, post_title FROM {$wpdb->prefix}posts WHERE post_type = 'product' AND post_status = 'publish' AND post_title LIKE %s ORDER BY ID DESC LIMIT 10", array( '%'.$search.'%' ));237 if ($attribute_name == "woocommerce_product") { 238 if (class_exists('WooCommerce')) { 239 $sql = $wpdb->prepare("SELECT ID, post_title FROM {$wpdb->prefix}posts WHERE post_type = 'product' AND post_status = 'publish' AND post_title LIKE %s ORDER BY ID DESC LIMIT 10", array('%' . $search . '%')); 250 240 $listPosts = $wpdb->get_results($sql); 251 241 if (sizeof($listPosts) > 0) { … … 257 247 } 258 248 259 if ($attribute_name == "woocommerce_price") {260 if (class_exists('WooCommerce')) { 261 $sql = $wpdb->prepare( "SELECT meta.meta_value as price FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product'262 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_price' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array( '%'.$search.'%' ));249 if ($attribute_name == "woocommerce_price") { 250 if (class_exists('WooCommerce')) { 251 $sql = $wpdb->prepare("SELECT meta.meta_value as price FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product' 252 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_price' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array('%' . $search . '%')); 263 253 $listPrices = $wpdb->get_results($sql); 264 254 if (sizeof($listPrices) > 0) { … … 270 260 } 271 261 272 if ($attribute_name == "woocommerce_sale_price") {273 if (class_exists('WooCommerce')) { 274 $sql = $wpdb->prepare( "SELECT meta.meta_value as sale_price FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product'275 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_sale_price' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array( '%'.$search.'%' ));262 if ($attribute_name == "woocommerce_sale_price") { 263 if (class_exists('WooCommerce')) { 264 $sql = $wpdb->prepare("SELECT meta.meta_value as sale_price FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product' 265 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_sale_price' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array('%' . $search . '%')); 276 266 $listPrices = $wpdb->get_results($sql); 277 267 if (sizeof($listPrices) > 0) { … … 283 273 } 284 274 285 if ($attribute_name == "woocommerce_regular_price") {286 if (class_exists('WooCommerce')) { 287 $sql = $wpdb->prepare( "SELECT meta.meta_value as regular_price FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product'288 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_regular_price' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array( '%'.$search.'%' ));275 if ($attribute_name == "woocommerce_regular_price") { 276 if (class_exists('WooCommerce')) { 277 $sql = $wpdb->prepare("SELECT meta.meta_value as regular_price FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product' 278 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_regular_price' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array('%' . $search . '%')); 289 279 $listPrices = $wpdb->get_results($sql); 290 280 if (sizeof($listPrices) > 0) { … … 296 286 } 297 287 298 if ($attribute_name == "woocommerce_rating") {299 if (class_exists('WooCommerce')) { 300 $sql = $wpdb->prepare( "SELECT meta.meta_value as average_rating FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product'301 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_wc_average_rating' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array( '%'.$search.'%' ));288 if ($attribute_name == "woocommerce_rating") { 289 if (class_exists('WooCommerce')) { 290 $sql = $wpdb->prepare("SELECT meta.meta_value as average_rating FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product' 291 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_wc_average_rating' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array('%' . $search . '%')); 302 292 $listPrices = $wpdb->get_results($sql); 303 293 if (sizeof($listPrices) > 0) { … … 309 299 } 310 300 311 if ($attribute_name == "woocommerce_stock_status") {312 if (class_exists('WooCommerce')) { 313 $sql = $wpdb->prepare( "SELECT meta.meta_value as stock_status FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product'314 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_stock_status' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array( '%'.$search.'%' ));301 if ($attribute_name == "woocommerce_stock_status") { 302 if (class_exists('WooCommerce')) { 303 $sql = $wpdb->prepare("SELECT meta.meta_value as stock_status FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_type = 'product' 304 AND posts.post_status = 'publish' AND meta.post_id = posts.ID AND meta.meta_key = '_stock_status' AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array('%' . $search . '%')); 315 305 $listPrices = $wpdb->get_results($sql); 316 306 if (sizeof($listPrices) > 0) { … … 322 312 } 323 313 324 if ($attribute_name == "woocommerce_attributes") {325 if (class_exists('WooCommerce')) { 326 327 $sql = $wpdb->prepare( "SELECT attributes.attribute_name as attribute_slug FROM {$wpdb->prefix}woocommerce_attribute_taxonomies as attributes", array());314 if ($attribute_name == "woocommerce_attributes") { 315 if (class_exists('WooCommerce')) { 316 317 $sql = $wpdb->prepare("SELECT attributes.attribute_name as attribute_slug FROM {$wpdb->prefix}woocommerce_attribute_taxonomies as attributes", array()); 328 318 $listAttributes = $wpdb->get_results($sql); 329 319 if (sizeof($listAttributes) > 0) { 330 320 foreach ($listAttributes as $singleAttribute) { 331 $sql = $wpdb->prepare( "SELECT terms.slug as slug, terms.name as name FROM {$wpdb->prefix}term_taxonomy as ttaxonomy, {$wpdb->prefix}terms as terms WHERE ttaxonomy.taxonomy = 'pa_".$singleAttribute->attribute_slug."'332 AND terms.term_id = ttaxonomy.term_id AND terms.name LIKE %s GROUP BY terms.term_id LIMIT 10", array( '%'.$search.'%' ));321 $sql = $wpdb->prepare("SELECT terms.slug as slug, terms.name as name FROM {$wpdb->prefix}term_taxonomy as ttaxonomy, {$wpdb->prefix}terms as terms WHERE ttaxonomy.taxonomy = 'pa_" . $singleAttribute->attribute_slug . "' 322 AND terms.term_id = ttaxonomy.term_id AND terms.name LIKE %s GROUP BY terms.term_id LIMIT 10", array('%' . $search . '%')); 333 323 $listVariations = $wpdb->get_results($sql); 334 324 if (sizeof($listVariations) > 0) { … … 342 332 } 343 333 344 if ($attribute_name == "woocommerce_on_sale") {334 if ($attribute_name == "woocommerce_on_sale") { 345 335 if (class_exists('WooCommerce')) { 346 336 $attributeValues[] = array("id" => 1, "text" => "Products On Sale"); … … 349 339 } 350 340 351 352 353 354 341 /* *************** WP Guidant Custom Field ATTRIBUTES *************** */ 355 342 356 343 if (strpos($attribute_name, 'post_meta_') !== false) { 357 344 $attribute_name = str_replace("post_meta_", "", $attribute_name); 358 $sql = $wpdb->prepare( "SELECT meta.meta_value as feild_value FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_status = 'publish'359 AND meta.post_id = posts.ID AND meta.meta_key = %s AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array( $attribute_name, '%'.$search.'%' ));345 $sql = $wpdb->prepare("SELECT meta.meta_value as feild_value FROM {$wpdb->prefix}posts as posts, {$wpdb->prefix}postmeta as meta WHERE posts.post_status = 'publish' 346 AND meta.post_id = posts.ID AND meta.meta_key = %s AND meta.meta_value LIKE %s GROUP BY meta.meta_value LIMIT 10", array($attribute_name, '%' . $search . '%')); 360 347 $listValues = $wpdb->get_results($sql); 361 348 if (sizeof($listValues) > 0) { … … 369 356 } 370 357 371 372 373 358 } 374 359 } -
guidant/trunk/readme.txt
r2807738 r2878617 289 289 == Changelog == 290 290 291 = 1.0.9 = 292 1. Improved: Performance of the plugin has been improved. 293 291 294 = 1.0.8 = 292 295 1. Fixed: Issues with filtering WooCommerce Categories having unicode text as Category Title.
Note: See TracChangeset
for help on using the changeset viewer.