Skip to content

Commit

Permalink
Fix/cc 440 comment login signup errors (#683)
Browse files Browse the repository at this point in the history
* filter out woocommerce specific lists from the forms plugin

* this is not serving any purpose

* return early if we do not have any lists

* while we should have a list item for each, do an empty check before trying to add to array

* wp core get_option only has 2 parameters available to it.
  • Loading branch information
tw2113 authored Oct 8, 2024
1 parent 177e9a6 commit ff30665
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions includes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,20 @@ protected function register_fields_general() {
]
);

$lists = constant_contact()->builder->get_lists();
$lists = constant_contact()->builder->get_lists();
$woo_lists = [
'WooCommerce - All Customers',
'WooCommerce - First time Customers',
'WooCommerce - Lapsed Customers',
'WooCommerce - Potential Customers',
'WooCommerce - Recent Customers',
'WooCommerce - Repeat Customers',
];
foreach( $lists as $list_id => $list_name ) {
if ( in_array( $list_name, $woo_lists ) ) {
unset( $lists[ $list_id ] );
}
}

if ( $lists && is_array( $lists ) ) {

Expand All @@ -391,8 +404,6 @@ protected function register_fields_general() {
]
);

$lists[0] = esc_html__( 'Select a list', 'constant-contact-forms' );

$cmb->add_field(
[
'name' => esc_html__( 'Add subscribers to', 'constant-contact-forms' ),
Expand Down Expand Up @@ -735,12 +746,14 @@ public function optin_form_field() {
if ( ! constant_contact()->api->is_connected() ) {
return;
}

$saved_label = constant_contact_get_option( '_ctct_optin_label', '' );

$lists = $this->get_optin_list_options();
$label = $saved_label ?: esc_html__( 'Sign up to our newsletter.', 'constant-contact-forms' );

if ( empty( $lists ) ) {
return;
}

$saved_label = constant_contact_get_option( '_ctct_optin_label', '' );
$label = $saved_label ?: esc_html__( 'Sign up to our newsletter.', 'constant-contact-forms' );
?>
<p class="ctct-optin-wrapper" style="padding: 0 0 1em 0;">
<p><?php echo esc_attr( $label ); ?></p>
Expand Down Expand Up @@ -1078,7 +1091,7 @@ private function get_default_spam_error() {
}

/**
* Returns formated list of available lists during opt-in.
* Returns formatted list of available lists during opt-in.
*
* @author Scott Anderson <scott.anderson@webdevstudios.com>
* @since 1.12.0
Expand All @@ -1099,8 +1112,11 @@ private function get_optin_list_options() {
];
$list = get_posts( $list_args );

$formatted_lists[ $list_id ] = $list[0]->post_title;
if ( ! empty( $list ) ) {
$formatted_lists[ $list_id ] = $list[0]->post_title;
}
}

return $formatted_lists;
}
}
Expand All @@ -1122,7 +1138,7 @@ function constant_contact_get_option( $key = '', $default = null ) {
return cmb2_get_option( constant_contact()->settings->key, $key, $default );
}

$options = get_option( constant_contact()->settings->key, $key, $default );
$options = get_option( $key, $default );
$value = $default;

if ( 'all' === $key ) {
Expand Down

0 comments on commit ff30665

Please sign in to comment.