10. 1 Xây dựng module panel (ok)
Previous9. Load file wpf-themplate_ct.js và phương thức Save (ok)Next10.2 Xây dựng module panel name (ok)
Last updated
Was this helpful?
Last updated
Was this helpful?
C:\xampp\htdocs\test\wp-content\plugins\plugin-name\includes\class-wpf-form_ct.php
<?php
class WPF_Form_CT {
protected $plugin_name;
protected $version;
protected $themplate_id = false;
public function __construct($plugin_name, $version, $themplate_id = false) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->themplate_id = $themplate_id;
}
public function form() {
$sort_cmb = array_merge(WPF_Utils_CT::get_wc_attributes(), WPF_Utils_CT::get_default_fields());
$languages = array(
'en' => array(
'name' => '',
'selected' => true,
),
);
natcasesort($sort_cmb);
$layout = $data = array();
$this->add_fields($data);
?>
<input type="hidden" value="" name="layout" id="wpf_layout" />
<input type="hidden" value="<?php echo $this->themplate_id ?>" id="wpf_themplate_id" name="themplate_id" />
<div class="wpf_back_builder">
<div class="wpf_back_module_panel">
<?php foreach ($sort_cmb as $type => $name): ?>
<div <?php if (!empty($layout[$type])): ?>style="display:none;"<?php endif; ?> data-type="<?php echo $type ?>" id="wpf_cmb_<?php echo $type ?>" class="wpf_back_module">
<?php
echo '<pre>';
var_export($type);
var_export($name);
echo '</pre>';
?>
</div>
<?php endforeach; ?>
</div>
<div class="wpf_back_row_content" id="wpf_module_content">
</div>
</div>
<?php
}
private function add_fields($data = array()) {
$layouts = array(
'vertical' => __('Vertical Layout', 'wpf'),
'horizontal' => __('Horizontal Layout', 'wpf')
);
?>
<div class="wpf_lightbox_row">
<div class="wpf_lightbox_label"><label for="wpf_name"><?php _e('Form Title', 'wpf'); ?></label></div>
<div class="wpf_lightbox_input">
<input id="wpf_name" class="wpf_towidth" type="text" value="<?php echo !empty($data['name']) ? $data['name'] : '' ?>" name="name" />
</div>
</div>
<div class="wpf_lightbox_row ">
<div class="wpf_lightbox_label"><?php _e('Layout', 'wpf'); ?></div>
<div class="wpf_lightbox_input wpf_grid wpf_changed">
<?php foreach ($layouts as $id => $ch): ?>
<input id="wpf_<?php echo $id ?>" type="radio" value="<?php echo $id; ?>" name="type" <?php if ((!$data && $id === 'vertical' ) || ( isset($data['type']) && $data['type'] == $id )): ?>checked="checked"<?php endif; ?>/>
<label title="<?php echo $ch ?>" for="wpf_<?php echo $id ?>" class="wpf_grid_<?php echo $id; ?>"></label>
<?php endforeach; ?>
</div>
</div>
<?php
}
public function save_themplate(array $post) {
$result = false;
if (!empty($post['layout'])) {
$option = WPF_Options_CT::get_option($this->plugin_name, $this->version);
if (empty($post['name'])) {
$post['name'] = uniqid($this->plugin_name . '_');
}
$themplate_id = !empty($post['themplate_id']) ? $post['themplate_id'] : $option->unique_name($post['name']);
$layout = stripslashes_deep($post['layout']);
}
echo '<pre>';
var_export($themplate_id);
echo '</pre>';
die('aaaaaaa');
return $result;
}
}
?>