Created
March 12, 2012 19:31
-
-
Save micahwave/2024189 to your computer and use it in GitHub Desktop.
bitly processs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Cron to process all of the posts that don't have bitly urls | |
| */ | |
| function time_process_bitly() { | |
| global $wpdb; | |
| // get 100 published posts that don't have a bitly url | |
| $query = $wpdb->prepare( | |
| " | |
| SELECT $wpdb->posts.ID | |
| FROM $wpdb->posts | |
| WHERE NOT EXISTS ( | |
| SELECT ID | |
| FROM $wpdb->postmeta | |
| WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id | |
| AND $wpdb->postmeta.meta_key = 'time_bitly_url' | |
| ) | |
| AND $wpdb->posts.post_type = 'post' | |
| AND ( $wpdb->posts.post_status = 'publish' ) | |
| GROUP BY $wpdb->posts.ID | |
| ORDER BY $wpdb->posts.post_date DESC | |
| LIMIT 0, 100 | |
| " | |
| ); | |
| $posts = $wpdb->get_results( $query ); | |
| if( $posts ) { | |
| // process these posts | |
| foreach( $posts as $p ) { | |
| time_get_bitly_url( $p->ID ); | |
| } | |
| } else { | |
| // kill our scheduled event | |
| add_option( 'time_bitly_processed', 1 ); | |
| wp_clear_scheduled_hook( 'time_bitly_hourly_hook' ); | |
| } | |
| } | |
| add_action( 'time_bitly_hourly_hook', 'time_process_bitly' ); | |
| $bitly_processed = get_option( 'time_bitly_processed' ); | |
| if ( !wp_next_scheduled( 'time_bitly_hourly_hook' ) && !$bitly_processed ) { | |
| wp_schedule_event( time() + 300, 'hourly', 'time_bitly_hourly_hook' ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment