定制 wpbones/wptables 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wpbones/wptables

Composer 安装命令:

composer require wpbones/wptables

包简介

A fluent implementation of WordPress WP List Table for WP Bones

README 文档

README

Latest Stable Version   Latest Unstable Version   Total Downloads   License   Monthly Downloads

images

A fluent implementation of WordPress WP List Table for WP Bones

Requirements

This package works with a WordPress plugin written with WP Bones framework library.

Installation

You can install third party packages by using:

php bones require wpbones/wptables

I advise to use this command instead of composer require because doing this an automatic renaming will done.

You can use composer to install this package:

composer require wpbones/wptables

You may also to add "wpbones/wptables": "^1.0" in the composer.json file of your plugin:

  "require": {
    "php": ">=7.4",
    "wpbones/wpbones": "~0.8",
    "wpbones/wptables": "~1.0"
  },

and run

composer install

How to

You can use WP Tables either like subclass or like fluent class instance.

Subclassing

As subclass class instance you may create a your own class as show below:

<?php

namespace WPKirk\Http\Controllers;

use WPKirk\WPTables\Html\WPTable;

class ExampleTable extends WPTable
{

  protected $name = 'Discos';

  public function getColumnsAttribute()
  {
    return [
      'id'          => 'Name',
      'description' => 'Description',
    ];
  }

  public function getItems( $args = [] )
  {

    $fake = [];

    for( $i = 0; $i < 20; $i++ ) {
      $fake[] = [
        'id' => "Example {$i}",
        'description' => 'Some description...'
      ];
    }

    return $fake;

  }
}

In your view controller you have to use the load method in order to register the screen options:

...
  public function load()
  {
    ExampleTable::registerScreenOption();
  }

  public function index()
  {
    $table = new ExampleTable();

    return WPKirk()
      ->view( 'dashboard.table' )
      ->with( 'table', $table );
  }
...

In your ExampleTable you may override:

public function getCheckBoxValueAttribute( $item )
{
   return $item[ 'my_colum' ];
}

// or

public function getCheckBoxColumnNameAttribute()
{
   return 'my_colum';
}

This will be the value used in the checkbox value.

Fluent

If you like use the WPTable as fluent instance, you have to set the columns twice.

...
  public function loadFluentExample()
  {
    WPTable::name( 'Books' )
           ->columns(
              [
                'id'          => 'Name',
                'description' => 'Description',
              ]
            )
           ->screenOptionLabel( 'Rows' )
           ->registerScreenOption();
  }

  public function indexFluentExample()
  {

    $items = [];

    for ( $i = 0; $i < 20; $i++ ) {
      $items[] = [
        'id'          => "Book {$i}",
        'description' => 'Some description...',
      ];
    }

    $table = WPTable::name( 'Books' )
                    ->singular( 'Book' )
                    ->plural( 'Books' )
                    ->columns(
                      [
                        'id'          => 'Name',
                        'description' => 'Description',
                      ]
                    )
                    ->setItems( $items );

    return WPKirk()
      ->view( 'dashboard.table' )
      ->with( 'table', $table );
  }

统计信息

  • 总下载量: 2.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固