posts in the category: Hacking

Posted by: bob on Thursday September 15th 2011 no comments
Tags: events, publish_future_post, publish_post

This problem has been bothering me for a while now, and I only just came across the solution this week. The issue was that when you schedule a post for the future, when it does finally post it was seemingly not running the publish_post hook that I had set. Multiple solutions suggested using future_to_publish as a hook, and that did not work either. The actual solution was to hook to publish_future_post, but in addition the function I was executing had to be modified a bit.

The original function was something along these lines: When a post is published for the first time, post a link to it on Twitter. publish_post also fires when you update a post, so to make sure it was only posted on the original posting the accepted solution was to make sure post_date and post_modified dates were equal. Here is an simple example.

PHP Code:
<?php

// accepted solution, but this will not work as expected
// on scheduled posts.

add_action('publish_post','bob_on_publish_post');
add_action('publish_future_post','bob_on_publish_post');

function 
bob_on_publish_post($id) {
    
$post get_post($id);
    if(
$post->post_modified != $post->post_date) return;
    
    
// la de da, doing stuff.
    
    
return;    
}

?>

The reason this fails is that it turns out when a post is scheduled for future posting, post_date and post_modified are not equal after all. This issue caught me by surprise because it does not exist when working with Drafts. If the post is marked as draft, saved, and then manually published later, this test will still allow the hook to run. This is probably due to how WordPress handles filling up your database with redundant revisions, but it even works if you have a Plugin disabling revisions (like me).

Continue reading about the scheduled publish hook…

Posted by: bob on Wednesday March 23rd 2011 no comments
Tags: filters

I have made three observations on my own platforms related to the return of the admin bar in WordPress 3.1. First, it is annoying. Second, I have noticed a considerable slowdown in the page’s ability to render while it is being displayed, and oddly it seems to actually lag a bit in the processing too though I have no benchmarks to prove that. Third, I have noticed it breaking a lot of themes. Sometimes web development does not make sense and you just have to go with the answer “I hate it”, so here is how to get rid of that floating top admin bar on your theme.

Open up your theme’s functions.php file and drop this line in there. I added mine near the top.

PHP Code:
<?php

add_filter
('show_admin_bar','__return_false');

?>

Continue reading…

Posted by: bob on Monday March 21st 2011 no comments
Tags: filters, tags

I like all my categories to be structured pretty, and with nicely formatted words. I like my tags to be quick and all lowercase. After spending too much time fighting WordPress for duplicate slugs (e.g. multiple “PHP” categories and a “php” tag) I gave up on that. I decided to let WordPress have its category and tag both be the same “term”. The problem now is that all my tags looked nice except for a few, which were uppercased matching the category names they conflicted with.

After a little bit of filter debauchery, I crafted up this simple enough solution.

Continue reading…