> For the complete documentation index, see [llms.txt](https://learnphp.gitbook.io/learnphp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnphp.gitbook.io/learnphp/wordpress-advand/9.-load-file-wpf-themplate_ct.js-va-phuong-thuc-save-ok.md).

# 9. Load file wpf-themplate\_ct.js và phương thức Save (ok)

C:\xampp\htdocs\test\wp-content\plugins\plugin-name\admin\class-wpf-admin\_ct.php

```
<?php
class WPF_Admin_CT {
  private $plugin_name;
  private $version;
  public function __construct($plugin_name, $version) {
    $this->plugin_name = $plugin_name;
    $this->version     = $version;
    add_action('admin_menu', array($this, 'add_plugin_admin_menu_ct'));
    add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 11);
    add_action('wp_ajax_wpf_add_ct', array($this, 'add_template'));
    add_action('wp_ajax_wpf_ct_ajax_themes_save',array($this,'save_themplate'));
  }
  public function add_plugin_admin_menu_ct() {
    add_menu_page(
      __('Product Filters', 'wpf_ct'), __('Lionel Product Filters', 'wpf_ct'), 'manage_options', 'wpf_search_ct', array($this, 'display_search_forms_ct'), 'dashicons-welcome-write-blog', '50'
    );
    $this->plugin_about_page();
  }
  public function plugin_about_page() {
    add_submenu_page(
      'wpf_search_ct',
      __('About', 'wpf'),
      __('About', 'wpf'),
      'manage_options',
      'wpf_about',
      array($this, 'create_about_page')
    );
  }
  public function display_search_forms_ct() {
    include_once 'partials/list_ct.php';
  }
  public function enqueue_scripts($hook) {
    $screen = get_current_screen();
    if ($screen->id != 'customize') {
      $plugin_dir = plugin_dir_url(__FILE__);
      wp_register_script($this->plugin_name, $plugin_dir . 'js/wpf-admin_ct.js', array('jquery'), $this->version, false);
      wp_enqueue_script($this->plugin_name);
      wp_enqueue_style($this->plugin_name, $plugin_dir . 'css/wpf-themplate.css', array(), $this->version, 'all');
      wp_enqueue_script($this->plugin_name.'-template', $plugin_dir . 'js/wpf-themplate_ct.js', array('jquery'), $this->version, false);
    }
  }
  public function add_template() {
    check_ajax_referer($this->plugin_name . '_edit', 'nonce', true);
    if (current_user_can('manage_options')) {
      if ($_REQUEST['action'] === 'wpf_edit' && !empty($_REQUEST['slug'])) {
        global $cpt_id;
        $cpt_id = sanitize_key($_REQUEST['slug']);
      }
      include_once 'partials/form_ct.php';
    }
    wp_die();
  }
  public function save_themplate(){
    check_ajax_referer($this->plugin_name .'_them_ajax', $this->plugin_name .'_nonce', true);
    $form = new WPF_Form_CT($this->plugin_name,$this->version);
    $result = $form->save_themplate($_POST);
    if($result){
      echo  wp_json_encode($result);
    }
    wp_die();
  }
}
?>
```

C:\xampp\htdocs\test\wp-content\plugins\plugin-name\admin\js\wpf-themplate\_ct.js

```
var WPF;
(function ($, window, document, undefined) {
	// Builder Function
	WPF = {
		prefix: 'wpf_ct_',
		template_type: false,
		init: function ($options) {
			$options = $.extend({
        prefix: this.prefix,
        template_type: this.template_type
    	},$options);
    	this.prefix = $options.prefix;
      this.template_type = $options.template_type;
      this.bindEvents();
		},
		bindEvents: function () {
			this.Save();
		},
		Save: function () {
			var self = this;
			$('#' + self.prefix + 'submit').click(function (event) {
				console.log('aaaaaaaaa');
			});
		}
	}
}(jQuery, window, document));
```

C:\xampp\htdocs\test\wp-content\plugins\plugin-name\admin\partials\form\_ct.php

```
<?php
global $cpt_id;
?>
<form method="post" action="<?php echo add_query_arg(['action' => $this->plugin_name . '_ajax_themes_save'], admin_url('admin-ajax.php')) ?>">
	<input type="hidden" value="<?php echo wp_create_nonce($this->plugin_name . '_them_ajax'); ?>" name="<?php echo $this->plugin_name ?>_nonce"/>
	<?php $form = new WPF_Form_CT($this->plugin_name, $this->version, $cpt_id);?>
	<?php $form->form();?>
	<p class="submit">
		<button id="<?php echo $this->plugin_name ?>_submit" class="button button-primary"><?php _e('Save', 'wpf_ct')?></button>
  </p>
  <div id="<?php echo $this->plugin_name ?>_success_text" class="updated"></div>
	<div class="<?php echo $this->plugin_name ?>_wait"></div>
</form>
<script type="text/javascript">
    jQuery(function () {
      WPF.init({
        prefix: '<?php echo $this->plugin_name; ?>_'
      });
    });
</script>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/wordpress-advand/9.-load-file-wpf-themplate_ct.js-va-phuong-thuc-save-ok.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
