14.3 Phương thức $option->set($data) (ok)

C:\xampp\htdocs\test\wp-content\plugins\plugin-name\includes\class-wpf-form_ct.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']);
      $data = $option->get();
      $layout = stripslashes_deep($post['layout']);
      if (empty($data[$themplate_id])) {
        $data[$themplate_id] = array();
      }
      $data[$themplate_id]['layout'] = json_decode($layout, true);
      $data[$themplate_id]['data'] = array();
      $_keys = array( 'name', 'empty', 'group','reset_button', 'type', 'page', 'sort', 'pagination', 'posts_per_page', 'result', 'out_of_stock', 'scroll', 'result_type', 'tax_relation', 'pagination_type', 'no_found_message', 'infinitybuffer', 'clear_label' );
      foreach ($_keys as $k) {
        if (!empty($post[$k])) {
          $data[$themplate_id]['data'][$k] = $post[$k];
        }
      }
      // $data[$themplate_id]['data'] array ( 'name' => 'wpf_ct_6019a31f48871', 'type' => 'vertical')
      $data[$themplate_id]['data']['date'] = current_time('timestamp');
      $data = apply_filters('wpf_template_save', $data, $themplate_id);
      $option->set($data);
      $result = array(
        'id' => $themplate_id,
        'status' => '1',
        'text' => __('Template successfully updated', 'wpf')
      );
    }
    return $result;
  }

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

public function set($value) {
    return update_option(self::$settings_key, $value);
  }

Last updated