Skip to content

Conversation

@mgiannopoulos24
Copy link

@mgiannopoulos24 mgiannopoulos24 commented Jan 7, 2026

Description

This PR implements CSV import functionality for recipes, allowing users to bulk import recipes from CSV files. The feature includes support for all major recipe fields including ingredients with substitutions, directions, nutrition data, categories, and tags.

Related Issue

Closes #72

Changes

  • New CSV Import Handler (includes/class.cooked-csv-import.php)

    • Parses CSV files and validates required fields
    • Imports recipes with all metadata (ingredients, directions, nutrition, etc.)
    • Supports ingredient substitutions using double pipe separator (||)
    • Handles taxonomy assignment (categories and tags)
    • Creates recipes as drafts for review before publishing
  • Updated Import Interface (includes/class.cooked-import.php)

    • Added new "CSV Import" tab to the import page
    • Added field_csv_upload() method for CSV upload form
    • Updated import description to include CSV format instructions
  • AJAX Handlers (includes/class.cooked-ajax.php)

    • Added upload_csv() handler for file upload
    • Added process_csv() handler for CSV processing
    • Includes proper error handling and file cleanup
  • JavaScript Updates (assets/admin/js/cooked-migration.js)

    • Added CSV import functionality with progress tracking
    • Improved error message handling (fixes "undefined" error)
    • Added proper validation for file selection
  • CSS Updates (assets/admin/css/style.css)

    • Fixed width issue for CSV import tab (now matches other tabs at 1000px)
    • Added styles for CSV import form elements
    • Added styles for CSV progress indicators
  • Translation Support (includes/class.cooked-admin-enqueues.php)

    • Added i18n_csv_no_file and i18n_csv_invalid_file translation strings
  • Mock Data (tests/test_data/*.csv)

    • Added some files for testing with 1,3 and 10 recipes.

CSV Format

The CSV import supports the following columns:

  • title (required) - Recipe title
  • excerpt - Recipe description
  • prep_time - Prep time in minutes
  • cook_time - Cook time in minutes
  • difficulty_level - 1=Beginner, 2=Intermediate, 3=Advanced
  • ingredients - All ingredients in a single pipe-separated string
    • Format for each ingredient: amount|measurement|name (e.g., 2|cups|All-Purpose Flour)
    • Ingredients without amounts: name (e.g., Salt and Pepper to taste)
    • Section headings: #Section Name (e.g., #Meat Sauce)
    • Multiple ingredients separated by single pipe |
    • Substitutions: Use double pipe || followed by substitution parts
      • Example: 1|cup|Butter||1|cup|Margarine (Butter can be substituted with Margarine)
      • Full format: amount|measurement|name||sub_amount|sub_measurement|sub_name
  • directions - Pipe-separated instructions (each step separated by |)
    • Section headings: #Section Name (e.g., #For the Sauce)
  • notes - Recipe notes
  • categories - Comma-separated category names
  • tags - Comma-separated tag names

Screenshots

  • Import tab

  • Progress during import

  • Message after import

  • Imported recipes in the recipes list

  • Imported recipe ingredients

  • Imported recipe directions

Checklist

Please check if your PR fulfills the following requirements:

  • Tested in latest version of WordPress
  • No JavaScript errors or warnings in the console
  • No PHP errors or warnings logs
  • Generate language files, if necessary
  • Extended the README / documentation / etc, if necessary

Testing Notes

  • Tested with small (1 recipe), medium (3 recipes), and large (10 recipes) CSV files
  • Verified ingredient substitutions are properly imported
  • Confirmed recipes are created as drafts
  • Tested error handling for invalid files and missing required fields
  • Verified taxonomy assignment works correctly

Let me know if you would like any changes!

@mgiannopoulos24 mgiannopoulos24 changed the base branch from main to develop January 7, 2026 21:16
@XjSv XjSv added the enhancement New feature or request label Jan 7, 2026
@XjSv XjSv self-assigned this Jan 7, 2026
@XjSv XjSv added this to the 1.12.0 milestone Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import Recipes via CSV

2 participants