function set_meta_description() {
	global $post;
	$description = get_bloginfo('description');

	if ( is_category() ) {
		// アーカイブページでは、カテゴリーの説明文を取得
		$description = category_description();
	}
	elseif ( is_single() ) {
		if ( $post->post_excerpt ) {
			// 投稿記事、カスタム投稿では、記事本文から抜粋を取得
			$description = strip_tags($post->post_excerpt);
		} else {
			// 抜粋がない時は、記事の冒頭60文字を抜粋して取得
			$description = strip_tags($post->post_content);
			$description = str_replace("\n", "", $description);
			$description = str_replace("\r", "", $description);
			$description = mb_substr($description, 0, 60) . "...";
		}
	}
	echo esc_html($description);
}
/**
 * set meta url
 * og:url twitter:url
 */
function set_meta_ogurl() {
	if ( is_home() || is_front_page() ) {
		echo esc_url(home_url());
	} else {
		echo esc_url(home_url()) . htmlspecialchars($_SERVER["REQUEST_URI"], ENT_QUOTES, 'UTF-8');
	}
}


/**
 * set meta image
 * og:image twitter:image
 */
function set_meta_image() {
	$meta_image = get_stylesheet_directory_uri()."/asset/images/ogp.jpg";
	if (is_single()||is_page()) {
		if (has_post_thumbnail()) {
			$image_id = get_post_thumbnail_id();
			$image = wp_get_attachment_image_src( $image_id, 'full');
			$meta_image = $image[0];
		}
	}
	echo esc_url($meta_image);
}
/**
 * 投稿画面のカテゴリー選択部分「新規カテゴリーを追加」と「よく使うもの」を非表示
 */
function hide_category_tabs_adder() {
  global $pagenow;
  global $post_type;
  if ( is_admin() && ($pagenow=='post-new.php' || $pagenow=='post.php') ) {
    echo '<style type="text/css">
    #category-tabs, #category-adder {display:none;}
    #menu_ctg-tabs, #menu_ctg-adder {display:none;}

    .categorydiv .tabs-panel {padding: 0 !important; background: none; border: none !important;}
    </style>';
  }
}
add_action( 'admin_head', 'hide_category_tabs_adder' );
/**
 * 固定ページではビジュアルリッチエディタを表示しない
 */

function my_default_editor( $r ) {
	if ( 'page'== get_current_screen()->id ) {
		return false;
	}
	return $r;
}
add_filter('user_can_richedit' , 'my_default_editor');
/**
 * RSS配信設定
 */
function custom_post_rss_set($query) {
    if(is_feed()) {
		$query->set('post_type',Array('news'));
        return $query;
    }
}
add_filter('pre_get_posts', 'custom_post_rss_set');

/**
 * アイキャッチ画像表示
 */
add_theme_support('post-thumbnails');

/**
 * テーマディレクトリショートコード[tp]
 */
add_shortcode( 'tp', 'shortcode_tp' );
function shortcode_tp( $atts, $content = '' ) {
	return get_template_directory_uri().$content;
}


/**
 * home url ショートコード[home]
 */
add_shortcode( 'home', 'shortcode_home' );
function shortcode_home() {
	return home_url();
}
/**
 * ファイルサイズ取得 echo get_filesize( 'ファイルのパス' )
 */
if ( ! function_exists( 'get_filesize' ) ) {
  function get_filesize( $file_path ) {
    $file_fullpath = str_replace( site_url(), ABSPATH, $file_path );
    if ( is_file( $file_fullpath ) ) {
      $file_size = size_format( filesize( $file_fullpath ) );
      return $file_size;
    }
  }
}
/**
 *ログイン画面のカスタマイズ
 */
function my_login_logo_url() {
    return home_url();
}
add_filter( 'login_headerurl', 'my_login_logo_url' );

function my_login_logo() { ?>
    <style type="text/css">
        body.login div#login h1 a {
            background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/asset/images/common/logo.png);width:320px;height:59.5px;background-size:320px 59.5px;
            padding-bottom: 30px;
        }
    </style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );
