Advertisement
brandonjp

mb_cardinal_contacts

Jan 13th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.45 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * REGISTER THE TAXONOMY
  5.  */
  6.  
  7. //
  8. function cardinalpm_contacts_register_taxonomy()
  9. {
  10.  
  11.     $args = array(
  12.         'label'                => esc_html__('Contacts', 'text-domain'),
  13.         'labels'               => array(
  14.             'menu_name'                  => esc_html__('Contacts', 'text-domain'),
  15.             'all_items'                  => esc_html__('All Contacts', 'text-domain'),
  16.             'edit_item'                  => esc_html__('Edit Contact', 'text-domain'),
  17.             'view_item'                  => esc_html__('View Contact', 'text-domain'),
  18.             'update_item'                => esc_html__('Update Contact', 'text-domain'),
  19.             'add_new_item'               => esc_html__('Add new Contact', 'text-domain'),
  20.             'new_item_name'              => esc_html__('New Contact', 'text-domain'),
  21.             'parent_item'                => esc_html__('Parent Contact', 'text-domain'),
  22.             'parent_item_colon'          => esc_html__('Parent Contact:', 'text-domain'),
  23.             'search_items'               => esc_html__('Search Contacts', 'text-domain'),
  24.             'popular_items'              => esc_html__('Popular Contacts', 'text-domain'),
  25.             'separate_items_with_commas' => esc_html__('Separate Contacts with commas', 'text-domain'),
  26.             'add_or_remove_items'        => esc_html__('Add or remove Contacts', 'text-domain'),
  27.             'choose_from_most_used'      => esc_html__('Choose most used Contacts', 'text-domain'),
  28.             'not_found'                  => esc_html__('No Contacts found', 'text-domain'),
  29.             'name'                       => esc_html__('Contacts', 'text-domain'),
  30.             'singular_name'              => esc_html__('Contact', 'text-domain'),
  31.         ),
  32.         'public'               => true,
  33.         'show_ui'              => true,
  34.         'show_in_menu'         => true,
  35.         'show_in_nav_menus'    => true,
  36.         'show_tagcloud'        => false,
  37.         'show_in_quick_edit'   => true,
  38.         'show_admin_column'    => true,
  39.         'show_in_rest'         => true,
  40.         'hierarchical'         => false,
  41.         'query_var'            => true,
  42.         'sort'                 => false,
  43.         'rewrite_no_front'     => false,
  44.         'rewrite_hierarchical' => false,
  45.         'rewrite'              => true,
  46.     );
  47.  
  48.     register_taxonomy('contact', array('cardinal-job'), $args);
  49. }
  50. add_action('init', 'cardinalpm_contacts_register_taxonomy', 0);
  51.  
  52. /*
  53.  * DEFINE CUSTOM TABLE
  54.  */
  55.  
  56. add_action('init', 'create_table_for_contacts');
  57. function create_table_for_contacts()
  58. {
  59.     if (!class_exists('MB_Custom_Table_API')) {
  60.         return;
  61.     }
  62.     MB_Custom_Table_API::create('cardinal_contacts', array(
  63.         'contact_email'    => 'VARCHAR(240) NOT NULL',
  64.         'contact_phone'    => 'TEXT NOT NULL',
  65.         'related_customer' => 'INT(11) NOT NULL',
  66.         'contact_notes'    => 'TEXT NOT NULL',
  67.     ));
  68. }
  69.  
  70. /*
  71.  * THE ACTUAL META BOXES
  72.  */
  73.  
  74. //
  75. add_filter('rwmb_meta_boxes', 'contactdetails_register_meta_boxes');
  76.  
  77. function contactdetails_register_meta_boxes($meta_boxes)
  78. {
  79.     $prefix = '';
  80.  
  81.     $meta_boxes[] = array(
  82.         'title'        => esc_html__('Contact Details', 'text-domain'),
  83.         'id'           => 'contact-details',
  84.         'storage_type' => 'custom_table',
  85.         'table'        => 'cardinal_contacts',
  86.         'fields'       => array(
  87.             array(
  88.                 'id'    => 'contact_email',
  89.                 'name'  => esc_html__('Email', 'text-domain'),
  90.                 'type'  => 'email',
  91.                 'class' => 'wide',
  92.             ),
  93.             array(
  94.                 'id'    => 'contact_phone',
  95.                 'type'  => 'text',
  96.                 'name'  => esc_html__('Phone', 'text-domain'),
  97.                 'class' => 'wide',
  98.             ),
  99.             array(
  100.                 'id'         => 'related_customer',
  101.                 'type'       => 'taxonomy_advanced',
  102.                 'name'       => esc_html__('Company', 'text-domain'),
  103.                 'taxonomy'   => 'customer',
  104.                 'field_type' => 'select_advanced',
  105.                 'add_new'    => true,
  106.             ),
  107.             array(
  108.                 'id'   => 'contact_notes',
  109.                 'type' => 'textarea',
  110.                 'name' => esc_html__('Notes', 'text-domain'),
  111.             ),
  112.         ),
  113.         'taxonomies'   => 'contact',
  114.         'autocomplete' => 'off',
  115.     );
  116.  
  117.     return $meta_boxes;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement