Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/js/ctct-plugin-admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/ctct-plugin-admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/ctct-plugin-admin.min.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion assets/js/ctct-plugin-admin/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ window.CTCTBuilder = {};
if ('custom' === map.value) {
fieldLabel.classList.add('form-field-is-custom-field');
} else {
fieldLabel.classList.remove('form-field-is-custom-field')
fieldLabel.classList.remove('form-field-is-custom-field');
}
if ('custom' === map.value || 'custom_text_area' === map.value) {
fieldLabel.setAttribute('maxlength', '50');
} else {
fieldLabel.removeAttribute('maxlength');
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions includes/class-builder-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,25 @@ public function unique_label_messaging( array $field_args, CMB2_Field $field ) {
'</a>'
)
);

if ( constant_contact()->get_api()->is_connected() ) {
$custom_fields_data = constant_contact()->get_api()->cc()->get_custom_fields();
if (
is_array( $custom_fields_data['custom_fields'] ) &&
! empty( $custom_fields_data['custom_fields'] )
) {
if ( array_key_exists( 'label', $custom_fields_data['custom_fields'][0] ) ) {
$labels = wp_list_pluck( $custom_fields_data['custom_fields'], 'label' );
sort( $labels );

printf(
'<p>%1$s<br/><strong>%2$s</strong></p>',
esc_html__( 'Available fields from your account:', 'constant-contact-forms' ),
implode( ', ', $labels )
);
}
}
}
}

/**
Expand Down
22 changes: 18 additions & 4 deletions includes/class-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,24 @@ public function create_update_contact( array $args = [] ) {
* Get configured custom fields for contacts.
*
* @since 2.0.0
* @since NEXT Added limit parameter.
*
* @param string $limit How many custom fields to retrieve. Default 50. Max 100.
* @return array
*/
public function get_custom_fields() {
return $this->get( 'contact_custom_fields', $this->base_args );
public function get_custom_fields( $limit = '50' ) {
$endpoint = 'contact_custom_fields';

if ( ! empty( $limit ) ) {
if ( ! is_numeric( $limit ) ) {
$limit = '50'; //fallback in case non-numbers got passed in.
}
$endpoint = add_query_arg(
[ 'limit' => $limit ],
'contact_custom_fields'
);
}
return $this->get( $endpoint, $this->base_args );
}

/**
Expand All @@ -134,7 +148,7 @@ public function get_custom_field( string $field_id ) {
* @return bool
*/
public function custom_field_exists( string $field_name ) {
$fields = $this->get_custom_fields();
$fields = $this->get_custom_fields( '100' );
if ( ! empty( $fields ) && array_key_exists( 'custom_fields', $fields ) ) {
$field_keys = wp_list_pluck( $fields['custom_fields'], 'label' );
return in_array( $field_name, $field_keys, true );
Expand All @@ -151,7 +165,7 @@ public function custom_field_exists( string $field_name ) {
* @return mixed|string
*/
public function get_custom_field_by_name( string $field_name ) {
$fields = $this->get_custom_fields();
$fields = $this->get_custom_fields( '100' );
if ( ! empty( $fields ) && array_key_exists( 'custom_fields', $fields ) ) {
foreach ( $fields['custom_fields'] as $field ) {
if ( $field['label'] === $field_name ) {
Expand Down