This is more of my own niche technical fixes that is more interesting in that I learned a new trick, added a small feature to a WordPress site, all only because I inadvertently capitalized the header column of a CSV import.

Or again, my own habit of narrating my work for what I have heard is characterized as a “mythological reader” (aka you).

Cori is putting to use this year for her high school students a WordPress site we conjured up in 2019? 2020? for students in a program at multiple schools share and give each other feedback in writing. This makes me wonder how much/little remains of K-12 teachers creating public spaces for student reflecting. Remember when student blogging was more than a “thing”?

I pretty much over documented the site customizations in April 2020 so most of the nuts and bolts are there. They key feature explained there is I set up a way to add a profile field to indicate the name of a student’s school. This is not displayed anywhere, and is purely present to allow the teachers (who have admin access) the ability to easily sort posts, comments, users by their own school.

What? Okay, I made it so the school names of an author are a column in the view of Posts (all student posts when published are set as Pending status for a teacher to review, and make public). A click on a school name filters all posts to ones from students at that school:

And I even got fancier, and added a similar column on user profiles, but also, an admin interface feature to filter users by school name:

All is working perfectly in a new version of the site for 2022 (thanks to Reclaim Hosting, I was easily able to clone the original site to an archive, and strip out all old student users and posts for a clean start.

The other night Cori asked about a student’s account at one of the other schools that had no data in this profile field. Here is what it looks like, at the bottom of the basic WordPress profile, I added one more field (they are populated when I use a plugin to create accounts from an uploaded CSV file that includes a column for school name.

This is what it looks like from one of my test accounts (Felix makes an appearance!)

I then realized this field was editable by the student- what if they changed or wiped it out? I poked around the WordPress Codex for some ideas and then searched wider on how one can make a user profile field only editable by admins.

The answer came from a post at WordPress Q&A – how to make custom field in WordPress user profile read only? It seems like something there would be a WordPress hook/action for, but its more of a small bit of Javascript added to the admin pages that is invoked/inserted only for non-admin users, and then renders a specified profile form element to be “disabled” or “read only”.

Here’s the magic juice:

And it worked on the first try! As an admin, I can edit Felix’s account like shown above, to update their school association. But an author trying to edit their own profile will see that School field is not edible:

An author account can see what School they are associated with, but the form field is editable only by site admins.

This all worked fine on my development space, so I updated theme. Then the weirdness settled in. I noticed that all student accounts from one school were showing no data for this profile field! And any effort to edit in a new value would return a blank form field.

Now I had to go in deep, I peeked in the database via phpMyAdmin, and diving into the user_meta table I spotted the problem. No student had edited their profile field for school. In fact, what I noticed was the meta_key_name for accounts lacking a school name was labeled Student while the working accounts, the meta_key_name value was lowercase.

Thus the error was on me- the Excel spreadsheet I used to generate the CSV values needed to import in bulk to WordPress I had wrongly entered capital case ‘School” in my header fields.All the data was there, just mislabeled.

A quick mySQL update query reset the metakey name to be lower case. This is rather obscure but maybe one day it can hep.

As usual, my paths to solutions take a good deal of wandering, but finding a working path (there is never a right one) is insanely valuable to me, even for a feature only a mythological reader will notice.


Featured Image: found in an Openverse search on “read only”

Writing / Editing
Writing / Editing flickr photo by stanjourdan shared under a Creative Commons (BY-SA) license

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as @cogdog@cosocial.ca

Comments

  1. If I am a mythological reader, I may also be mythological writer.

    I make capitalization mistakes enough that they’re #2 in my problem solving check. That is not a flex.

    I like the filtering setup in the admin view. I will probably need something like that in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *