Nip over to Otto’s blog and read his post entitled don’t include wp-load, please which I’m in complete and total agreement with. I’d like to add to the solutions with the following method of adding data to your page for use by your plugin’s JavaScript: wp_localize_script. Continue reading ‘Including data in the page for your plugin’s JavaScript’
Tag Archive for 'wordpress'
I have a client with a lot lot lot lot of WordPress sites, and I’m helping them craft a strategy for dealing with WordPress throughout their business. One thing we wanted to do was to take stock of all the plugins they have installed on all their sites, work out how many are in common, understand if any have security issues and so forth. Logging into hundreds of WordPress sites, even if we did have their login details, isn’t my idea of fun so I hacked some of the WordPress plugin functions to output a report on any plugins it finds in a directory. Continue reading ‘Taking stock’
So WordPress 3.0 is out, and some of the useful admin area load-* hooks that I use have vanished or changed. To refresh your memory, there are individual and specific hooks which run whenever WordPress loads an admin page. These hooks are named after the PHP file in the URL to the admin page, for example the URL to create a new post is post-new.php so the action you can hook when this page is loaded is “load-post-new.php“. All good. Very handy.
In WordPress 3.0 the URLs to create a post and edit a post are now all post-new.php and post.php, with the post type being passed in a GET parameter like so: post-new.php?post_type=page… i.e. load-page-new.php and load-page.php action hooks have both vanished! Never fear, there are two ways around this problem, read on… Continue reading ‘Eeek! The load-page-new.php and load-page.php actions have vanished!’
The lovely Thickbox jQuery plugin appears to no longer be supported by it’s creator, Cody Lindley, but it’s included with WordPress (it provides the “popup” overlays in the post editor for uploading and inserting images and other media), very flexible and that’s good enough reason for me to use it for the time being.
I’ve always been a bit shy of using Thickbox in the front end of WP sites, as the close button and loading animation paths are hard-coded relative to the WP admin area… in short, they don’t work at the front without tinkering. Today I realised that the required tinkering was (relatively) trivial, so here’s my code for including thickbox at the front end, you can drop it into the functions.php of your theme or make it into a plugin.
function my_load_thickbox() {
add_thickbox();
?>
<script type="text/javascript">
/* <![CDATA[ */
var tb_pathToImage = '<?php echo esc_js( includes_url( '/js/thickbox/loadingAnimation.gif' ) ); ?>';
var tb_closeImage = '<?php echo esc_js( includes_url( '/js/thickbox/tb-close.png' ) ); ?>';
/* ]]> */
</script>
<?php
}
add_action( 'wp_head', 'my_load_thickbox', 0 );
Taking this section by section:
The add_thickbox function is a wrapper for adding the styling and script for Thickbox; the style gets added to the HTML HEAD element, and the script is added to the footer.
The script block is where the Thickbox image paths are corrected, the technique works because the WP Thickbox script checks if these two paths are set a JS vars before it sets them and uses any pre-existing values. Because the vars in the function above are set before the Thickbox script is loaded (the script has been added to the footer, remember) we are able to override and set some paths which will work on the front end of a WP site. The include_urls function is a handy way to reference some code inside the wp_includes directory (which the two Thickbox images are). The esc_js escapes text for a JS context, it’s included to prevent something hairy and completely unexpected getting into the JS and making a security mess everywhere (it’s always a good idea to escape anywhere and everywhere you can).
Here’s the code in a separate file, which you may find easier to read: thickboxing.phps
(One gotcha: because the scripts are added to the footer, your theme must include a wp_footer action.)
So you’ve migrated a bunch of users over from another system and then, horror, you discover that they don’t have roles in WordPress. The WP Users admin screen doesn’t cope with this issue (why should it), so the only option would be to go through and manually select the roles for each user with no role… fine, right? Except I just migrated 8,000 ish users and there’s no way my meta carpels will take that abuse. This plugin finds any users on your system with no role and gives them the role of ‘subscriber’, it does this in batches of 1,000 users per page load and once it has finished it replaces your entire blog with a message saying it’s finished… so don’t leave it running unattended kids, eh? (I know that’s rude, but coding “echo ‘blah; exit;’ is SO much quicker and it’s only a dirty data migration tool.
You can download the source here: Fix Users with No Role – Data Migration tool as WordPress plugin
Need to edit many posts at once in WordPress? Is the standard limit of 15 posts on the Posts Edit screen just not enough for you? Well, there is a hack you might be interested in. This involves editing the core WP files, so is not recommended as a permanent solution or for production sites… it works for me, but it might kill your cat and devastate the area around your home. You have been warned. Continue reading ‘Editing many posts at once in WordPress’
There are a number of really handy hooks, each of which are specific to a page in the WordPress admin area. You can use these action hooks to enqueue scripts on particular pages, to process form requests, etc, etc.
Despite these hooks being so handy, and despite using them a great deal, every time I want to use one I have to dig through the code to try and work out how they work and what they’re called… so for my own benefit, here’s what I think is a complete list: Continue reading ‘Page load hooks in the WordPress admin area’
I’ve spent quite a bit of time over the last week getting to grips with custom taxonomies in WordPress, and I’m really pleased with what I’ve found. A taxonomy is a classification, and WordPress already has two taxonomies buil in: tags and categories. Categories lean towards a more formal taxonomy, which you might setup with forethought and some planning, whereas tags lean more towards a more casual folksonomy, which you might construct “on the wing” in a less formal and more ad hoc style. WordPress uses a generic taxonomy setup to create the tag and category taxonomies, and you can use the same functions to create your own taxonomies.
I’m going to take you through the process of creating a basic taxonomy, creating some terms in it and relating those terms to some posts. There’s some demonstration code in the form of a proof of concept WordPress plugin, which you may find helpful.
Live text streams for the National Care Service
We were approached by the Department of Health to further enhance their WordPress based website for the launch of theĀ National Care Service. The launch was to have a live web video stream and The Department of Health wanted live text updates to accompany the video. The text updates would allow late comers to catch up, mean the launch team could provide annotations, links and accompanying materials as the launch progressed, and would provide a text record of the event afterwards. The projected maximum audience for this event reached well into the thousands, so the solution we provided would have to scale appropriately, while not consuming so many resources that the webserver could not fulfil it’s other duties (like serving other pages and so forth).
Continue reading ‘Live text streams for the National Care Service’