Code Monkey home page Code Monkey logo

faker's Introduction

Faker

Fake post data with wp-cli. Made for WordPress.

Build Status

Relies on nelmio/alice and fzaninotto/Faker.

Install

wp package install trendwerk/faker

Requires wp-cli >= 0.23.

Usage

wp faker fake <files>...

Options

Parameter Default Required Description
<file> null Yes Location to an Alice YAML file

Delete data

wp faker delete

Deletes all fake data.

Support

The YAML file supports:

Fields Description
WP_Post All properties from wp_insert_post
meta Post meta
terms Terms for taxonomies, see Terms
acf Advanced Custom Fields fields, see ACF

YAML / Faker

Your YAML file(s) could look like any the examples below.

For more understanding of the internals:

Basic

Trendwerk\Faker\Entity\Post:
  post{1..100}:
    post_content: <paragraphs(4, true)>
    post_title: '<sentence()>'

Generates 100 posts with a title and content.

Post Type

Trendwerk\Faker\Entity\Post:
  post{1..100}:
    post_title: '<sentence()>'
    post_type: 'testimonials'

Generates 100 posts from the post type testimonials with a title.

Meta

Trendwerk\Faker\Entity\Post:
  post{1..100}:
    post_title: '<sentence()>'
    post_type: 'testimonials'
    meta:
      name: '<name()>'
      address: '<address()>'

Generates 100 testimonials with a title and a custom field called name and one called address.

Terms

Trendwerk\Faker\Entity\Post:
  post{1..100}:
    post_content: <paragraphs(3, true)>
    post_title: '<sentence()>'
    terms:
      category: <terms('category', 1)>
      post_tag: <terms('post_tag', 7)>

Generates 100 posts with a title, content, 1 random category and 7 random tags.

Using <terms> is not required. You could also provide an array of integers yourself or use randomElements.

Options

Parameter Default Required
taxonomy null Yes
amount 1 No

ACF

Trendwerk\Faker\Entity\Post:
  post{1..100}:
    post_content: <paragraphs(3, true)>
    post_title: '<sentence()>'
    acf:
      name: '<name()>'
      address: '<address()>'

Generates 100 posts with a title, content, and two filled ACF fields: name and address.

Duplicate field names

In ACF, it is possible to have multiple fields with the same name. This could cause formatting conflicts when faking data with this library. If you have two fields with the same name, using the unique field key is recommended:

Trendwerk\Faker\Entity\Post:
  post{1..100}:
    post_content: <paragraphs(3, true)>
    post_title: '<sentence()>'
    acf:
      field_56cf2f782e9b1: '<name()>' # Name
      address: '<address()>'

Attachments

Currently the only type of supported attachments are images.

Images

Trendwerk\Faker\Entity\Image:
  image{1..3}:
    data: '<image()>'

Generates 3 image attachments. Images are provided by Faker, which in turn are provided by LoremPixel.

Post + (Featured) Image

# image.yml
Trendwerk\Faker\Entity\Image:
  image{1..3}:
    data: '<image()>'
# post.yml
Trendwerk\Faker\Post:
  post{1..1}:
    post_content: <paragraphs(3, true)>
    post_title: '<sentence()>'
    meta:
      _thumbnail_id: '@image*->id'

You can now supply both files to wp faker fake:

wp faker fake image.yml post.yml

Make sure you load the file that contains the referenced objects first.

faker's People

Contributors

haroldangenent avatar danielbachhuber avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.