{"id":15065459,"url":"https://github.com/nlemoine/wp-cli-fixtures","last_synced_at":"2025-05-16T15:06:40.337Z","repository":{"id":45033303,"uuid":"74666976","full_name":"nlemoine/wp-cli-fixtures","owner":"nlemoine","description":"Easily generate custom fake data for WordPress using YAML and WP-CLI","archived":false,"fork":false,"pushed_at":"2025-02-28T06:51:20.000Z","size":155,"stargazers_count":103,"open_issues_count":3,"forks_count":18,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-12T11:58:46.285Z","etag":null,"topics":["fake","fake-content","fixtures","wordpress","wp-cli","wp-cli-package"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlemoine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-11-24T11:28:14.000Z","updated_at":"2025-03-26T16:03:00.000Z","dependencies_parsed_at":"2024-06-21T19:24:01.084Z","dependency_job_id":"f5012b11-bc38-4d8d-9cb3-a09c742df94a","html_url":"https://github.com/nlemoine/wp-cli-fixtures","commit_stats":{"total_commits":74,"total_committers":5,"mean_commits":14.8,"dds":"0.22972972972972971","last_synced_commit":"9da465a62cf9356c5d03e05cd7c81e602e2c6119"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-cli-fixtures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-cli-fixtures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-cli-fixtures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-cli-fixtures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlemoine","download_url":"https://codeload.github.com/nlemoine/wp-cli-fixtures/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254553959,"owners_count":22090417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fake","fake-content","fixtures","wordpress","wp-cli","wp-cli-package"],"created_at":"2024-09-25T00:38:43.018Z","updated_at":"2025-05-16T15:06:40.320Z","avatar_url":"https://github.com/nlemoine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"wp-cli-fixtures\n=========================\n\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/nlemoine/wp-cli-fixtures/Testing?style=flat-square)](https://github.com/nlemoine/wp-cli-fixtures/actions/workflows/testing.yml?query=branch%3Amaster+workflow%3ATesting)\n![Packagist Downloads](https://img.shields.io/packagist/dt/hellonico/wp-cli-fixtures?style=flat-square)\n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/hellonico/wp-cli-fixtures?style=flat-square)\n\nInspired by [Faker](https://github.com/trendwerk/faker), this package provides an easy way to create massive and custom fake data for your WordPress installation.\nThis package is based on [nelmio/alice](https://github.com/nelmio/alice) and [fzaninotto/Faker](https://github.com/fzaninotto/Faker). Please refer to these packages docs for advanced usage.\n\n![wp-cli-fixtures demo](https://hellonico.s3.eu-west-1.amazonaws.com/dev/wp-cli-fixtures.gif)\n\n**WARNING:** This package is mostly intented to be used for development purposes. Use it at your own risk, don't run it on a production database or make sure to back it up first.\n\nQuick links: [Install](#install) | [Usage](#usage) | [Contribute](#contribute)\n\n## Install\n\n```bash\nwp package install git@github.com:nlemoine/wp-cli-fixtures.git\n```\n\nRequires PHP `^7.3`.\n\n## Usage\n\n### Create fixtures\n\nAt the root of your project, create a `fixtures.yml` file (you can download it [here](https://raw.githubusercontent.com/nlemoine/wp-cli-fixtures/master/examples/fixtures.yml)):\n\n```yaml\n#\n# USERS\n#\nHellonico\\Fixtures\\Entity\\User:\n  user{1..10}:\n    user_login (unique): \u003cusername()\u003e # '(unique)' is required\n    user_pass: 123456\n    user_email: \u003csafeEmail()\u003e\n    user_url: \u003curl()\u003e\n    user_registered: \u003cdateTimeThisDecade()\u003e\n    first_name: \u003cfirstName()\u003e\n    last_name: \u003clastName()\u003e\n    description: \u003csentence()\u003e\n    role: \u003crandomElement(['subscriber', 'editor'])\u003e\n    meta:\n      phone_number: \u003cphoneNumber()\u003e\n      address: \u003cstreetAddress()\u003e\n      zip: \u003cpostcode()\u003e\n      city: \u003ccity()\u003e\n    acf:\n      facebook_url: \u003curl()\u003e\n      twitter_url: \u003curl()\u003e\n\n#\n# ATTACHMENTS\n#\nHellonico\\Fixtures\\Entity\\Attachment:\n  default (template): # templates can be extended to keep things DRY\n    post_title: \u003cwords(2, true)\u003e\n    post_date: \u003cdateTimeThisDecade()\u003e\n    post_content: \u003cparagraphs(5, true)\u003e\n  images{1..15} (extends default):\n    file: \u003cimage(\u003cuploadDir()\u003e, 1200, 1200, 'cats')\u003e # \u003cuploadDir()\u003e is required, image() is the default faker provider and gets images from lorempixel.\n  pics{1..15} (extends default):\n    file: \u003cpicsum(\u003cuploadDir()\u003e, 1200, 1200)\u003e # Alternatively we provide a picsum() provider which uses picsum for images. It's quicker but doesn't support image categories.\n  documents{1..2} (extends default):\n    file: \u003cfileIn('relative/path/to/pdfs')\u003e\n  custom_images{1..10} (extends default):\n    file: \u003cfileIn('relative/path/to/images')\u003e\n\n#\n# TERMS\n#\nHellonico\\Fixtures\\Entity\\Term:\n  category{1..10}:\n    name (unique): \u003cwords(2, true)\u003e # '(unique)' is required\n    description: \u003csentence()\u003e\n    parent: '50%? \u003ctermId(childless=1)\u003e' # 50% of created categories will have a top level parent category\n    taxonomy: 'category' # could be skipped, default to 'category'\n  tag{1..40}:\n    name (unique): \u003cwords(2, true)\u003e # '(unique)' is required\n    description: \u003csentence()\u003e\n    taxonomy: post_tag\n  places{1..4}: # custom taxonomy\n    name (unique): \u003cwords(2, true)\u003e # '(unique)' is required\n    description: \u003csentences(3, true)\u003e\n    taxonomy: place\n    acf:\n      address: \u003cstreetAddress\u003e\n      zip: \u003cpostcode()\u003e\n      city: \u003ccity()\u003e\n      image: '@custom_images*-\u003eID'\n\n#\n# POSTS\n#\nHellonico\\Fixtures\\Entity\\Post:\n\n  # TEMPLATE\n  default (template):\n    post_title: \u003cwords(2, true)\u003e\n    post_date: \u003cdateTimeThisDecade()\u003e\n    post_content: \u003cparagraphs(5, true)\u003e\n    post_excerpt: \u003cparagraphs(1, true)\u003e\n    meta:\n      _thumbnail_id: '@attachment*-\u003eID'\n\n  # POSTS\n  post{1..30} (extends default):\n    # 'meta' and 'meta_input' are basically the same, you can use one or both,\n    # they will be merged, just don't provide the same keys in each definition\n    meta:\n      _thumbnail_id: '@attachment*-\u003eID'\n    meta_input:\n      _extra_field: \u003cparagraphs(1, true)\u003e\n    post_category: '3x @category*-\u003eterm_id' # post_category only accepts IDs\n    tax_input:\n      post_tag: '5x @tag*-\u003eterm_id'\n      # post_tag: '5x \u003cwords(2, true)\u003e # Or tags can be dynamically created\n\n  # PAGES\n  page{contact, privacy}:\n    post_title: \u003ccurrent()\u003e\n    post_type: page\n\n  # CUSTOM POST TYPE\n  product{1..15}:\n    post_type: product\n    acf:\n      # number field\n      price: \u003cnumberBetween(10, 200)\u003e\n      # gallery field\n      gallery: '3x @attachment*-\u003eID'\n      # oembed field\n      video: https://www.youtube.com/watch?v=E90_aL870ao\n      # link field\n      link:\n        url: https://www.youtube.com/watch?v=E90_aL870ao\n        title: \u003cwords(2, true)\u003e\n        target: _blank\n      # repeater field\n      features:\n        - label: \u003cwords(2, true)\u003e\n          value: \u003csentence()\u003e\n        - label: \u003cwords(2, true)\u003e\n          value: \u003csentence()\u003e\n        - label: \u003cwords(2, true)\u003e\n          value: \u003csentence()\u003e\n      # layout field\n      blocks:\n        - acf_fc_layout: text_image\n          title: \u003cwords(4, true)\u003e\n          content: \u003csentences(8, true)\u003e\n          image: '@attachment*-\u003eID'\n        - acf_fc_layout: image_image\n          image_left: '@attachment*-\u003eID'\n          image_right: '@attachment*-\u003eID'\n\n#\n# COMMENTS\n#\nHellonico\\Fixtures\\Entity\\Comment:\n  comment{1..50}:\n    comment_post_ID: '@post*-\u003eID'\n    user_id: '@user*-\u003eID'\n    comment_date: \u003cdateTimeThisDecade()\u003e\n    comment_author: \u003cusername()\u003e\n    comment_author_email: \u003csafeEmail()\u003e\n    comment_author_url: \u003curl()\u003e\n    comment_content: \u003cparagraphs(2, true)\u003e\n    comment_agent: \u003cuserAgent()\u003e\n    comment_author_IP: \u003cipv4()\u003e\n    comment_approved: 1\n    comment_karma: \u003cnumberBetween(1, 100)\u003e\n    # 'meta' and 'comment_meta' are basically the same, you can use one or both,\n    # they will be merged, just don't provide the same keys in each definition\n    comment_meta:\n      some_key: \u003csentence()\u003e\n    meta:\n      another_key: \u003csentence()\u003e\n\n#\n#  NAV MENUS\n#\nHellonico\\Fixtures\\Entity\\NavMenu:\n  header:\n    name: header\n    locations:\n      - header\n      - footer\n\n#\n#  NAV MENUS ITEMS\n#\nHellonico\\Fixtures\\Entity\\NavMenuItem:\n  custom_menu:\n    menu_item_url: \u003curl()\u003e\n    menu_item_title: \u003cwords(4, true)\u003e\n    menu_id: '@header-\u003eterm_id'\n  categories{1..3}:\n    menu_item_object: '@category*'\n    menu_id: '@header-\u003eterm_id'\n  posts{1..3}:\n    menu_item_object: '@post*'\n    menu_id: '@header-\u003eterm_id'\n  page:\n    menu_item_object: '@page*'\n    menu_id: '@header-\u003eterm_id'\n```\n\nThe example above will generate:\n\n- 10 users\n- 15 attachments\n- 10 categories\n- 40 tags\n- 30 posts with a thumbnail, 3 categories and 5 tags\n- 10 pages\n- 15 custom post types named 'product'\n- 50 comments associated with post and user\n- 1 nav menu\n- 6 nav menu items\n\n**IMPORTANT:** Make sure referenced IDs are placed **BEFORE** they are used.\n\nExample: `Term` or `Attachment` objects **must** be placed before `Post` if you're referencing them in your fixtures.\n\n### Load fixtures\n\n```\nwp fixtures load\n```\n\nYou can also specify a custom file by using the `--file` argument:\n\n```\nwp fixtures load --file=data.yml\n```\n\n### Delete fixtures\n\n```\nwp fixtures delete\n```\n\nYou also can delete a single fixture type:\n\n```\nwp fixtures delete post\n```\n\nValid types are `post`, `attachment`, `comment`, `term`, `user`.\n\n### Add fake data to existing content\n\n`wp-cli-fixtures` allows you to add/update content to existing entities by passing the ID as a constructor argument.\n\nAdd/update data to post ID 1:\n\n```yaml\nHellonico\\Fixtures\\Entity\\Post:\n  my_post:\n    __construct: [1] # Pass your post ID as the constructor argument\n    post_title: '\u003csentence()\u003e'\n    post_content: '\u003cparagraphs(5, true)\u003e'\n    post_excerpt: '\u003cparagraphs(1, true)\u003e'\n```\n\nAdd/update data to 10 random existing posts:\n\n```yaml\nHellonico\\Fixtures\\Entity\\Post:\n  post{1..10}:\n    __construct: [\u003cpostId()\u003e] # Use a custom formatters to return a random post ID as the constructor argument\n    post_title: '\u003csentence()\u003e'\n    post_content: '\u003cparagraphs(5, true)\u003e'\n    post_excerpt: '\u003cparagraphs(1, true)\u003e'\n```\n\n### Entities\n\n#### Post\n\n`Hellonico\\Fixtures\\Entity\\Post` can take any parameters available in [`wp_insert_post`](https://developer.wordpress.org/reference/functions/wp_insert_post/#parameters) + `meta` and `acf` key.\n\n*Note: `post_date_gmt` and `post_modified_gmt` have been disabled, there are set from `post_date` and `post_modified`.*\n\n#### Attachment\n\n`Hellonico\\Fixtures\\Entity\\Attachment` can take any parameters available in [`wp_insert_attachment`](https://developer.wordpress.org/reference/functions/wp_insert_attachment/#parameters) + `meta`, `file` and `acf` custom keys.\n\n*Note: `parent` must be passed with `post_parent` key.*\n\n#### Term\n\n`Hellonico\\Fixtures\\Entity\\Term` can take any parameters available in [`wp_insert_term`](https://developer.wordpress.org/reference/functions/wp_insert_term/#parameters) + `meta` and `acf` custom keys.\n\n*Note: `term` and `taxonomy` must be respectively passed with `name` and `taxonomy` key.*\n\n#### User\n\n`Hellonico\\Fixtures\\Entity\\User` can take any parameters available in [`wp_insert_user`](https://developer.wordpress.org/reference/functions/wp_insert_user/#parameters) + `meta` and `acf` custom keys.\n\n#### Comment\n\n`Hellonico\\Fixtures\\Entity\\Comment` can take any parameters available in [`wp_insert_comment`](https://developer.wordpress.org/reference/functions/wp_insert_comment/#parameters) + `meta` custom key.\n\n`comment_date_gmt` has been disabled, it is set from `comment_date`.\n\n#### Nav menu\n\n`Hellonico\\Fixtures\\Entity\\NavMenu` is a term just like `Hellonico\\Fixtures\\Entity\\Term`. It takes an addiotional `locations` parameter to set the menu location.\n\n```yaml\nHellonico\\Fixtures\\Entity\\NavMenu:\n  header:\n    name: header\n    locations:\n      - header\n```\n\n#### Nav menu item\n\n`Hellonico\\Fixtures\\Entity\\NavMenuItem` takes the same parameters as `$menu_item_data` in [`wp_update_nav_menu_item`](https://developer.wordpress.org/reference/functions/wp_update_nav_menu_item/#parameters)\n\n*Note 1: replace dashes with underscore in keys (e.g. `menu-item-object` becomes `menu_item_object`).*\n\n*Note 2: `menu-item-object` can also accept an entity object, if so, `menu-item-type` and `menu-item-object-id` will be filled automatically with appropriate values*\n\n\n### ACF Support\n\nEach ACF supported entity (post, term, user) can have an `acf` key, which works just like `meta`.\n\n```yaml\nHellonico\\Fixtures\\Entity\\Post:\n  post{1..30}:\n    post_title: \u003cwords(3, true)\u003e\n    post_date: \u003cdateTimeThisDecade()\u003e\n    acf:\n      # number field\n      number: \u003cnumberBetween(10, 200)\u003e\n      # repeater field\n      features:\n        - label: \u003cwords(2, true)\u003e\n          value: \u003csentence()\u003e\n        - label: \u003cwords(2, true)\u003e\n          value: \u003csentence()\u003e\n        - label: \u003cwords(2, true)\u003e\n          value: \u003csentence()\u003e\n```\nBe careful with duplicate field keys, if you have multiple field with the same key, prefer using ACF field key (`field_948d1qj5mn4d3`).\n\n### MetaBox Support\n\n#### MetaBox Custom Fields\nMetaBox fields can be adressed using the `meta` key\n```yaml\nHellonico\\Fixtures\\Entity\\Post:\n  post{1..30}:\n    post_title: \u003cwords(3, true)\u003e\n    post_date: \u003cdateTimeThisDecade()\u003e\n    meta:\n      # number field\n      number: \u003cnumberBetween(10, 200)\u003e\n      meta_box_custom_field: \u003csentence()\u003e\n```\n\n#### MetaBox Relationships (https://docs.metabox.io/extensions/mb-relationships/#using-code)\nWhen using the MB Relationships extension, the relationships can be set/defined using the key `mb_relations`. For each relationship you want to create a fixture for, you use the relationship-ID which is used to register the MB-relation \n```php\n MB_Relationships_API::register( [\n        'id'   =\u003e 'post_to_term',\n        'from'   =\u003e 'post',\n        'to' =\u003e [\n            'object_type' =\u003e 'term',\n            'taxonomy'=\u003e 'custom_term'\n        ],\n        \n    ] );\n```\nand the post/term ID of the object you want it to have a relationship with.\n```yaml\nHellonico\\Fixtures\\Entity\\Post:\n  post{1..30}:\n    post_title: \u003cwords(3, true)\u003e\n    post_date: \u003cdateTimeThisDecade()\u003e\n    mb_relations:\n      post_to_term: '1x @custom_term*-\u003eterm_id'\n      post_to_post: '1x @custom_post*-\u003eID'\n```\n\n\n### Custom formatters\n\nIn addition to formatters provided by [fzaninotto/Faker](https://github.com/fzaninotto/Faker#formatters), you can use custom formatters below.\n\n#### `postId($args)`\n\nReturns a random existing post ID.\n`$args` is optional and can take any arguments from [`get_posts`](https://developer.wordpress.org/reference/functions/get_posts/#parameters)\n\nExample:\n\n```\n\u003cpostId(category=1,2,3)\u003e\n```\n\n#### `attachmentId($args)`\n\nReturns a random existing attachment ID.\n`$args` is optional and can take any arguments from [`get_posts`](https://developer.wordpress.org/reference/functions/get_posts/#parameters)\n\nExample:\n\n```\n\u003cattachmentId(year=2016)\u003e\n```\n\n#### `termId($args)`\n\nReturns a random existing term ID.\n`$args` is optional and can take any arguments from [`get_terms`](https://developer.wordpress.org/reference/functions/get_terms/#parameters)\n\nExample:\n\n```\n\u003ctermId(taxonomy=post_tag)\u003e\n```\n\n#### `userId($args)`\n\nReturns a random existing user ID.\n`$args` is optional and can take any arguments from [`get_users`](https://developer.wordpress.org/reference/functions/get_users/#parameters)\n\nExample:\n\n```\n\u003cuserId(role=subscriber)\u003e\n```\n\n#### `fileContent($file)`\n\nReturns the content of a file.\n\nExample:\n\n```\n\u003cfileContent('path/to/file.html')\u003e\n```\n\n#### `fileIn($src, $target, false)`\n\nWrapper around [file provider](https://github.com/fzaninotto/Faker#fakerproviderfile) because some Faker providers [conflicts with PHP native ](https://github.com/nelmio/alice/blob/master/doc/getting-started.md#symfony). Returns file path or file name in a directory (`$src` relative to `fixtures.yml`).\n\nDefault target is the WordPress `uploads`.\n\nExample:\n\n```\n\u003cfileIn('my/set/of/images')\u003e\n```\n\n#### Tips\n\nWhile playing with fixtures, the [database command](https://github.com/ernilambar/database-command) package can be useful to reset database faster than `wp fixtures delete` and start over.\n\n## Contribute\n\nThis package follows PSR2 coding standards and is tested with Behat. Execute `composer run test` to ensure your PR passes.\n\n\u003e You will need to run `composer run prepare-tests` before your first run.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlemoine%2Fwp-cli-fixtures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlemoine%2Fwp-cli-fixtures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlemoine%2Fwp-cli-fixtures/lists"}