Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Awesome Support Custom Fields Starter Kit
<?php
/**
* @package Awesome Support/Custom Fields
* @author ThemeAvenue <web@themeavenue.net>
* @license GPL-2.0+
* @link http://themeavenue.net
* @copyright 2014 ThemeAvenue
*
* @wordpress-plugin
* Plugin Name: Awesome Support: My Custom Fields
* Plugin URI: http://getawesomesupport.com
* Description: Adds custom fields to the Awesome Support ticket submission form.
* Version: 0.1.0
* Author: ThemeAvenue
* Author URI: http://themeavenue.net
* Text Domain: wpas
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
add_action( 'plugins_loaded', 'wpas_user_custom_fields' );
/**
* Register all custom fields after the plugin is safely loaded.
*/
function wpas_user_custom_fields() {
/* You can start adding your custom fields safely after this line */
/* Do NOT write anything after this line */
}
@julien731
Copy link
Author

julien731 commented Oct 26, 2015

When using wpas_add_custom_field() or wpas_add_custom_taxonomy(), please make sure to wrap them inside a function_exists() check.

Example

if ( function_exists( 'wpas_add_custom_field' ) ) {
    wpas_add_custom_field( 'my_custom_field',  array( 'title' => __( 'My Custom Field', 'awesome-support' ) ) );
}

@nooh43
Copy link

nooh43 commented Oct 26, 2018

I added it according to the instructions in the documentation, but still it's not showing up.
do I need to add any codes to the templates ?

@syedamirali14
Copy link

syedamirali14 commented Dec 29, 2018

yes i followed the same procedure it is not working

@Jan-Paul-Kleijn
Copy link

Jan-Paul-Kleijn commented Feb 25, 2019

The 'plugins_loaded action' is triggered before the theme is loaded. So if it's used in your functions.php it is has already been called. You could rather use the action 'after_setup_theme'.

But it does not work regardless unfortunately.

My input:

add_action( 'after_setup_theme', 'wpas_user_custom_fields' );
function wpas_user_custom_fields() {
  if ( function_exists( 'wpas_add_custom_field' ) ) {
    wpas_add_custom_field( 'my_custom_field',  array( 'title' => __( 'My Custom Field', 'awesome-support' ) ) );
  }
}

@dadodd
Copy link

dadodd commented Mar 15, 2019

For all of you not managing to get plugin working.

  1. In plugins folder create new folder and put awesome-support-custom-fields.php inside.
    Example wp-content/plugins/as-plugin/awesome-support-custom-fields.php
<?php
/*
Plugin Name: AS Customizations
Plugin URI: https://getawesomesupport.com/
Version: 1.0.0
Author: ThemeAvenue
Author URI: http://themeavenue.net
Description: This example plugin shows how to add <a href="https://getawesomesupport.com/documentation/awesome-support/custom-fields/">custom fields</a> and conditional logic to the Ticket Submission form.
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

// Allow agents/admin to see the forms
add_filter( 'wpas_agent_submit_front_end', '__return_true' );



// Register all custom fields after the plugin is safely loaded.
add_action( 'plugins_loaded', 'wpas_user_custom_fields' );
function wpas_user_custom_fields() {
	wpas_add_custom_field( 'phone_name', 
		array(
			'title' => __( 'Proizvođač', 'wpas' ),
			'field_type' => 'text',
			'required' => true
			)
		);
		
	wpas_add_custom_field( 'issue_name', 
		array(
			'title' => __( 'Uređaj', 'wpas' ),
			'field_type' => 'text',
			'required' => true
			)
		);	
}

@crimean-resident
Copy link

crimean-resident commented Mar 22, 2019

For those who, like me, have tried all the examples above, and still could not get it to work:
In fact, we add a plugin that needs to be activated on plugins page, just like any other downloaded plugin. Spent 40 minutes to figure it out. lol

@vinnyparker
Copy link

vinnyparker commented Oct 15, 2019

how to setup a mandatory custom field?

@logalleon
Copy link

logalleon commented Jan 31, 2020

Following these examples doesn't have any effect. Are there any additional options in the admin interface that need to be enable in order for custom fields to show up in the "Fields" Settings tab? Additionally, do custom fields even work with Remote Tickets in the first place?

@philip-yan-99
Copy link

philip-yan-99 commented Sep 21, 2020

After add awesome-support-custom-fields.php in the plugin folder, we must return to the plugin page. And you must activate the new plugin which named "Awesome Support: My Custom Fields", then the filed can be used in the ticket page.

@gdourrom
Copy link

gdourrom commented Dec 11, 2020

I downloaded the "Code Snippet" plugin and put the following code inside.

add_action ('after_setup_theme', 'wpas_user_custom_fields');
function wpas_user_custom_fields () {
   if (function_exists ('wpas_add_custom_field')) {
     wpas_add_custom_field ('my_custom_field', array ('title' => __ ('My Custom Field', 'awesome-support')));
   }
}

download code snippets

@paulopais
Copy link

paulopais commented Dec 29, 2020

Hi, its possible get the department tag to send in email notification?

@hassanshahzadaheer
Copy link

hassanshahzadaheer commented Feb 14, 2022

Hi, I added the code in the plugins folder as per the given description click here and active this plugin but now I'm not sure where to see the output of this code.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment