/** * Generates template for field item. * @param array $args */ protected function list_field_template($args = array()) { $defaults = array('url-field-id' => '', 'url-field-name' => '', 'url-value' => '', 'label-field-id' => '', 'label-field-name' => '', 'label-value' => ''); $args = wp_parse_args($args, $defaults); $icon_class = 'dashicons dashicons-plus'; if ($icon = si_get_social_icon_name($args['url-value'])) { $icon_class = 'socicon socicon-' . $icon; } ?> <li class="social-icons-field"> <div class="social-icons-wrap"> <div class="social-icons-inputs"><?php printf('<input class="widefat social-icons-field-url" id="%1$s" name="%2$s[]" type="text" placeholder="%3$s" value="%4$s">', $args['url-field-id'], $args['url-field-name'], esc_url(__('http://', 'social-icons')), esc_attr($args['url-value'])); printf('<input class="widefat social-icons-field-label" id="%1$s" name="%2$s[]" type="text" placeholder="%3$s" value="%4$s">', $args['label-field-id'], $args['label-field-name'], esc_attr(__('Label', 'social-icons')), esc_attr($args['label-value'])); ?> </div> </div> <span class="social-icons-field-handle <?php echo $icon_class; ?> "></span> <a class="social-icons-field-remove" href="#"> <span class="dashicons dashicons-no-alt"></span> </a> </li><?php }
/** * Save meta box data. * @param int $post_id */ public static function save($post_id) { // Add/replace data to array $background_style = si_clean($_POST['background_style']); $icon_font_size = si_clean($_POST['icon_font_size']); $manage_label = isset($_POST['_manage_label']) ? 'yes' : 'no'; $greyscale_icons = isset($_POST['_greyscale_icons']) ? 'yes' : 'no'; $open_new_tab = isset($_POST['_open_new_tab']) ? 'yes' : 'no'; // Sortable Icons. $sortable_icons = array(); if (isset($_POST['_si_icon_urls'])) { $icon_labels = isset($_POST['_si_icon_labels']) ? $_POST['_si_icon_labels'] : array(); $icon_urls = isset($_POST['_si_icon_urls']) ? wp_unslash(array_map('trim', $_POST['_si_icon_urls'])) : array(); $icon_url_size = sizeof($icon_urls); $allowed_icons = si_get_allowed_socicons(); for ($i = 0; $i < $icon_url_size; $i++) { if (!empty($icon_urls[$i])) { $icon_url = esc_url_raw($icon_urls[$i]); $icon_name = si_get_social_icon_name($icon_url); $icon_label = si_clean($icon_labels[$i]); // Validate the icon supported. if (!in_array($icon_name, $allowed_icons)) { SI_Admin_Meta_Boxes::add_error(sprintf(__('The social url %s cannot be used as it does not have an allowed icon.', 'social-icons'), '<code>' . esc_url($icon_url) . '</code>')); continue; } $sortable_icons[$icon_name] = array('label' => $icon_label, 'url' => $icon_url); } } } // Save update_post_meta($post_id, 'background_style', $background_style); update_post_meta($post_id, 'icon_font_size', $icon_font_size); update_post_meta($post_id, '_manage_label', $manage_label); update_post_meta($post_id, '_greyscale_icons', $greyscale_icons); update_post_meta($post_id, '_open_new_tab', $open_new_tab); update_post_meta($post_id, '_sortable_icons', $sortable_icons); do_action('social_icons_group_options_save', $post_id); }