Update form && API

This commit is contained in:
Hoang Huu
2019-10-09 17:23:19 +07:00
parent 7b67843a52
commit a7f217d7a4
12 changed files with 576 additions and 56 deletions

View File

@@ -17,6 +17,11 @@ if ( ! defined( 'ABSPATH' ) ) {
class Opalestate_Taxonomy_Amenities {
/**
* Constant.
*/
const OPALESTATE_AMENITY = 'opalestate_amenities';
/**
* Opalestate_Taxonomy_Amenities constructor.
*/
@@ -26,7 +31,7 @@ class Opalestate_Taxonomy_Amenities {
}
/**
*
* Definition.
*/
public function definition() {
@@ -44,7 +49,7 @@ class Opalestate_Taxonomy_Amenities {
'menu_name' => esc_html__( 'Amenities', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_amenities', 'opalestate_property', [
register_taxonomy( static::OPALESTATE_AMENITY, 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_amenities_labels', $labels ),
'hierarchical' => true,
'query_var' => 'amenity',
@@ -54,8 +59,23 @@ class Opalestate_Taxonomy_Amenities {
] );
}
public static function get_list() {
return get_terms( 'opalestate_amenities', [ 'hide_empty' => false ] );
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list( $args = [] ) {
$default = apply_filters( 'opalestate_amenity_args', [
'taxonomy' => static::OPALESTATE_AMENITY,
'hide_empty' => false,
] );
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
public function taxonomy_metaboxes() {
@@ -65,7 +85,7 @@ class Opalestate_Taxonomy_Amenities {
'id' => $prefix . 'edit',
'title' => esc_html__( 'Type Metabox', 'opalestate-pro' ),
'object_types' => [ 'term' ],
'taxonomies' => [ 'opalestate_amenities' ],
'taxonomies' => [ static::OPALESTATE_AMENITY ],
] );
$cmb_term->add_field( [

View File

@@ -17,9 +17,13 @@ if ( ! defined( 'ABSPATH' ) ) {
}
class Opalestate_Taxonomy_Categories {
/**
* Constant.
*/
const OPALESTATE_CATEGORY = 'property_category ';
/**
*
* Init
*/
public static function init() {
@@ -40,7 +44,7 @@ class Opalestate_Taxonomy_Categories {
*/
public static function definition() {
register_taxonomy( 'property_category', 'opalestate_property', apply_filters( 'opalestate_taxonomy_args_property_category', [
register_taxonomy( static::OPALESTATE_CATEGORY, 'opalestate_property', apply_filters( 'opalestate_taxonomy_args_property_category', [
'labels' => [
'name' => esc_html__( 'Categories', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Category', 'opalestate-pro' ),
@@ -61,15 +65,15 @@ class Opalestate_Taxonomy_Categories {
public static function taxonomy_metaboxes() {
$prefix = 'opalestate_category_';
/**
* Metabox to add fields to categories and tags
*/
$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' => [ 'property_category' ], // 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_CATEGORY ],
] );
$cmb_term->add_field( [
@@ -80,9 +84,15 @@ class Opalestate_Taxonomy_Categories {
] );
}
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => 'property_category',
'taxonomy' => static::OPALESTATE_CATEGORY,
'hide_empty' => true,
];
@@ -95,7 +105,7 @@ class Opalestate_Taxonomy_Categories {
public static function dropdown_list( $selected = 0 ) {
$id = 'property_category' . rand();
$id = static::OPALESTATE_CATEGORY . rand();
$args = [
'show_option_none' => esc_html__( 'Select Category', 'opalestate-pro' ),
@@ -103,10 +113,10 @@ class Opalestate_Taxonomy_Categories {
'class' => 'form-control',
'show_count' => 0,
'hierarchical' => '',
'name' => 'types',
'name' => 'cat',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'property_category',
'taxonomy' => static::OPALESTATE_CATEGORY,
'echo' => 0,
];
@@ -115,10 +125,10 @@ class Opalestate_Taxonomy_Categories {
echo $label . wp_dropdown_categories( $args );
}
public static function get_multi_check_list( $scategory ) {
public static function get_multi_check_list( $scategory = '' ) {
$list = self::get_list();
echo opalestate_terms_multi_check( $list, $scategory );
echo opalestate_categories_multi_check( $list );
}
}

View File

@@ -18,6 +18,11 @@ if ( ! defined( 'ABSPATH' ) ) {
class Opalestate_Taxonomy_Status {
/**
* Constant.
*/
const OPALESTATE_STATUS = 'opalestate_status';
/**
* Opalestate_Taxonomy_Status constructor.
*/
@@ -28,7 +33,7 @@ class Opalestate_Taxonomy_Status {
}
/**
*
* Definition.
*/
public function definition() {
$labels = [
@@ -44,7 +49,7 @@ class Opalestate_Taxonomy_Status {
'new_item_name' => esc_html__( 'New Status', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Status', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_status', 'opalestate_property', [
register_taxonomy( static::OPALESTATE_STATUS , 'opalestate_property', [
'labels' => apply_filters( 'opalestate_status_labels', $labels ),
'hierarchical' => true,
'query_var' => 'status',
@@ -66,23 +71,25 @@ class Opalestate_Taxonomy_Status {
*/
$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_status' ], // 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_STATUS ],
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Background', 'opalestate-pro' ),
'desc' => esc_html__( 'Set background of label', 'opalestate-pro' ),
'id' => $prefix . 'lb_bg',
'type' => 'colorpicker',
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Color', 'opalestate-pro' ),
'desc' => esc_html__( 'Set background of text', 'opalestate-pro' ),
'id' => $prefix . 'lb_color',
'type' => 'colorpicker',
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Order', 'opalestate-pro' ),
'desc' => esc_html__( 'Set a priority to display', 'opalestate-pro' ),
@@ -107,7 +114,7 @@ class Opalestate_Taxonomy_Status {
*/
public static function get_list( $args = [] ) {
$default = apply_filters( 'opalestate_status_args', [
'taxonomy' => 'opalestate_status',
'taxonomy' => static::OPALESTATE_STATUS ,
'hide_empty' => false,
'hierarchical' => false,
'parent' => 0,
@@ -135,7 +142,7 @@ class Opalestate_Taxonomy_Status {
* @return string
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'palestate_status' . rand();
$id = static::OPALESTATE_STATUS . rand();
$args = [
'show_option_none' => esc_html__( 'Select Status', 'opalestate-pro' ),
@@ -146,7 +153,7 @@ class Opalestate_Taxonomy_Status {
'name' => 'status',
'value_field' => 'slug',
'selected' => $selected,
'taxonomy' => 'opalestate_status',
'taxonomy' => static::OPALESTATE_STATUS ,
'echo' => 0,
];

View File

@@ -17,9 +17,13 @@ if ( ! defined( 'ABSPATH' ) ) {
}
class Opalestate_Taxonomy_Type {
/**
* Constant.
*/
const OPALESTATE_TYPES = 'opalestate_types';
/**
*
* Opalestate_Taxonomy_Type constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
@@ -30,17 +34,16 @@ class Opalestate_Taxonomy_Type {
* Hook in and add a metabox to add fields to taxonomy terms
*/
public function taxonomy_metaboxes() {
$prefix = 'opalestate_type_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Type Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_types' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
'title' => esc_html__( 'Type Metabox', 'opalestate-pro' ),
'object_types' => [ 'term' ],
'taxonomies' => [ static::OPALESTATE_TYPES ],
] );
$cmb_term->add_field( [
@@ -67,10 +70,9 @@ class Opalestate_Taxonomy_Type {
}
/**
*
* Definition.
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Types', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Type', 'opalestate-pro' ),
@@ -85,7 +87,7 @@ class Opalestate_Taxonomy_Type {
'menu_name' => esc_html__( 'Types', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_types', [ 'opalestate_property' ], [
register_taxonomy( static::OPALESTATE_TYPES, [ 'opalestate_property' ], [
'labels' => apply_filters( 'opalestate_taxomony_types_labels', $labels ),
'hierarchical' => true,
'query_var' => 'type',
@@ -99,13 +101,27 @@ class Opalestate_Taxonomy_Type {
}
public static function get_list() {
return get_terms( 'opalestate_types', [ 'hide_empty' => false ] );
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list( $args = [] ) {
$default = apply_filters( 'opalestate_types_args', [
'taxonomy' => static::OPALESTATE_TYPES,
'hide_empty' => false,
] );
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
public static function dropdown_list( $selected = 0 ) {
$id = 'opalestate_types' . rand();
$id = static::OPALESTATE_TYPES . rand();
$args = [
'show_option_none' => esc_html__( 'Select Type', 'opalestate-pro' ),
@@ -116,7 +132,7 @@ class Opalestate_Taxonomy_Type {
'name' => 'types',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_types',
'taxonomy' => static::OPALESTATE_TYPES,
'echo' => 0,
];
@@ -129,7 +145,6 @@ class Opalestate_Taxonomy_Type {
$list = self::get_list();
echo opalestate_terms_multi_check( $list, $stypes );
}
}