Skip to content

Instantly share code, notes, and snippets.

@brandondove
Created October 22, 2011 17:47
Show Gist options
  • Save brandondove/1306271 to your computer and use it in GitHub Desktop.
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.
<?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