Menu

Colin Devroe

Reverse Engineer. Blogger.

Hacking rather than waiting

Yesterday afternoon Sarah Pressler retweeted Jono Young’s request for a plugin that would add a submenu to the WordPress’ Admin with the current pages for the site under the Pages menu. This would reduce the number of clicks to get to the page editor.

I was waiting for an upload to finish and I thought, given the code I have laying around from other projects, I’d be able to supply Jono with something passable for what he needed. Though it is far from what I would recommend using, it is a start.

Here is what I did:

  • I used get_pages to get a list of WordPress pages the were published.
  • While looping through each page I used add_submenu_page to add the page titles under the Pages menu
  • I used JavaScript to replace the HREF attribute on the links to link to the page editor

That last step is the hacky part in my opinion. add_submenu_page() asks for a function name to call to build the page for the menu item when it is clicked. In other words, for each item on the Admin menu there is a corresponding function that will show you the page that it results in. But I didn’t want to create a new page, I wanted the link to go to the page editor.

I dug around for five minutes or so and I didn’t see an apparent way to change the links for the page titles (though I’m sure there is a better way if I had the time to continue looking) and so after the page loads I use JavaScript to replace the attributes with links to the page editor.

Nowhere near perfect but, in a pinch, it is one step closer to what Jono wanted. Hopefully he or someone else can build upon and it make something a little more reliable and less hacky.

You can see the source on Github.

A date picker to schedule posts in WordPress

On Sunday mornings I make some coffee, sit down at my computer, and choose 7 images to publish to my blog throughout the week. After I’ve chosen and edited the images I schedule them in WordPress to be published each morning at around 9:00am. I can then go about my week knowing that each day there will be a new image automatically published to my site.

There was a problem though. I think in days not dates. Like, “what image should I post on Wednesday?” instead of “what image should I post on the 12th?”. So when I used WordPress’ default date selector for scheduling the post I found myself wishing that I could see what day each date was.

So I searched the plugin directory but I didn’t find anything (more on this in a second). I was surprised. So, I quickly cobbled together a plugin of my own which I’ve open sourced on Github this morning. And, while I’m not finished with it, it works. I can see which day each date of the week is and that helps me. So now my Sunday morning’s will be a bit happier.

It turns out there is a plugin for this, which Sal Ferrarello linked me to in the BurbsWP Slack, called Publish Date DatePicker. I don’t think I found it because I searched terms like “scheduled posts” and “date picker” with a space in the name. Oh well. Now I have my own and I plan on improving upon it slightly before I roll it together as a release.

Update: To make sure you have the latest version of this plugin visit the releases page on Github.