Update taxonomies.

This commit is contained in:
Hoang Huu 2019-10-10 10:18:42 +07:00
parent 20c3fd2e19
commit a701ccc5f4
5 changed files with 86 additions and 50 deletions

@ -62,6 +62,9 @@ class Opalestate_Search_Form_Api extends Opalestate_Base_API {
$fields['status'] = Opalestate_Taxonomy_Status::get_list();
$fields['cat'] = Opalestate_Taxonomy_Categories::get_list();
$fields['amenities'] = Opalestate_Taxonomy_Amenities::get_list();
$fields['location'] = Opalestate_Taxonomy_Location::get_list();
$fields['city'] = Opalestate_Taxonomy_City::get_list();
$fields['state'] = Opalestate_Taxonomy_State::get_list();
$response['fields'] = $fields;
return $this->get_response( 200, $response );

@ -19,7 +19,12 @@ if ( ! defined( 'ABSPATH' ) ) {
class Opalestate_Taxonomy_City {
/**
*
* Constant.
*/
const OPALESTATE_CITY = 'opalestate_city';
/**
* Init
*/
public static function init() {
add_action( 'init', [ __CLASS__, 'definition' ] );
@ -27,7 +32,7 @@ class Opalestate_Taxonomy_City {
}
/**
*
* Definition.
*/
public static function definition() {
@ -45,7 +50,7 @@ class Opalestate_Taxonomy_City {
'menu_name' => esc_html__( 'Cities / Towns', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_city', 'opalestate_property', [
register_taxonomy( static::OPALESTATE_CITY, 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_city_labels', $labels ),
'hierarchical' => true,
'query_var' => 'city',
@ -66,9 +71,9 @@ class Opalestate_Taxonomy_City {
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'City Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_city' ], // Tells CMB2 which taxonomies should have these fields
'title' => esc_html__( 'City Metabox', 'opalestate-pro' ),
'object_types' => [ 'term' ],
'taxonomies' => [ static::OPALESTATE_CITY ],
] );
$cmb_term->add_field( [
@ -82,7 +87,6 @@ class Opalestate_Taxonomy_City {
],
] );
////
$cmb_term->add_field( [
'name' => esc_html__( 'Country', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in countries of estate panel', 'opalestate-pro' ),
@ -91,7 +95,6 @@ class Opalestate_Taxonomy_City {
'type' => 'taxonomy_select',
] );
///
$cmb_term->add_field( [
'name' => esc_html__( 'State / Province', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in City/Town of estate panel', 'opalestate-pro' ),
@ -109,7 +112,7 @@ class Opalestate_Taxonomy_City {
*/
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => 'opalestate_city',
'taxonomy' => static::OPALESTATE_CITY,
'hide_empty' => true,
];
@ -127,7 +130,7 @@ class Opalestate_Taxonomy_City {
* @return string
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'opalestate_city' . rand();
$id = static::OPALESTATE_CITY . rand();
$args = [
'show_option_none' => esc_html__( 'Select City', 'opalestate-pro' ),
'id' => $id,
@ -137,7 +140,7 @@ class Opalestate_Taxonomy_City {
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_city',
'taxonomy' => static::OPALESTATE_CITY,
'orderby' => 'name',
'order' => 'ASC',
'echo' => 0,

@ -17,14 +17,16 @@ if ( ! defined( 'ABSPATH' ) ) {
}
class Opalestate_Taxonomy_Label {
/**
* Constant.
*/
const OPALESTATE_LABEL = 'opalestate_label';
/**
*
* Opalestate_Taxonomy_Label constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
add_filter( 'opalestate_taxomony_label_metaboxes', [ $this, 'metaboxes' ] );
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ], 999 );
}
@ -33,7 +35,6 @@ class Opalestate_Taxonomy_Label {
*
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Label', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Label', 'opalestate-pro' ),
@ -48,7 +49,7 @@ class Opalestate_Taxonomy_Label {
'menu_name' => esc_html__( 'Label', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_label', 'opalestate_property', [
register_taxonomy( static::OPALESTATE_LABEL, 'opalestate_property', [
'labels' => apply_filters( 'opalestate_label_labels', $labels ),
'hierarchical' => true,
'query_var' => 'property-label',
@ -73,10 +74,9 @@ class Opalestate_Taxonomy_Label {
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Category Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_label' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
'title' => esc_html__( 'Category Metabox', 'opalestate-pro' ),
'object_types' => [ 'term' ],
'taxonomies' => [ static::OPALESTATE_LABEL ],
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Background', 'opalestate-pro' ),
@ -111,7 +111,7 @@ class Opalestate_Taxonomy_Label {
*/
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => 'opalestate_label',
'taxonomy' => static::OPALESTATE_LABEL,
'hide_empty' => false,
];
@ -129,7 +129,7 @@ class Opalestate_Taxonomy_Label {
* @return string
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'opalestate_label' . rand();
$id = static::OPALESTATE_LABEL . rand();
$args = [
'show_option_none' => esc_html__( 'Select Label', 'opalestate-pro' ),
@ -140,7 +140,7 @@ class Opalestate_Taxonomy_Label {
'name' => 'label',
'value_field' => 'slug',
'selected' => $selected,
'taxonomy' => 'opalestate_label',
'taxonomy' => static::OPALESTATE_LABEL,
];
return wp_dropdown_categories( $args );

@ -17,9 +17,13 @@ if ( ! defined( 'ABSPATH' ) ) {
}
class Opalestate_Taxonomy_Location {
/**
* Constant.
*/
const OPALESTATE_LOCATION = 'opalestate_location';
/**
*
* Opalestate_Taxonomy_Location constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
@ -28,10 +32,9 @@ class Opalestate_Taxonomy_Location {
}
/**
*
* Definition.
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Countries', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Country', 'opalestate-pro' ),
@ -46,7 +49,7 @@ class Opalestate_Taxonomy_Location {
'menu_name' => esc_html__( 'Countries', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_location', 'opalestate_property', [
register_taxonomy( static::OPALESTATE_LOCATION, 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_location_labels', $labels ),
'hierarchical' => true,
'query_var' => 'location',
@ -74,10 +77,9 @@ class Opalestate_Taxonomy_Location {
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Country Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_location' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
'title' => esc_html__( 'Country Metabox', 'opalestate-pro' ),
'object_types' => [ 'term' ],
'taxonomies' => [ static::OPALESTATE_LOCATION ],
] );
$cmb_term->add_field( [
@ -93,17 +95,29 @@ class Opalestate_Taxonomy_Location {
}
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list() {
return get_terms( 'opalestate_location', [ 'hide_empty' => false ] );
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => static::OPALESTATE_LOCATION,
'hide_empty' => true,
];
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
/**
*
*/
public static function dropdown_agents_list( $selected = 0 ) {
$id = "opalestate_location" . rand();
$id = static::OPALESTATE_LOCATION . rand();
$args = [
'show_option_none' => esc_html__( 'Select Country', 'opalestate-pro' ),
'id' => $id,
@ -123,7 +137,7 @@ class Opalestate_Taxonomy_Location {
*
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'opalestate_location' . rand();
$id = static::OPALESTATE_LOCATION . rand();
$args = [
'show_option_none' => esc_html__( 'Select Country', 'opalestate-pro' ),
'id' => $id,
@ -133,7 +147,7 @@ class Opalestate_Taxonomy_Location {
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_location',
'taxonomy' => static::OPALESTATE_LOCATION,
'orderby' => 'name',
'order' => 'ASC',
'echo' => 0,

@ -17,6 +17,11 @@ if ( ! defined( 'ABSPATH' ) ) {
}
class Opalestate_Taxonomy_State {
/**
* Constant.
*/
const OPALESTATE_STATE = 'opalestate_state';
/**
* Opalestate_Taxonomy_State constructor.
*/
@ -27,7 +32,7 @@ class Opalestate_Taxonomy_State {
}
/**
*
* Definition.
*/
public function definition() {
$labels = [
@ -44,7 +49,7 @@ class Opalestate_Taxonomy_State {
'menu_name' => esc_html__( 'States / Provinces', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_state', 'opalestate_property', [
register_taxonomy( static::OPALESTATE_STATE, 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_state_labels', $labels ),
'hierarchical' => true,
'query_var' => 'state',
@ -69,10 +74,9 @@ class Opalestate_Taxonomy_State {
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'State Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_state' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
'title' => esc_html__( 'State Metabox', 'opalestate-pro' ),
'object_types' => [ 'term' ],
'taxonomies' => [ static::OPALESTATE_STATE ],
] );
$cmb_term->add_field( [
@ -86,7 +90,6 @@ class Opalestate_Taxonomy_State {
],
] );
////
$cmb_term->add_field( [
'name' => esc_html__( 'Country', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in countries of estate panel', 'opalestate-pro' ),
@ -94,16 +97,29 @@ class Opalestate_Taxonomy_State {
'taxonomy' => 'opalestate_location', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
] );
///
}
public static function get_list() {
return get_terms( 'opalestate_state', [ 'hide_empty' => false ] );
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => static::OPALESTATE_STATE,
'hide_empty' => true,
];
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
public static function dropdown_agents_list( $selected = 0 ) {
$id = "opalestate_state" . rand();
$id = static::OPALESTATE_STATE . rand();
$args = [
'show_option_none' => esc_html__( 'Select State', 'opalestate-pro' ),
'id' => $id,
@ -120,7 +136,7 @@ class Opalestate_Taxonomy_State {
}
public static function dropdown_list( $selected = 0 ) {
$id = "opalestate_state" . rand();
$id = static::OPALESTATE_STATE . rand();
$args = [
'show_option_none' => esc_html__( 'Select State', 'opalestate-pro' ),
'id' => $id,
@ -130,7 +146,7 @@ class Opalestate_Taxonomy_State {
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_state',
'taxonomy' => static::OPALESTATE_STATE,
'orderby' => 'name',
'order' => 'ASC',
'echo' => 0,