Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************
- * create project metaboxes
- ***************************/
- function p52_register_project_meta_boxes( $meta_boxes ) {
- $prefix = 'p52_';
- // Get all customer custom post type posts
- $customers = get_posts( array(
- 'posts_per_page' => -1,
- 'post_type' => 'p52-contact'
- ) );
- // project content tabs
- $meta_box = array(
- 'title' => 'Project Info',
- 'pages' => 'p52-project',
- 'tabs' => array(
- 'contacts' => array(
- 'label' => 'Customer Info',
- 'icon' => 'dashicons-businessman',
- ),
- 'tasks' => array(
- 'label' => 'Tasks',
- 'icon' => 'dashicons-clipboard',
- ),
- 'documents' => array(
- 'label' => 'Documents',
- 'icon' => 'dashicons-portfolio',
- ),
- 'images' => array(
- 'label' => 'Images',
- 'icon' => 'dashicons-format-image',
- ),
- 'key' => array(
- 'label' => 'Key Contacts',
- 'icon' => 'dashicons-networking',
- ),
- 'expenses' => array(
- 'label' => 'Expenses',
- 'icon' => 'dashicons-editor-ol',
- ),
- ), // end tabs
- 'tab_style' => 'default',
- 'fields' => array(
- // Client Info
- array(
- 'name' => 'Client Info',
- 'id' => $prefix . 'client',
- 'type' => 'group',
- 'tab' => 'contacts',
- 'fields' => array(
- array(
- 'name' => 'Name',
- 'id' => $prefix . 'name',
- 'type' => 'post',
- 'post_type' => 'p52-contact',
- 'placeholder' => 'Select a Customer',
- ),
- array(
- 'name' => 'Phone',
- 'id' => $prefix . 'phone',
- 'type' => 'hidden',
- ),
- array(
- 'name' => 'Email',
- 'id' => $prefix . 'email',
- 'type' => 'hidden',
- ),
- array(
- 'name' => 'Address',
- 'id' => $prefix . 'address',
- 'type' => 'hidden',
- ),
- ), // end customer fields
- ), //end customer
- // project tasks meta box
- array(
- 'name' => 'Tasks',
- 'id' => $prefix . 'tasks',
- 'type' => 'group',
- 'clone' => true,
- 'tab' => 'tasks',
- 'fields' => array(
- array(
- 'name' => 'Task Name',
- 'id' => $prefix . 'task_name',
- 'type' => 'text',
- ),
- array(
- 'name' => 'Task Description',
- 'id' => $prefix . 'task_description',
- 'type' => 'wysiwyg',
- ),
- array(
- 'name' => 'Task Style',
- 'id' => $prefix . 'task_style',
- 'type' => 'select',
- 'options' => array(
- 'task_email' => 'Email',
- 'task_phone' => 'Phone',
- 'task_meeting' => 'Meeting',
- 'task_skype' => 'Skype',
- 'task_mockup' => 'Mockup',
- 'task_wireframe' => 'Wireframe',
- 'task_design' => 'Design',
- 'task_photography' => 'Photography',
- 'task_production' => 'Production',
- ),
- 'placeholder' => 'Select a style',
- ),
- array(
- 'name' => 'Due Date',
- 'id' => $prefix . 'task_due',
- 'type' => 'datetime',
- ),
- array(
- 'name' => 'Status',
- 'id' => $prefix . 'task_status',
- 'type' => 'select',
- 'options' => array(
- 'task_not-started' => 'Not Started',
- 'task_in_progress' => 'In Progess',
- 'task_waiting_customer' => 'Waiting Customer',
- 'task_completed' => 'Completed',
- ),
- 'placeholder' => 'Select a status',
- ),
- array(
- 'name' => 'Date Complete',
- 'id' => $prefix . 'task_date_completed',
- 'type' => 'datetime',
- ),
- ),// end task fields
- ), // end tasks
- // Document Uploads
- array(
- 'name' => 'Documents',
- 'desc' => 'Please select files to upload',
- 'id' => $prefix . 'files',
- 'type' => 'file_advanced',
- 'tab' => 'documents',
- ), // end documents
- // Private document Uploads
- array(
- 'name' => 'Private Documents',
- 'desc' => 'Please select files to upload',
- 'id' => $prefix . 'pvt_files',
- 'type' => 'file_advanced',
- 'tab' => 'documents',
- ), // end documents
- // image uploads
- array(
- 'name' => 'Images',
- 'desc' => 'Upload the finished images',
- 'id' => $prefix . 'images',
- 'type' => 'image_advanced',
- 'tab' => 'images',
- ), // end images
- // Key contacts
- array(
- 'name' => 'Key Contact',
- 'id' => $prefix . 'key_contact',
- 'type' => 'group',
- 'clone' => true,
- 'tab' => 'key',
- 'fields' => array(
- array(
- 'name' => 'Name',
- 'id' => $prefix . 'key_name',
- 'type' => 'post',
- 'post_type' => 'p52-contact',
- 'placeholder' => 'Select a Customer',
- ),
- array(
- 'name' => 'Company',
- 'id' => $prefix . 'key_company',
- 'type' => 'text',
- ),
- array(
- 'name' => 'Phone',
- 'id' => $prefix . 'key_phone',
- 'type' => 'text',
- ),
- array(
- 'name' => 'Email',
- 'id' => $prefix . 'key_email',
- 'type' => 'text',
- ),
- array(
- 'name' => 'Project Role',
- 'id' => $prefix . 'key_role',
- 'type' => 'select',
- 'options' => array(
- 'model' => 'Model',
- 'caterer' => 'Caterer',
- 'car' => 'Car Hire',
- 'hire' => 'Gear Hirer',
- 'venue' => 'Venue',
- 'printer' => 'Printer',
- 'airline' => 'Airline',
- 'other' => 'Other',
- ),
- 'placeholder' => 'Select a role',
- ),
- ), // end key contact fields
- ), // end key contacts
- // project expenses meta box
- array(
- //'name' => 'Expenses',
- 'id' => $prefix . 'expenses',
- 'type' => 'group',
- 'clone' => true,
- 'tab' => 'expenses',
- 'fields' => array(
- array(
- 'name' => 'Description',
- 'id' => $prefix . 'exp_description',
- 'type' => 'textarea',
- 'columns' => 4
- ),
- array(
- 'name' => 'Qty/Hrs',
- 'id' => $prefix . 'exp_qty',
- 'type' => 'text',
- 'columns' => 2
- ),
- array(
- 'name' => 'Price',
- 'id' => $prefix . 'exp_price',
- 'type' => 'text',
- 'columns' => 2
- ),
- array(
- 'name' => 'Tax',
- 'id' => $prefix . 'exp_tax',
- 'type' => 'text',
- 'columns' => 2
- ),
- array(
- 'name' => 'Total',
- 'id' => $prefix . 'exp_total',
- 'type' => 'text',
- 'columns' => 2
- ),
- ), // end expenses fields
- ), // end expenses
- ), // end main fields
- ); // end project content
- // Append phone or another field of customer to meta box above.
- foreach ( $customers as $customer )
- {
- // Show this email field if match name.
- $meta_box['fields'][] = array(
- 'name' => 'Email',
- 'id' => $prefix . 'email_' . $customer->ID,
- 'type' => 'text',
- 'std' => get_post_meta( $customer->ID, 'p52_contact_email', true ),
- 'visible' => array( $prefix . 'name', $customer->ID ),
- );
- // Show this phone field if match name.
- $meta_box['fields'][] = array(
- 'name' => 'Phone',
- 'id' => $prefix . 'phone_' . $customer->ID,
- 'type' => 'text',
- 'std' => get_post_meta( $customer->ID, 'p52_contact_phone', true ),
- 'visible' => array( $prefix . 'name', $customer->ID ),
- );
- // Show this company field if match name.
- $meta_box['fields'][] = array(
- 'name' => 'Company',
- 'id' => $prefix . 'company_' . $customer->ID,
- 'type' => 'text',
- 'std' => get_post_meta( $customer->ID, 'p52_contact_company', true ),
- 'visible' => array( $prefix . 'name', $customer->ID ),
- );
- // Show this address field if match name.
- $meta_box['fields'][] = array(
- 'name' => 'Address',
- 'id' => $prefix . 'address_' . $customer->ID,
- 'type' => 'textarea',
- 'std' => get_post_meta( $customer->ID, 'p52_contact_address', true ),
- 'visible' => array( $prefix . 'name', $customer->ID ),
- );
- }
- $meta_boxes[] = $meta_box;
- $meta_boxes[] = array(
- 'id' => 'project_description',
- 'title' => 'Project Description',
- 'pages' => array('p52-project'),
- 'context' => 'normal',
- 'priority' => 'low',
- 'fields' => array(
- array(
- 'name' => 'Description',
- 'id' => $prefix . 'proj_descriptions',
- 'type' => 'wysiwyg',
- ),
- ), // end description fields
- ); // end description
- // project status meta box
- $meta_boxes[] = array(
- 'id' => 'project_status',
- 'title' => 'Project Status',
- 'pages' => array('p52-project'),
- 'context' => 'side',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'name' => 'Commence Date',
- 'desc' => 'Date commenced',
- 'id' => $prefix . 'commence',
- 'type' => 'date',
- ),
- array(
- 'name' => 'Project Status',
- 'id' => $prefix . 'status',
- 'type' => 'select',
- 'options' => array(
- 'contact' => 'Initial Contact',
- 'quote' => 'Quoted',
- 'won' => 'Won',
- 'started' => 'Started',
- 'lost' => 'Lost',
- 'completed' => 'Completed',
- ),
- 'placeholder' => 'Select a status',
- ),
- array(
- 'name' => 'Closed Date',
- 'desc' => 'Date completed',
- 'id' => $prefix . 'closed',
- 'type' => 'date',
- ),
- ), // end status fields
- ); // status
- return $meta_boxes;
- }
- add_filter( 'rwmb_meta_boxes', 'p52_register_project_meta_boxes' );
- // Save data to phone field
- add_action('rwmb_before_save_post', function($post_id)
- {
- // Get person ID to save from "Select a Customer" field
- $person_to_save = intval( $_POST['p52_project_name'] );
- // Save related field to phone field
- $_POST['p52_project_phone'] = $_POST['p52_project_phone_' . $person_to_save];
- // Unset all hidden fields
- foreach ( $_POST as $key => $value )
- {
- if ( strpos( $key, 'p52_project_phone_' ) || strpos( $key, 'p52_project_email_' ) || strpos( $key, 'p52_project_address_' ) )
- unset( $_POST[$key] );
- }
- // Save related field to email field
- $_POST['p52_project_email'] = $_POST['p52_project_email_' . $person_to_save];
- // Unset all hidden fields
- foreach ( $_POST as $key => $value )
- {
- if ( strpos( $key, 'p52_project_email_' ) || strpos( $key, 'p52_project_address_' ))
- unset( $_POST[$key] );
- }
- // Save related field to address field
- $_POST['p52_project_address'] = $_POST['p52_project_address_' . $person_to_save];
- // Unset all hidden fields
- foreach ( $_POST as $key => $value )
- {
- if ( strpos( $key, 'p52_project_address_' ) )
- unset( $_POST[$key] );
- }
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement