Last active
June 3, 2018 05:00
-
-
Save akahigeg/0f9262769ab5a85061330378bdb47e5e to your computer and use it in GitHub Desktop.
functions.php for WordPress post guide.
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 | |
// 管理画面にCSSとJSの読み込みを追加 | |
function enqueue_post_guide_files() { | |
wp_enqueue_style('post-guide-style' , get_stylesheet_directory_uri() . '/css/post_guide.css'); | |
wp_enqueue_script('post-guide-js' , get_stylesheet_directory_uri() . '/js/post_guide.js'); | |
} | |
add_action('admin_enqueue_scripts', 'enqueue_post_guide_files'); | |
// 指定されたpost_idの投稿の投稿タイプを返す | |
function ajax_post_type_by_post_id() { | |
if ($_POST['post_type'] != '') { | |
// post_typeがわたってきた場合はそのまま返す | |
echo $_POST['post_type']; | |
} else { | |
// post_idがわたってきた場合は投稿タイプを判別して返す | |
echo get_post_type($_POST['post_id']); | |
} | |
die(); | |
} | |
add_action('wp_ajax_ajax_post_type_by_post_id', 'ajax_post_type_by_post_id'); | |
function ajax_post_guide_html() { | |
$guide_content_path = get_stylesheet_directory() . '/post_guide/' . $_POST['item_key'] . '.html'; | |
if (file_exists($guide_content_path)) { | |
$html = file_get_contents($guide_content_path); | |
} else { | |
$html = $guide_content_path; | |
} | |
echo $html; | |
die(); | |
} | |
add_action('wp_ajax_ajax_post_guide_html', 'ajax_post_guide_html'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment