/**
  * 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);
 }
 /**
  * Check if we're saving, the trigger an action based on the post type.
  * @param int $post_id
  * @param object $post
  */
 public function save_meta_boxes($post_id, $post)
 {
     // $post_id and $post are required
     if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
         return;
     }
     // Don't save meta boxes for revisions or autosaves
     if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
         return;
     }
     // Check the nonce
     if (empty($_POST['social_icons_meta_nonce']) || !wp_verify_nonce($_POST['social_icons_meta_nonce'], 'social_icons_save_data')) {
         return;
     }
     // Check the post being saved == the $post_id to prevent triggering this call for other save_post events
     if (empty($_POST['post_ID']) || $_POST['post_ID'] != $post_id) {
         return;
     }
     // Check user has permission to edit
     if (!current_user_can('edit_post', $post_id)) {
         return;
     }
     // We need this save event to run once to avoid potential endless loops. This would have been perfect:
     self::$saved_meta_boxes = true;
     // Check the post type
     if (in_array($post->post_type, array('social_icon'))) {
         do_action('social_icons_process_' . $post->post_type . '_meta', $post_id, $post);
     }
 }