function mg_items_meta_save($post_id) { if (isset($_POST['mg_item_noncename'])) { // authentication checks if (!wp_verify_nonce($_POST['mg_item_noncename'], 'lcwp_nonce')) { return $post_id; } // check user permissions if ($_POST['post_type'] == 'page') { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } require_once MG_DIR . '/functions.php'; require_once MG_DIR . '/classes/simple_form_validator.php'; $validator = new simple_fv(); $indexes = array(); // thumb center $indexes[] = array('index' => 'mg_thumb_center', 'label' => 'Thumbnail Center'); // main type and layout $indexes[] = array('index' => 'mg_main_type', 'label' => 'Item Type'); $indexes[] = array('index' => 'mg_layout', 'label' => 'Display Mode'); $indexes[] = array('index' => 'mg_lb_max_w', 'label' => 'Lightbox Max-width'); $indexes[] = array('index' => 'mg_img_maxheight', 'label' => 'Full size image max-height'); // custom attributes if (is_array(mg_get_type_opt_indexes($_POST['mg_main_type']))) { foreach (mg_get_type_opt_indexes($_POST['mg_main_type']) as $copt) { $indexes[] = array('index' => $copt, 'label' => $copt); } } // type attributes $type_opt = mg_types_meta_opt($_POST['mg_main_type']); if ($type_opt) { foreach ($type_opt as $opt) { $indexes[] = $opt['validate']; } } $validator->formHandle($indexes); $fdata = $validator->form_val; $error = $validator->getErrors(); // clean data foreach ($fdata as $key => $val) { if (!is_array($val)) { $fdata[$key] = stripslashes($val); } else { $fdata[$key] = array(); foreach ($val as $arr_val) { $fdata[$key][] = stripslashes($arr_val); } } } // save data foreach ($fdata as $key => $val) { delete_post_meta($post_id, $key); add_post_meta($post_id, $key, $fdata[$key], true); } // update the grid categories mg_upd_item_upd_grids($post_id); } return $post_id; }
function mg_wc_meta_save($post_id) { if (isset($_POST['mg_wc_noncename'])) { // authentication checks if (!wp_verify_nonce($_POST['mg_wc_noncename'], 'lcwp_nonce')) { return $post_id; } // check user permissions if ($_POST['post_type'] == 'page') { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } include_once MG_DIR . '/functions.php'; include_once MG_DIR . '/classes/simple_form_validator.php'; $validator = new simple_fv(); $indexes = array(); // thumb center $indexes[] = array('index' => 'mg_thumb_center', 'label' => 'Thumbnail Center'); // layout and img settings $indexes[] = array('index' => 'mg_main_type', 'label' => 'Enable product'); $indexes[] = array('index' => 'mg_layout', 'label' => 'Display Mode'); $indexes[] = array('index' => 'mg_lb_max_w', 'label' => 'Lightbox Max-width'); $indexes[] = array('index' => 'mg_wc_prod_cats', 'label' => 'Product categories'); $indexes[] = array('index' => 'mg_img_maxheight', 'label' => 'Image max height'); // multiple images $indexes[] = array('index' => 'mg_slider_add_featured', 'label' => 'Prepend featured image'); foreach (mg_types_meta_opt('img_gallery') as $opt) { $indexes[] = $opt['validate']; } $validator->formHandle($indexes); $fdata = $validator->form_val; $error = $validator->getErrors(); // clean data foreach ($fdata as $key => $val) { if (!is_array($val)) { $fdata[$key] = stripslashes($val); } else { $fdata[$key] = array(); foreach ($val as $arr_val) { $fdata[$key][] = stripslashes($arr_val); } } } // save data foreach ($fdata as $key => $val) { delete_post_meta($post_id, $key); add_post_meta($post_id, $key, $fdata[$key], true); } // assign mg cats to this product if (!is_array($fdata['mg_wc_prod_cats'])) { $fdata['mg_wc_prod_cats'] = array(); } wp_set_post_terms($post_id, $fdata['mg_wc_prod_cats'], 'mg_item_categories', $append = false); // update the grid categories mg_upd_item_upd_grids($post_id); } return $post_id; }