array(
'slug' => 'ticket_form_fields',
'icon' => 'contact-form',
'label' => esc_attr__( 'Ticket Form Fields', 'supportcandy' ),
'callback' => 'wpsc_get_tff',
),
'ticket-fields' => array(
'slug' => 'ticket_fields',
'icon' => 'ticket-alt',
'label' => esc_attr__( 'Ticket Fields', 'supportcandy' ),
'callback' => 'wpsc_get_ticket_fields',
),
'customer-fields' => array(
'slug' => 'customer_fields',
'icon' => 'user-tie',
'label' => esc_attr__( 'Customer Fields', 'supportcandy' ),
'callback' => 'wpsc_get_customer_fields',
),
'agent-only-fields' => array(
'slug' => 'agent_only_fields',
'icon' => 'headset',
'label' => esc_attr__( 'Agent Only Fields', 'supportcandy' ),
'callback' => 'wpsc_get_agent_only_fields',
),
)
);
self::$current_section = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : 'ticket-form-fields'; //phpcs:ignore
}
/**
* Add localizations to local JS
*
* @param array $localizations - localizations.
* @return array
*/
public static function localizations( $localizations ) {
if ( ! self::$is_current_page ) {
return $localizations;
}
// Humbargar Titles.
$localizations['humbargar_titles'] = self::get_humbargar_titles();
// Current section.
$localizations['current_section'] = self::$current_section;
return $localizations;
}
/**
* UI foundation for this screen
*
* @return void
*/
public static function layout() {
?>
$section ) {
$active = self::$current_section === $key ? 'active' : '';
?>
' . esc_attr( $section['label'] ) . '';
$titles[ $section['slug'] ] = ob_get_clean();
}
return $titles;
}
/**
* Register JS functions to call on document ready
*
* @return void
*/
public static function register_js_ready_function() {
if ( ! self::$is_current_page ) {
return;
}
echo esc_attr( self::$sections[ self::$current_section ]['callback'] ) . '();' . PHP_EOL;
}
/**
* Register fields (ticket, agentonly, customer, etc.)
*
* @return void
*/
public static function register_fields() {
self::$fields = apply_filters( 'wpsc_custom_field_categories', array() );
}
/**
* Register allowed modules
*
* @return void
*/
public static function register_allowed_modules() {
self::$allowed_modules = apply_filters(
'wpsc_cf_allowed_modules',
array(
'ticket-form' => array( 'ticket', 'customer' ),
'ticket-list' => array( 'ticket', 'customer', 'agentonly' ),
'ticket-filter' => array( 'ticket', 'customer', 'agentonly' ),
'ticket-macro' => array( 'ticket', 'customer', 'agentonly' ),
)
);
}
/**
* Add new custom field form
*
* String $field - custom field (ticket, agentonly, customer, etc.).
*
* @return void
*/
public static function get_add_new_custom_field() {
if ( check_ajax_referer( 'wpsc_get_add_new_custom_field', '_ajax_nonce', false ) !== 1 ) {
wp_send_json_error( 'Unauthorised request!', 401 );
}
if ( ! WPSC_Functions::is_site_admin() ) {
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
}
$field = isset( $_POST['field'] ) ? sanitize_text_field( wp_unslash( $_POST['field'] ) ) : '';
if ( ! $field ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
?>
field = $field;
$cf->name = isset( $_POST['label'] ) ? sanitize_text_field( wp_unslash( $_POST['label'] ) ) : '';
if ( ! $cf->name ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
$cf->type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
if ( ! $cf->type ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
$cf->type::set_cf_properties( $cf, self::$fields[ $field ] );
// set load after.
$load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__';
if ( $load_after != '__END__' ) {
$count = 1;
if ( $load_after == '__TOP__' ) {
$cf->load_order = $count++;
$cf->save();
}
foreach ( WPSC_Custom_Field::$custom_fields as $cff ) {
if ( $cff->field != $cf->field || $cff->slug == $cf->slug ) {
continue;
}
$cff->load_order = $count++;
$cff->save();
if ( $cff->slug == $load_after ) {
$cf->load_order = $count++;
$cf->save();
}
}
}
wp_die();
}
/**
* Get edit custom field screen
*
* @return void
*/
public static function get_edit_custom_field() {
global $wpdb;
if ( check_ajax_referer( 'wpsc_get_edit_custom_field', '_ajax_nonce', false ) != 1 ) {
wp_send_json_error( 'Unauthorised request!', 401 );
}
if ( ! WPSC_Functions::is_site_admin() ) {
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
}
$id = isset( $_POST['cf_id'] ) ? intval( $_POST['cf_id'] ) : 0;
if ( ! $id ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
$cf = new WPSC_Custom_Field( $id );
if ( ! $cf->id ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
?>
id ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
$cf->name = isset( $_POST['label'] ) ? sanitize_text_field( wp_unslash( $_POST['label'] ) ) : '';
if ( ! $cf->name ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
$cf->type::set_cf_properties( $cf, self::$fields[ $cf->field ] );
// set load after.
$load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__';
if ( $load_after != '__END__' ) {
$count = 1;
if ( $load_after == '__TOP__' ) {
$cf->load_order = $count++;
$cf->save();
}
foreach ( WPSC_Custom_Field::$custom_fields as $cff ) {
if ( $cff->field != $cf->field || $cff->slug == $cf->slug ) {
continue;
}
$cff->load_order = $count++;
$cff->save();
if ( $cff->slug == $load_after ) {
$cf->load_order = $count++;
$cf->save();
}
}
} else {
$max_load_order = (int) $wpdb->get_var( "SELECT max(load_order) FROM {$wpdb->prefix}psmsc_custom_fields WHERE field='{$cf->field}'" );
$cf->load_order = ++$max_load_order;
$cf->save();
}
wp_die();
}
/**
* Delete custom feild
*/
public static function delete_custom_field() {
if ( check_ajax_referer( 'wpsc_delete_custom_field', '_ajax_nonce', false ) != 1 ) {
wp_send_json_error( 'Unauthorised request!', 401 );
}
if ( ! WPSC_Functions::is_site_admin() ) {
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
}
$id = isset( $_POST['cf_id'] ) ? intval( $_POST['cf_id'] ) : 0;
if ( ! $id ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
$cf = new WPSC_Custom_Field( $id );
if ( ! $cf->id ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
do_action( 'wpsc_delete_custom_field', $cf );
WPSC_Custom_Field::destroy( $id );
wp_die();
}
/**
* Static snippets for this page
*
* @return void
*/
public static function print_snippets() {
?>