WP REST API Custom Fields to Google Maps

Manuel, the young shrimp-picker, five years old, and a mountain of child-labor oyster shells behind him. He worked last year. Understands not a word of English. Dunbar, Lopez, Dukate Company. Location: Biloxi, Mississippi. (LOC) flickr photo by The Library of Congress shared with no copyright restriction (Flickr Commons) 1 I had a site we used for the Great VCU Bike Race course that’s been sitting around. I knew it had lat/lng data for lots of urban bicycle related posts. My goal was to get it into Google Maps via the REST API. Get Custom Field in JSON By default you won’t see custom field data in your JSON endpoints. There are some plugins to make that happen but I wanted to take a stab at doing it myself. Given the documentation, it was pretty trivial.2 The code below in a plugin or the function.php file would make the lat_long custom field show up in the post JSON. Using this URL, I can get the 30 most recent posts.3 Some Map Stuff Google wants lat/lng separate but it’s coming in as one item split by a comma. These little functions split it up nicely. In javascript, split breaks up a string by the defined element (comma in this case) and returns the pieces as an array. Since I’ll get two pieces […]

WordPress – Comments to Spreadsheet

Image from page 981 of “A system of instruction in X-ray methods and medical uses of light, hot-air, vibration and high-frequency currents : a pictorial system of teaching by clinical instruction plates with explanatory text : a series of photographic cli flickr photo by Internet Archive Book Images shared with no copyright restriction (Flickr Commons) This is a bit odd but if you work in education it’s quite possible it’ll come up . . . Sometimes people just want the blog comments in a nice friendly CSV file. That might be for grading, it might be for further analysis in Voyant or something like that. What I need to do is write a little plugin for the export like Alan did for posts but until I get around to that I took advantage of another plugin Alan wrote to expand comments to the 100 most recent comments. So since I have lots of comments available in the feed, I can just use the =IMPORTXML function to port right into Google Sheets. There’s probably a smart way to parse out multiple XML fields at a time but this seems to work ok. All the functions I used are broken down in the sheet embedded below. Most are simply some version of IMPORTXML(b1,”//title”). B1 is the URL for the feed and the […]

13

500 Error on wp-admin after upgrade

This happened with one of our individual installs and it’s happened before (but I forgot the solution) so I’m writing it down. After the upgrade to 4.7.1, the front of the sight still worked but attempts to get to wp-admin failed with a 500 error and the URL was redirecting to something with upgrade.php? in the URL. Solution Change the name of the plugin folder (I just prepend an underscore). Revisit your login URL. Run the database upgrade as prompted. You should now be in the admin zone. Fix your plugin folder name. Easy but also easy to forget.

Bootstrap Collapsible Shortcode Plugin

There are a bunch of these out there but the ones I knew of didn’t quite do what was needed by the Focused Inquiry faculty involved in this project. They wanted a couple things to be possible. The ability to link to specific elements via URL and have them expand. The URL to those elements to remain consistent even if the order of the elements was changed. An “email this URL” link to enable faculty to send the URL to students Plus/Minus indicators based on expanded/collapsed. Most shortcode plugins I’ve seen either don’t have an ID for the collapse element or make it sequential (which changes if you shift the order). Neither works well for a URL that needs to be consistent. I’ve never seen one to do the email element. In my head, I made this way harder than it needed to be. It ends up being just two shortcodes- one for the collapsible container and one for the item-level elements. I found this Bootstrap snippet that did most of the functional Bootstrap stuff that I needed. I found a script to let me expand elements via URL parameters. I reminded myself what a freaking mailto link structure looked like. Now I just had to figure out what variables needed to be set in the shortcode and how the […]

Minimal WordPress

Sometimes people just want a little bit of WordPress. Before hanging a left with the anth101.com site, we pruned it waaaaay down and tried to make it as simple as possible. This is a pretty solid example that WordPress can be just about anything you want if you’re willing to put in a bit of time and effort. I figure having all these things in one place will help someone else (me most likely) at some point. Hide Posts from Other Authors If you have many authors, you often don’t want them seeing a bunch of posts in the admin area that they can’t edit. Make their lives easier and hide everything else. I believe this is where I found the code. Remove Sidebar Options To further clean up the sidebar for authors, the following code removes lots of things that you don’t want students bothering with anyway. You can get lots of details on this in the codex. Go to Directly to Post, Do Not Pass Dashboard This shunts people directly to the posts area rather than going to the dashboard on login. Posts in Single Column This sets the posts to single column display to simplify writing and was found here. Purify and Rename the Post Page This chunk removes certain meta boxes and restructures the language on […]

Vue and the WordPress REST API

I’ve continued to play around with using Vue and WordPress’s API. The Vue stuff is entirely new to me but it’s pushing my javascript knowledge. The main reason I’m excited about the WordPress/Vue (or whatever framework) combinations is simply speed. If you have any doubts give the pagination at the bottom of this demo site a shot. Crazy fast . . . and running stock on shared hosting. No caching plugins etc. The site is running the Vuetiful WordPress theme which has been an interesting thing to look at and see how it all works. Github is such a good thing. Below or linked here is the WP JSON/Vue pagination I eventually got working. It’s forked from this demo by Brian Krosgard.1 Even with that large head start, a few things hung me up. First, the navigation of the JSON elements is a bit tricky if you’re not used to it. You’ll want to use the _embed parameter2 to get access to the featured image data. That’s an option I didn’t know about previously. https://anth101.com/wp-json/wp/v2/posts?_embed&per_page=24&page=1 Since I named my main JSON objects ‘post’– to access the thumbnail URL, I’d use post._embedded[‘wp:featuredmedia’][0].media_details.sizes.thumbnail.source_url The part you need to pay attention to is the square brackets and the number following it. Notice there is no period between _embedded and [‘wp:featuredmedia’]. You might also […]

Instagram-ish WordPress Filter Shortcode Plugin

That beautiful link-bait title and a picture of a dead leaf! That’s why I’m a social media guru. With that self-promotion out of the way . . . I found this CSS library from Una.1 It lets you apply instagram-like filters to image via CSS. Also got to have a nice interaction with Una via Twitter to clarify the license. @twoodwar :+1: its MIT so go ahead — Una Kravets (@Una) December 6, 2016 It fit a need that a professor was expressing for one of our WordPress installs so I wrapped it in a plugin/shortcode combination. The structure goes like so . . . [ cssgram img=”https://c2.staticflickr.com/6/5745/31413304786_48ab865a34_c.jpg” filter=”_1977″ ] Plain Image A Few Filtered Examples _1977 Inkwell Xpro2 1 Check out her site if you’re into developer stuff at all.

Rampages Stats vs My Own Data

flickr photo shared by NASA on The Commons with no copyright restriction (Flickr Commons) It’s that time of year when you try to prove to your institution that the work you do matters . . . and I am prepared to make it rain datums.1 I’m not sure how valuable this will be to others but who knows and it helps me to write it down. Currently, my former team of 5 is now just me. So this stuff is sole mio23 and compasses everything from manual password resets to full on custom development work with faculty. Can you tell when the semester started? That’s an increase of abut 2,400 sites in about 3 weeks. I’ve got our weekly Twitter/Google Sheet spitting this out and writing it to a spreadsheet so this data was handy. I’ve been playing with logging data for a variety of reasons. For instance I now tag my rampages support emails in GMail and that logs them to a spreadsheet each night. I’m at least mostly consistent doing that because it’s a very light weight action on my part. I can then get an idea how stuff is really playing out rather than simply my perception of things (although that matters too). The chart above represents rampages email support over the last 30 days as of […]

WordPress Plugins & Random Thoughts

Do you use WordPress for teaching and learning? What plugins do you recommend for a multisite install? cc @brlamb @clintlalonde @jimgroom — George Veletsianos (@veletsianos) September 8, 2016 Sparked by a tweet, this is reposted from a conversation here (thanks to Alan) but I figured that much writing ought to also be a blog post. flickr photo shared by Internet Archive Book Images with no copyright restriction (Flickr Commons) And a pre-warning, I may have overdone this . . . . As a secondary warning, I may not give the best advice. Add grains of salt as needed. There seems to be two big buckets here for me. One is managing a large multisite and stuff around that. The other is plugins that are useful when helping people build educational things. Security/Management Be careful with security plugins associated with IP addresses (Jetpack got me early on, more on that later). That can turn bad very quickly if your school shares IPs etc. iframe related – I’ve done iframes via the plugin Alan mentioned but found that getting people to do that was a hassle, I wrote a little plugin that I activate blog by blog that adds a chunk of allowed iframe parameters to the kses file. This way they keep doing things the way they think they should and […]

HTTPS Insecure Content Fixer Plugin

If you’ve got a site running on HTTPS and you try to throw in some HTTP content, the browser gets nervous. If you’ve recently made a shift to HTTPS you might notice content that was successfully embedded disappearing. If you look in the browser (right click>inspect element in Chrome), you’ll see an error like the one above. What you want in this scenario is protocol relative URLS . . . essentially a URL without the leading http/https. That lets the page load via the one protocol that matches (assuming it exists- some sites won’t supply HTTPS options).1 I ran into this problem with files we uploaded via Gravity Forms prior to the switch to HTTPS. There are a number of ways to deal with this (including search/replace at the database level) but we’re under a very heavy load at the moment and I just needed a quick fix. This solution will also allow people to do whatever they want on an ongoing basis better than a database response. This tiny little filter plugin is the result. All it does is use PHP’s preg_replace (regex) function to find any instances of HTTP or HTTPS (capital or lowercase) and remove them. I’m still amazed by regex but always end up having to spend a bit of time reminding myself of how it […]