Skip to content

Add theme existence validation to activate_theme() in wordpress-local.sh #43

@PAMulligan

Description

@PAMulligan

Description

The activate_theme() function in wordpress-local.sh doesn't check whether the specified theme directory exists before attempting activation. This leads to confusing Docker/WP-CLI errors when a user mistypes a theme name.

Current Behavior

./wordpress-local.sh activate-theme typo-theme
# Outputs a confusing WP-CLI error from inside Docker

Expected Behavior

./wordpress-local.sh activate-theme typo-theme
# Error: Theme not found: themes/typo-theme
# Available themes:
#   flavian

Task

Add a directory existence check in the activate_theme() function before calling Docker.

Suggested Fix (around line 141)

activate_theme() {
    local theme_slug="$1"

    if [ -z "$theme_slug" ]; then
        print_error "Usage: ./wordpress-local.sh activate-theme <theme-slug>"
        echo ""
        echo "Available themes:"
        ls -1 themes/
        exit 1
    fi

    # Add this validation:
    if [ ! -d "themes/$theme_slug" ]; then
        print_error "Theme not found: themes/$theme_slug"
        echo ""
        echo "Available themes:"
        ls -1 themes/
        exit 1
    fi

    docker-compose exec wordpress wp theme activate "$theme_slug" --allow-root
}

Files to Edit

  • wordpress-local.shactivate_theme() function (around line 141)

Acceptance Criteria

  • Script exits with helpful error if theme directory doesn't exist
  • Available themes are listed to help the user
  • Existing empty-slug validation still works
  • Uses print_error function consistent with rest of script

Metadata

Metadata

Assignees

No one assigned

    Labels

    code qualityCode quality improvementsgood first issueGood for newcomershelp wantedExtra attention is neededwordpressWordPress-specific functionality

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions