baxtian/wp_importer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

baxtian/wp_importer

Composer 安装命令:

composer require baxtian/wp_importer

包简介

Class to be inherite to create importers

README 文档

README

Base class for creating WordPress importers/exporters (CSV + XLSX). Appears under Tools → Import in the WordPress admin.

Usage

class MyImporter extends \Baxtian\WP_Importer
{
    use \Baxtian\SingletonTrait;

    protected function __construct()
    {
        $this->tipo   = 'product';        // singular slug
        $this->tipos  = 'products';       // plural slug
        $this->accion = 'import_products';// importer action slug

        add_action('init', [$this, 'init']);
        parent::__construct();
    }

    public function init(): void
    {
        $this->campos = [...];  // define here — translations are loaded
        $this->textos = [
            'import_button'       => __('Import Products', 'domain'),
            'import_file'         => __('Products file', 'domain'),
            'plural'              => __('products', 'domain'),
            'description'         => __('Import products from CSV or XLSX.', 'domain'),
            'mensaje_publicacion' => __('Created: %d, Updated: %d, Linked: %d', 'domain'),
            // ↑ Use commas as separators — JS splits by "," to build a bullet list
        ];
        // For custom DB tables, hook import/export here:
        add_filter('MrkImporter/import_data', [$this, 'handle_import'], 10, 4);
        add_filter('MrkImporter/export_data', [$this, 'handle_export'], 10, 4);
        parent::init();
    }
}

Important: define $campos and $textos inside init(), not the constructor — translations must be loaded first. Call parent::init() at the end of init().

Campo types

typedescription
idPost ID — used for matching on import
fieldpost_title or any direct post field
thumbnailFeatured image (URL on export, URL/path on import)
termTaxonomy term (comma-separated on export)
postmetaGeneric postmeta value
postmeta_boolBoolean postmeta — exports as 1/0
postmeta_textareaMultiline postmeta
postmeta_dateDate postmeta (Y-m-d)
postmeta_datetimeDatetime postmeta (Y-m-d H:i:s)
p2pPost-to-post relationship — requires 'p2p' key

Hooks

HookTypeArgsWhen
MrkImporter/import_datafilter(false, $tipo, $data, $campos)Before importing — return ['nuevas'=>int, 'modificadas'=>int, 'terminos_nuevos'=>int] to replace built-in import; return false to fall through
MrkImporter/export_datafilter($data, $tipo, $tipos, $campos)Before writing the export file — return numeric array of rows (row 0 = header of campo names)
MrkImporter/row_addedaction($post_id, $tipo, $line)After each imported row (built-in importer only)
MrkImporter/attach_imageaction($attach_id, $attach_data)After each image is uploaded and processed

Export format

handle_export must return a numeric array where row 0 is the header (campo name values) and rows 1…N are data rows (numeric arrays aligned with the header). rename_columns() translates names → titles for the downloaded file.

$rows   = [['name', 'email', 'webinars']]; // header
$rows[] = ['John', 'john@example.com', 'Webinar 1'];
return $rows;

XLSX date cells

Cells formatted as dates in Excel are automatically converted to Y-m-d H:i:s strings. No manual serial-number handling needed in the importer.

Access control

WordPress restricts Tools → Import to users with the import capability. Grant it explicitly for custom roles:

add_role('my_role', 'My Role', ['read' => true, 'import' => true]);

Maintainers

Juan Sebastián Echeverry baxtian.echeverry@gmail.com

Changelog

See CHANGELOG.md.

baxtian/wp_importer 适用场景与选型建议

baxtian/wp_importer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 410 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 baxtian/wp_importer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 baxtian/wp_importer 我们能提供哪些服务?
定制开发 / 二次开发

基于 baxtian/wp_importer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-02-10