';
}
return $picture_source . $picture_img;
}
/**
* 投稿の背景画像IDを取得
* rerurn: idあれば intで返す URLあれば文字列で返す
*/
public static function get_post_ttlbg_id( $post_id ) {
$meta = get_post_meta( $post_id, 'swell_meta_ttlbg', true );
if ( false !== strpos( $meta, 'http' ) ) {
// まだ画像のとき
$id = attachment_url_to_postid( $meta );
// idに変換できなければURLのまま返す
if ( ! $id ) return $meta;
// IDで再保存
$updated = update_post_meta( $post_id, 'swell_meta_ttlbg', (string) $id );
if ( ! $updated ) return $meta;
} else {
$id = $meta;
}
if ($id ) return absint( $id );
// デフォルト画像
$id = self::get_setting( 'ttlbg_dflt_imgid' );
if ($id ) return absint( $id );
// デフォルト画像 URLでのデータだけ残ってしまっている場合
$url = self::get_setting( 'ttlbg_default_img' );
if ( $url ) return $url;
// アイキャッチ
$id = get_post_thumbnail_id( $post_id );
if ($id ) return absint( $id );
// NOIMAGE
return self::get_noimg( 'id' ) ?: self::get_noimg( 'url' );
}
/**
* タームの背景画像IDを取得
*/
public static function get_term_ttlbg_id( $term_id ) {
$meta = get_term_meta( $term_id, 'swell_term_meta_ttlbg', 1 );
if ( false !== strpos( $meta, 'http' ) ) {
$id = attachment_url_to_postid( $meta );
// idに変換できなければURLのまま返す
if ( ! $id ) return $meta;
$updated = update_term_meta( $term_id, 'swell_term_meta_image', (string) $id );
if ( ! $updated ) return $meta;
} else {
$id = $meta;
}
if ($id ) return absint( $id );
// デフォルト画像
$id = self::get_setting( 'ttlbg_dflt_imgid' );
if ($id ) return absint( $id );
// デフォルト画像 URLでのデータだけ残ってしまっている場合
$url = self::get_setting( 'ttlbg_default_img' );
if ( $url ) return $url;
// アイキャッチ
$id = self::get_term_thumb_id( $term_id );
if ($id ) return absint( $id );
// NOIMAGE
return self::get_noimg( 'id' ) ?: self::get_noimg( 'url' );
}
/**
* タームのアイキャッチ画像IDを取得
*/
public static function get_term_thumb_id( $term_id ) {
$meta = get_term_meta( $term_id, 'swell_term_meta_image', 1 );
if ( false !== strpos( $meta, 'http' ) ) {
$id = attachment_url_to_postid( $meta );
// idに変換できなければURLのまま返す
if ( ! $id ) return $meta;
$updated = update_term_meta( $term_id, 'swell_term_meta_image', (string) $id );
if ( ! $updated ) return $meta;
}
return absint( $meta );
}
/**
* SNS CTAのデータ
*/
public static function get_sns_cta_data() {
$cached_data = wp_cache_get( 'sns_cta_data', 'swell' );
if ( $cached_data ) return $cached_data;
$data = apply_filters( 'swell_get_sns_cta_data', [
'tw_id' => self::get_setting( 'show_tw_follow_btn' ) ? self::get_setting( 'tw_follow_id' ) : '',
'fb_url' => self::get_setting( 'show_fb_like_box' ) ? self::get_setting( 'fb_like_url' ) : '',
'insta_id' => self::get_setting( 'show_insta_follow_btn' ) ? self::get_setting( 'insta_follow_id' ) : '',
] );
wp_cache_set( 'sns_cta_data', $data, 'swell' );
return $data;
}
/**
* ページ種別スラッグ(キャッシュ用)
*/
public static function get_page_type_slug() {
if ( self::is_top() && ! is_paged() ) {
return 'top';
} elseif ( is_single() ) {
return 'single';
} elseif ( is_page() ) {
return 'page';
} elseif ( is_archive() || is_home() ) {
return 'archive';
} else {
return 'other';
}
}
/**
* Google font
*/
public static function get_google_font() {
$google_font = '';
$body_font = self::get_setting( 'body_font_family' );
if ( ! self::is_android() && 'notosans' === $body_font ) {
$google_font = 'https://fonts.googleapis.com/css?family=Noto+Sans+JP:400,700&display=swap';
} elseif ( 'serif' === $body_font ) {
$google_font = 'https://fonts.googleapis.com/css?family=Noto+Serif+JP:400,700&display=swap';
}
return $google_font;
}
/**
* SWELL最新版のバージョンを取得
*/
public static function get_swl_latest_version() {
$latest_version = get_transient( 'swl_latest_version' );
if ( false === $latest_version ) {
$latest_version = \SWELL_Theme::remote_get( 'https://loos-cdn.com/swell-theme/api/?action=get_latest_version', [], true );
set_transient( 'swl_latest_version', $latest_version, DAY_IN_SECONDS * 7 );
}
if ( ! is_array( $latest_version ) ) {
return '';
}
return $latest_version['ver'] ?? '';
}
/**
* 利用規約の最終変更日を取得
*/
public static function get_term_changed_date() {
// キャッシュ確認
$term_changed_date = get_transient( 'swl_term_changed_date' );
if ( false === $term_changed_date ) {
$term_changed_date = \SWELL_Theme::remote_get( 'https://loos-cdn.com/swell-theme/api/?action=get_term_changed', [], true );
set_transient( 'swl_term_changed_date', $term_changed_date, DAY_IN_SECONDS * 7 );
}
if ( ! is_array( $term_changed_date ) ) {
return '';
}
return end( $term_changed_date );
}
/**
* SWELL JSON ディレクトリ取得
*/
public static function get_swl_json_dir() {
$json_dir = get_transient( 'swl_json_dir_ver' );
if ( false === $json_dir ) {
$json_dir = \SWELL_Theme::remote_get( 'https://loos-cdn.com/swell-theme/api/?action=get_json_dir', [] );
set_transient( 'swl_json_dir_ver', $json_dir, DAY_IN_SECONDS * 5 );
}
if ( ! $json_dir ) {
return '';
}
return $json_dir;
}
/**
* 検索結果ページのタイトル
*/
public static function get_search_title() {
// 検索されたテキスト
$s_query = get_search_query();
$s_title = $s_query ? sprintf( __( '「%s」の検索結果', 'swell' ), $s_query ) : __( '検索結果', 'swell' );
return apply_filters( 'swell_get_search_title', $s_title );
}
/**
* カスタム投稿タイプに紐付いたタクソノミーを一つだけ取得する
*/
public static function get_tax_of_post_type( $the_post_type = '' ) {
$the_post_type = $the_post_type ?: get_post_type();
$the_tax = 'category';
// カスタム投稿タイプの場合
if ( 'post' !== $the_post_type ) {
// キャッシュ取得
$cache_key = 'tax_of_' . $the_post_type;
$the_tax = wp_cache_get( $cache_key, 'swell' ) ?: '';
if ( ! $the_tax ) {
// 投稿タイプに紐づいたタクソノミーを取得
$tax_array = get_object_taxonomies( $the_post_type, 'names' );
$core_tax = [ 'category', 'post_tag', 'post_format' ];
foreach ( $tax_array as $tax_name ) {
// コアの標準タクソノミーを除いて1つ目を取得
if ( ! in_array( $tax_name, $core_tax, true ) ) {
$the_tax = $tax_name;
break;
}
}
wp_cache_set( $cache_key, $the_tax, 'swell' );
}
}
return apply_filters( 'swell_get_tax_of_post_type', $the_tax, $the_post_type );
}
/**
* PR表記
*/
public static function get_pr_notation_size( $the_id = '', $setting_key = 'show_pr_notation' ) {
$show_pr_notation = SWELL::get_setting( $setting_key ) ?? 'off';
$pr_notation_type = SWELL::get_setting( 'pr_notation_type' ) ?? 's';
$meta_show_pr = get_post_meta( $the_id, 'swell_meta_show_pr_notation', true ) ?: '';
// 投稿ごとの上書き指定
if ( 'hide' === $meta_show_pr ) {
return false;
}
if ( 'show' === $meta_show_pr ) {
return $pr_notation_type;
}
// ベース設定
if ( 'off' === $show_pr_notation ) {
return false;
}
if ( 'off' !== $show_pr_notation ) {
return $pr_notation_type;
}
}
/**
* 検索の絞り込み状況を取得
* ... 製作途中 ...
* see: https://github.com/loos/SWELL/issues/128
*/
/*
public static function get_searched_status() {
$s_status = [];
// カテゴリー指定があれば
if ( isset( $_GET['cat'] ) ) {
$catid = get_query_var( 'cat', 0 );
$cat_data = get_term_by( 'id', $catid, 'category' );
if ( ! $cat_data ) {
$s_status['category'] = sprintf( __( '不明なカテゴリーID: %s', 'swell' ), $catid );
} else {
$s_status['category'] = $cat_data->name ?? '';
}
} elseif ( isset( $_GET['category_name'] ) ) {
$cat_slug = get_query_var( 'category_name', '' );
$cat_data = get_term_by( 'slug', $cat_slug, 'category' );
if ( ! $cat_data ) {
$s_status['category'] = sprintf( __( '不明なカテゴリー: %s', 'swell' ), $cat_slug );
} else {
$s_status['category'] = $cat_data->name ?? '';
}
}
// タグの指定があれば
if ( isset( $_GET['tag'] ) ) {
$tag_slug = get_query_var( 'tag', '' );
$tag_data = get_term_by( 'slug', $tag_slug, 'post_tag' );
if ( ! $tag_data ) {
$s_status['post_tag'] = sprintf( __( '不明なカテゴリー: %s', 'swell' ), $tag_slug );
} else {
$s_status['post_tag'] = $tag_data->name ?? '';
}
}
$return_text = '';
foreach ( $s_status as $key => $value ) {
$tax = get_taxonomy( $key );
if ( ! $tax ) continue;
$return_text .= '' . $tax->label . ' : ' . $value . '
';
}
// 検索結果タイトル
return apply_filters( 'swell_get_search_terms_status', $return_text );
}
*/
}