2019-09-10 06:27:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Opalestate_Taxonomy_Amenities
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
}
|
|
|
|
|
|
|
|
class Opalestate_Taxonomy_Amenities {
|
|
|
|
|
2019-10-09 12:23:19 +02:00
|
|
|
/**
|
|
|
|
* Constant.
|
|
|
|
*/
|
|
|
|
const OPALESTATE_AMENITY = 'opalestate_amenities';
|
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
/**
|
|
|
|
* Opalestate_Taxonomy_Amenities constructor.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
add_action( 'init', [ $this, 'definition' ] );
|
|
|
|
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ], 999 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-09 12:23:19 +02:00
|
|
|
* Definition.
|
2019-09-10 06:27:33 +02:00
|
|
|
*/
|
|
|
|
public function definition() {
|
|
|
|
|
|
|
|
$labels = [
|
|
|
|
'name' => esc_html__( 'Amenities', 'opalestate-pro' ),
|
|
|
|
'singular_name' => esc_html__( 'Properties By Amenity', 'opalestate-pro' ),
|
|
|
|
'search_items' => esc_html__( 'Search Amenities', 'opalestate-pro' ),
|
|
|
|
'all_items' => esc_html__( 'All Amenities', 'opalestate-pro' ),
|
|
|
|
'parent_item' => esc_html__( 'Parent Amenity', 'opalestate-pro' ),
|
|
|
|
'parent_item_colon' => esc_html__( 'Parent Amenity:', 'opalestate-pro' ),
|
|
|
|
'edit_item' => esc_html__( 'Edit Amenity', 'opalestate-pro' ),
|
|
|
|
'update_item' => esc_html__( 'Update Amenity', 'opalestate-pro' ),
|
|
|
|
'add_new_item' => esc_html__( 'Add New Amenity', 'opalestate-pro' ),
|
|
|
|
'new_item_name' => esc_html__( 'New Amenity', 'opalestate-pro' ),
|
|
|
|
'menu_name' => esc_html__( 'Amenities', 'opalestate-pro' ),
|
|
|
|
];
|
|
|
|
|
2019-10-09 12:23:19 +02:00
|
|
|
register_taxonomy( static::OPALESTATE_AMENITY, 'opalestate_property', [
|
2019-09-10 06:27:33 +02:00
|
|
|
'labels' => apply_filters( 'opalestate_taxomony_amenities_labels', $labels ),
|
|
|
|
'hierarchical' => true,
|
|
|
|
'query_var' => 'amenity',
|
|
|
|
'rewrite' => [ 'slug' => _x( 'amenity', 'slug', 'opalestate-pro' ), 'with_front' => false, 'hierarchical' => true ],
|
|
|
|
'public' => true,
|
|
|
|
'show_ui' => true,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2019-10-09 12:23:19 +02:00
|
|
|
/**
|
|
|
|
* 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 );
|
2019-09-10 06:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function taxonomy_metaboxes() {
|
|
|
|
$prefix = 'opalestate_amt_';
|
2019-09-26 08:28:57 +02:00
|
|
|
|
2019-09-10 06:27:33 +02:00
|
|
|
$cmb_term = new_cmb2_box( [
|
|
|
|
'id' => $prefix . 'edit',
|
2019-09-26 08:28:57 +02:00
|
|
|
'title' => esc_html__( 'Type Metabox', 'opalestate-pro' ),
|
|
|
|
'object_types' => [ 'term' ],
|
2019-10-09 12:23:19 +02:00
|
|
|
'taxonomies' => [ static::OPALESTATE_AMENITY ],
|
2019-09-26 08:28:57 +02:00
|
|
|
] );
|
|
|
|
|
|
|
|
$cmb_term->add_field( [
|
|
|
|
'name' => esc_html__( 'Icon', 'opalestate-pro' ),
|
|
|
|
'desc' => esc_html__( 'Select an icon.', 'opalestate-pro' ),
|
|
|
|
'id' => $prefix . 'icon',
|
|
|
|
'type' => 'opal_iconpicker',
|
2019-09-10 06:27:33 +02:00
|
|
|
] );
|
|
|
|
|
|
|
|
$cmb_term->add_field( [
|
|
|
|
'name' => esc_html__( 'Image Icon', 'opalestate-pro' ),
|
|
|
|
'desc' => esc_html__( 'Select an image icon (SVG, PNG or JPEG).', 'opalestate-pro' ),
|
|
|
|
'id' => $prefix . 'image',
|
|
|
|
'type' => 'file',
|
|
|
|
'preview_size' => [ 50, 50 ],
|
|
|
|
'options' => [
|
|
|
|
'url' => false, // Hide the text input for the url
|
|
|
|
],
|
|
|
|
'query_args' => [
|
|
|
|
'type' => [
|
|
|
|
'image/gif',
|
|
|
|
'image/jpeg',
|
|
|
|
'image/png',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new Opalestate_Taxonomy_Amenities();
|