{"id":34956704,"url":"https://github.com/ericrasch/wp-cli-sheet-automation","last_synced_at":"2026-05-22T00:05:00.333Z","repository":{"id":288653489,"uuid":"968686536","full_name":"ericrasch/wp-cli-sheet-automation","owner":"ericrasch","description":"This repository provides a structured and repeatable system for automating WordPress cleanup tasks — including post deletions, permalink updates, and search-replace operations — using WP-CLI commands generated directly from a Google Sheet.","archived":false,"fork":false,"pushed_at":"2025-04-18T19:24:12.000Z","size":297,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T07:48:09.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericrasch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-04-18T14:41:55.000Z","updated_at":"2025-04-18T19:24:16.000Z","dependencies_parsed_at":"2025-04-19T07:58:15.642Z","dependency_job_id":null,"html_url":"https://github.com/ericrasch/wp-cli-sheet-automation","commit_stats":null,"previous_names":["ericrasch/wp-cli-sheet-automation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ericrasch/wp-cli-sheet-automation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fwp-cli-sheet-automation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fwp-cli-sheet-automation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fwp-cli-sheet-automation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fwp-cli-sheet-automation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericrasch","download_url":"https://codeload.github.com/ericrasch/wp-cli-sheet-automation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fwp-cli-sheet-automation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28062467,"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","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-12-26T22:17:19.036Z","updated_at":"2025-12-26T22:17:21.872Z","avatar_url":"https://github.com/ericrasch.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP-CLI + Google Sheets: Automating WordPress URL Cleanup\n\n![License](https://img.shields.io/badge/license-MIT-green)\n![Status](https://img.shields.io/badge/status-active-blue)\n\n## Overview\n\nThis repository provides a structured and repeatable system for automating WordPress cleanup tasks — including post deletions, permalink updates, and search-replace operations — using WP-CLI commands generated directly from a Google Sheet.\n\nGoogle Apps Scripts are included to:\n- Generate categorized `.sh` shell scripts from the spreadsheet\n- Sort and group commands by type (delete, update, replace)\n- Log all output and failures\n- Streamline cleanup for large WordPress datasets across multiple domains\n\n![example-redirect-sheet-clean](https://github.com/ericrasch/wp-cli-sheet-automation/blob/main/examples/screenshot-example-redirect-sheet-clean.png?raw=true)\n\n![export_wp_posts](https://github.com/ericrasch/wp-cli-sheet-automation/blob/main/examples/screenshot-export_wp_posts.png?raw=true)\n\n---\n\n## 🔧 Features\n\n- **Grouped Command Execution**:\n  - STEP 1: `wp post delete`\n  - STEP 2: `wp post update` (permalink updates)\n  - STEP 3: `wp search-replace` (internal links)\n\n- **Command Resilience**:\n  - All commands wrapped in `run_or_log_fail` for error tolerance\n  - Failures are logged to `failed.log`\n\n- **Sorting by Specificity**:\n  - Commands can be sorted by URL length to prioritize deep paths first\n\n---\n\n## 📊 Google Sheet Structure\n\n| Column | Header                                      | Purpose                                                                 |\n|--------|---------------------------------------------|-------------------------------------------------------------------------|\n| A      | URL                                         | Original full URL                                                      |\n| B      | Action                                      | Type of action: `301`, `410`, or `Keep`                                |\n| C      | New URL                                     | Destination URL for 301 redirects; `N/A` if 410                        |\n| D      | url: ORIG                                   | Original relative path                                                 |\n| E      | url: NEW                                    | New relative path                                                      |\n| F      | post ID                                     | WordPress post ID if known                                             |\n| G      | STEP 1: Remove unwanted posts (301/410)     | Generates `wp post delete` command if action = 410                     |\n| H      | STEP 2: Change Post URL                     | (Optional) Updates post URL metadata                                   |\n| I      | STEP 3: Search/Replace URL                  | Updates internal links across database                                 |\n| J      | STEP 4: URL Length Sort                     | Calculates length of `url: ORIG`                                       |\n| K      | STEP 5: Combined CLI Command                | Combines Steps 1 + 3 with newlines                                     |\n\n\n## 🧮 Google Sheets Formulas\n\n**STEP 1: Remove Unwanted Posts (Column Y)**  \n```excel\n=IF(Q2=410, IF(ISNUMBER(W2), \"wp post delete \" \u0026 W2 \u0026 \" --force --allow-root\", \"MISSING\"), \"\")\n```\n\n**STEP 2: Change Post URL (Column Z)**  \n```excel\n=IF(AND($W2\u003c\u003e\"\", $Q2\u003c\u003e410), \"wp post update \" \u0026 $W2 \u0026 \" --meta_input='{\"custom_permalink\":\"\" \u0026 $V2 \u0026 \"\"}' --allow-root\", \"\")\n```\n\n**STEP 3: Search/Replace URL (Column AA)**  \n```excel\n=IF(AND($U2\u003c\u003e\"\", $Q2\u003c\u003e410), \"wp search-replace '\" \u0026 $U2 \u0026 \"' '\" \u0026 $V2 \u0026 \"' --all-tables --skip-tables=wp_redirection* --report-changed-only --precise --allow-root\", \"\")\n```\n\n---\n\n## 📂 File Layout\n\n```bash\nwp-cli-sheet-automation/\n├── .gitignore\n├── README.md\n├── LICENSE\n├── scripts/\n│   └── downloadShellScript.gs         # Apps Script to generate the bash file\n├── docs/\n│   └── sheet-setup.md             # Full column breakdown + Reusable formulas and logic\n├── examples/\n│   └── WP-CLI_Cleanup_Example_Public.xlsx\n```\n\n---\n\n## 🚀 Getting Started\n\n1. Clone or download the repository.\n2. Open the `WP-CLI_Cleanup_Example_Public.xlsx` sheet in `/examples/`.\n3. Adjust your own data and formulas as needed in the same format.\n\n---\n\n## ▶️ Usage\n\n1. Open your working Google Sheet.\n2. Add the script in `/scripts/downloadShellScript.gs` to **Apps Script Editor**.\n3. Run `downloadShellScript()` to generate a `.sh` script in your Drive.\n4. Download the file and run it in your WordPress CLI environment:\n\n```bash\nchmod +x wp_cli_batch_YYYYMMDD_HHMMSS.sh\n./wp_cli_batch_YYYYMMDD_HHMMSS.sh\n```\n\n---\n\n## 📥 Example Output\n\n```bash\n#!/bin/bash\n\ntimestamp=$(date +\"%Y%m%d_%H%M%S\")\nlogfile=\"wp_cli_log_$timestamp.log\"\nexec \u003e \u003e(tee -i \"$logfile\")\nexec 2\u003e\u00261\n\necho \"=== Starting WP-CLI Batch Processing ===\"\n\nrun_or_log_fail() {\n  \"$@\" || echo \"❌ Failed: $*\" \u003e\u003e failed.log\n}\n\necho \"=== STEP 1: Deleting Unwanted Posts ===\"\nrun_or_log_fail wp post delete 1001 --force --allow-root\n\necho \"=== STEP 2: Updating Custom Permalinks ===\"\nrun_or_log_fail wp post update 1002 --meta_input='{\"custom_permalink\":\"pages/about\"}' --allow-root\n\necho \"=== STEP 3: Running Search \u0026 Replace ===\"\nrun_or_log_fail wp search-replace '/about-us' '/pages/about' --all-tables ...\n```\n\n---\n\n## 🧠 Credits\n\n**Author:** Eric Rasch  \n**GitHub:** [github.com/ericrasch](https://github.com/ericrasch)\n\n---\n\n## 📄 License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericrasch%2Fwp-cli-sheet-automation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericrasch%2Fwp-cli-sheet-automation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericrasch%2Fwp-cli-sheet-automation/lists"}