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

View File

@ -62,6 +62,9 @@ class Opalestate_Search_Form_Api extends Opalestate_Base_API {
$fields['status'] = Opalestate_Taxonomy_Status::get_list(); $fields['status'] = Opalestate_Taxonomy_Status::get_list();
$fields['cat'] = Opalestate_Taxonomy_Categories::get_list(); $fields['cat'] = Opalestate_Taxonomy_Categories::get_list();
$fields['amenities'] = Opalestate_Taxonomy_Amenities::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; $response['fields'] = $fields;
return $this->get_response( 200, $response ); return $this->get_response( 200, $response );

View File

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

View File

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

View File

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

View File

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