| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main settings page template |
| 4 |
* |
| 5 |
* @package Mailchimp |
| 6 |
*/ |
| 7 |
|
| 8 |
use function Mailchimp\WordPress\Includes\Admin\admin_notice_error; |
| 9 |
|
| 10 |
$user = get_option( 'mc_user' ); |
| 11 |
$is_logged_in = ! ( ! $user || ( ! get_option( 'mc_api_key' ) && ! mailchimp_sf_get_access_token() ) ); |
| 12 |
|
| 13 |
// If we have an API Key, see if we need to change the lists and its options |
| 14 |
mailchimp_sf_change_list_if_necessary(); |
| 15 |
|
| 16 |
$is_list_selected = false; |
| 17 |
?> |
| 18 |
<div id="mailchimp-sf-settings-page"> |
| 19 |
<?php |
| 20 |
// Header. |
| 21 |
include_once MCSF_DIR . 'includes/admin/templates/header.php'; // phpcs:ignore PEAR.Files.IncludingFile.UseRequireOnce |
| 22 |
|
| 23 |
// If user is not logged in, show login form. |
| 24 |
if ( ! $is_logged_in ) { |
| 25 |
include_once MCSF_DIR . 'includes/admin/templates/login.php'; |
| 26 |
} else { |
| 27 |
$user = get_option( 'mc_user' ); |
| 28 |
|
| 29 |
// Settings header. |
| 30 |
include_once MCSF_DIR . 'includes/admin/templates/settings-header.php'; |
| 31 |
?> |
| 32 |
|
| 33 |
<div class="wrap"> |
| 34 |
<?php |
| 35 |
// Just get out if nothing else matters... |
| 36 |
$api = mailchimp_sf_get_api(); |
| 37 |
if ( ! $api ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
?> |
| 41 |
<div class="mailchimp-sf-settings-page-wrapper"> |
| 42 |
<div class="mailchimp-sf-settings-page"> |
| 43 |
<hr class="wp-header-end" /> |
| 44 |
<?php settings_errors(); ?> |
| 45 |
<div class="mailchimp-sf-settings-list-wrapper"> |
| 46 |
<p class="mailchimp-sf-settings-list-note"> |
| 47 |
<?php esc_html_e( 'Please select the Mailchimp list you\'d like to connect to your form.', 'mailchimp' ); ?> |
| 48 |
</p> |
| 49 |
<p class="mailchimp-sf-settings-list-description"> |
| 50 |
<strong><?php esc_html_e( 'Note:', 'mailchimp' ); ?></strong> <?php esc_html_e( 'List settings are fetched from Mailchimp, fetching a new list will override your current settings.', 'mailchimp' ); ?> |
| 51 |
</p> |
| 52 |
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'page' => 'mailchimp_sf_options' ), admin_url( 'admin.php' ) ) ); ?>"> |
| 53 |
<?php |
| 54 |
// we *could* support paging, but few users have that many lists (and shouldn't) |
| 55 |
$lists = $api->get( 'lists', 100, array( 'fields' => 'lists.id,lists.name' ) ); |
| 56 |
if ( is_wp_error( $lists ) ) { |
| 57 |
$msg = sprintf( |
| 58 |
/* translators: %s: error message */ |
| 59 |
esc_html__( 'Uh-oh, we couldn\'t get your lists from Mailchimp! Error: %s', 'mailchimp' ), |
| 60 |
esc_html( $lists->get_error_message() ) |
| 61 |
); |
| 62 |
admin_notice_error( $msg ); |
| 63 |
} elseif ( isset( $lists['lists'] ) && count( $lists['lists'] ) === 0 ) { |
| 64 |
$msg = sprintf( |
| 65 |
/* translators: %s: link to Mailchimp */ |
| 66 |
esc_html__( 'Uh-oh, you don\'t have any lists defined! Please visit %s, login, and setup a list before using this tool!', 'mailchimp' ), |
| 67 |
"<a href='http://www.mailchimp.com/'>Mailchimp</a>" |
| 68 |
); |
| 69 |
admin_notice_error( $msg ); |
| 70 |
} else { |
| 71 |
$lists = $lists['lists']; |
| 72 |
$option = get_option( 'mc_list_id' ); |
| 73 |
$list_ids = array_map( |
| 74 |
function ( $ele ) { |
| 75 |
return $ele['id']; |
| 76 |
}, |
| 77 |
$lists |
| 78 |
); |
| 79 |
$is_list_selected = in_array( $option, $list_ids, true ); |
| 80 |
?> |
| 81 |
<div class="mailchimp-sf-settings-list-select-wrapper"> |
| 82 |
<div class="mailchimp-sf-settings-list-select"> |
| 83 |
<label class="screen-reader-text" for="mc_list_id"><?php esc_html_e( 'Select a list', 'mailchimp' ); ?></label> |
| 84 |
<select id="mc_list_id" name="mc_list_id"> |
| 85 |
<option value=""> — <?php esc_html_e( 'Select A List', 'mailchimp' ); ?> — </option> |
| 86 |
<?php |
| 87 |
foreach ( $lists as $list ) { |
| 88 |
?> |
| 89 |
<option value="<?php echo esc_attr( $list['id'] ); ?>"<?php selected( $list['id'], $option ); ?>><?php echo esc_html( $list['name'] ); ?></option> |
| 90 |
<?php |
| 91 |
} |
| 92 |
?> |
| 93 |
</select> |
| 94 |
</div> |
| 95 |
<div class="mailchimp-sf-settings-list-select-button"> |
| 96 |
<input type="hidden" name="mcsf_action" value="update_mc_list_id" /> |
| 97 |
<input type="submit" name="submit" value="<?php esc_attr_e( 'Fetch list settings', 'mailchimp' ); ?>" class="mailchimp-sf-button btn-secondary" /> |
| 98 |
</div> |
| 99 |
</div> |
| 100 |
<?php |
| 101 |
} //end select list |
| 102 |
?> |
| 103 |
</form> |
| 104 |
</div> |
| 105 |
|
| 106 |
<?php |
| 107 |
// Just get out if nothing else matters... |
| 108 |
if ( ! $is_list_selected ) { |
| 109 |
?> |
| 110 |
</div></div></div></div> |
| 111 |
<?php |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Render the user sync status, start cta etc... |
| 117 |
*/ |
| 118 |
do_action( 'mailchimp_sf_user_sync_before_form' ); |
| 119 |
|
| 120 |
// Load the form settings. |
| 121 |
include_once MCSF_DIR . 'includes/admin/templates/setup-page.php'; |
| 122 |
|
| 123 |
// Load the user sync settings. |
| 124 |
include_once MCSF_DIR . 'includes/admin/templates/user-sync.php'; |
| 125 |
?> |
| 126 |
</div> |
| 127 |
</div> |
| 128 |
</div> |
| 129 |
<?php |
| 130 |
} |
| 131 |
?> |
| 132 |
</div> |
| 133 |
|