Added: Search properties in admin by SKU & Address

This commit is contained in:
Hoang Huu 2020-05-29 10:21:37 +07:00
parent 1245c12d50
commit 3b24e7c6d2
5 changed files with 82 additions and 25 deletions

View File

@ -1,4 +1,7 @@
= 1.4.9.8 - 2020-05-28 =
= 1.5 - 2020-05-29 =
* Added - Search properties in admin by SKU & Address.
= 1.4.9.5 - 2020-05-28 =
* Fixes - Enquire email.
= 1.4.9.4 - 2020-05-27 =

View File

@ -1,17 +1,4 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
@ -37,6 +24,7 @@ class Opalestate_Admin_Property {
add_action( 'admin_menu', [ $this, 'remove_meta_boxes' ] );
// add_action( 'transition_post_status', array( __CLASS__, 'save_post' ), 10, 3 );
add_action( 'parse_query', [ $this, 'search_custom_fields' ] );
}
/**
@ -97,13 +85,13 @@ class Opalestate_Admin_Property {
public function columns( $columns ) {
$comments = $columns['comments'];
unset( $columns['author'], $columns['date'], $columns['comments'] );
$columns['featured'] = esc_html__( 'Featured', 'opalestate-pro' );
$columns['sku'] = esc_html__( 'Sku', 'opalestate-pro' );
$columns['address'] = esc_html__( 'Address', 'opalestate-pro' );
$columns['comments'] = $comments;
$columns['author'] = esc_html__( 'Author', 'opalestate-pro' );
$columns['date'] = esc_html__( 'Date', 'opalestate-pro' );
$columns['expiry_date'] = esc_html__( 'Expiry Date', 'opalestate-pro' );
$columns['featured'] = esc_html__( 'Featured', 'opalestate-pro' );
$columns['sku'] = esc_html__( 'Sku', 'opalestate-pro' );
$columns['address'] = esc_html__( 'Address', 'opalestate-pro' );
$columns['comments'] = $comments;
$columns['author'] = esc_html__( 'Author', 'opalestate-pro' );
$columns['date'] = esc_html__( 'Date', 'opalestate-pro' );
$columns['expiry_date'] = esc_html__( 'Expiry Date', 'opalestate-pro' );
return $columns;
}
@ -168,7 +156,33 @@ class Opalestate_Admin_Property {
remove_meta_box( 'authordiv', 'opalestate_property', 'normal' );
}
/**
* Query custom fields as well as content.
*
* @param \WP_Query $wp The WP_Query object.
*
* @access private
*/
public function search_custom_fields( $wp ) {
global $pagenow;
if ( 'edit.php' !== $pagenow
|| empty( $wp->query_vars['s'] )
|| 'opalestate_property' !== $wp->query_vars['post_type']
|| ! isset( $_GET['s'] ) ) {
return;
}
$post_ids = opalestate_search_property_by_term( opalestate_clean( wp_unslash( $_GET['s'] ) ) ); // WPCS: input var ok, sanitization ok.
if ( ! empty( $post_ids ) ) {
// Remove "s" - we don't want to search order name.
unset( $wp->query_vars['s'] );
// Query by found posts.
$wp->query_vars['post__in'] = array_merge( $post_ids, [ 0 ] );
}
}
}
new Opalestate_Admin_Property();
?>

View File

@ -1431,3 +1431,40 @@ function opalestate_get_autocomplete_restrictions() {
return json_encode( $results );
}
/**
* Query property data for a term and return IDs.
*
* Use for 'post__in' in WP_Query.
*
* @param string $term The term to search.
* @return array
*/
function opalestate_search_property_by_term( $term ) {
global $wpdb;
// Filters the search fields.
$search_fields = array_map( 'opalestate_clean', apply_filters( 'opalestate_search_property_fields', [
'opalestate_ppt_sku',
'opalestate_ppt_address',
] ) );
// Prepare search bookings.
$property_ids = [];
if ( is_numeric( $term ) ) {
$property_ids[] = absint( $term );
}
if ( ! empty( $search_fields ) ) {
$search = $wpdb->get_col( $wpdb->prepare(
"SELECT DISTINCT `p1`.`post_id` FROM {$wpdb->postmeta} AS `p1` WHERE `p1`.`meta_value` LIKE %s AND `p1`.`meta_key` IN ('" . implode( "','",
array_map( 'esc_sql', $search_fields ) ) . "')", // @codingStandardsIgnoreLine
'%' . $wpdb->esc_like( opalestate_clean( $term ) ) . '%'
) );
$property_ids = array_unique( array_merge( $property_ids, $search ) );
}
return apply_filters( 'opalestate_search_property_results', $property_ids, $term, $search_fields );
}

View File

@ -3,7 +3,7 @@
* Plugin Name: Opal Estate Pro
* Plugin URI: https://wpdocs.gitbook.io/opal-estate/
* Description: Opal Real Estate Plugin is an ideal solution and brilliant choice for you to set up a professional estate website.
* Version: 1.4.9.5
* Version: 1.5
* Author: WPOPAL
* Author URI: http://www.wpopal.com
* Requires at least: 4.9
@ -150,7 +150,7 @@ if ( ! class_exists( 'OpalEstate' ) ) {
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'opalestate-pro' ), '1.4.9.5' );
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'opalestate-pro' ), '1.5' );
}
/**
@ -159,7 +159,7 @@ if ( ! class_exists( 'OpalEstate' ) ) {
public function setup_constants() {
// Plugin version
if ( ! defined( 'OPALESTATE_VERSION' ) ) {
define( 'OPALESTATE_VERSION', '1.4.9.5' );
define( 'OPALESTATE_VERSION', '1.5' );
}
// Plugin Folder Path

View File

@ -152,6 +152,9 @@ This section describes how to install the plugin and get it working.
* System tickets support 24/7 available : [free support](https://themelexus.ticksy.com/ "Visit the Plugin support Page")
== Changelog ==
= 1.5 - 2020-05-29 =
* Added - Search properties in admin by SKU & Address.
= 1.4.9.5 - 2020-05-28 =
* Fixes - Enquire email.