Skip to content

Instantly share code, notes, and snippets.

@dikiyforester
Created February 8, 2018 18:03
Show Gist options
  • Save dikiyforester/7ff947709c2d17cc0f88700d906698cc to your computer and use it in GitHub Desktop.
Save dikiyforester/7ff947709c2d17cc0f88700d906698cc to your computer and use it in GitHub Desktop.
Registers custom Banks and Brands taxonomies for the AppThemes Clipper Coupons
<?php
/*
* Plugin Name: Clipper Custom Taxonomies
* Description: Registers custom Banks and Brands taxonomies for the Clipper Coupons.
* Version: 1.0.0
* Author: Artem Frolov (dikiyforester)
* Author URI: https://www.appthemes.com/members/dikiyforester/
* Text Domain: clipper-custom-taxonomies
*/
/**
* Register custom taxonomies.
*/
function dkf_clipper_custom_taxonomy_register() {
// Register the Bank taxonomy for coupons.
$labels = array(
'name' => _x( 'Banks', 'taxonomy general name', 'clipper-custom-taxonomies' ),
'singular_name' => _x( 'Bank', 'taxonomy singular name', 'clipper-custom-taxonomies' ),
'search_items' => __( 'Search Banks', 'clipper-custom-taxonomies' ),
'popular_items' => __( 'Popular Banks', 'clipper-custom-taxonomies' ),
'all_items' => __( 'All Banks', 'clipper-custom-taxonomies' ),
'parent_item' => __( 'Parent Bank', 'clipper-custom-taxonomies' ),
'parent_item_colon' => __( 'Parent Bank:', 'clipper-custom-taxonomies' ),
'edit_item' => __( 'Edit Bank', 'clipper-custom-taxonomies' ),
'view_item' => __( 'View Bank', 'clipper-custom-taxonomies' ),
'update_item' => __( 'Update Bank', 'clipper-custom-taxonomies' ),
'add_new_item' => __( 'Add New Bank', 'clipper-custom-taxonomies' ),
'new_item_name' => __( 'New Bank Name', 'clipper-custom-taxonomies' ),
'separate_items_with_commas' => __( 'Separate banks with commas', 'clipper-custom-taxonomies' ),
'add_or_remove_items' => __( 'Add or remove banks', 'clipper-custom-taxonomies' ),
'choose_from_most_used' => __( 'Choose from the most common banks', 'clipper-custom-taxonomies' ),
'not_found' => __( 'No banks found.', 'clipper-custom-taxonomies' ),
'no_terms' => __( 'No banks', 'clipper-custom-taxonomies' ),
'items_list_navigation' => __( 'Coupon tags list navigation', 'clipper-custom-taxonomies' ),
'items_list' => __( 'Coupon tags list', 'clipper-custom-taxonomies' ),
'menu_name' => _x( 'Banks', 'taxonomy menu name', 'clipper-custom-taxonomies' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'show_ui' => true,
'query_var' => true,
'update_count_callback' => '_update_post_term_count',
'rewrite' => array( 'slug' => 'bank', 'with_front' => false, 'hierarchical' => true ),
);
register_taxonomy( 'bank', APP_POST_TYPE, $args );
// Same with 'brand' taxonomy.
$labels = array(
'name' => _x( 'Brands', 'taxonomy general name', 'clipper-custom-taxonomies' ),
'singular_name' => _x( 'Brand', 'taxonomy singular name', 'clipper-custom-taxonomies' ),
'search_items' => __( 'Search Brands', 'clipper-custom-taxonomies' ),
'popular_items' => __( 'Popular Brands', 'clipper-custom-taxonomies' ),
'all_items' => __( 'All Brands', 'clipper-custom-taxonomies' ),
'parent_item' => __( 'Parent Brand', 'clipper-custom-taxonomies' ),
'parent_item_colon' => __( 'Parent Brand:', 'clipper-custom-taxonomies' ),
'edit_item' => __( 'Edit Brand', 'clipper-custom-taxonomies' ),
'view_item' => __( 'View Brand', 'clipper-custom-taxonomies' ),
'update_item' => __( 'Update Brand', 'clipper-custom-taxonomies' ),
'add_new_item' => __( 'Add New Brand', 'clipper-custom-taxonomies' ),
'new_item_name' => __( 'New Brand Name', 'clipper-custom-taxonomies' ),
'separate_items_with_commas' => __( 'Separate brands with commas', 'clipper-custom-taxonomies' ),
'add_or_remove_items' => __( 'Add or remove brands', 'clipper-custom-taxonomies' ),
'choose_from_most_used' => __( 'Choose from the most common brands', 'clipper-custom-taxonomies' ),
'not_found' => __( 'No brands found.', 'clipper-custom-taxonomies' ),
'no_terms' => __( 'No brands', 'clipper-custom-taxonomies' ),
'items_list_navigation' => __( 'Coupon tags list navigation', 'clipper-custom-taxonomies' ),
'items_list' => __( 'Coupon tags list', 'clipper-custom-taxonomies' ),
'menu_name' => _x( 'Brands', 'taxonomy menu name', 'clipper-custom-taxonomies' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'show_ui' => true,
'query_var' => true,
'update_count_callback' => '_update_post_term_count',
'rewrite' => array( 'slug' => 'brand', 'with_front' => false, 'hierarchical' => true ),
);
register_taxonomy( 'brand', APP_POST_TYPE, $args );
}
add_action( 'init', 'dkf_clipper_custom_taxonomy_register' );
/**
* Register custom taxonomies in Coupon Importer.
*
* @param array $args
*
* @return array
*/
function dkf_clipper_csv_importer_args( $args ) {
$args['taxonomies'][] = 'bank';
$args['taxonomies'][] = 'brand';
return $args;
}
add_filter( 'clpr_csv_importer_args', 'dkf_clipper_csv_importer_args' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment