承接 wefabric/wp-excel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wefabric/wp-excel

Composer 安装命令:

composer require wefabric/wp-excel

包简介

Implementation to use Excel export as a bulk action in the WordPress backend.

README 文档

README

Implementation to use Excel export as a bulk action in the WordPress backend. To use with the Wefabric themosis implementation. It uses the https://github.com/SpartnerNL/Laravel-Excel (v3.0) package.

Requirements

  • Wefabric WP Support
  • Themosis

Installation

Run the following command

composer require wefabric/wp-excel

Publish the config file

php console vendor:publish --tag=wp-excel

Usage

Every post type needs to be registered for export before usage. In the following example we will register the export class for a default WordPress post

  1. First you need to create the class which converts the posts data to an Illuminate Collection. To do this run the following command
php console make:export PostsExport
  1. Add the logic to export the WordPress posts to the Illuminate collection for example:
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Wefabric\WPExcel\Concerns\WpPostsExcellable;

class PostsExport implements FromCollection, WithHeadings, WpPostsExcellable
{

    protected array $postIds = [];

    public function headings(): array
    {
        return [
            'Id',
            'Title',
        ];
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection(): Collection
    {
        $args = [
            'post_type' => 'post',
            'posts_per_page' => -1,
        ];

        if($this->postIds) {
            $args['post__in'] = $this->postIds;
        }

        $posts = get_posts($args);
        $collection = new Collection();
        foreach ($posts as $post) {
            $collection->push([
                'Id' => $post->ID,
                'Title' => $post->post_title,
            ]);
        }
        return $collection;
    }

    public function setPostIds(array $postIds)
    {
        $this->postIds = $postIds;
    }
}
  1. Add the class to the wp-excel config file (config/wp-excel.php). Where 'post' is the post type name and the second parameter is the export class
return [
  'post_types' => [
    'post' => \App\Exports\PostsExport::class,
  ]
]
  1. Go to the WordPress backend (wp-admin/edit.php), select a post and run the bulk action.

Export formats

The default export format is 'XLSX'. To use a different export format change the 'default_format' in the wp-excel config file (config/wp-excel.php) to the correct format. The allowed export formats are located here: https://docs.laravel-excel.com/3.0/exports/export-formats.html

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固