Add or Remove Default Fields

Introduced in WP-CRM System 2.0.11, we have a filter that allows developers to modify the fields that are available to the user. In order to modify the existing fields you first have to remove all of the existing fields, then add back the fields you want to use and any additional fields you may need to add. If you only want to add fields, you can skip the removing portion below.

Remove Existing Fields #

To remove the existing fields, you will need to remove the filter which adds the default fields. 

// remove fields in campaigns
remove_filter( 'wpcrm_system_fields', 'wpcrm_system_campaign_fields', 10);
// remove fields in contacts
remove_filter( 'wpcrm_system_fields', 'wpcrm_system_contact_fields', 10);
// remove fields in organizations
remove_filter( 'wpcrm_system_fields', 'wpcrm_system_organization_fields', 10);
// remove fields in opportunities
remove_filter( 'wpcrm_system_fields', 'wpcrm_system_opportunity_fields', 10);
// remove fields in projects
remove_filter( 'wpcrm_system_fields', 'wpcrm_system_project_fields', 10);
// remove fields in tasks
remove_filter( 'wpcrm_system_fields', 'wpcrm_system_task_fields', 10);

If you use the code above, all of your fields will be removed from the edit pages of your WP-CRM System records. However, all of the data will still exist for these fields in the database.

Add Fields #

Now we can add back the fields that we want. You can copy the existing fields from the following files:

  • /wp-crm-system/wcs-fields-campaign.php
  • /wp-crm-system/wcs-fields-contact.php
  • /wp-crm-system/wcs-fields-opportunity.php
  • /wp-crm-system/wcs-fields-organization.php
  • /wp-crm-system/wcs-fields-project.php
  • /wp-crm-system/wcs-fields-task.php

Note: fields will be displayed in the order that they are added to the array below. 

Let’s say we want to add all of the organization fields back, and swap the location of the email and phone fields. We also want to add a new field at the bottom of the edit page. 

function my_organization_fields($fields){
  $organizationFields = array(
    array(
      'name'        => 'organization-email',
      'title'       => WPCRM_EMAIL,
      'description' => '',
      'placeholder' => '',
      'type'        => 'email',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '<div class="wp-crm-first wp-crm-one-half">',
      'after'        => '',
      'icon'        => 'dashicons dashicons-email wpcrm-dashicons',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-phone',
      'title'       => WPCRM_PHONE,
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '',
      'after'        => '',
      'icon'        => 'dashicons dashicons-phone wpcrm-dashicons',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-website',
      'title'       => WPCRM_WEBSITE,
      'description' => '',
      'placeholder' => 'http://',
      'type'        => 'url',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '',
      'after'        => '</div>',
      'icon'        => 'dashicons dashicons-admin-links wpcrm-dashicons',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-address1',
      'title'       => WPCRM_ADDRESS_1,
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '<div class="wp-crm-one-half"><div class="wp-crm-inline">',
      'after'        => '</div>',
      'icon'        => 'dashicons dashicons-location wpcrm-dashicons',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-address2',
      'title'       => WPCRM_ADDRESS_2,
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => '',
      'before'        => '<div class="wp-crm-inline">',
      'after'        => '</div>',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-city',
      'title'       => WPCRM_CITY,
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => '',
      'before'        => '<div class="wp-crm-first wp-crm-inline">',
      'after'        => '</div>',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-state',
      'title'       => WPCRM_STATE,
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => '',
      'before'        => '<div class="wp-crm-inline">',
      'after'        => '</div>',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-postal',
      'title'       => WPCRM_POSTAL,
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => '',
      'before'        => '<div class="wp-crm-inline">',
      'after'        => '</div>',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-country',
      'title'       => WPCRM_COUNTRY,
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '',
      'after'        => '</div>',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-information',
      'title'       => WPCRM_ADDITIONAL,
      'description' => '',
      'placeholder' => '',
      'type'        => 'wysiwyg',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '',
      'after'        => '',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-dropbox',
      'title'       => WPCRM_DROPBOX,
      'description' => '',
      'placeholder' => '',
      'type'        => 'dropbox',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '',
      'after'        => '',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
    array(
      'name'        => 'organization-test-field',
      'title'       => 'my field',
      'description' => '',
      'placeholder' => '',
      'type'        => 'default',
      'scope'       => array( 'wpcrm-organization' ),
      'style'        => 'wp-crm-first',
      'before'        => '',
      'after'        => '',
      'icon'        => '',
      'capability'  => WPCRM_USER_ACCESS
    ),
  );
  $fields = array_merge( $organizationFields, $fields );
  return $fields;
}
add_filter( 'wpcrm_system_fields', 'my_organization_fields' );

It is important to note the $fields = array_merge( $organizationFields, $fields ); line. All fields in WP-CRM System are stored in the same $fields array. If you forget to merge your new fields into the existing array, you will end up losing all fields from the other record types.

Array Keys #

Each field is made up of an array that requires certain keys. Many of the values are optional, but you should include all of the keys with an empty value if it is not needed for your purposes.

  • ‘name’ => Used as the field’s input name and id. Will be prefixed by _wpcrm_ If you enter a name value of ‘your_field_name’ the input’s name and id will be _wpcrm_your_field_name.
  • ‘title’ => The display name for the field (i.e. First Name)
  • ‘description’ => Optionally display a description for the field’s use
  • ‘placeholder’ => For certain text inputs you can include placeholder text here
  • ‘type’ => The type of input you are expecting. See Field Types below.
  • ‘scope’ => The post type(s) that this field will be used on in an array. If you wish to add it to more than one post type, you can add it to the array.
  • ‘style’ => Optionally add a class to the <div> that wraps around this field.
  • ‘before’ => Optionally add content before the field.
  • ‘after’ => Optionally add content after the field.
    • The before and after keys can be used to create groups of fields for separating content. For example, add a <div class=”my-group”> to the before of the first field in your grouping, and a </div> to the after for the last field in your grouping.
  • ‘icon’ => Optionally display an icon before the field’s value. Uses Dashicons.
  • ‘capability’ => Provide the capability that a user must have in order to edit the field. Default is ‘manage_wp_crm’, which is defined in the constant WPCRM_USER_ACCESS.

Field Types #

WP-CRM System comes with a number of field types that are built in. All validation and sanitizing of the field values are handled for you. Certain fields will only accept a limited number of responses.

  • selectcontact: Displays a select menu of all WP-CRM System contacts.
  • selectproject: Displays a select menu of all WP-CRM System projects.
  • selectorganization: Displays a select menu of all WP-CRM System organizations.
  • selectcampaign: Displays a select menu of all WP-CRM System campaigns.
  • selectprogress: Displays a select menu of values counting by 5 between 0-100 (i.e. 0, 5, 10, 15, 20, 25, etc.).
  • selectwonlost: Displays a select menu with the following values. Not Set, Won, Lost, Suspended, or Abandoned.
  • selectpriority: Displays a select menu with the following values. Low, Medium, or High.
  • selectstatus: Displays a select menu with the following values. Not Started, In Progress, Complete, On Hold.
  • selectnameprefix: Displays a select menu with the following values. Mr, Mrs, Miss, Ms, Dr, Master, Coach, Rev, Fr, Atty, Prof, Hon, Pres, Gov, Ofc, Supt, Rep, Sen, Amb.
  • selectuser: Displays a select menu of all users with access to WP-CRM System.
  • datepicker: Displays a text input with a calendar popup for date selection.
  • currency: Displays a text input that only accepts numeric input. Also shows currency selected in settings.
  • number: Displays a text input that only accepts numeric input.
  • wysiwyg: Displays a WYSIWYG editor for text, and HTML input similar to the post edit screen.
  • textarea: Displays a multi-line text area for basic text entry. No styling or HTML input is allowed.
  • url: Displays a text input that only accepts URL values.
  • email: Displays a text input that only accepts email addresses as values.
  • checkbox: Displays a single checkbox with binary input (checked = yes unchecked = no).
  • addcontact: Displays a text input that will create a new contact with the name entered in the box.
  • addorganization: Displays a text input that will create a new organization with the name entered in the box.
  • addproject: Displays a text input that will create a new project with the name entered in the box.
  • addcampaign: Displays a text input that will create a new campaign with the name entered in the box.
  • default: Displays a single line text input field.

You may add your own field types, but you will need to handle sanitizing and validating the field’s values on your own.