diff --git a/super-simple-slideshow.php b/super-simple-slideshow.php index ed3426b..80d41b2 100644 --- a/super-simple-slideshow.php +++ b/super-simple-slideshow.php @@ -1,122 +1,187 @@
Lagra.
'; +/** + * Return valid image attachment IDs from a comma-separated value. + * + * @param string $value Comma-separated attachment IDs. + * @return int[] + */ +function super_simple_slideshow_image_ids($value) +{ + if (!is_string($value) || $value === '') { + return array(); } - $ids = get_option('super_simple_slideshow_ids',''); + $ids = array_map('absint', explode(',', $value)); + $ids = array_values(array_unique(array_filter($ids))); + + return array_values(array_filter($ids, 'wp_attachment_is_image')); +} + +function super_simple_slideshow_admin() +{ + if (!current_user_can('manage_options')) { + return; + } + + $notice = ''; + if (isset($_POST['super_simple_save'])) { + check_admin_referer('super_simple_slideshow_save', 'super_simple_slideshow_nonce'); + + $submitted_ids = isset($_POST['super_simple_ids']) + ? sanitize_text_field(wp_unslash($_POST['super_simple_ids'])) + : ''; + $ids = super_simple_slideshow_image_ids($submitted_ids); + update_option('super_simple_slideshow_ids', implode(',', $ids)); + $notice = '' . esc_html__('Settings saved.', 'super-simple-slideshow') . '