// 画像ディレクトリを取得しショートコードを作成する
function get_image_dir() {
return get_bloginfo('template_directory');
}
add_shortcode( 'get_image_dir', 'get_image_dir' );
// 絶対URLを取得しショートコードを作成する
function get_root_url() {
return esc_url(home_url('/'));
}
add_shortcode( 'get_root_url', 'get_root_url' );
// 固定ページのみ自動整形機能を無効化します。
function disable_page_wpautop() {
if ( is_page() ) remove_filter( 'the_content', 'wpautop' );
}
add_action( 'wp', 'disable_page_wpautop' );
// 固定ページではビジュアルエディタを利用できないようにする
function disable_visual_editor_in_page(){
global $typenow;
if( $typenow == 'page' ){
add_filter('user_can_richedit', 'disable_visual_editor_filter');
}
}
//PCでのみ表示するコンテンツ
function if_is_pc($atts, $content = null ) {
$content = do_shortcode( $content);
if(!wp_is_mobile()) {
return $content;
}
}
add_shortcode('pc', 'if_is_pc');
//スマートフォン・タブレットでのみ表示するコンテンツ
function if_is_nopc($atts, $content = null ) {
$content = do_shortcode( $content);
if(wp_is_mobile()) {
return $content;
}
}
add_shortcode('sp', 'if_is_nopc');
// 選択できるカテゴリを1つだけにする
function limit_category_select() {
?>
insert( 'wp_schedules', array(
'department' => intval($post_data['department']),
'time' => intval($post_data['time' ]),
'uketsuke' => intval($post_data['uketsuke' ]),
'mon' => esc_str($post_data['mon']),
'tue' => esc_str($post_data['tue']),
'wed' => esc_str($post_data['wed']),
'thu' => esc_str($post_data['thu']),
'fri' => esc_str($post_data['fri']),
'sat' => esc_str($post_data['sat']),
), array('%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s'));
$inset_id = $wpdb->insert_id;
return $result;
}
// 診療時間更新SQL
function update_schedule($post_data){
global $wpdb;
//更新したい内容(post_statusを更新する)
$data = array(
'department' => intval($post_data['department']),
'time' => intval($post_data['time' ]),
'uketsuke' => intval($post_data['uketsuke' ]),
'mon' => esc_str($post_data['mon']),
'tue' => esc_str($post_data['tue']),
'wed' => esc_str($post_data['wed']),
'thu' => esc_str($post_data['thu']),
'fri' => esc_str($post_data['fri']),
'sat' => esc_str($post_data['sat']),
'delete_flg' => intval($post_data['delete_flg']),
);
//更新したい行の条件
$condition = array(
'id' => $post_data['id'],
);
$dataFormat = array('%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d');
$conditionsFormat = array('%d');
$result = $wpdb->update('wp_schedules', $data, $condition,$dataFormat,$conditionsFormat);
return $result;
}
// 診療時間一覧取得SQL
function get_schedules(){
global $wpdb;
$sql = "SELECT "
. "* "
. "FROM "
. " wp_schedules "
. "WHERE "
. " delete_flg = 0 "
. "ORDER BY "
. "id ASC ";
$result = $wpdb->get_results($sql, ARRAY_A);
return $result;
}
// IDをキーに診療時間を1件取得するSQL
function get_schedule_one($id){
global $wpdb;
$sql = "SELECT "
. "* "
. "FROM "
. " wp_schedules "
. "WHERE "
. " delete_flg = 0 and "
. "id = ".$id.";";
$result = $wpdb->get_results($sql, ARRAY_A);
return $result[0];
}
// 科別診療時間取得SQL
function get_schedule_department($dpt){
global $wpdb;
$sql = "SELECT "
. "* "
. "FROM "
. " wp_schedules "
. "WHERE "
. " delete_flg = 0 and "
. " department = ".$dpt.";";
$result = $wpdb->get_results($sql, ARRAY_A);
return $result;
}
// 受付IDをキーに日本語に変換する
function chk_uketsuke($uid) {
$uketsukeArray = array('', '当日受付', '当日受付①', '当日受付②', '当日受付③', '予約診療');
return $uketsukeArray[$uid];
}
// 診療時間更新
function scheduleedit() {
// GETパラメーターがあれば更新ページのテンプレートの読み込み
if(isset($_GET['id'])){
include_once get_template_directory()."/admin-template/admin-scheduleedit.php";
} else {
// それ以外(更新完了時などリダイレクトせずに一覧ページを表示したいときなど)
include_once get_template_directory()."/admin-template/admin-schedulelist.php";
}
}
// HTMLタグの除去&エスケープ+改行コード変換を行う
function esc_str($str) {
$str = strip_tags($str);
$text = nl2br($str);
return $text;
}
// 管理ページにスラッグ名を表示したい
function add_page_columns_name($columns) {
$columns['slug'] = "スラッグ";
return $columns;
}
function add_page_column($column_name, $post_id) {
if( $column_name == 'slug' ) {
$post = get_post($post_id);
$slug = $post->post_name;
echo attribute_escape($slug);
}
}
add_filter( 'manage_pages_columns', 'add_page_columns_name');
add_action( 'manage_pages_custom_column', 'add_page_column', 10, 2);
// 自動的に挿入されるスクリプトタグからタイプを消す
function remove_script_type($tag) {
return str_replace("type='text/javascript' ", "", $tag);
}
add_filter('script_loader_tag','remove_script_type');