Wordpress drill-down admin pages II

January 18, 2010

wordpress-logo-300x300I never did do a follow-up on the Wordpress drill-down admin menus post. A lot of people continue to hit that article so I’ll take the time to give an example of how I easily resolved the issue.

The problem was that after an upgrade to Wordpress Mu v 2.8.4a all my dynamically created, drill-down admin pages quit working because they now needed to be registered with Wordpress for — completely understandable — security reasons.  As far as I can tell, the only way to register an admin page is through the menu system. Since I don’t want my drill down pages to be on the menu I needed a better way to do it.

One solution suggested was to just use the registered menu page as the callback to handle requests and that is for the most part what I did. The only issue with the solution is that the callback page has to also serve all the content since it can’t request an admin page that is not registered. Using one page to parse all requests and serve the appropriate content will get unwieldy for anything but the simplest of applications and if your application was that simple you wouldn’t be trying to figure out how to add custom drill-down admin menus.

I like modularity and easily managed code so my philosophy is that multiple small files are better than one huge file. I needed a way to solve the problem without breaking my philosophy or changing a lot of my existing code, which was already in multiple small files.

The idea is to build a container page to register on the admin menu and have the container page decide on which code to include based on analyzing the url. The included code can then handle and GET or POST requests and serve the appropriate page output.

<?php
/*
 * Descrition: gcgc admin page. This is the main container page
 * for all admin panels. All POSTS and GETS from all pages route
 * through this page and are handled by the appropriate included file.
*/
global $gcgc_Manager;
echo $gcgc_Manager->getHeader();
//analyze the url to determine which page to load

if (isset($_GET['panel'])){
    switch ($_GET['panel']){

    	case 'cache-admin' :
    	    include (dirname(__FILE__)."/gcgc-admin-cache.php");
    			break;

    	case 'vector-admin' :
           include (dirname(__FILE__)."/gcgc-admin-vector.php");
           break;

    	default :
           include (dirname(__FILE__)."/gcgc-admin-home.php");
    }
}else{
    include (dirname(__FILE__)."/gcgc-admin-home.php");
}

$gcgc_Manager->getFooter();
?>

I kept the above example brief but you can imagine that there can be an unlimited number of admin pages. And this way I didn’t have to change the included files at all — all I had to do was add the ‘&panel=’ parameter to existing request urls and problem solved.

  • Share/Bookmark

MySQL Upgrade: 1and1 is not the best host in the world

March 3, 2009

mysqladminLast night I upgraded the MySQL database behind this site from version 4 to 5. I needed to test the process before I upgrade the Gulf Coast Texas Magazine site. If I dig around in the documentation at 1and1 I could probably tell from which version to which, but the options on the setup menu are MySQL 4 or MySQL 5.  Suffice to say the version 4  was low enough that the Simple:Press forum plugin for WordPress wouldn’t install. Even if I don’t ultimately use the plugin, I simply have to look under the hood of that bad boy.

The worst thing about the whole MySQL upgrade process — which involves dumping the schema and data from the version 4 database into a SQL file and then running the SQL dump on a new, empty MySQL version 5 database — was that 1and1 had difficulty managing the upload of the SQL dump file and then running the SQL. When I uploaded the file it took forever and finally reported complete but there were no tables — still an empty database. I tried it twice. Took forever twice. Twice no tables.

So I manually split the SQL dump file into several little chunks and built the version 5 database a wee bit at a time. How ridiculous is that when the entire process should have taken five minutes, ten at the most, but your hosting service provider sucks so bad that the job required a couple of hours. Hard for a developer to make money that wy.

It says in the 1and1 documentation:

Note: If the database export does not work correctly you can try to export one table at a time. Select the table from the left side of the MySQL Administration screen and click Export.

Lame. So I guess I’m not surprised. How hard could it be to simply make the feature work?

The faq’s that I found confirming that there is no automatic process to upgrade a database are hard to find on the 1and1 search, you need to use another, real  search engine to find the information. You can check these if interested in the 1and1 MySQL upgrade process –> Export, Import

But here is the real complaint. After the long ordeal descibed above I finally had the entire database loaded so I edited my wp-config to point to the new database and it’s like nothing ever happened… Except that there seems to be a bunch of funny capital A’s with little hats  all throughout the text of every post. And that sucks.

  • Share/Bookmark

Get a list of MySQL tables

February 14, 2009

If you ever need to access the system wide schema info for a MySQL server, check out this very nice diagram of the MySQL Information_Schema.

What can you do with this information? Well, lots of stuff. For example you can get a list of tables and columns for a particular database, like

SELECT table_name, column_name, data_type [,...]
FROM information_schema.columns
WHERE table_schema = dbname;

Which could be handy for any number of reasons, such as seeing if a table or exists or if a column exists in a table, etc.

  • Share/Bookmark

Why execute php from a Wordpress Mu post

February 13, 2009

In the previous post I mentioned some issues with injecting php into a Wordpress Mu blog post. Some people probably don’t understand why would you want to execute php code from inside a blog post. Well the most obvious answer now that I’ve done some research and what seems to be the primary concern of Jim Groom and the many followers of the issue is the ability to configure and display dynamically aggregated RSS feeds for posts as well as doing some fancy stuff in the widgets. I can imagine the possibilities are endless.

But the obvious reason isn’t what initially got me started on the search to execute php from inside a post or page. I want to be able to add a set of custom fields to certain categories of posts and then execute sql commands against them. For example on an outdoor photography blog, for all posts in the ‘Trip Report’ category I might add some fields called ‘location’,  ‘mileage’, ‘meals’, ‘fuel’, ‘other_expenses’.  Then I could have a page called ‘Trip Expenses’ that would query all the Trip Report posts and display the results in tables, charts, and/or graphs. A Wordpress page with embedded php could create  fancy charts and graphs laid out however you like, like the Quickbooks dashboard, for example.  The page would re-calculate every time it’s opened. How sweet is that?

Another example:  On a blog chronicling a fitness program I could add custom fields to the ‘Daily Workout’ posts like ‘exercise_type’, ‘total_distance’, ‘total_time’, ‘5k_time’, ‘peak_heart_rate’, ‘two_min_recovery_heart_rate’, ‘etc…’. Then I could have a Page called ‘Treadmill Progress Report’ or ‘Bench Press Progress Report’ that spits out graphs based on the fields in all the Daily Workout posts.

Using this technique you could easily build simple database applications within a wordpress blog. You could also build large, complex applications like this but that would be silly, wouldn’t it?

  • Share/Bookmark

Versatility using symbolic links

August 27, 2007

I noticed over the weekend that my domain dcdo isn’t working. The tip off was that I wasn’t getting any spam in my inbox. How likely is that not to happen, really? Ping returns the new IP address but doesn’t reply. Probably some further adjustment to the DNS records needs to be made.

I haven’t taken the time to mess with the DNS issues because I haven’t been here much except for on weekends and this past weekend I was busy trying to figure out how to run WordpressMU; the multi-blog, mult-user version of the software I am running now. This is a key step in the process of changing my infrastructure from Domino to hosted WordPress. It wont be any fun maintaining and posting to a half-dozen or so blogs that each have a seperate installation.

Like on the other thing I got it working half-assed but then I had to keep tinkering with it to make it work how I want it too. The closest configuration I found as a model was from Dan Frey at the Office of the Provost Web Team blog at the University at Buffalo:

“Our situation is interesting, but I would not call it unique. We have a server that has multiple domains pointed at it. We installed MU in a directory off of the root of our server, /wordpressmu. Our default domain name is ugly – the idea was that we wanted folks to be able to go to nicedomain.buffalo.edu and get to their blog on our server.

Easier said than done…

Yep pretty much what I’ve found out. My situation is the same except I want to point any domain to any blog regardless of where the blog is and regardless of where the domain is. This is what I have so far:

Domain setup

I know the symlinks are the way to go and that’s how I found Dan Frey’s article–by Googling wordpress mu symbolic link. I’m pretty sure Dan has it figured out I just have to tinker with it some more.

But dang I can’t mess around with it forever. It’s one of those deals that I’ll have to revisit after I get a few other things worked out, like my damn mailserver at dcdo.

  • Share/Bookmark