{"id":26878149,"url":"https://github.com/ericrasch/script-reset-wp-symlinks","last_synced_at":"2025-03-31T12:19:39.583Z","repository":{"id":281239884,"uuid":"944654720","full_name":"ericrasch/script-reset-wp-symlinks","owner":"ericrasch","description":"This script automates the process of resetting symbolic links for WordPress theme directories in a LocalWP environment.","archived":false,"fork":false,"pushed_at":"2025-03-07T23:01:06.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T12:19:35.967Z","etag":null,"topics":["localwp","symlinks","wordpress"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","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":"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}},"created_at":"2025-03-07T18:21:38.000Z","updated_at":"2025-03-11T18:48:36.000Z","dependencies_parsed_at":"2025-03-08T02:02:13.508Z","dependency_job_id":null,"html_url":"https://github.com/ericrasch/script-reset-wp-symlinks","commit_stats":null,"previous_names":["ericrasch/reset-wp-symlinks","ericrasch/script-reset-wp-symlinks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-reset-wp-symlinks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-reset-wp-symlinks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-reset-wp-symlinks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-reset-wp-symlinks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericrasch","download_url":"https://codeload.github.com/ericrasch/script-reset-wp-symlinks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246465249,"owners_count":20781919,"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":["localwp","symlinks","wordpress"],"created_at":"2025-03-31T12:19:38.811Z","updated_at":"2025-03-31T12:19:39.572Z","avatar_url":"https://github.com/ericrasch.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Reset Symlinks for LocalWP**  \n\n## **Overview**  \nThis script automates the process of **resetting symbolic links** for WordPress theme directories in a **LocalWP environment**. Each time you sync down from WP Engine, your theme files may be overwritten. This script ensures that your LocalWP themes always point to their respective **GitHub repositories** by recreating symlinks as needed. \n\n## **Why did I make this?**  \nSince we use [LocalWP](https://localwp.com/) to download and work on our sites locally, I wanted an easy way to link each site's theme folder to its corresponding GitHub repo (which lives in a separate folder path). This script runs through a defined list of LocalWP theme folders, checks them against a matching list of GitHub theme folders, and automatically creates the necessary symlinks.\n\nThe end result? You can edit and commit changes directly in your GitHub repo while instantly seeing those updates reflected in your LocalWP site. 🚀\n\n## **Why Use This Script?**  \n✔ **Prevents WP Engine sync from overriding symlinks**  \n✔ **Automatically detects and fixes incorrect symlinks**  \n✔ **Ensures consistency between LocalWP and GitHub repo**  \n✔ **Automates tedious manual work**  \n✔ **Supports multiple WordPress installations**  \n\n---\n\n## **How It Works**  \n1. **Checks if the symlink exists and is correct**  \n   - If correct, it **skips re-creation**  \n2. **Detects incorrect symlinks and fixes them**  \n   - If a symlink exists but points to the wrong location, it **removes and replaces it**  \n3. **Handles overwritten theme directories**  \n   - If WP Engine has replaced a symlink with an actual folder, it **removes it and recreates the symlink**  \n4. **Ensures missing directories are created automatically**  \n\n---\n\n## **Installation \u0026 Setup**  \n### **1️⃣ Save the Script**  \n- Place the script in a directory, e.g., `~/scripts/reset_wp_symlinks.sh`\n- Ensure it has **execute permissions**:\n  ```bash\n  chmod +x ~/scripts/reset_wp_symlinks.sh\n  ```\n\n### **2️⃣ Run the Script Manually**  \n```bash\n~/scripts/reset_wp_symlinks.sh\n```\n\n---\n\n## **Customizing for Your System**  \nTo use this script on your own system, you will need to update the following lines in the script:\n\n1. **GitHub Repository Paths**  \n   - Update the `GITHUB_THEMES` array to reflect the correct paths to your theme folders inside your **GitHub repository**.\n   ```bash\n   GITHUB_THEMES=(\n       \"$HOME/path/to/github-repo/wp-content/themes/YOUR-THEME\"\n   )\n   ```\n\n2. **LocalWP Theme Paths**  \n   - Update the `LOCAL_THEMES` array to point to your LocalWP installation’s **themes folder**.\n   ```bash\n   LOCAL_THEMES=(\n       \"$HOME/path/to/local-wp-site/app/public/wp-content/themes/YOUR-THEME\"\n   )\n   ```\n\n3. **If Using a Different Shell**  \n   - If you are using `zsh` instead of `bash`, update alias commands accordingly in `.zshrc` instead of `.bashrc`.\n\n---\n\n## **Post-Sync Setup: Installing Dependencies**  \nIf the **GitHub repository** contains a `package.json` file in the theme directory, you may need to install dependencies before development. This step is **separate from the WPE/LocalWP sync process** and typically only needs to be done once when first downloading the repository.  \n\nRun the following command inside the GitHub theme directory to install required Node.js packages and rebuild assets:\n```bash\ncd ~/path/to/github-repo/YOUR-THEME-FOLDER\nnpm install\n```\n✅ **This ensures that necessary modules, HTML, and CSS are built properly.**  \n\n---\n\n## **Automating the Process**  \nInstead of running this script manually, you can **automate it using different methods**:\n\n### **1️⃣ Auto-Run When WP Engine Syncs (Using `fswatch`)**\nAutomatically run the script when WP Engine **syncs down**:\n\n```bash\nfswatch -o \"$HOME/path/to/local-wp-site/app/public/wp-content/themes/\" | xargs -n1 ~/scripts/reset_wp_symlinks.sh\n```\n✅ **Automatically resets symlinks when LocalWP files change.**  \n\n---\n\n### **2️⃣ Schedule Automatic Execution (Using `cron`)**  \nRun the script **every 10 minutes** to ensure symlinks are always correct:\n\n```bash\ncrontab -e\n```\n\nAdd this line to **run the script every 10 minutes**:\n```bash\n*/10 * * * * ~/scripts/reset_wp_symlinks.sh\n```\n✅ **Set it and forget it!**  \n\n---\n\n### **3️⃣ Quick Terminal Command (Using an Alias)**\nCreate a **shortcut command** for easy manual execution:\n\n```bash\necho 'alias resetsymlinks=\"~/scripts/reset_wp_symlinks.sh\"' \u003e\u003e ~/.bashrc\nsource ~/.bashrc\n```\nNow, simply type:\n```bash\nresetsymlinks\n```\n✅ **Quick \u0026 easy manual execution!**  \n\n---\n\n## **Customization \u0026 Expansion**  \nYou can **modify this script** to support additional functionality:  \n🛠 **Track plugin folders** in addition to themes.  \n🛠 **Auto-push changes to GitHub** after fixing symlinks.  \n🛠 **Integrate with GitHub Actions** for more automation.  \n\n---\n\n## **License**  \nThis project is licensed under the **MIT License**. You are free to use, modify, and distribute it as needed. See the `LICENSE.md` file for full details.  \n\n---\n\n## **Final Thoughts**  \n🔥 This script **saves time** and **ensures consistency** in your LocalWP workflow. By using automation techniques like `fswatch` and `cron`, you can **eliminate manual intervention** and keep your LocalWP sites synced with GitHub effortlessly.  \n\n🎯 **Ready to make WordPress development with Local WP smoother?** Give it a try! 🚀\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericrasch%2Fscript-reset-wp-symlinks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericrasch%2Fscript-reset-wp-symlinks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericrasch%2Fscript-reset-wp-symlinks/lists"}