wordpress add_submenu_page adds broken link

WordPress is doing exactly what you’re telling it to do. Refer to the Codex entry for add_submenu_page(). The functions arguments are like so: <?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); ?> So, you’re assigning the same string to $parent_slug and $menu_slug. For obvious reasons, these two need to be different. $parent_slug is the … Read more

Bug: Post needs to be updated twice when adding action for save_post hook

You’re doing several things wrong, and they’re all silly, avoidable, basic logic mistakes. Firstly, you’re not checking if this is an autosave. Autosaves do not save the custom fields, only the original core wordpress fields, like content, so an autosave will giv eyou unset/blank values. Add this to the top of your save function: if … Read more

Adding columns to core tables

Two Problems Problem #1 – You shouldn’t ever change the default schema that ships with WordPress. This schema might change in the future (entire tables could be dropped and re-built in an update). Problem #2 – You shouldn’t really be creating new tables in the first place. If you create a new table with your … Read more

Loading Modernizr (or other JavaScript libraries) for use in a plugin

wp_enqueue_script() utilizes the WP_Scripts class, which extends the WP_Dependencies class. If you checkout that class, you will see a bunch of arrays at the top. So you could actually loop through list of queued scripts like so: global $wp_scripts; // If inside a function foreach($wp_scripts->queue as $script) { // Do some tomfoolery here… 😉 } … Read more

How to pull user/author profile data in a plugin?

If you’re trying to get user data for the displayed profile, you can do it like so: $thisauthor = get_userdata(intval($author)); That’ll return an object filled with everything you need. For instance, if you need the user ID, you can call it like so: $thisauthor->ID I use this extensively on the profiles on my site: http://androidandme.com/user/clark … Read more