PluginProbe
WP Attachments – Smarter File Management & Download Lists / 6.1
WP Attachments – Smarter File Management & Download Lists v6.1
6.1 6.0.2 6.0.3 trunk 2.0 3 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.2 3.2.1 3.2.2 3.2.3 3.2.4 3.3 3.4 3.5 3.5.1 3.5.2 3.5.3 All 53 releases
wp-attachments / inc / settings.php

settings.php in WP Attachments – Smarter File Management & Download Lists 6.1, at inc/settings.php

459 lines 29.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function wpatt_plugin_options()
4 {
5 if (!current_user_can('manage_options')) {
6 wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'wp-attachments'));
7 }
8
9 $updated = false;
10
11 // Handle general settings submission securely
12 if (isset($_POST['submit-general'])) {
13 check_admin_referer('wpatt_general_settings');
14
15 update_option('wpatt_option_localization', sanitize_text_field($_POST["wpatt_option_localization_n"] ?? ''));
16 update_option('wpatt_option_date_localization', sanitize_text_field($_POST["wpatt_option_date_localization_n"] ?? ''));
17
18 $heading_tag = sanitize_key($_POST['wpatt_option_heading_tag_n'] ?? 'h3');
19 update_option('wpatt_option_heading_tag', in_array($heading_tag, array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'), true) ? $heading_tag : 'h3');
20
21 update_option('wpatt_show_orderby', !empty($_POST['wpatt_show_orderby_n']) ? '1' : '0');
22 update_option('wpatt_option_includeimages', !empty($_POST['wpatt_option_includeimages_n']) ? '1' : '0');
23 update_option('wpatt_option_targetblank', !empty($_POST['wpatt_option_targetblank_n']) ? '1' : '0');
24 update_option('wpatt_option_restrictload', !empty($_POST['wpatt_option_restrictload_n']) ? '1' : '0');
25 update_option('wpatt_counter', !empty($_POST['wpatt_counter_n']) ? '1' : '0');
26 update_option('wpatt_excludelogged_counter', !empty($_POST['wpatt_excludelogged_counter_n']) ? '1' : '0');
27
28 // Save per-post-type metabox and frontend settings
29 $post_types = get_post_types(['public' => true], 'objects');
30 foreach ($post_types as $post_type) {
31 if ($post_type->name === 'attachment') continue;
32
33 // Save metabox enabled/disabled
34 $metabox_enabled = !empty($_POST['wpatt_enable_' . $post_type->name]) ? '1' : '0';
35 update_option('wpatt_enable_metabox_' . $post_type->name, $metabox_enabled);
36
37 // Save frontend list enabled/disabled
38 $frontend_enabled = !empty($_POST['wpatt_frontend_' . $post_type->name]) ? '1' : '0';
39 update_option('wpatt_enable_frontend_' . $post_type->name, $frontend_enabled);
40
41 // Replaced by the frontend switch above.
42 delete_option('wpatt_enable_display_' . $post_type->name);
43 }
44 $updated = true;
45 }
46
47 // Handle appearance settings submission securely
48 if (isset($_POST['submit-appearance'])) {
49 check_admin_referer('wpatt_appearance_settings');
50
51 $pack = (int) ($_POST['style'] ?? 0);
52 update_option('wpa_ict', (string) (($pack >= 0 && $pack <= WPATT_PACK_MODERN) ? $pack : 0));
53 $template = (int) ($_POST['template'] ?? 0);
54 update_option('wpa_template', (string) (($template >= 0 && $template <= WPATT_TEMPLATE_CARD) ? $template : 0));
55 $color_mode = sanitize_key($_POST['wpatt_icons_color'] ?? 'type');
56 update_option('wpatt_icons_color', in_array($color_mode, array('type', 'theme', 'custom'), true) ? $color_mode : 'type');
57 // Modern Card: unticked checkboxes are not posted, so start from all off;
58 // wpatt_get_card_options() validates layout and width.
59 $card_post = isset($_POST['wpatt_card']) && is_array($_POST['wpatt_card']) ? wp_unslash($_POST['wpatt_card']) : array();
60 $card_save = array();
61 foreach (array('ext', 'size', 'date', 'downloads', 'caption') as $flag) {
62 $card_save[$flag] = empty($card_post[$flag]) ? 0 : 1;
63 }
64 $card_save['layout'] = sanitize_key($card_post['layout'] ?? 'grid');
65 $card_save['width'] = sanitize_key($card_post['width'] ?? 'normal');
66 update_option('wpatt_card', wpatt_get_card_options($card_save));
67
68 $custom_color = sanitize_hex_color(wp_unslash($_POST['wpatt_icons_custom_color'] ?? ''));
69 if ($custom_color) {
70 update_option('wpatt_icons_custom_color', $custom_color);
71 }
72 update_option('wpa_template_custom', wp_kses_post($_POST['wpa_template_custom'] ?? ''));
73 $updated = true;
74 }
75
76 if ($updated) {
77 add_settings_error('wpatt_messages', 'wpatt_message', __('Settings Saved', 'wp-attachments'), 'updated');
78 }
79
80 wpa_register_initial_settings();
81
82 echo '<div class="wrap wpatt-settings-wrap">';
83
84 echo '<div style="float:right; margin-top: 20px;">
85 <a href="https://wordpress.org/support/plugin/wp-attachments/reviews/#new-post" target="_blank" class="button">' . esc_html__('Rate this plugin �
86 �
87 �
88 �
89 �
90 ', 'wp-attachments') . '</a>
91 <a href="https://wordpress.org/plugins/wp-attachments/#developers" target="_blank" class="button">' . esc_html__('Changelog', 'wp-attachments') . '</a>
92 </div>';
93
94 echo '<h1>' . esc_html__('WP Attachments Settings', 'wp-attachments') . '</h1>';
95
96 settings_errors('wpatt_messages');
97
98 echo '<style>
99 .wpatt-settings-wrap .nav-tab-wrapper { margin-bottom: 24px; }
100 .wpatt-settings-wrap .form-table th { width: 220px; vertical-align: top; padding-top: 16px; }
101 .wpatt-settings-wrap .form-table td { padding-top: 12px; }
102 .wpatt-settings-wrap input[type="text"] { width: 100%; max-width: 400px; }
103 .wpatt-settings-wrap .wpatt-desc { color: #666; font-size: 0.9em; margin-top: 4px; display: block; }
104 .wpatt-settings-wrap .wpatt-checkbox-group label { display: block; margin-top: 8px; }
105 .wpatt-settings-wrap .wpatt-heading-tag { margin: 10px 0 0; }
106 .wpatt-settings-wrap .wpatt-heading-tag label { margin-right: 8px; }
107 .wpatt-settings-wrap textarea { font-family: monospace; width: 100%; max-width: 600px; }
108 /* Appearance: one bordered row per option, title and description aligned. */
109 .wpatt-settings-wrap .wpatt-intro { margin: 0 0 10px; }
110 .wpatt-settings-wrap .wpatt-options { display: flex; flex-direction: column; gap: 8px; max-width: 760px; }
111 .wpatt-settings-wrap .wpatt-option { padding: 12px 14px; background: #fff; border: 1px solid #dcdcde; border-radius: 4px; }
112 .wpatt-settings-wrap .wpatt-option:has(> .wpatt-option-head input:checked) { border-color: #2271b1; box-shadow: 0 0 0 1px #2271b1; }
113 .wpatt-settings-wrap .wpatt-option-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
114 .wpatt-settings-wrap .wpatt-option-head input[type="radio"] { margin: 0; }
115 .wpatt-settings-wrap .wpatt-option-title { font-weight: 600; }
116 .wpatt-settings-wrap .wpatt-option-icons { display: inline-flex; gap: 6px; align-items: center; margin-left: auto; }
117 .wpatt-settings-wrap .wpatt-option-icons img, .wpatt-settings-wrap .wpatt-option-icons .wpa-icon { display: block; width: 16px; height: 16px; margin: 0; }
118 .wpatt-settings-wrap .wpatt-option-desc { margin: 4px 0 0 26px; color: #646970; font-size: 12px; }
119 .wpatt-settings-wrap .wpatt-suboptions { margin: 12px 0 0 26px; padding-top: 12px; border-top: 1px solid #f0f0f1; }
120 .wpatt-settings-wrap .wpatt-suboptions .wpatt-option-desc { margin-left: 0; }
121 .wpatt-settings-wrap .wpatt-field { display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: start; gap: 8px; min-height: 30px; }
122 .wpatt-settings-wrap .wpatt-field-name { line-height: 30px; }
123 .wpatt-settings-wrap .wpatt-field-controls { min-height: 30px; }
124 .wpatt-settings-wrap .wpatt-field + .wpatt-field { margin-top: 6px; }
125 .wpatt-settings-wrap .wpatt-field-name { font-weight: 600; }
126 .wpatt-settings-wrap .wpatt-field-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; }
127 .wpatt-settings-wrap .wpatt-field-controls label { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
128 .wpatt-settings-wrap .wpatt-field-controls input[type="radio"], .wpatt-settings-wrap .wpatt-field-controls input[type="checkbox"] { margin: 0; }
129 .wpatt-settings-wrap .wpatt-color { width: 40px; height: 28px; padding: 2px; margin-left: -10px; border: 1px solid #8c8f94; border-radius: 4px; background: #fff; cursor: pointer; }
130 .wpatt-settings-wrap .wpatt-hint { color: #646970; font-size: 12px; }
131 .wpatt-settings-wrap .wpatt-preview { margin: 12px 0 0 26px; padding: 12px 14px; background: #f6f7f7; border-radius: 4px; font-size: 14px; }
132 .wpatt-settings-wrap .wpatt-preview .wpa-attachments-block { margin: 0; }
133 .wpatt-settings-wrap .wpatt-preview ul.wpa-cards li.post-attachment { background: #fff; }
134 .wpatt-settings-wrap .wpatt-preview li { margin-bottom: 4px; }
135 .wpatt-settings-wrap .wpatt-code { margin: 10px 0 0 26px; }
136 .wpatt-settings-wrap .wpatt-code summary { cursor: pointer; color: #2271b1; font-size: 12px; }
137 .wpatt-settings-wrap .wpatt-code code { display: block; margin: 8px 0; padding: 8px 10px; background: #f6f7f7; font-size: 12px; word-break: break-all; }
138 .wpatt-settings-wrap .wpatt-suboptions textarea { display: block; max-width: none; }
139 .wpatt-cpt-table { border-collapse: collapse; width: 100%; max-width: 600px; margin-top: 10px; background: #fff; border: 1px solid #ccd0d4; }
140 .wpatt-cpt-table th, .wpatt-cpt-table td { text-align: left; padding: 10px; border-bottom: 1px solid #ccd0d4; }
141 .wpatt-cpt-table th { background: #f6f7f7; font-weight: 600; }
142 .wpatt-cpt-table th + th { text-align: center; }
143 .wpatt-cpt-table tr:last-child td { border-bottom: none; }
144 </style>';
145
146 $current = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'general';
147
148 $tabs = array(
149 'general' => esc_html__('General Settings', 'wp-attachments'),
150 'appearance' => esc_html__('Appearance & Templates', 'wp-attachments')
151 );
152
153 echo '<h2 class="nav-tab-wrapper">';
154 foreach ($tabs as $tab => $name) {
155 $class = ($tab === $current) ? ' nav-tab-active' : '';
156 echo "<a class='nav-tab{$class}' href='" . esc_url(add_query_arg('tab', $tab)) . "'>{$name}</a>";
157 }
158 echo '</h2>';
159
160 echo '<form method="post" action="">';
161
162 switch ($current) {
163 case 'general':
164 wp_nonce_field('wpatt_general_settings');
165 echo '<table class="form-table">';
166 echo '<tr valign="top">
167 <th scope="row">' . esc_html__('List Header', 'wp-attachments') . '</th>
168 <td>
169 <input type="text" name="wpatt_option_localization_n" value="' . esc_attr(get_option('wpatt_option_localization')) . '" />
170 <span class="wpatt-desc">' . esc_html__('Text displayed above the attachments list (e.g., "Downloads" or "Attachments"). Leave empty to hide the heading.', 'wp-attachments') . '</span>
171 <p class="wpatt-heading-tag">
172 <label for="wpatt_heading_tag">' . esc_html__('Heading level', 'wp-attachments') . '</label>
173 <select id="wpatt_heading_tag" name="wpatt_option_heading_tag_n">';
174 foreach (array('h1', 'h2', 'h3', 'h4', 'h5', 'h6') as $tag) {
175 echo '<option value="' . esc_attr($tag) . '" ' . selected(wpatt_heading_tag(), $tag, false) . '>' . esc_html(strtoupper($tag)) . '</option>';
176 }
177 echo ' </select>
178 </p>
179 </td>
180 </tr>';
181
182 echo '<tr valign="top">
183 <th scope="row">' . esc_html__('Display Options', 'wp-attachments') . '</th>
184 <td>
185 <div class="wpatt-checkbox-group">
186 <label>
187 <input type="checkbox" name="wpatt_show_orderby_n" ' . (get_option('wpatt_show_orderby') == '1' ? 'checked' : '') . '/>
188 ' . esc_html__('Show the sort links above the list (Date, Name)', 'wp-attachments') . '
189 </label>
190 <label>
191 <input type="checkbox" name="wpatt_option_includeimages_n" ' . (get_option('wpatt_option_includeimages') == '1' ? 'checked' : '') . '/>
192 ' . esc_html__('Include images in the attachments list (.jpg, .png, etc.)', 'wp-attachments') . '
193 </label>
194 <label>
195 <input type="checkbox" name="wpatt_option_targetblank_n" ' . (get_option('wpatt_option_targetblank') == '1' ? 'checked' : '') . '/>
196 ' . esc_html__('Open links in a new tab', 'wp-attachments') . '
197 </label>
198 <label>
199 <input type="checkbox" name="wpatt_option_restrictload_n" ' . (get_option('wpatt_option_restrictload') == '1' ? 'checked' : '') . '/>
200 ' . esc_html__('Restrict loading to single posts/pages only (disable on archives/home)', 'wp-attachments') . '
201 </label>
202 </div>
203 </td>
204 </tr>';
205
206 echo '<tr valign="top">
207 <th scope="row">' . esc_html__('Date Format', 'wp-attachments') . '</th>
208 <td>
209 <input type="text" name="wpatt_option_date_localization_n" value="' . esc_attr(get_option('wpatt_option_date_localization')) . '" />
210 <span class="wpatt-desc">' . sprintf(
211 /* translators: %s: the WordPress date format, e.g. F j, Y */
212 esc_html__('Format for the %%DATE%% tag, following PHP date standards (e.g. d.m.Y). Leave empty to use the WordPress date format: %s', 'wp-attachments'),
213 '<code>' . esc_html(get_option('date_format')) . '</code>'
214 ) . '</span>
215 </td>
216 </tr>';
217
218 echo '<tr valign="top">
219 <th scope="row">' . esc_html__('Download Tracker', 'wp-attachments') . '</th>
220 <td>
221 <div class="wpatt-checkbox-group">
222 <label>
223 <input type="checkbox" name="wpatt_counter_n" ' . (get_option('wpatt_counter') == '1' ? 'checked' : '') . '/>
224 ' . esc_html__('Enable download counter', 'wp-attachments') . '
225 </label>
226 <label>
227 <input type="checkbox" name="wpatt_excludelogged_counter_n" ' . (get_option('wpatt_excludelogged_counter') == '1' ? 'checked' : '') . '/>
228 ' . esc_html__('Exclude logged-in users from counting', 'wp-attachments') . '
229 </label>
230 </div>
231 </td>
232 </tr>';
233
234 echo '<tr valign="top">
235 <th scope="row">' . esc_html__('Post Type Permissions', 'wp-attachments') . '</th>
236 <td>
237 <p class="description">' . esc_html__('Configure where WP Attachments should be available.', 'wp-attachments') . '<br>' . esc_html__('"Enable Frontend" shows the list after the content. Each post can still hide it from the Media Attachments box of the editor.', 'wp-attachments') . '</p>
238 <table class="wpatt-cpt-table">
239 <thead>
240 <tr>
241 <th>' . esc_html__('Post Type', 'wp-attachments') . '</th>
242 <th>' . esc_html__('Enable Metabox', 'wp-attachments') . '</th>
243 <th>' . esc_html__('Enable Frontend', 'wp-attachments') . '</th>
244 </tr>
245 </thead>
246 <tbody>';
247 $post_types = get_post_types(['public' => true], 'objects');
248 foreach ($post_types as $post_type) {
249 if ($post_type->name === 'attachment') continue;
250 $mb_enabled = get_option('wpatt_enable_metabox_' . $post_type->name, '1');
251 $fe_enabled = wpatt_is_frontend_enabled($post_type->name) ? '1' : '0';
252 echo '<tr>
253 <td><strong>' . esc_html($post_type->labels->singular_name) . '</strong></td>
254 <td style="text-align:center;">
255 <input type="checkbox" name="wpatt_enable_' . esc_attr($post_type->name) . '" value="1" ' . checked($mb_enabled, '1', false) . ' />
256 </td>
257 <td style="text-align:center;">
258 <input type="checkbox" name="wpatt_frontend_' . esc_attr($post_type->name) . '" value="1" ' . checked($fe_enabled, '1', false) . ' />
259 </td>
260 </tr>';
261 }
262 echo '</tbody></table>
263 </td>
264 </tr>';
265 echo '</table>';
266 submit_button(__('Save General Settings', 'wp-attachments'), 'primary', 'submit-general');
267 break;
268
269 case 'appearance':
270 wp_nonce_field('wpatt_appearance_settings');
271 echo '<table class="form-table" role="presentation">';
272
273 /* ---------- Icon pack ---------- */
274 echo '<tr>
275 <th scope="row" id="wpatt-pack-heading">' . esc_html__('Icon Pack', 'wp-attachments') . '</th>
276 <td>
277 <div class="wpatt-options" role="radiogroup" aria-labelledby="wpatt-pack-heading">';
278
279 $icon_packs = [
280 WPATT_PACK_MODERN => ['label' => 'Modern SVG', 'desc' => __('Sharp vector icons for every file type. Used by the Modern Card template too.', 'wp-attachments')],
281 0 => ['label' => 'Fugue Icons', 'author' => 'Yusuke Kamiyamane'],
282 1 => ['label' => 'Crystal Clear', 'author' => 'Everaldo Coelho', 'url' => 'https://www.everaldo.com/'],
283 2 => ['label' => 'Diagona Icons', 'author' => 'Asher Abbasi'],
284 3 => ['label' => 'Page Icons', 'author' => 'Matthew Skiles', 'url' => 'https://iconblock.com/'],
285 // Dropped from this list in 5.0.12 by mistake: sites that had
286 // picked it kept using it but saw no option selected here.
287 4 => ['label' => 'Matrilineare'],
288 ];
289 foreach ($icon_packs as $val => $pack) {
290 if (WPATT_PACK_MODERN === $val) {
291 // Same markup as the site, so the colour option shows here too.
292 $colors = wpatt_icons_color_attrs();
293 $icons = '<span class="wpatt-option-icons' . $colors['class'] . '"'
294 . ($colors['style'] ? ' style="' . esc_attr($colors['style']) . '"' : '') . '>';
295 foreach (array('pdf', 'doc', 'sheet', 'archive') as $type) {
296 $icons .= '<span class="wpa-type-' . $type . '">' . wpatt_get_file_icon_svg($type, 'wpa-icon') . '</span>';
297 }
298 $icons .= '</span>';
299 } else {
300 $icons = '<span class="wpatt-option-icons">';
301 foreach (array('document', 'document-word', 'document-pdf') as $png) {
302 $icons .= '<img src="' . esc_url(plugins_url('styles/' . $val . '/' . $png . '.png', dirname(__FILE__))) . '" alt="" width="16" height="16" />';
303 }
304 $icons .= '</span>';
305 }
306
307 if (isset($pack['desc'])) {
308 $meta = esc_html($pack['desc']);
309 } elseif (isset($pack['author'])) {
310 $meta = esc_html__('Author', 'wp-attachments') . ': ' . (isset($pack['url']) ? '<a href="' . esc_url($pack['url']) . '" target="_blank" rel="noopener noreferrer">' . esc_html($pack['author']) . '</a>' : esc_html($pack['author']));
311 } else {
312 $meta = '';
313 }
314
315 echo '<div class="wpatt-option">
316 <label class="wpatt-option-head">
317 <input type="radio" value="' . esc_attr($val) . '" name="style" ' . checked(wpatt_icon_pack(), $val, false) . ' />
318 <span class="wpatt-option-title">' . esc_html($pack['label']) . '</span>' . $icons . '
319 </label>'
320 . ($meta ? '<p class="wpatt-option-desc">' . $meta . '</p>' : '');
321
322 if (WPATT_PACK_MODERN === $val) {
323 // Outside the <label>: a label holding other controls would
324 // also tick the pack radio on every click.
325 $color_mode = wpatt_icons_color_mode();
326 echo '<div class="wpatt-suboptions">
327 <div class="wpatt-field" role="radiogroup" aria-labelledby="wpatt-color-heading">
328 <span class="wpatt-field-name" id="wpatt-color-heading">' . esc_html__('Icon colour', 'wp-attachments') . '</span>
329 <span class="wpatt-field-controls">
330 <label><input type="radio" name="wpatt_icons_color" value="type" ' . checked($color_mode, 'type', false) . ' /> ' . esc_html__('By file type', 'wp-attachments') . '</label>
331 <label><input type="radio" name="wpatt_icons_color" value="theme" ' . checked($color_mode, 'theme', false) . ' /> ' . esc_html__('Theme text colour', 'wp-attachments') . '</label>
332 <label><input type="radio" name="wpatt_icons_color" value="custom" ' . checked($color_mode, 'custom', false) . ' /> ' . esc_html__('Custom', 'wp-attachments') . '</label>
333 <input type="color" class="wpatt-color" name="wpatt_icons_custom_color" value="' . esc_attr(wpatt_icons_custom_color()) . '" aria-label="' . esc_attr__('Custom colour', 'wp-attachments') . '" />
334 </span>
335 </div>
336 <p class="wpatt-option-desc">' . esc_html__('Also applies to the Modern Card template, whatever the icon pack. Choose a custom colour dark enough to stand out against the page.', 'wp-attachments') . '</p>
337 </div>';
338 }
339
340 echo '</div>';
341 }
342 echo '</div></td></tr>';
343
344 /* ---------- Display template ---------- */
345 echo '<tr>
346 <th scope="row" id="wpatt-template-heading">' . esc_html__('Display Template', 'wp-attachments') . '</th>
347 <td>
348 <p class="description wpatt-intro">' . esc_html__('Previews use sample files and the saved settings.', 'wp-attachments') . '</p>
349 <div class="wpatt-options" role="radiogroup" aria-labelledby="wpatt-template-heading">';
350
351 $card = wpatt_get_card_options();
352 $templates = [
353 WPATT_TEMPLATE_CARD => [__('Modern Card', 'wp-attachments'), __('Always uses the Modern SVG icons.', 'wp-attachments')],
354 0 => [__('Simple List', 'wp-attachments'), ''],
355 1 => [__('List with date', 'wp-attachments'), ''],
356 2 => [__('Detailed List', 'wp-attachments'), ''],
357 ];
358 foreach ($templates as $val => $tpl) {
359 $code = wpatt_get_template_string($val, $card);
360
361 echo '<div class="wpatt-option">
362 <label class="wpatt-option-head">
363 <input type="radio" value="' . esc_attr($val) . '" name="template" ' . checked(wpatt_template_id(), $val, false) . ' />
364 <span class="wpatt-option-title">' . esc_html($tpl[0]) . '</span>
365 </label>'
366 . ($tpl[1] ? '<p class="wpatt-option-desc">' . esc_html($tpl[1]) . '</p>' : '');
367
368 if (WPATT_TEMPLATE_CARD === $val) {
369 $flags = array(
370 'ext' => __('Extension', 'wp-attachments'),
371 'size' => __('Size', 'wp-attachments'),
372 'date' => __('Date', 'wp-attachments'),
373 'downloads' => __('Downloads', 'wp-attachments'),
374 'caption' => __('Caption', 'wp-attachments'),
375 );
376 echo '<div class="wpatt-suboptions">
377 <div class="wpatt-field" role="group" aria-labelledby="wpatt-card-show">
378 <span class="wpatt-field-name" id="wpatt-card-show">' . esc_html__('Show', 'wp-attachments') . '</span>
379 <span class="wpatt-field-controls">';
380 foreach ($flags as $key => $flag_label) {
381 echo '<label><input type="checkbox" name="wpatt_card[' . esc_attr($key) . ']" value="1" ' . checked($card[$key], 1, false) . ' /> ' . esc_html($flag_label) . '</label>';
382 }
383 echo '</span>
384 </div>
385 <div class="wpatt-field" role="radiogroup" aria-labelledby="wpatt-card-layout">
386 <span class="wpatt-field-name" id="wpatt-card-layout">' . esc_html__('Layout', 'wp-attachments') . '</span>
387 <span class="wpatt-field-controls">
388 <label><input type="radio" name="wpatt_card[layout]" value="grid" ' . checked($card['layout'], 'grid', false) . ' /> ' . esc_html__('Grid', 'wp-attachments') . '</label>
389 <label><input type="radio" name="wpatt_card[layout]" value="rows" ' . checked($card['layout'], 'rows', false) . ' /> ' . esc_html__('One per row', 'wp-attachments') . '</label>
390 </span>
391 </div>
392 <div class="wpatt-field">
393 <label class="wpatt-field-name" for="wpatt-card-width">' . esc_html__('Card width', 'wp-attachments') . '</label>
394 <span class="wpatt-field-controls">
395 <select id="wpatt-card-width" name="wpatt_card[width]">
396 <option value="compact" ' . selected($card['width'], 'compact', false) . '>' . esc_html__('Compact', 'wp-attachments') . '</option>
397 <option value="normal" ' . selected($card['width'], 'normal', false) . '>' . esc_html__('Normal', 'wp-attachments') . '</option>
398 <option value="wide" ' . selected($card['width'], 'wide', false) . '>' . esc_html__('Wide', 'wp-attachments') . '</option>
399 </select>
400 <span class="wpatt-hint">' . esc_html__('Grid only. Downloads appear when the download counter is on.', 'wp-attachments') . '</span>
401 </span>
402 </div>
403 </div>';
404 }
405
406 // inert: the sample links must not be focusable or clickable.
407 echo '<div class="wpatt-preview" inert aria-hidden="true">' . wpatt_render_template_preview($val) . '</div>
408 <details class="wpatt-code">
409 <summary>' . esc_html__('Template code', 'wp-attachments') . '</summary>
410 <code>' . esc_html($code) . '</code>
411 <button type="button" class="button button-small wpatt-use-template hide-if-no-js" data-code="' . esc_attr($code) . '">' . esc_html__('Use as custom template', 'wp-attachments') . '</button>
412 </details>
413 </div>';
414 }
415
416 $custom = (string) get_option('wpa_template_custom');
417 echo '<div class="wpatt-option">
418 <label class="wpatt-option-head">
419 <input type="radio" value="3" name="template" ' . checked(wpatt_template_id(), 3, false) . ' />
420 <span class="wpatt-option-title">' . esc_html__('Custom Template', 'wp-attachments') . '</span>
421 </label>
422 <div class="wpatt-suboptions">
423 <textarea id="wpa_template_custom" name="wpa_template_custom" rows="4" aria-label="' . esc_attr__('Custom Template', 'wp-attachments') . '">' . esc_textarea($custom) . '</textarea>
424 <p class="wpatt-option-desc">' . esc_html__('Tags:', 'wp-attachments') . ' <code>%URL%</code> <code>%TITLE%</code> <code>%SIZE%</code> <code>%DATE%</code> <code>%DOWNLOADS%</code> <code>%CAPTION%</code> <code>%DESCRIPTION%</code> <code>%AUTHOR%</code> <code>%EXT%</code> <code>%MIME%</code> <code>%ICON%</code></p>
425 </div>'
426 . ('' !== trim($custom) ? '<div class="wpatt-preview" inert aria-hidden="true">' . wpatt_render_template_preview(3) . '</div>' : '') . '
427 </div>';
428
429 echo '</div></td></tr>';
430 echo '</table>';
431
432 // Admin only: copy a template into the custom one; picking a colour
433 // selects the Custom colour option.
434 echo '<script>
435 document.addEventListener("click", function (e) {
436 var button = e.target.closest(".wpatt-use-template");
437 if (!button) { return; }
438 var field = document.getElementById("wpa_template_custom");
439 if (field.value.trim() !== "" && !window.confirm(' . wp_json_encode(__('Replace the current custom template?', 'wp-attachments')) . ')) { return; }
440 field.value = button.getAttribute("data-code");
441 document.querySelector("input[name=template][value=\'3\']").checked = true;
442 field.focus();
443 });
444 document.addEventListener("input", function (e) {
445 if (e.target.classList && e.target.classList.contains("wpatt-color")) {
446 document.querySelector("input[name=wpatt_icons_color][value=custom]").checked = true;
447 }
448 });
449 </script>';
450 submit_button(__('Save Appearance Settings', 'wp-attachments'), 'primary', 'submit-appearance');
451 break;
452 }
453
454 echo '</form>';
455 echo '</div>';
456 }
457
458 ?>
459