PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.84
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.84
51.1.87 51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 All 41 releases
king-addons / includes / helpers / Woo_Builder / templates / endpoints-admin-page.php

endpoints-admin-page.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.84, at includes/helpers/Woo_Builder/templates/endpoints-admin-page.php

214 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * My Account Endpoints screen.
4 *
5 * @package King_Addons
6 *
7 * @var array<string,array<string,mixed>> $endpoints Endpoints with their settings.
8 * @var bool $is_pro Whether the paid tier is active.
9 * @var array<int,string> $templates Elementor templates to pick from.
10 * @var array<string,string> $roles Roles an endpoint can be limited to.
11 */
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 require_once KING_ADDONS_PATH . 'includes/admin/shared/page-shell.php';
18
19 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
20 $ka_notice = isset($_GET['ka-notice']) ? sanitize_key(wp_unslash($_GET['ka-notice'])) : '';
21
22 $ka_notices = [];
23
24 if ('added' === $ka_notice) {
25 $ka_notices[] = ['type' => 'success', 'text' => esc_html__('Endpoint added. Give it a template below so it has something to show.', 'king-addons')];
26 } elseif ('removed' === $ka_notice) {
27 $ka_notices[] = ['type' => 'success', 'text' => esc_html__('Endpoint removed.', 'king-addons')];
28 } elseif ('exists' === $ka_notice) {
29 $ka_notices[] = ['type' => 'error', 'text' => esc_html__('An endpoint with that address already exists.', 'king-addons')];
30 } elseif ('pro' === $ka_notice) {
31 $ka_notices[] = ['type' => 'warning', 'text' => esc_html__('Custom endpoints are part of King Addons Pro. Your other changes were saved.', 'king-addons')];
32 }
33
34 if (!class_exists('WooCommerce')) {
35 $ka_notices[] = [
36 'type' => 'warning',
37 'text' => esc_html__('WooCommerce is not active, so there is no My Account page to arrange.', 'king-addons'),
38 ];
39 }
40
41 uasort($endpoints, static function ($a, $b) {
42 return ((int) ($a['position'] ?? 10)) <=> ((int) ($b['position'] ?? 10));
43 });
44
45 ka_admin_page_open([
46 'title' => esc_html__('My Account Endpoints', 'king-addons'),
47 'subtitle' => esc_html__('Rename, reorder, hide or replace the pages inside the WooCommerce account area.', 'king-addons'),
48 'icon' => 'dashicons-admin-users',
49 'icon_color' => 'purple',
50 'saved' => 'saved' === $ka_notice,
51 'notices' => $ka_notices,
52 ]);
53 ?>
54
55 <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
56 <input type="hidden" name="action" value="king_addons_myaccount_endpoints_save">
57 <input type="hidden" name="ka_remove_endpoint" id="ka-remove-endpoint" value="">
58 <?php wp_nonce_field('king_addons_myaccount_endpoints_save'); ?>
59
60 <?php foreach ($endpoints as $ka_slug => $ka_data) : ?>
61 <?php
62 $ka_field = 'ka_endpoint[' . esc_attr($ka_slug) . ']';
63 $ka_id = 'ka-ep-' . sanitize_html_class($ka_slug);
64 $ka_custom = !empty($ka_data['is_custom']);
65 $ka_enabled = !empty($ka_data['enabled']);
66 ?>
67 <div class="ka-card ka-endpoint-card<?php echo $ka_enabled ? '' : ' is-off'; ?>">
68 <div class="ka-card-header">
69 <span class="dashicons <?php echo $ka_custom ? 'dashicons-admin-links' : 'dashicons-admin-page'; ?>"></span>
70 <h2><?php echo esc_html($ka_data['label'] ?? $ka_slug); ?></h2>
71 <code class="ka-endpoint-slug">/<?php echo esc_html($ka_slug); ?></code>
72 <?php if ($ka_custom) : ?>
73 <span class="ka-badge ka-badge-neutral"><?php esc_html_e('Custom', 'king-addons'); ?></span>
74 <?php endif; ?>
75 <label class="ka-check ka-endpoint-toggle">
76 <input type="checkbox" name="<?php echo $ka_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>[enabled]"
77 value="1" <?php checked($ka_enabled); ?>>
78 <span><?php esc_html_e('Visible', 'king-addons'); ?></span>
79 </label>
80 </div>
81 <div class="ka-card-body">
82 <?php ka_admin_row_open(esc_html__('Menu label', 'king-addons'), $ka_id . '-label'); ?>
83 <input type="text" id="<?php echo esc_attr($ka_id); ?>-label"
84 name="<?php echo $ka_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>[label]"
85 value="<?php echo esc_attr((string) ($ka_data['label'] ?? '')); ?>">
86 <?php ka_admin_row_close(); ?>
87
88 <?php ka_admin_row_open(esc_html__('Order', 'king-addons'), $ka_id . '-position'); ?>
89 <input type="number" min="0" max="9999" step="5" id="<?php echo esc_attr($ka_id); ?>-position"
90 name="<?php echo $ka_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>[position]"
91 value="<?php echo esc_attr((string) ($ka_data['position'] ?? 10)); ?>" style="max-width:110px">
92 <?php ka_admin_row_close(esc_html__('Lower numbers come first in the account menu.', 'king-addons')); ?>
93
94 <?php ka_admin_row_open(esc_html__('Content', 'king-addons'), $ka_id . '-template'); ?>
95 <select id="<?php echo esc_attr($ka_id); ?>-template"
96 name="<?php echo $ka_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>[template_id]"
97 <?php disabled(!$is_pro); ?>>
98 <option value="0"><?php esc_html_e('WooCommerce default', 'king-addons'); ?></option>
99 <?php foreach ($templates as $ka_tpl_id => $ka_tpl_title) : ?>
100 <option value="<?php echo esc_attr((string) $ka_tpl_id); ?>"
101 <?php selected((int) ($ka_data['template_id'] ?? 0), (int) $ka_tpl_id); ?>>
102 <?php echo esc_html($ka_tpl_title); ?>
103 </option>
104 <?php endforeach; ?>
105 </select>
106 <?php if (!$is_pro) : ?>
107 <input type="hidden" name="<?php echo $ka_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>[template_id]"
108 value="<?php echo esc_attr((string) ($ka_data['template_id'] ?? 0)); ?>">
109 <?php endif; ?>
110 <?php ka_admin_row_close(
111 $is_pro
112 ? esc_html__('Replace what this endpoint shows with an Elementor template.', 'king-addons')
113 : esc_html__('Replacing an endpoint with an Elementor template is part of King Addons Pro.', 'king-addons')
114 ); ?>
115
116 <?php ka_admin_row_open(esc_html__('Who can see it', 'king-addons')); ?>
117 <div class="ka-check-group ka-check-group--inline">
118 <?php foreach ($roles as $ka_role => $ka_role_label) : ?>
119 <label class="ka-check">
120 <input type="checkbox"
121 name="<?php echo $ka_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>[roles][]"
122 value="<?php echo esc_attr($ka_role); ?>"
123 <?php checked(in_array($ka_role, (array) ($ka_data['roles'] ?? []), true)); ?>>
124 <span><?php echo esc_html($ka_role_label); ?></span>
125 </label>
126 <?php endforeach; ?>
127 </div>
128 <?php ka_admin_row_close(esc_html__('Leave everything unticked to show it to all logged-in customers.', 'king-addons')); ?>
129
130 <?php if ('customer-logout' === $ka_slug) : ?>
131 <?php ka_admin_row_open(esc_html__('Logging out', 'king-addons')); ?>
132 <label class="ka-check">
133 <input type="checkbox"
134 name="<?php echo $ka_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>[confirm]"
135 value="1" <?php checked(!empty($ka_data['confirm'])); ?>>
136 <span><?php esc_html_e('Ask for confirmation first', 'king-addons'); ?></span>
137 </label>
138 <?php ka_admin_row_close(); ?>
139 <?php endif; ?>
140
141 <?php if ($ka_custom) : ?>
142 <div class="ka-row ka-row--danger">
143 <div class="ka-row-label"><?php esc_html_e('Remove', 'king-addons'); ?></div>
144 <div class="ka-row-field">
145 <button type="submit" class="ka-btn ka-btn-secondary ka-endpoint-remove"
146 data-slug="<?php echo esc_attr($ka_slug); ?>"
147 data-confirm="<?php echo esc_attr(sprintf(
148 /* translators: %s: endpoint address. */
149 esc_html__('Remove the "%s" endpoint? Anything it linked to will 404.', 'king-addons'),
150 $ka_slug
151 )); ?>">
152 <span class="dashicons dashicons-trash"></span>
153 <?php esc_html_e('Delete this endpoint', 'king-addons'); ?>
154 </button>
155 </div>
156 </div>
157 <?php endif; ?>
158 </div>
159 </div>
160 <?php endforeach; ?>
161
162 <?php ka_admin_card_open(esc_html__('Add your own endpoint', 'king-addons'), 'dashicons-plus-alt'); ?>
163 <?php if (!$is_pro) : ?>
164 <p class="ka-pro-notice">
165 <?php esc_html_e('Custom endpoints are part of King Addons Pro.', 'king-addons'); ?>
166 <a href="https://kingaddons.com/pricing/?utm_source=kng-myaccount-endpoints&utm_medium=plugin&utm_campaign=kng" target="_blank" rel="noopener">
167 <?php esc_html_e('See plans', 'king-addons'); ?>
168 </a>
169 </p>
170 <?php endif; ?>
171
172 <?php ka_admin_row_open(esc_html__('Address', 'king-addons'), 'ka-new-endpoint-slug'); ?>
173 <input type="text" id="ka-new-endpoint-slug" name="ka_new_endpoint_slug"
174 placeholder="my-downloads" <?php disabled(!$is_pro); ?>>
175 <?php ka_admin_row_close(esc_html__('Letters, numbers and dashes. It becomes /my-account/your-address/.', 'king-addons')); ?>
176
177 <?php ka_admin_row_open(esc_html__('Menu label', 'king-addons'), 'ka-new-endpoint-label'); ?>
178 <input type="text" id="ka-new-endpoint-label" name="ka_new_endpoint_label"
179 placeholder="<?php esc_attr_e('My downloads', 'king-addons'); ?>" <?php disabled(!$is_pro); ?>>
180 <?php ka_admin_row_close(); ?>
181 <?php ka_admin_card_close(); ?>
182
183 <p class="ka-submit">
184 <button type="submit" class="ka-btn ka-btn-primary">
185 <span class="dashicons dashicons-yes"></span>
186 <?php esc_html_e('Save Changes', 'king-addons'); ?>
187 </button>
188 </p>
189 </form>
190
191 <script>
192 (function () {
193 document.querySelectorAll('.ka-endpoint-remove').forEach(function (button) {
194 button.addEventListener('click', function (event) {
195 if (!window.confirm(button.dataset.confirm)) {
196 event.preventDefault();
197 return;
198 }
199 document.getElementById('ka-remove-endpoint').value = button.dataset.slug;
200 });
201 });
202
203 // Dim a card the moment its visibility is switched off, so the state is
204 // obvious before saving.
205 document.querySelectorAll('.ka-endpoint-toggle input').forEach(function (input) {
206 input.addEventListener('change', function () {
207 input.closest('.ka-endpoint-card').classList.toggle('is-off', !input.checked);
208 });
209 });
210 })();
211 </script>
212
213 <?php ka_admin_page_close(); ?>
214