Skip to content

Instantly share code, notes, and snippets.

@orangerdev
Created May 29, 2018 16:16
Show Gist options
  • Save orangerdev/a5f32bfebfbe36bb50b2cf6be10cc132 to your computer and use it in GitHub Desktop.
Save orangerdev/a5f32bfebfbe36bb50b2cf6be10cc132 to your computer and use it in GitHub Desktop.
Library to register wordpress taxonomy easier
<?php
namespace JBSF\Admin;
class Taxonomy
{
private $label = [];
/**
* Construction
*/
public function __construct()
{
}
/**
* Set taxonomy label
* @param string $singular [description]
* @param string $plural [description]
*/
private function set_label($singular,$plural = '')
{
$plural = (empty($plural) || '' === $plural) ? $singular.'s' : $plural;
$this->label = array(
'name' => _x( ucfirst($plural), 'taxonomy general name', 'jbsf' ),
'singular_name' => _x( ucfirst($singular), 'taxonomy singular name', 'jbsf' ),
'search_items' => __( 'Search '.ucfirst($plural), 'jbsf' ),
'all_items' => __( 'All '.ucfirst($plural), 'jbsf' ),
'parent_item' => __( 'Parent '.ucfirst($singular), 'jbsf' ),
'parent_item_colon' => __( 'Parent '.ucfirst($singular).':', 'jbsf' ),
'edit_item' => __( 'Edit '.ucfirst($singular), 'jbsf' ),
'update_item' => __( 'Update '.ucfirst($singular), 'jbsf' ),
'add_new_item' => __( 'Add New '.ucfirst($singular), 'jbsf' ),
'new_item_name' => __( 'New '.ucfirst($singular).' Name', 'jbsf' ),
'menu_name' => __( ucfirst($singular), 'jbsf' ),
);
}
/**
* Set taxonomy detail
* @param string $taxonomy [description]
* @param array $post_types [description]
* @param array $args [description]
*/
private function set_taxonomy($taxonomy,$post_types,$args)
{
$args = wp_parse_args($args,[
'hierarchical' => true,
'labels' => $this->label,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => ['slug' => $taxonomy],
]);
register_taxonomy( $taxonomy,$post_types, $args );
}
/**
* Register role taxonomy
* @return void
*/
public function register_role()
{
return;
$this->set_label('Job Role');
$this->set_taxonomy('job-role',['job_listing'],[
'show_admin_column' => false
]);
}
/**
* Register skill taxonomy
* @return void
*/
public function register_skill()
{
return;
$this->set_label('Job Skill');
$this->set_taxonomy('job-skill',['job_listing'],[
'show_admin_column' => false
]);
}
/**
* Register sector
* @return [type] [description]
*/
public function register_sector()
{
$this->set_label('Job Sector');
$this->set_taxonomy('job-sector',['job_listing'],[
'show_admin_column' => false
]);
}
/**
* Register job education
* @return [type] [description]
*/
public function register_education()
{
$this->set_label('Education');
$this->set_taxonomy('job-education',['job_listing'],[
'show_admin_column' => false
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment