I moved most of the link management code into functions. Here’s what we have:
- get_link() – Fetches a link object from the DB
- get_link_to_edit() – Fetches link object and formats fields for editing
- add_link() – Creates a new link from form POST data
- edit_link() – Updates an existing link with data from POST
- wp_insert_link() – Creates a new link in the DB
- wp_update_link() – Updates an existing link in the DB
- wp_delete_link() – Deletes a link from the DB
The code to change visibilty and set attributes for all links in a category needs to be broken out as well.
Link categories need a similar treatment.