PHPackages                             raicem/wefg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. raicem/wefg

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

raicem/wefg
===========

WEFG (WordPress Export File Generator) allows developers to programmatically create WXR files for migrating data to WordPress.

1.0.1(3mo ago)10GPL-2.0-or-laterPHPPHP ^7.4

Since Feb 1Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/raicem/wefg)[ Packagist](https://packagist.org/packages/raicem/wefg)[ RSS](/packages/raicem-wefg/feed)WikiDiscussions trunk Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

WEFG — WordPress Export File Generator
======================================

[](#wefg--wordpress-export-file-generator)

A PHP library for programmatically creating WXR (WordPress eXtended RSS) files. Use it to migrate content from any source — a legacy CMS, a database, an API — into WordPress.

WEFG generates a standard WXR XML file that can be imported using the built-in [WordPress Importer](https://wordpress.org/plugins/wordpress-importer/) plugin.

Installation
------------

[](#installation)

```
composer require raicem/wefg
```

Requires PHP 7.4+ and the DOM extension (included with most PHP installations).

Quick Start
-----------

[](#quick-start)

```
use Raicem\WEFG\Post;
use Raicem\WEFG\SiteSettings;
use Raicem\WEFG\WXRFile;

$settings = new SiteSettings(
    link: 'https://example.com',
    title: 'My Site',
    description: 'A WordPress site',
    language: 'en-US'
);

$wxr = new WXRFile($settings);

$wxr->addPost(new Post(
    title: 'Hello World',
    content: 'Welcome to my site.',
    excerpt: 'A welcome post',
    authorLogin: 'admin',
    publishDate: '2024-01-01 12:00:00',
    slug: 'hello-world'
));

$wxr->save('export.xml');
```

Then import `export.xml` via **Tools &gt; Import &gt; WordPress** in wp-admin, or with WP-CLI:

```
wp import export.xml --authors=create
```

Usage
-----

[](#usage)

### Authors

[](#authors)

```
use Raicem\WEFG\Author;

$wxr->addAuthor(new Author(
    login: 'johndoe',
    email: 'john@example.com',
    display_name: 'John Doe',
    first_name: 'John',
    last_name: 'Doe',
    author_id: 1
));
```

### Posts and Pages

[](#posts-and-pages)

```
use Raicem\WEFG\Post;
use Raicem\WEFG\Meta;

$post = new Post(
    title: 'My Post',
    content: 'Post content here.',
    excerpt: 'Short summary',
    authorLogin: 'johndoe',
    publishDate: '2024-06-15 09:00:00',
    slug: 'my-post',
    status: 'publish',
    postId: 42,
    post_type: 'post',
    meta: [
        new Meta('custom_field', 'value'),
    ]
);

$wxr->addPost($post);
```

Use `post_type: 'page'` for pages, or any custom post type string.

### Categories, Tags, and Custom Taxonomies

[](#categories-tags-and-custom-taxonomies)

Define taxonomy terms at the file level, then reference them on posts.

```
use Raicem\WEFG\Terms\Category;
use Raicem\WEFG\Terms\Tag;
use Raicem\WEFG\Terms\Term;

// File-level definitions
$wxr->addCategory(new Category(1, 'tutorials', 'Tutorials'));
$wxr->addTag(new Tag(1, 'php', 'PHP'));
$wxr->addTerms([
    new Term(1, 'location', 'new-york', 'New York', ''),
]);

// Reference on a post
$post = new Post(
    title: 'Learn PHP',
    content: '...',
    excerpt: '',
    authorLogin: 'admin',
    publishDate: '2024-01-01 12:00:00',
    slug: 'learn-php',
    categories: ['Tutorials'],
    tags: ['PHP'],
    terms: [
        'location' => ['New York'],
    ]
);
```

**Non-ASCII names:** When a category, tag, or term name contains non-ASCII characters, pass an array with explicit `name` and `slug` keys. The default slug derivation does not transliterate, so `Müze` would become `müze` instead of `muze`, breaking WordPress matching.

```
$post = new Post(
    // ...
    categories: [
        ['name' => 'Arkeoloji Müzeleri', 'slug' => 'arkeoloji-muzeleri'],
    ],
    terms: [
        'location' => [
            ['name' => 'İstanbul', 'slug' => 'istanbul'],
        ],
    ],
);
```

### Attachments

[](#attachments)

```
use Raicem\WEFG\Attachment;

$post = new Post(
    title: 'My Post',
    content: '...',
    excerpt: '',
    authorLogin: 'admin',
    publishDate: '2024-01-01 12:00:00',
    slug: 'my-post',
    postId: 1,
    meta: [
        new Meta('_thumbnail_id', '1001'), // References the attachment postId
    ]
);

$attachment = new Attachment(
    title: 'Featured Image',
    attachment_url: 'http://example.com/images/photo.jpg',
    parent: $post,
    postId: 1001,
    slug: 'my-post-image'
);

$wxr->addPost($post);
$wxr->addPost($attachment);
```

During import, WordPress downloads the file from `attachment_url` and sets it as the post's featured image via the `_thumbnail_id` meta.

**Important:** WordPress's importer rejects `http://localhost` URLs. Use `http://127.0.0.1` when serving files locally.

### Comments

[](#comments)

```
use Raicem\WEFG\Comment;
use Raicem\WEFG\Meta;

$comment = new Comment(
    comment_author: 'Jane',
    comment_author_email: 'jane@example.com',
    comment_content: 'Great post!',
    comment_date: '2024-01-15 10:30:00',
    comment_approved: '1',
    comment_id: 101
);

// Optional metadata
$comment->meta[] = new Meta('rating', '5');

// Reply to a comment
$reply = new Comment(
    comment_author: 'Admin',
    comment_author_email: 'admin@example.com',
    comment_content: 'Thanks!',
    comment_parent: '101'
);

$post->comments = [$comment, $reply];
```

Testing
-------

[](#testing)

```
# Unit tests (no external dependencies)
vendor/bin/phpunit --testsuite unit

# All tests including integration (requires MySQL via Docker)
docker compose up -d
composer setup-wp-tests   # first time only
vendor/bin/phpunit
```

License
-------

[](#license)

GPL-2.0-or-later

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance86

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d8034cfc9140d8140dd734c596c058662d0aa22fd55149e7a4c0f6f8496d4760?d=identicon)[raicem](/maintainers/raicem)

---

Top Contributors

[![raicem](https://avatars.githubusercontent.com/u/10389957?v=4)](https://github.com/raicem "raicem (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/raicem-wefg/health.svg)

```
[![Health](https://phpackages.com/badges/raicem-wefg/health.svg)](https://phpackages.com/packages/raicem-wefg)
```

###  Alternatives

[symfony/polyfill-uuid

Symfony polyfill for uuid functions

688335.4M63](/packages/symfony-polyfill-uuid)[symfony/uid

Provides an object-oriented API to generate and represent UIDs

610280.0M754](/packages/symfony-uid)[phpflo/phpflo

Flow-based programming for PHP

2173.3k4](/packages/phpflo-phpflo)[jaspaul/laravel-rollout

A package to integrate rollout into your Laravel project.

2493.8k](/packages/jaspaul-laravel-rollout)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
