Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tuts+ Create a Simple CRM in WordPress: Part 3
<?php
/**
* Plugin Name: Tuts+ CRM
* Plugin URI: #
* Version: 1.0
* Author: Tuts+
* Author URI: http://code.tutsplus.com
* Description: A simple CRM system for WordPress
* License: GPL2
*/
/**
* Set Advanced Custom Fields to Lite mode, so it does not appear
* in the WordPress Administration Menu
*/
include_once( 'advanced-custom-fields/acf.php' );
define( 'ACF_LITE', true );
class WPTutsCRM {
/**
* Constructor. Called when plugin is initialised
*/
function __construct() {
add_action( 'init', array( &$this, 'register_custom_post_type' ) );
add_action( 'plugins_loaded', array( &$this, 'acf_fields' ) );
}
/**
* Registers a Custom Post Type called contact
*/
function register_custom_post_type() {
register_post_type( 'contact', array(
'labels' => array(
'name' => _x( 'Contacts', 'post type general name', 'tuts-crm' ),
'singular_name' => _x( 'Contact', 'post type singular name', 'tuts-crm' ),
'menu_name' => _x( 'Contacts', 'admin menu', 'tuts-crm' ),
'name_admin_bar' => _x( 'Contact', 'add new on admin bar', 'tuts-crm' ),
'add_new' => _x( 'Add New', 'contact', 'tuts-crm' ),
'add_new_item' => __( 'Add New Contact', 'tuts-crm' ),
'new_item' => __( 'New Contact', 'tuts-crm' ),
'edit_item' => __( 'Edit Contact', 'tuts-crm' ),
'view_item' => __( 'View Contact', 'tuts-crm' ),
'all_items' => __( 'All Contacts', 'tuts-crm' ),
'search_items' => __( 'Search Contacts', 'tuts-crm' ),
'parent_item_colon' => __( 'Parent Contacts:', 'tuts-crm' ),
'not_found' => __( 'No contacts found.', 'tuts-crm' ),
'not_found_in_trash' => __( 'No contacts found in Trash.', 'tuts-crm' ),
),
// Frontend
'has_archive' => false,
'public' => false,
'publicly_queryable' => false,
// Admin
'capability_type' => 'post',
'menu_icon' => 'dashicons-businessman',
'menu_position' => 10,
'query_var' => true,
'show_in_menu' => true,
'show_ui' => true,
'supports' => array(
'title',
'author',
'comments',
),
) );
}
/**
* Register ACF Field Groups and Fields
*/
function acf_fields() {
if(function_exists("register_field_group")) {
register_field_group(array (
'id' => 'acf_contact-details',
'title' => 'Contact Details',
'fields' => array (
array (
'key' => 'field_5323276db7e18',
'label' => 'Email Address',
'name' => 'email_address',
'type' => 'email',
'required' => 1,
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
array (
'key' => 'field_53232a6cf3800',
'label' => 'Phone Number',
'name' => 'phone_number',
'type' => 'number',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
array (
'key' => 'field_53232aa9f3801',
'label' => 'Photo',
'name' => 'photo',
'type' => 'image',
'save_format' => 'object',
'preview_size' => 'thumbnail',
'library' => 'all',
),
array (
'key' => 'field_53232c2ff3802',
'label' => 'Type',
'name' => 'type',
'type' => 'select',
'required' => 1,
'choices' => array (
'Prospect' => 'Prospect',
'Customer' => 'Customer',
),
'default_value' => '',
'allow_null' => 0,
'multiple' => 0,
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'contact',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'default',
'hide_on_screen' => array (
0 => 'permalink',
1 => 'excerpt',
2 => 'custom_fields',
3 => 'discussion',
4 => 'comments',
5 => 'revisions',
6 => 'slug',
7 => 'author',
8 => 'format',
9 => 'featured_image',
10 => 'categories',
11 => 'tags',
12 => 'send-trackbacks',
),
),
'menu_order' => 1,
));
}
}
}
$wpTutsCRM = new WPTutsCRM;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.