PluginProbe
Mailchimp List Subscribe Form / 2.0.1
Mailchimp List Subscribe Form v2.0.1
1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 All 55 releases
mailchimp / includes / admin / templates / settings.php

settings.php in Mailchimp List Subscribe Form 2.0.1, at includes/admin/templates/settings.php

134 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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=""> &mdash; <?php esc_html_e( 'Select A List', 'mailchimp' ); ?> &mdash; </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 <?php wp_nonce_field( 'update_mc_list_id_action', 'update_mc_list_id_nonce' ); ?>
98 <input type="submit" name="submit" value="<?php esc_attr_e( 'Fetch list settings', 'mailchimp' ); ?>" class="mailchimp-sf-button btn-secondary" />
99 </div>
100 </div>
101 <?php
102 } //end select list
103 ?>
104 </form>
105 </div>
106
107 <?php
108 // Just get out if nothing else matters...
109 if ( ! $is_list_selected ) {
110 ?>
111 </div></div></div></div>
112 <?php
113 return;
114 }
115
116 /**
117 * Render the user sync status, start cta etc...
118 */
119 do_action( 'mailchimp_sf_user_sync_before_form' );
120
121 // Load the form settings.
122 include_once MCSF_DIR . 'includes/admin/templates/setup-page.php';
123
124 // Load the user sync settings.
125 include_once MCSF_DIR . 'includes/admin/templates/user-sync.php';
126 ?>
127 </div>
128 </div>
129 </div>
130 <?php
131 }
132 ?>
133 </div>
134