PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.17
UiCore Elements – Free widgets and templates for Elementor v1.3.17
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
← All changes | includes/class-admin.php +167 -40 1.0.31.3.17 View file →
@@ -1,62 +1,189 @@
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 -class Admin {
10 +class Admin
11 +{
12 + /**
13 + * Constructor function to initialize hooks
14 + *
15 + * @return void
16 + * @author Andrei Voica <andrei@uicore.co>
17 + * @since 1.0.0
18 + */
19 + public function __construct()
20 + {
21 + add_action('admin_menu', [$this, 'admin_menu']);
22 + add_action('admin_init', [$this, 'init_hooks']);
9 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 + }
34 + }
35 +
10 36 /**
11 - * Constructor function to initialize hooks
37 + * Add admin menu page
12 38 *
13 39 * @return void
40 + * @author Andrei Voica <andrei@uicore.co>
41 + * @since 1.0.5
14 42 */
15 - public function __construct() {
16 - $this->elementor_style();
43 + public function admin_menu()
44 + {
45 + // Settings page (only required if uicore framework is not active)
46 + // if (!\class_exists('\UiCore\Helper')) {
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 + );
55 +
56 + // }
57 +
58 + // Connect handle
59 + // add_submenu_page(
60 + // null,
61 + // 'UiCore Connect',
62 + // 'UiCore Connect',
63 + // 'manage_options',
64 + // 'uicore_connect_free',
65 + // [$this, 'connect_page_callback']
66 + // );
17 67 }
18 68
19 69 /**
20 - * Elementor Editor Style, Fonts and Scripts
70 + * Initialize hooks for settings fields and sections
21 71 *
22 72 * @return void
23 - * @author Andrei Voica <andrei@uicore.co
24 - * @since 1.0.0
73 + * @author Andrei Voica <andrei@uicore.co>
74 + * @since 1.0.5
25 75 */
26 - public function elementor_style()
76 + public function init_hooks()
27 77 {
28 - add_action('elementor/editor/before_enqueue_scripts', function () {
78 + // Register settings for reCAPTCHA
79 + register_setting('uicore_elements_recaptcha', 'uicore_elements_recaptcha_site_key', ['sanitize_callback' => 'sanitize_text_field']);
80 + register_setting('uicore_elements_recaptcha', 'uicore_elements_recaptcha_secret_key', ['sanitize_callback' => 'sanitize_text_field']);
29 81
30 - echo '<style id="uicore-csss" >
31 - .elementor-element .icon .ui-e-widget:after {
32 - height: 28px;
33 - width: 28px;
34 - margin-right: 10px;
35 - border-radius: 3px;
36 - background-color: #532df5;
37 - 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");
38 - background-size: 16px;
39 - background-position: center;
40 - background-repeat: no-repeat;
41 - }
82 + // Register settings for Mailchimp
83 + register_setting('uicore_elements_newsletter_service', 'uicore_elements_newsletter_service_key', ['sanitize_callback' => 'sanitize_text_field']);
42 84
43 - .elementor-element .icon .ui-e-widget:after {
44 - content: "";
45 - position: absolute;
46 - right: 5px;
47 - top: 5px;
48 - margin-right: 0;
49 - width: 16px;
50 - height: 16px;
51 - background-size: 9px;
52 - background-color: #656c7196;
53 - transition: background-color .3s ease-in-out;
54 - }
55 - .elementor-element:hover .icon .ui-e-widget:after {
56 - background-color: #532df5;
57 - transition: background-color .3s ease-in-out;
58 - }
59 - </style>';
60 - });
85 + // Add settings sections
86 + add_settings_section('uicore_elements_recaptcha_section', 'reCAPTCHA Keys', [$this, 'recaptcha_section'], 'uicore_elements_recaptcha');
87 + add_settings_section('uicore_elements_newsletter_service_section', 'Newsletter Service Key', [$this, 'newsletter_service_section'], 'uicore_elements_newsletter_service');
88 +
89 + // Add settings fields
90 + add_settings_field('uicore_elements_recaptcha_site_key', 'Site Key', [$this, 'site_key'], 'uicore_elements_recaptcha', 'uicore_elements_recaptcha_section');
91 + add_settings_field('uicore_elements_recaptcha_secret_key', 'Secret Key', [$this, 'secret_key'], 'uicore_elements_recaptcha', 'uicore_elements_recaptcha_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');
61 93 }
62 -}
94 +
95 + /**
96 + * Render plugin page
97 + *
98 + * @return void
99 + * @author Andrei Voica <andrei@uicore.co>
100 + * @since 1.0.5
101 + */
102 + public function plugin_page()
103 + {
104 + // check user capabilities
105 + if (!current_user_can('manage_options')) {
106 + return;
107 + }
108 +
109 +
110 + // show error/update messages
111 + settings_errors('uicoreelements_messages');
112 +
113 + // display plugin page
114 +?>
115 + <div class="wrap">
116 + <h1>UiCore Elements Settings</h1>
117 +
118 + <form method="post" action="options.php" style="margin-top:40px">
119 + <?php
120 + settings_fields('uicore_elements_recaptcha');
121 + do_settings_sections('uicore_elements_recaptcha');
122 + submit_button();
123 + ?>
124 + </form>
125 +
126 + <form method="post" action="options.php" style="margin-top:40px">
127 + <?php
128 + settings_fields('uicore_elements_newsletter_service');
129 + do_settings_sections('uicore_elements_newsletter_service');
130 + submit_button();
131 + ?>
132 + </form>
133 +
134 + </div>
135 +<?php
136 + }
137 +
138 + /**
139 + * Newsletter Services sections
140 + *
141 + * @return void
142 + * @author Andrei Voica <andrei@uicore.co>
143 + *
144 + * recaptcha @since 1.0.5
145 + * mailchimp @since 1.0.7
146 + * constant contact, brevo, a, c @since 1.3.3
147 + */
148 +
149 + public function recaptcha_section()
150 + {
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>';
152 + }
153 + public function newsletter_service_section()
154 + {
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 + );
161 + }
162 +
163 + /**
164 + * Render Uicore Elements settings fields
165 + *
166 + * @return void
167 + * @author Andrei Voica <andrei@uicore.co>
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
172 + */
173 +
174 + public function site_key()
175 + {
176 + $site_key = get_option('uicore_elements_recaptcha_site_key');
177 + echo '<input type="text" name="uicore_elements_recaptcha_site_key" value="' . esc_attr($site_key) . '" class="regular-text" />';
178 + }
179 + public function secret_key()
180 + {
181 + $secret_key = get_option('uicore_elements_recaptcha_secret_key');
182 + echo '<input type="text" name="uicore_elements_recaptcha_secret_key" value="' . esc_attr($secret_key) . '" class="regular-text" />';
183 + }
184 + public function newsletter_service_key()
185 + {
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" />';
188 + }
189 +}