Last active
September 16, 2015 13:33
-
-
Save kurozumi/bc2a674cb7d783e136f5 to your computer and use it in GitHub Desktop.
【ワードプレス】テーマフォルダのパスを取得するショートコード作成とビジュアルモードでショートコードを展開するプラグイン
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
<?php | |
/* | |
Plugin Name: Template Url ShortCode | |
Version: 0.1-alpha | |
Description: Template Url ShortCode | |
Author: kurozumi | |
Author URI: http://a-zumi.net | |
Plugin URI: http://a-zumi.net | |
Text Domain: template-url-shortcode | |
Domain Path: /languages | |
*/ | |
$tpl_url_shortcode = new TemplateUrlShortCode; | |
$tpl_url_shortcode->register(); | |
class TemplateUrlShortCode | |
{ | |
public function register() | |
{ | |
add_action('plugins_loaded', array($this, 'plugins_loaded')); | |
} | |
public function plugins_loaded() | |
{ | |
// 新規投稿と投稿ページのみ反映 | |
add_action('admin_head-post-new.php',array($this, 'add_mce_external_plugins')); | |
add_action('admin_head-post.php' ,array($this, 'add_mce_external_plugins')); | |
// ショートコード | |
add_shortcode('template_url', array($this, 'template_url')); | |
} | |
public function template_url() | |
{ | |
// 子テーマに対応させるためget_stylesheet_directory_uri()を使う | |
return get_stylesheet_directory_uri(); | |
} | |
function add_mce_external_plugins() | |
{ | |
// ビジュアルリッチエディターの場合 | |
if (get_user_option('rich_editing') == 'true') { | |
add_filter("mce_external_plugins", array($this, "mce_external_plugins")); | |
// 子テーマに対応させるためget_stylesheet_directory_uri()を使う | |
$tpl_url = get_stylesheet_directory_uri(); | |
echo <<< EOF | |
<script type='text/javascript'> | |
var tpl_url = '{$tpl_url}'; | |
</script> | |
EOF; | |
} | |
} | |
// tinymceにエディタープラグインを追加する | |
public function mce_external_plugins() | |
{ | |
$plugin_array['tpl_url_conv'] = plugin_dir_url(__FILE__) . 'tpl-url-editor-plugin.js'; | |
return $plugin_array; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment