15. Xây dựng Title, Shortcode, Fields List, Date (ok)

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

function column_title($item) {
    $page                = isset($_REQUEST['page']) ? $_REQUEST['page'] : 'wpf_search';
    static $nonce_edit   = null;
    static $nonce_delete = null;
    if (is_null($nonce_edit)) {
      $nonce_edit = wp_create_nonce($this->plugin_name . '_edit');
    }
    if (is_null($nonce_delete)) {
      $nonce_delete = wp_create_nonce($this->plugin_name . '_delete');
    }
    //Build row actions
    $actions = array(
      'edit'   => sprintf(
        '<a title="%1$s" href="%2$s" class="wpf_lightbox wpf_edit">%3$s</a>', sprintf(__('Edit Product Filter %s', 'wpf'), $item['name']), add_query_arg(array('action' => 'wpf_edit', 'nonce' => $nonce_edit, 'slug' => $item['slug']), admin_url('admin-ajax.php')), __('Edit', 'wpf')
      ),
      'export' => sprintf(
        '<a title="%1$s" href="%2$s" class="wpf_export">%3$s</a>', sprintf(__('Export Product Filter %s', 'wpf'), $item['name']), add_query_arg(array('page' => $page, 'action' => 'wpf_export', 'slug' => $item['slug']), admin_url('admin.php')), __('Export', 'wpf')
      ),
      'delete' => sprintf(
        '<a title="%1$s" href="%2$s" class="wpf_delete">%3$s</a>', sprintf(__('Delete Product Filter %s', 'wpf'), $item['name']), add_query_arg(array('action' => 'wpf_delete', 'nonce' => $nonce_delete, 'slug' => $item['slug']), admin_url('admin-ajax.php')), __('Delete', 'wpf')
      ),
    );
    return sprintf('%1$s %2$s', $item['name'], $this->row_actions($actions)
    );
  }

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

function column_shortcode($item) {
    return '<input type="text" readonly="readonly" class="widefat" onclick="this.select()" value="' . esc_attr( '[searchandfilter id="' . $item['slug'] . '"]' ) . '" />';
}

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

function column_field_list($item) {
    $items = array();
    if (!empty($item['field_list'])) {
      static $fields = null;
      if (is_null($fields)) {
        $fields = array_merge(WPF_Utils_CT::get_wc_attributes(), WPF_Utils_CT::get_default_fields());
      }
      foreach ($item['field_list'] as $it) {
        if (isset($fields[$it])) {
          $items[] = $fields[$it];
        }
      }
      natcasesort($items);
    }
    return implode(', ', $items);
  }

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

function column_date($item) {
    static $time = NULL;
    if(is_null($time)){
        $time = current_time('timestamp');;
    }
    return human_time_diff($item['date'], $time ).' '.__('ago','wpf');
  }

Last updated