Skip to content

refactor: clean up legacy code in index.php #235

@akshayurankar48

Description

@akshayurankar48

Summary

Several legacy code patterns in `index.php` need cleanup:

1. Duplicate enqueue logic (`post_enqueue` / `post_new_enqueue`)

Both methods contain ~30 lines of near-identical script/style enqueue code, differing only in the hook value checked. Should be extracted into a single shared private method.

2. Dead code in `bsf_color_scripts()`

The method checks `if ( 3.5 <= $wp_version )` to decide between `wp-color-picker` and the older `farbtastic`. Since the plugin requires WP 3.7+, the `farbtastic` branch can never execute and should be removed.

3. Bare `die()` in AJAX handlers

`submit_request()` and `submit_color()` both call bare `die()` to terminate. WordPress AJAX handlers should use `wp_die()` for proper interoperability.

4. `esc_html_e()` misused in ternary expressions

`esc_html_e()` echoes and returns `null`, so the ternary condition is always truthy — incorrect output when the operation fails. Should be restructured with `if/else`.

Acceptance Criteria

  • `post_enqueue` / `post_new_enqueue` share a single extracted helper
  • Dead `farbtastic` branch removed from `bsf_color_scripts()`
  • `die()` replaced with `wp_die()` in AJAX handlers
  • Ternary `esc_html_e` antipattern fixed in `submit_request()` and `submit_color()`
  • PHPCS/PHPStan pass with no new errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions