Navigation Menu

Skip to content
This repository has been archived by the owner on Oct 4, 2017. It is now read-only.

Commit

Permalink
jsonp support
Browse files Browse the repository at this point in the history
  • Loading branch information
benbalter committed Jul 5, 2012
1 parent c7dfa53 commit 7348c07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions includes/boilerplate-classes/enqueue.php
Expand Up @@ -90,11 +90,11 @@ function enqueue_js( $name ) {

$data = str_replace( '-', '_', $name . '_data' );
$this->$data = apply_filters( 'localize_script', $this->$data, $name );

if ( empty( $this->$data ) )
if ( empty( $this->data ) )
return;

wp_localize_script( $this->parent->slug, $this->parent->slug_, $this->$data );
wp_localize_script( $this->parent->slug, $this->parent->slug_, $this->data );

}

Expand Down
10 changes: 9 additions & 1 deletion templates/resume-json.php
Expand Up @@ -85,8 +85,16 @@

$output = apply_filters( 'json_resume', $output );

//check for callback and sanitize
//http://stackoverflow.com/a/10900911/1082542
$callback = ( isset( $_GET['callback'] ) ) ? $_GET['callback'] : false;

if ( preg_match( '/[^0-9a-zA-Z\$_]|^(abstract|boolean|break|byte|case|catch|char|class|const|continue|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|volatile|void|while|with|NaN|Infinity|undefined)$/', $callback) )
$callback = false;

//push json output to browser
echo json_encode($output);
$json = json_encode($output);
echo ( $callback ) ? "{$callback}($json)" : $json;

//reset WP query
wp_reset_query();

0 comments on commit 7348c07

Please sign in to comment.