PHP code example of raicem / wefg

1. Go to this page and download the library: Download raicem/wefg library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raicem / wefg example snippets


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: '<p>Welcome to my site.</p>',
    excerpt: 'A welcome post',
    authorLogin: 'admin',
    publishDate: '2024-01-01 12:00:00',
    slug: 'hello-world'
));

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

use Raicem\WEFG\Author;

$wxr->addAuthor(new Author(
    login: 'johndoe',
    email: '[email protected]',
    display_name: 'John Doe',
    first_name: 'John',
    last_name: 'Doe',
    author_id: 1
));

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

$post = new Post(
    title: 'My Post',
    content: '<p>Post content here.</p>',
    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 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'],
    ]
);

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

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);

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

$comment = new Comment(
    comment_author: 'Jane',
    comment_author_email: '[email protected]',
    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: '[email protected]',
    comment_content: 'Thanks!',
    comment_parent: '101'
);

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