Opal-Estate-Pro/inc/taxonomies/class-taxonomy-categories.php

136 lines
3.5 KiB
PHP
Raw Normal View History

2019-09-10 06:27:33 +02:00
<?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
}
class Opalestate_Taxonomy_Categories {
2019-10-09 12:23:19 +02:00
/**
* Constant.
*/
const OPALESTATE_CATEGORY = 'property_category ';
2019-09-10 06:27:33 +02:00
/**
2019-10-09 12:23:19 +02:00
* Init
2019-09-10 06:27:33 +02:00
*/
public static function init() {
add_action( 'init', [ __CLASS__, 'definition' ] );
add_filter( 'opalestate_taxomony_category_metaboxes', [ __CLASS__, 'metaboxes' ] );
add_action( 'cmb2_admin_init', [ __CLASS__, 'taxonomy_metaboxes' ], 999 );
}
public static function metaboxes() {
}
/**
*
*/
public static function definition() {
2019-10-09 12:23:19 +02:00
register_taxonomy( static::OPALESTATE_CATEGORY, 'opalestate_property', apply_filters( 'opalestate_taxonomy_args_property_category', [
2019-09-10 06:27:33 +02:00
'labels' => [
'name' => esc_html__( 'Categories', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Category', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Category', 'opalestate-pro' ),
],
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => [ 'slug' => _x( 'property-category', 'slug', 'opalestate-pro' ), 'with_front' => false, 'hierarchical' => true ],
] ) );
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public static function taxonomy_metaboxes() {
$prefix = 'opalestate_category_';
2019-10-09 12:23:19 +02:00
2019-09-10 06:27:33 +02:00
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
2019-10-09 12:23:19 +02:00
'title' => esc_html__( 'Category Metabox', 'opalestate-pro' ),
'object_types' => [ 'term' ],
'taxonomies' => [ static::OPALESTATE_CATEGORY ],
2019-09-10 06:27:33 +02:00
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image', 'opalestate-pro' ),
'desc' => esc_html__( 'Category image', 'opalestate-pro' ),
'id' => $prefix . 'image',
'type' => 'file',
] );
}
2019-10-09 12:23:19 +02:00
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
2019-09-10 06:27:33 +02:00
public static function get_list( $args = [] ) {
$default = [
2019-10-09 12:23:19 +02:00
'taxonomy' => static::OPALESTATE_CATEGORY,
2019-09-10 06:27:33 +02:00
'hide_empty' => true,
];
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
public static function dropdown_list( $selected = 0 ) {
2019-09-17 05:01:35 +02:00
2019-10-09 12:23:19 +02:00
$id = static::OPALESTATE_CATEGORY . rand();
2019-09-10 06:27:33 +02:00
$args = [
2019-09-17 05:01:35 +02:00
'show_option_none' => esc_html__( 'Select Category', 'opalestate-pro' ),
2019-09-10 06:27:33 +02:00
'id' => $id,
'class' => 'form-control',
'show_count' => 0,
'hierarchical' => '',
2019-10-09 12:23:19 +02:00
'name' => 'cat',
2019-09-10 06:27:33 +02:00
'selected' => $selected,
2019-09-17 05:01:35 +02:00
'value_field' => 'slug',
2019-10-09 12:23:19 +02:00
'taxonomy' => static::OPALESTATE_CATEGORY,
2019-09-17 05:01:35 +02:00
'echo' => 0,
2019-09-10 06:27:33 +02:00
];
2019-09-17 05:01:35 +02:00
$label = '<label class="opalestate-label opalestate-label--category" for="' . esc_attr( $id ) . '">' . esc_html__( 'Category', 'opalestate-pro' ) . '</label>';
echo $label . wp_dropdown_categories( $args );
2019-09-10 06:27:33 +02:00
}
2019-10-09 12:23:19 +02:00
public static function get_multi_check_list( $scategory = '' ) {
2019-09-17 05:01:35 +02:00
$list = self::get_list();
2019-10-09 12:23:19 +02:00
echo opalestate_categories_multi_check( $list );
2019-09-17 05:01:35 +02:00
}
2019-09-10 06:27:33 +02:00
}
Opalestate_Taxonomy_Categories::init();