| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace UiCoreElements; |
| 4 | 4 | |
| 5 | +use UiCoreElements\Utils\Newsletter_Services as Services; | |
| 6 | + | |
| 5 | 7 | /** |
| 6 | 8 | * Admin Pages Handler |
| 7 | 9 | */ |
| 8 | 10 | class Admin |
| @@ -15,12 +17,21 @@ | ||
| 15 | 17 | * @since 1.0.0 |
| 16 | 18 | */ |
| 17 | 19 | public function __construct() |
| 18 | 20 | { |
| 19 | - $this->elementor_style(); | |
| 20 | - | |
| 21 | 21 | add_action('admin_menu', [$this, 'admin_menu']); |
| 22 | 22 | add_action('admin_init', [$this, 'init_hooks']); |
| 23 | + | |
| 24 | + // TODO: Remove this after, at least, 5 releases or 1 year from 1.3.3 | |
| 25 | + // Mailchimp to generic api key fields migration | |
| 26 | + if ( | |
| 27 | + get_option('uicore_elements_mailchimp_secret_key') | |
| 28 | + && !get_option('uicore_elements_newsletter_service_key') | |
| 29 | + ) { | |
| 30 | + $value = get_option('uicore_elements_mailchimp_secret_key'); | |
| 31 | + update_option('uicore_elements_newsletter_service_key', $value); | |
| 32 | + delete_option('uicore_elements_mailchimp_secret_key'); | |
| 33 | + } | |
| 23 | 34 | } |
| 24 | 35 | |
| 25 | 36 | /** |
| 26 | 37 | * Add admin menu page |
| @@ -32,16 +43,16 @@ | ||
| 32 | 43 | public function admin_menu() |
| 33 | 44 | { |
| 34 | 45 | // Settings page (only required if uicore framework is not active) |
| 35 | 46 | // if (!\class_exists('\UiCore\Helper')) { |
| 36 | - $hook = add_submenu_page( | |
| 37 | - 'options-general.php', | |
| 38 | - 'UiCore Elements', | |
| 39 | - 'UiCore Elements', | |
| 40 | - 'manage_options', | |
| 41 | - 'uicore-elements', | |
| 42 | - [$this, 'plugin_page'] | |
| 43 | - ); | |
| 47 | + $hook = add_submenu_page( | |
| 48 | + 'options-general.php', | |
| 49 | + 'UiCore Elements', | |
| 50 | + 'UiCore Elements', | |
| 51 | + 'manage_options', | |
| 52 | + 'uicore-elements', | |
| 53 | + [$this, 'plugin_page'] | |
| 54 | + ); | |
| 44 | 55 | |
| 45 | 56 | // } |
| 46 | 57 | |
| 47 | 58 | // Connect handle |
| @@ -63,18 +74,23 @@ | ||
| 63 | 74 | * @since 1.0.5 |
| 64 | 75 | */ |
| 65 | 76 | public function init_hooks() |
| 66 | 77 | { |
| 78 | + // Register settings for reCAPTCHA | |
| 67 | 79 | register_setting('uicore_elements_recaptcha', 'uicore_elements_recaptcha_site_key', ['sanitize_callback' => 'sanitize_text_field']); |
| 68 | 80 | register_setting('uicore_elements_recaptcha', 'uicore_elements_recaptcha_secret_key', ['sanitize_callback' => 'sanitize_text_field']); |
| 69 | - register_setting('uicore_elements_mailchimp', 'uicore_elements_mailchimp_secret_key', ['sanitize_callback' => 'sanitize_text_field']); | |
| 70 | 81 | |
| 82 | + // Register settings for Mailchimp | |
| 83 | + register_setting('uicore_elements_newsletter_service', 'uicore_elements_newsletter_service_key', ['sanitize_callback' => 'sanitize_text_field']); | |
| 84 | + | |
| 85 | + // Add settings sections | |
| 71 | 86 | add_settings_section('uicore_elements_recaptcha_section', 'reCAPTCHA Keys', [$this, 'recaptcha_section'], 'uicore_elements_recaptcha'); |
| 72 | - add_settings_section('uicore_elements_mailchimp_section', 'Mailchimp Key', [$this, 'mailchimp_section'], 'uicore_elements_mailchimp'); | |
| 87 | + add_settings_section('uicore_elements_newsletter_service_section', 'Newsletter Service Key', [$this, 'newsletter_service_section'], 'uicore_elements_newsletter_service'); | |
| 73 | 88 | |
| 89 | + // Add settings fields | |
| 74 | 90 | add_settings_field('uicore_elements_recaptcha_site_key', 'Site Key', [$this, 'site_key'], 'uicore_elements_recaptcha', 'uicore_elements_recaptcha_section'); |
| 75 | 91 | add_settings_field('uicore_elements_recaptcha_secret_key', 'Secret Key', [$this, 'secret_key'], 'uicore_elements_recaptcha', 'uicore_elements_recaptcha_section'); |
| 76 | - add_settings_field('uicore_elements_mailchimp_secret_key', 'API Key', [$this, 'mailchimp_key'], 'uicore_elements_mailchimp', 'uicore_elements_mailchimp_section'); | |
| 92 | + add_settings_field('uicore_elements_newsletter_service_key', 'API Key', [$this, 'newsletter_service_key'], 'uicore_elements_newsletter_service', 'uicore_elements_newsletter_service_section'); | |
| 77 | 93 | } |
| 78 | 94 | |
| 79 | 95 | /** |
| 80 | 96 | * Render plugin page |
| @@ -94,9 +110,9 @@ | ||
| 94 | 110 | // show error/update messages |
| 95 | 111 | settings_errors('uicoreelements_messages'); |
| 96 | 112 | |
| 97 | 113 | // display plugin page |
| 98 | - ?> | |
| 114 | +?> | |
| 99 | 115 | <div class="wrap"> |
| 100 | 116 | <h1>UiCore Elements Settings</h1> |
| 101 | 117 | |
| 102 | 118 | <form method="post" action="options.php" style="margin-top:40px"> |
| @@ -108,131 +124,66 @@ | ||
| 108 | 124 | </form> |
| 109 | 125 | |
| 110 | 126 | <form method="post" action="options.php" style="margin-top:40px"> |
| 111 | 127 | <?php |
| 112 | - settings_fields('uicore_elements_mailchimp'); | |
| 113 | - do_settings_sections('uicore_elements_mailchimp'); | |
| 128 | + settings_fields('uicore_elements_newsletter_service'); | |
| 129 | + do_settings_sections('uicore_elements_newsletter_service'); | |
| 114 | 130 | submit_button(); |
| 115 | 131 | ?> |
| 116 | 132 | </form> |
| 117 | 133 | |
| 118 | 134 | </div> |
| 119 | - <?php | |
| 135 | +<?php | |
| 120 | 136 | } |
| 121 | 137 | |
| 122 | 138 | /** |
| 123 | - * Render reCAPTCHA section description | |
| 139 | + * Newsletter Services sections | |
| 124 | 140 | * |
| 125 | 141 | * @return void |
| 126 | 142 | * @author Andrei Voica <andrei@uicore.co> |
| 127 | - * @since 1.0.5 | |
| 143 | + * | |
| 144 | + * recaptcha @since 1.0.5 | |
| 145 | + * mailchimp @since 1.0.7 | |
| 146 | + * constant contact, brevo, a, c @since 1.3.3 | |
| 128 | 147 | */ |
| 148 | + | |
| 129 | 149 | public function recaptcha_section() |
| 130 | 150 | { |
| 131 | 151 | echo '<p class="description">Go to your Google <a href="https://www.google.com/recaptcha/admin/create" target="_blank">reCAPTCHA</a>, choose between V2 or V3 versions and create your API keys</p>'; |
| 132 | 152 | } |
| 133 | - /** | |
| 134 | - * Render Mailchimp section description | |
| 135 | - * | |
| 136 | - * @return void | |
| 137 | - * @author Lucas Marini Falbo <lucas@uicore.co> | |
| 138 | - * @since 1.0.7 | |
| 139 | - */ | |
| 140 | - public function mailchimp_section() | |
| 153 | + public function newsletter_service_section() | |
| 141 | 154 | { |
| 142 | - echo "<p class='description'>If you don't have one yet, go to your <a href='https://admin.mailchimp.com/account/api/' target='_blank'>Mailchimp Dashboard</a> and create a new API key</p>"; | |
| 155 | + $services = '<strong>' . implode('</strong>, <strong>', Services::get_services_list('names')) . '</strong>'; | |
| 156 | + printf( | |
| 157 | + '<p class="description">%s %s.</p>', | |
| 158 | + esc_html__('Set your newsletter service provider API key. We support the following services:', 'uicore-elements'), | |
| 159 | + Helper::esc_string($services) //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 160 | + ); | |
| 143 | 161 | } |
| 144 | 162 | |
| 145 | 163 | /** |
| 146 | - * Render reCAPTCHA Site Key field | |
| 164 | + * Render Uicore Elements settings fields | |
| 147 | 165 | * |
| 148 | 166 | * @return void |
| 149 | 167 | * @author Andrei Voica <andrei@uicore.co> |
| 150 | - * @since 1.0.5 | |
| 168 | + * | |
| 169 | + * site key, secret key @since 1.0.5 | |
| 170 | + * mailchimp key @since 1.0.7 | |
| 171 | + * mailchim update for XX @since 1.3.3 | |
| 151 | 172 | */ |
| 173 | + | |
| 152 | 174 | public function site_key() |
| 153 | 175 | { |
| 154 | 176 | $site_key = get_option('uicore_elements_recaptcha_site_key'); |
| 155 | 177 | echo '<input type="text" name="uicore_elements_recaptcha_site_key" value="' . esc_attr($site_key) . '" class="regular-text" />'; |
| 156 | 178 | } |
| 157 | - | |
| 158 | - /** | |
| 159 | - * Render reCAPTCHA Secret Key field | |
| 160 | - * | |
| 161 | - * @return void | |
| 162 | - * @author Andrei Voica <andrei@uicore.co> | |
| 163 | - * @since 1.0.5 | |
| 164 | - */ | |
| 165 | 179 | public function secret_key() |
| 166 | 180 | { |
| 167 | 181 | $secret_key = get_option('uicore_elements_recaptcha_secret_key'); |
| 168 | 182 | echo '<input type="text" name="uicore_elements_recaptcha_secret_key" value="' . esc_attr($secret_key) . '" class="regular-text" />'; |
| 169 | 183 | } |
| 170 | - | |
| 171 | - /** | |
| 172 | - * Render Mailchimp API Key | |
| 173 | - * | |
| 174 | - * @return void | |
| 175 | - * @author Lucas Marini Falbo <lucas@uicore.co> | |
| 176 | - * @since 1.0.5 | |
| 177 | - */ | |
| 178 | - public function mailchimp_key() | |
| 184 | + public function newsletter_service_key() | |
| 179 | 185 | { |
| 180 | - $secret_key = get_option('uicore_elements_mailchimp_secret_key'); | |
| 181 | - echo '<input type="text" name="uicore_elements_mailchimp_secret_key" value="' . esc_attr($secret_key) . '" class="regular-text" />'; | |
| 182 | - } | |
| 183 | - | |
| 184 | - | |
| 185 | - /** | |
| 186 | - * Elementor Editor Style, Fonts and Scripts | |
| 187 | - * | |
| 188 | - * @return void | |
| 189 | - * @author Andrei Voica <andrei@uicore.co | |
| 190 | - * @since 1.0.0 | |
| 191 | - */ | |
| 192 | - public function elementor_style() | |
| 193 | - { | |
| 194 | - add_action('elementor/editor/before_enqueue_scripts', function () { | |
| 195 | - | |
| 196 | - echo '<style id="uicore-csss" > | |
| 197 | - .elementor-element .icon .ui-e-widget:after { | |
| 198 | - height: 28px; | |
| 199 | - width: 28px; | |
| 200 | - margin-right: 10px; | |
| 201 | - border-radius: 3px; | |
| 202 | - background-color: #532df5; | |
| 203 | - background-image: url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'16\' height=\'16\' viewBox=\'0 0 16 16\' xml:space=\'preserve\'%3E%3Cpath d=\'M5.383 15.217c3.1 0 5.4-2.3 5.4-5.3v-7.9h-2.9v7.9c0 1.4-1.1 2.5-2.5 2.5s-2.5-1.1-2.5-2.5v-7.9h-2.9v7.9c0 3 2.3 5.3 5.4 5.3zM14.283 4.117c1 0 1.7-.7 1.7-1.7s-.7-1.7-1.7-1.7-1.7.7-1.7 1.7.7 1.7 1.7 1.7zM15.683 15.017v-9.6h-2.8v9.6z\' fill=\'%23fff\'/%3E%3C/svg%3E"); | |
| 204 | - background-size: 16px; | |
| 205 | - background-position: center; | |
| 206 | - background-repeat: no-repeat; | |
| 207 | - } | |
| 208 | - | |
| 209 | - .elementor-element .icon .ui-e-widget:after { | |
| 210 | - content: ""; | |
| 211 | - position: absolute; | |
| 212 | - right: 5px; | |
| 213 | - top: 5px; | |
| 214 | - margin-right: 0; | |
| 215 | - width: 16px; | |
| 216 | - height: 16px; | |
| 217 | - background-size: 9px; | |
| 218 | - background-color: #656c7196; | |
| 219 | - transition: background-color .3s ease-in-out; | |
| 220 | - } | |
| 221 | - .elementor-element:hover .icon .ui-e-widget:after { | |
| 222 | - background-color: #532df5; | |
| 223 | - transition: background-color .3s ease-in-out; | |
| 224 | - } | |
| 225 | - #elementor-panel-categories{ | |
| 226 | - display: flex; | |
| 227 | - flex-direction: column; | |
| 228 | - } | |
| 229 | - #elementor-panel-category-basic, | |
| 230 | - #elementor-panel-category-layout, | |
| 231 | - #elementor-panel-category-favorites, | |
| 232 | - #elementor-panel-category-uicore{ | |
| 233 | - order: -1; | |
| 234 | - } | |
| 235 | - </style>'; | |
| 236 | - }); | |
| 186 | + $secret_key = get_option('uicore_elements_newsletter_service_key'); | |
| 187 | + echo '<input type="text" name="uicore_elements_newsletter_service_key" value="' . esc_attr($secret_key) . '" class="regular-text" />'; | |
| 237 | 188 | } |
| 238 | 189 | } |