__( '1/3rd of row', 'supportcandy' ), 'half' => __( 'Half width', 'supportcandy' ), 'full' => __( 'Full width', 'supportcandy' ), ); ?>

' . esc_attr__( 'Click here', 'supportcandy' ) . '' ); ?>
$settings ) : $cf = WPSC_Custom_Field::get_cf_by_slug( $slug ); if ( ! $cf ) { continue; } $vis_decoded = is_string( $settings['visibility'] ) ? json_decode( $settings['visibility'], true ) : $settings['visibility']; $visibility = ( ! empty( $vis_decoded ) ) ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ); ?>
name ); ?> slug == 'name' || $cf->slug == 'email' ) ) : echo esc_attr( ' | ' ); ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Insert form field * * @return void */ public static function set_add_new_tff() { if ( check_ajax_referer( 'wpsc_set_add_new_tff', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $tff = get_option( 'wpsc-tff', array() ); $cf = new WPSC_Custom_Field( $id ); if ( ! $cf->id || ! $cf->type::$is_ctf || ! in_array( $cf->field, WPSC_CF_Settings::$allowed_modules['ticket-form'] ) || isset( $tff[ $cf->slug ] ) ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $is_required = isset( $_POST['is-required'] ) ? intval( $_POST['is-required'] ) : 1; $width = isset( $_POST['width'] ) ? sanitize_text_field( wp_unslash( $_POST['width'] ) ) : 'full'; $load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__'; $visibility = isset( $_POST['visibility'] ) ? sanitize_text_field( wp_unslash( $_POST['visibility'] ) ) : ''; if ( ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_visibility_conditions', $visibility ) ) { wp_send_json_error( 'Bad request', 400 ); } $field = apply_filters( 'wpsc_tff_add_new', array( 'is-required' => $is_required, 'width' => $width, 'visibility' => $visibility, ), $cf ); switch ( $load_after ) { case '__TOP__': $tff = array_merge( array( $cf->slug => $field ), $tff ); break; case '__END__': $tff = array_merge( $tff, array( $cf->slug => $field ) ); break; default: $load_after = WPSC_Custom_Field::get_cf_by_slug( $load_after ); if ( ! $load_after || ! isset( $tff[ $load_after->slug ] ) ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } if ( count( $tff ) == 0 ) { $tff = array_merge( $tff, array( $cf->slug => $field ) ); } else { $offset = array_search( $load_after->slug, array_keys( $tff ) ) + 1; $arr1 = array_slice( $tff, 0, $offset ); $arr2 = array_slice( $tff, $offset ); $tff = array_merge( $arr1, array( $cf->slug => $field ), $arr2 ); } break; } update_option( 'wpsc-tff', $tff ); wp_die(); } /** * Edit ticket form field modal * * @return void */ public static function get_edit_tff() { if ( check_ajax_referer( 'wpsc_get_edit_tff', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $tff = get_option( 'wpsc-tff', array() ); $cf = new WPSC_Custom_Field( $id ); if ( ! $cf->id || ! $cf->type::$is_ctf || ! isset( $tff[ $cf->slug ] ) ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $field = $tff[ $cf->slug ]; $title = $cf->name; $unique_id = uniqid( 'wpsc_' ); // calculate load order. $tff_keys = array_keys( $tff ); $offset = array_search( $cf->slug, $tff_keys ); $load_after = $offset == 0 ? '__TOP__' : $tff_keys[ $offset - 1 ]; ob_start(); ?>
slug == 'name' || $cf->slug == 'email' ) ) : ?>
slug == 'name' || $cf->slug == 'email' ) ) { WPSC_Ticket_Conditions::print( 'visibility', 'wpsc_visibility_conditions', $field['visibility'], false, __( 'Visibility conditions', 'supportcandy' ) ); } ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Set edit data * * @return void */ public static function set_edit_tff() { if ( check_ajax_referer( 'wpsc_set_edit_tff', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $tff = get_option( 'wpsc-tff', array() ); $cf = new WPSC_Custom_Field( $id ); $load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__'; if ( ! $cf->id || ! $cf->type::$is_ctf || ! isset( $tff[ $cf->slug ] ) ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $visibility = isset( $_POST['visibility'] ) ? sanitize_text_field( wp_unslash( $_POST['visibility'] ) ) : ''; if ( ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_visibility_conditions', $visibility ) ) { wp_send_json_error( 'Bad request', 400 ); } // unset from tff so that load after should work. unset( $tff[ $cf->slug ] ); $field = apply_filters( 'wpsc_set_edit_tff', array( 'is-required' => isset( $_POST['is-required'] ) ? intval( $_POST['is-required'] ) : 1, 'width' => isset( $_POST['width'] ) ? sanitize_text_field( wp_unslash( $_POST['width'] ) ) : 'full', 'visibility' => $visibility, ), $cf ); // set load after. switch ( $load_after ) { case '__TOP__': $tff = array_merge( array( $cf->slug => $field ), $tff ); break; case '__END__': $tff = array_merge( $tff, array( $cf->slug => $field ) ); break; default: $load_after = WPSC_Custom_Field::get_cf_by_slug( $load_after ); if ( ! $load_after || ! isset( $tff[ $load_after->slug ] ) ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $offset = array_search( $load_after->slug, array_keys( $tff ) ) + 1; $arr1 = array_slice( $tff, 0, $offset ); $arr2 = array_slice( $tff, $offset ); $tff = array_merge( $arr1, array( $cf->slug => $field ), $arr2 ); break; } update_option( 'wpsc-tff', $tff ); wp_die(); } /** * Set load order * * @return void */ public static function set_load_order() { if ( check_ajax_referer( 'wpsc_set_tff_load_order', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 400 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $slugs = isset( $_POST['slugs'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['slugs'] ) ) : array(); if ( ! $slugs ) { wp_send_json_error( 'Bad Request', 400 ); } $tff = get_option( 'wpsc-tff', array() ); $new_tff = array(); foreach ( $slugs as $slug ) { if ( isset( $tff[ $slug ] ) ) { $new_tff[ $slug ] = $tff[ $slug ]; } } // Append any remaining fields (safety net) that were not part of the posted order. foreach ( $tff as $slug => $field ) { if ( ! isset( $new_tff[ $slug ] ) ) { $new_tff[ $slug ] = $field; } } update_option( 'wpsc-tff', $new_tff ); wp_send_json( array( 'success' => true ), 200 ); } /** * Delete form field * * @return void */ public static function delete_tff() { if ( check_ajax_referer( 'wpsc_delete_tff', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( 'Unauthorized request!', 401 ); } $tff = get_option( 'wpsc-tff', array() ); $cf = new WPSC_Custom_Field( $id ); if ( ! $cf->id || ! $cf->type::$is_ctf || ! in_array( $cf->field, array( 'customer', 'ticket' ) ) || ! isset( $tff[ $cf->slug ] ) ) { wp_send_json_error( 'Unauthorized request!', 401 ); } unset( $tff[ $cf->slug ] ); update_option( 'wpsc-tff', $tff ); wp_die(); } /** * Return JSON object for tff * * @param WPSC_TFF $tff - ticket form field. * @param boolean $is_array - is array. * @return array */ public static function get_visibility( $tff, $is_array = false ) { $visibility = $tff['visibility'] ? html_entity_decode( $tff['visibility'] ) : ''; if ( $is_array ) { return $visibility ? json_decode( $visibility, true ) : array(); } else { return $visibility ? json_decode( $visibility ) : new stdClass(); } } /** * Remove tff if related custom field got deleted * * @param WPSC_CF $cf - tff custom field. * @return void */ public static function delete_custom_field( $cf ) { $tff = get_option( 'wpsc-tff', array() ); if ( array_key_exists( $cf->slug, $tff ) ) { unset( $tff[ $cf->slug ] ); update_option( 'wpsc-tff', $tff ); } } /** * Filter conditions for visibility * * @param array $conditions - conditions to filter. * @return array */ public static function visibility_conditions( $conditions ) { foreach ( $conditions as $slug => $item ) { if ( $item['type'] == 'cf' ) { $cf = WPSC_Custom_Field::get_cf_by_slug( $slug ); if ( ! $cf->type::$is_visibility_conditions || ! in_array( $cf->field, array( 'ticket', 'customer' ) ) ) { unset( $conditions[ $slug ] ); } } else { // not custom field type. unset( $conditions[ $slug ] ); } } return $conditions; } } endif; WPSC_TFF::init();