Last active
March 6, 2016 14:49
-
-
Save fukasawah/a752c5bde01fa5ea3fa0 to your computer and use it in GitHub Desktop.
【WP】プレビュー画面に任意のJSやデータを送り込むサンプル
This file contains 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
class aaaa{ | |
public function __construct() | |
{ | |
add_action('wp_head', array( | |
$this,'register_preview_header' | |
)); | |
} | |
public function register_preview_header() | |
{ | |
if (! is_preview()) { | |
return; | |
} | |
wp_enqueue_script('vue', plugins_url('js/vender-libs/vue.js', __FILE__)); | |
wp_enqueue_script('preview-editor', plugins_url('js/preview-editor.js', __FILE__)); | |
wp_localize_script('preview-editor', '_meta_post_data', | |
array('article' => array( | |
'description' => 'テスト' | |
) | |
)); | |
} | |
} |
This file contains 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
if(undefined === _meta_post_data){ throw new Exception("_meta_post_data is not defined") } // check defined. | |
jQuery(function($){ | |
var entryContentVue = new Vue({ | |
el: 'article > .entry-content', | |
template: '<div>これはVueで書き換えたものです. {{article.description}}</div>', | |
data: _meta_post_data | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment