Created
October 22, 2011 17:47
-
-
Save brandondove/1306271 to your computer and use it in GitHub Desktop.
This method gets called on the admin_print_scripts hook. For some reason, the months array works on wp3.3 (trunk), but not on wp3.2.1.
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
<?php | |
function admin_print_scripts() { | |
if( get_post_type() == $this->type || get_query_var('post_type') == $this->type ) : | |
wp_enqueue_script( 'ads-admin' ); | |
// BEGIN hack to highlight expired/expiring ads | |
$now = time(); | |
$expired_ads = get_posts( | |
array( | |
'post_type' => 'ads', | |
'meta_query' => array( | |
array( | |
'key' => '_end_date', | |
'value' => $now, | |
'type' => 'numeric', | |
'compare' => '<' | |
) | |
), | |
'nopaging' => true | |
) | |
); | |
$expired_selectors = array(); | |
foreach( $expired_ads as $expired_ad ) : | |
$expired_selectors[] = '#post-'.$expired_ad->ID; | |
endforeach; | |
$expiring_ads = get_posts( | |
array( | |
'post_type' => 'ads', | |
'meta_query' => array( | |
array( | |
'key' => '_end_date', | |
'value' => array( $now, $now + ( 60 * 60 * 24 * 7 ) ), | |
'type' => 'numeric', | |
'compare' => 'BETWEEN' | |
) | |
), | |
'nopaging' => true | |
) | |
); | |
$expiring_selectors = array(); | |
foreach( $expiring_ads as $expiring_ad ) : | |
$expiring_selectors[] = '#post-'.$expiring_ad->ID; | |
endforeach; | |
wp_localize_script( | |
'ads-admin', | |
'adsanity', | |
array( | |
'expired_ads' => implode( ', ', $expired_selectors ), | |
'expiring_ads' => implode( ', ', $expiring_selectors ), | |
'adsanity_eol' => ADSANITY_EOL, | |
'months' => array( | |
__( 'January', 'adsanity' ), | |
__( 'February', 'adsanity' ), | |
__( 'March', 'adsanity' ), | |
__( 'April', 'adsanity' ), | |
__( 'May', 'adsanity' ), | |
__( 'June', 'adsanity' ), | |
__( 'July', 'adsanity' ), | |
__( 'August', 'adsanity' ), | |
__( 'September', 'adsanity' ), | |
__( 'October', 'adsanity' ), | |
__( 'November', 'adsanity' ), | |
__( 'December', 'adsanity' ), | |
) | |
) | |
); | |
// END hack to highlight expired/expiring ads | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment