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;
}
Example #2
0
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;
}
Example #3
0
function mg_meta_opt_generator($type, $post)
{
    $opt_arr = mg_types_meta_opt($type);
    $opt_data = '<table class="widefat lcwp_table lcwp_metabox_table">';
    foreach ($opt_arr as $opt) {
        if ($opt['type'] != 'empty') {
            $val = get_post_meta($post->ID, $opt['name'], true);
            if (!$val && isset($opt['def'])) {
                $val = $opt['def'];
            }
            $opt_data .= '
			<tr>
			  <td class="lcwp_label_td">' . $opt['label'] . '</td>
			  <td class="lcwp_field_td">';
            if ($opt['type'] == 'text') {
                $opt_data .= '<input type="text" name="' . $opt['name'] . '" value="' . $val . '" />';
            } elseif ($opt['type'] == 'select') {
                $opt_data .= '<select data-placeholder="' . __('Select an option', 'mg_ml') . ' .." name="' . $opt['name'] . '" class="lcweb-chosen" autocomplete="off">';
                foreach ($opt['options'] as $key => $name) {
                    $key == $val ? $sel = 'selected="selected"' : ($sel = '');
                    $opt_data .= '<option value="' . $key . '" ' . $sel . '>' . $name . '</option>';
                }
                $opt_data .= '</select>';
            } elseif ($opt['type'] == 'checkbox') {
                $val ? $sel = 'checked="checked"' : ($sel = '');
                $opt_data .= '<input type="checkbox" name="' . $opt['name'] . '" value="1" class="ip-checkbox" ' . $sel . ' autocomplete="off" />';
            } elseif ($opt['type'] == 'slider') {
                $opt_data .= '
				<div class="lcwp_slider" step="' . $opt['step'] . '" max="' . $opt['max_val'] . '" min="' . $opt['min_val'] . '"></div>
				<input type="text" value="' . $val . '" name="' . $opt['name'] . '" class="lcwp_slider_input" />
				<span>' . $opt['value'] . '</span>';
            } elseif ($opt['type'] == 'color') {
                $opt_data .= '
				<div class="lcwp_colpick">
                	<span class="lcwp_colblock" style="background-color: ' . $val . ';"></span>
                	<input type="text" name="' . $opt['name'] . '" value="' . $val . '" />
                </div>';
            }
            $opt_data .= ' 
			  </td>     
			  <td><span class="info">' . $opt['descr'] . '</span></td>
			</tr>
			';
        }
    }
    return $opt_data . '</table>';
}