Skip to content

Instantly share code, notes, and snippets.

@yurivictor
Created October 25, 2012 14:43
Show Gist options
  • Save yurivictor/3952957 to your computer and use it in GitHub Desktop.
Save yurivictor/3952957 to your computer and use it in GitHub Desktop.
wp_localize_script example
/**
* Enqueue the necessary CSS and JS that liveblog needs to function.
*
* @return If not a liveblog post
*/
public static function enqueue() {
// Only add files files if post is a liveblog
global $post;
if ( ! is_singular() && false === strpos( $post->post_content, '[liveblog]' ) )
return;
//css
wp_enqueue_style( self::key, plugins_url( '/css/liveblog.css', __FILE__ ), null, self::version );
//js
wp_enqueue_script( self::key, plugins_url( '/js/underscore-min.js', __FILE__ ), null, self::version, false );
wp_enqueue_script( self::key, plugins_url( '/js/backbone-min.js', __FILE__ ), null, self::version, false );
wp_enqueue_script( self::key, plugins_url( '/js/liveblog.js', __FILE__ ), null, self::version, false );
wp_localize_script( self::key, 'liveblog_settings',
apply_filters( 'liveblog_settings', array(
'url' => get_bloginfo( 'wpurl' ),
'post_parent' => get_the_id(),
'latest_timestamp' => self::$entry_query->get_latest_timestamp(),
'pages' => self::$entry_query->get_page_count(),
'live' => get_post_meta( get_the_id(), '_liveblog_active', true ),
'key' => self::key,
'nonce_key' => self::nonce_key,
'timeout' => self::timeout,
) )
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment