/
sns-share.php
682 lines (605 loc) · 22.3 KB
/
sns-share.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
<?php //SNS関係の関数
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
if ( !function_exists( 'is_sns_share_buttons_count_visible' ) ):
function is_sns_share_buttons_count_visible(){
return is_sns_top_share_buttons_count_visible() || is_sns_bottom_share_buttons_count_visible();
}
endif;
//_vis_numeric(0));
//ツイート数取得
if ( !function_exists( 'fetch_twitter_count_raw' ) ):
function fetch_twitter_count_raw($url){
$url = rawurlencode( $url );
$args = array( 'sslverify' => true );
$subscribers = wp_remote_get( "https://jsoon.digitiminimi.com/twitter/count.json?url=$url", $args );
$res = '0';
if (!is_wp_error( $subscribers ) && $subscribers["response"]["code"] === 200) {
$body = $subscribers['body'];
$json = json_decode( $body );
$res = ($json->{"count"} ? $json->{"count"} : '0');
}
return intval($res);
}
endif;
//count.jsoonからTwitterのツイート数を取得
if ( !function_exists( 'fetch_twitter_count' ) ):
function fetch_twitter_count($url = null) {
$transient_id = TRANSIENT_SHARE_PREFIX.'twitter_'.get_share_cache_ID();
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
return $count;
}
}
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_twitter_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_twitter_count_raw(get_another_scheme_url($url));
}
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
return $res;
}
endif;
//Twitterカウントの取得
if ( !function_exists( 'get_twitter_count' ) ):
function get_twitter_count($url = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_twitter_exists()) {
return scc_get_share_twitter();
} else {
return null;
}
}
endif;
//Facebookシェア数の取得
if ( !function_exists( 'fetch_facebook_count_raw' ) ):
function fetch_facebook_count_raw($url){
//URLをURLエンコード
$encoded_url = rawurlencode( $url );
//オプションの設定
$args = array( 'sslverify' => true );
//Facebookアクセストークンがある場合
if (get_facebook_access_token()) {
//Facebookにリクエストを送る
$request_url = 'https://graph.facebook.com/?id='.$encoded_url.'&fields=engagement&access_token='.trim(get_facebook_access_token());
$response = wp_remote_get( $request_url, $args );
$res = 0;
//取得に成功した場合
if (!is_wp_error( $response ) && $response["response"]["code"] === 200) {
$body = $response['body'];
$json = json_decode( $body ); //ジェイソンオブジェクトに変換する
$reaction_count = isset($json->{'engagement'}->{'reaction_count'}) ? $json->{'engagement'}->{'reaction_count'} : 0;
$comment_count = isset($json->{'engagement'}->{'comment_count'}) ? $json->{'engagement'}->{'comment_count'} : 0;
$share_count = isset($json->{'engagement'}->{'share_count'}) ? $json->{'engagement'}->{'share_count'} : 0;
$comment_plugin_count = isset($json->{'engagement'}->{'comment_plugin_count'}) ? $json->{'engagement'}->{'comment_plugin_count'} : 0;
$res = intval($reaction_count) + intval($comment_count) + intval($share_count) + intval($comment_plugin_count);
}
} else {//Facebookアクセストークンがない場合
//Facebookにリクエストを送る
$request_url = 'https://graph.facebook.com?id='.$encoded_url.'&fields=og_object{engagement}';
$response = wp_remote_get( $request_url );
$res = 0;
//取得に成功した場合
if (!is_wp_error( $response ) && $response["response"]["code"] === 200) {
$body = $response['body'];
//ジェイソンオブジェクトに変換する
$json = json_decode( $body );
//エンゲージメントカウントをシェア数として取得する
$res = (isset($json->{'og_object'}->{'engagement'}->{'count'}) ? $json->{'og_object'}->{'engagement'}->{'count'} : 0);
}
}
return intval($res);
//Facebookにリクエストを送る
$request_url = 'https://graph.facebook.com/?id='.$encoded_url.'&fields=engagement&access_token='.trim(get_facebook_access_token());
$response = wp_remote_get( $request_url, $args );
$res = 0;
//取得に成功した場合
if (!is_wp_error( $response ) && $response["response"]["code"] === 200) {
$body = $response['body'];
$json = json_decode( $body ); //ジェイソンオブジェクトに変換する
$res = (isset($json->{'engagement'}->{'reaction_count'}) ? $json->{'engagement'}->{'reaction_count'} : 0);
}
// return intval($res);
}
endif;
//Facebookシェア数を取得する
if ( !function_exists( 'fetch_facebook_count' ) ):
function fetch_facebook_count($url = null) {
$transient_id = TRANSIENT_SHARE_PREFIX.'facebook_'.get_share_cache_ID();
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
return $count;
}
}
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_facebook_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_facebook_count_raw(get_another_scheme_url($url));
}
//_v($res);
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
return $res;
}
endif;
//Facebookカウントの取得
if ( !function_exists( 'get_facebook_count' ) ):
function get_facebook_count($url = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_facebook_exists()) {
return scc_get_share_facebook();
} else {
return fetch_facebook_count($url);
}
}
endif;
//はてブ数の取得
if ( !function_exists( 'fetch_hatebu_count_raw' ) ):
function fetch_hatebu_count_raw($url){
//取得するURL(ついでにURLエンコード)
$encoded_url = rawurlencode($url);
//オプションの設定
$args = array( 'sslverify' => true );
//Facebookにリクエストを送る
$response = wp_remote_get( 'http://api.b.st-hatena.com/entry.count?url='.$encoded_url, $args );
$res = 0;
//取得に成功した場合
if (!is_wp_error( $response ) && $response["response"]["code"] === 200) {
$body = $response['body'];
$res = !empty($body) ? $body : 0;
}
return intval($res);
}
endif;
if ( !function_exists( 'fetch_hatebu_count' ) ):
function fetch_hatebu_count($url = null) {
$transient_id = TRANSIENT_SHARE_PREFIX.'hatebu_'.get_share_cache_ID();
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
// _edump(
// array('value' => $transient_id.'-'.$count, 'file' => __FILE__, 'line' => __LINE__),
// 'label', 'tag', 'ade5ac'
// );
return $count;
}
}
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_hatebu_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_hatebu_count_raw(get_another_scheme_url($url));
}
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
return $res;
}
endif;
//はてブカウントの取得
if ( !function_exists( 'get_hatebu_count' ) ):
function get_hatebu_count($url = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_hatebu_exists()) {
return scc_get_share_hatebu();
} else {
return fetch_hatebu_count($url);
}
}
endif;
//Google+シェア数の取得
if ( !function_exists( 'fetch_google_plus_count_raw' ) ):
function fetch_google_plus_count_raw($url){
$query = 'https://apis.google.com/_/+1/fastbutton?url=' . urlencode( $url );
//URL(クエリ)先の情報を取得
$args = array( 'sslverify' => true );
$result = wp_remote_get($query, $args);
$res = 0;
if (!is_wp_error($result)) {
// 正規表現でカウント数のところだけを抽出
preg_match( '/\[2,([0-9.]+),\[/', $result["body"], $count );
$res = isset($count[1]) ? intval($count[1]) : 0;
}
return intval($res);
}
endif;
//Google+カウントの取得
if ( !function_exists( 'fetch_google_plus_count' ) ):
function fetch_google_plus_count($url = null) {
$transient_id = TRANSIENT_SHARE_PREFIX.'google_plus_'.get_share_cache_ID();
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
return $count;
}
}
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_google_plus_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_google_plus_count_raw(get_another_scheme_url($url));
}
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
// 共有数を表示
return $res;
}
endif;
//Google+カウントの取得
if ( !function_exists( 'get_google_plus_count' ) ):
function get_google_plus_count($url = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_gplus_exists()) {
return scc_get_share_gplus();
} else {
return null;
}
}
endif;
//Pocketストック数の取得
if ( !function_exists( 'fetch_pocket_count_raw' ) ):
function fetch_pocket_count_raw($url){
$res = 0;
$url = urlencode($url);
$query = 'https://widgets.getpocket.com/api/saves?url='.$url;
$args = array( 'sslverify' => true );
//URL(クエリ)先の情報を取得
$result = wp_remote_get($query, $args);
//エラーチェック
if (!is_wp_error($result)) {
$body = isset($result["body"]) ? $result["body"] : null;
if ($body) {
$json = json_decode($body); //ジェイソンオブジェクトに変換する
$res = isset($json->{'saves'}) ? $json->{'saves'} : 0;
}
}
return intval($res);
}
endif;
//Pocketカウントの取得
if ( !function_exists( 'fetch_pocket_count' ) ):
function fetch_pocket_count($url = null) {
$transient_id = TRANSIENT_SHARE_PREFIX.'pocket_'.get_share_cache_ID();
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
return $count;
}
}
$res = 0;
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_pocket_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_pocket_count_raw(get_another_scheme_url($url));
}
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
// 共有数を表示
return $res;
}
endif;
//Pocketカウントの取得
if ( !function_exists( 'get_pocket_count' ) ):
function get_pocket_count($url = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_pocket_exists()) {
return scc_get_share_pocket();
} else {
return fetch_pocket_count($url);
}
}
endif;
//SNS Count Cacheプラグインはインストールされているか
function is_scc_exists(){
return function_exists('scc_get_share_twitter');
}
//ツイート数取得関数が存在しているか
function is_scc_twitter_exists(){
return function_exists('scc_get_share_twitter');
}
//Facebookシェア数取得関数が存在しているか
function is_scc_facebook_exists(){
return function_exists('scc_get_share_facebook');
}
//Google+シェア数取得関数が存在しているか
function is_scc_gplus_exists(){
return function_exists('scc_get_share_gplus');
}
//はてブ数取得関数が存在しているか
function is_scc_hatebu_exists(){
return function_exists('scc_get_share_hatebu');
}
//Pocketストック数取得関数が存在しているか
function is_scc_pocket_exists(){
return function_exists('scc_get_share_pocket');
}
//トータルシェア数取得関数が存在しているか
function is_scc_total_exists(){
return function_exists('scc_get_share_total');
}
//feedly購読者数取得関数が存在しているか
function is_scc_feedly_exists(){
return function_exists('scc_get_follow_feedly');
}
//Push7購読者数取得関数が存在しているか
function is_scc_push7_exists(){
return function_exists('scc_get_follow_push7');
}
//シェア対象ページのURLを取得する
if ( !function_exists( 'get_share_page_url' ) ):
function get_share_page_url(){
$url = get_requested_url();
if ( is_singular() ) {
$url = get_the_permalink();
} elseif (is_category() && !is_paged()) {
//カテゴリートップページ
$cat_id = get_query_var('cat');
$url = get_category_link($cat_id);
} elseif (is_tag() && !is_paged() && isset($tag->term_id)) {
//タグトップページ
$name = single_tag_title('', false);
$tag = get_term_by('name', $name, 'post_tag');
$url = get_tag_link($tag->term_id);
} elseif (is_front_page() && !is_paged()) {
//フロントトップページ
$url = user_trailingslashit(get_home_url());
}
return $url;
}
endif;
//シェア対象ページのタイトルを取得する
if ( !function_exists( 'get_share_page_title' ) ):
function get_share_page_title(){
if ( is_singular() ) {
$title = get_the_title();
} else {
$title = wp_get_document_title();
}
return html_entity_decode($title);
}
endif;
//Twitter IDを含めるURLパラメータを取得
function get_twitter_via_param(){
if ( get_the_author_twitter_id() && is_twitter_id_include() ) {
return '&via='.get_the_author_twitter_id();
}
}
//ツイート後にフォローを促すパラメータを取得
function get_twitter_related_param(){
if ( get_the_author_twitter_id() && is_twitter_related_follow_enable() ) {
return '&related='.get_the_author_twitter_id();//.':フォロー用の説明文';
}
}
//TwitterのシェアURLを取得
if ( !function_exists( 'get_twitter_share_url' ) ):
function get_twitter_share_url(){
$hash_tag = null;
if (get_twitter_hash_tag()) {
$hash_tag = '+'.urlencode( get_twitter_hash_tag() );
}
return 'https://twitter.com/intent/tweet?text='.urlencode( get_share_page_title() ).$hash_tag.'&url='.
urlencode( get_share_page_url() ).
get_twitter_via_param(). //ツイートにメンションを含める
get_twitter_related_param();//ツイート後にフォローを促す
}
endif;
//FacebookのシェアURLを取得
if ( !function_exists( 'get_facebook_share_url' ) ):
function get_facebook_share_url(){
return '//www.facebook.com/sharer/sharer.php?u='.urlencode( get_share_page_url() ).'&t='. urlencode( get_share_page_title() );//ツイート後にフォローを促す
}
endif;
//はてブのシェアURLを取得
if ( !function_exists( 'get_hatebu_share_url' ) ):
function get_hatebu_share_url(){
$url = get_share_page_url();
if (strpos($url, 'https://') === 0) {
$u = preg_replace('/https:\/\//', 's/', $url);
} else {
$u = preg_replace('/http:\/\//', '', $url);
}
return '//b.hatena.ne.jp/entry/'.htmlspecialchars($u, ENT_QUOTES, 'UTF-8');;
}
endif;
//Google+のシェアURLを取得
if ( !function_exists( 'get_google_plus_share_url' ) ):
function get_google_plus_share_url(){
return '//plus.google.com/share?url='.rawurlencode( get_share_page_url() );
}
endif;
//PocketのシェアURLを取得
if ( !function_exists( 'get_pocket_share_url' ) ):
function get_pocket_share_url(){
return '//getpocket.com/edit?url='.get_share_page_url();
}
endif;
//LINEのシェアURLを取得
if ( !function_exists( 'get_line_share_url' ) ):
function get_line_share_url(){
return '//timeline.line.me/social-plugin/share?url='.urlencode(get_share_page_url());
}
endif;
//PinterestのシェアURLを取得
if ( !function_exists( 'get_pinterest_share_url' ) ):
function get_pinterest_share_url(){
return '//www.pinterest.com/pin/create/button/?url='.urlencode(get_share_page_url());
}
endif;
//LinkedInのシェアURLを取得
if ( !function_exists( 'get_linkedin_share_url' ) ):
function get_linkedin_share_url(){
return '//www.linkedin.com/shareArticle?mini=true&url='.urlencode(get_share_page_url());
}
endif;
//コピーURLを取得
if ( !function_exists( 'get_copy_share_url' ) ):
function get_copy_share_url(){
if (is_amp()) {
return get_template_directory_uri().'/lib/common/copy.php?title='.urlencode( get_share_page_title() ).'&url='.urlencode(get_share_page_url());
} else {
return 'javascript:void(0)';
}
}
endif;
//シェアボタンを表示するか
if ( !function_exists( 'is_sns_share_buttons_visible' ) ):
function is_sns_share_buttons_visible($option){
$res = (is_sns_bottom_share_buttons_visible() && $option == SS_BOTTOM) ||
(is_sns_top_share_buttons_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_sns_share_buttons_visible', $res, $option);
}
endif;
//Twitterシェアボタンを表示するか
if ( !function_exists( 'is_twitter_share_button_visible' ) ):
function is_twitter_share_button_visible($option){
$res = (is_bottom_twitter_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_twitter_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_twitter_share_button_visible', $res, $option);
}
endif;
//Facebookシェアボタンを表示するか
if ( !function_exists( 'is_facebook_share_button_visible' ) ):
function is_facebook_share_button_visible($option){
$res = (is_bottom_facebook_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_facebook_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_facebook_share_button_visible', $res, $option);
}
endif;
//はてブシェアボタンを表示するか
if ( !function_exists( 'is_hatebu_share_button_visible' ) ):
function is_hatebu_share_button_visible($option){
$res = (is_bottom_hatebu_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_hatebu_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_hatebu_share_button_visible', $res, $option);
}
endif;
//Google+シェアボタンを表示するか
if ( !function_exists( 'is_google_plus_share_button_visible' ) ):
function is_google_plus_share_button_visible($option){
$res = (is_bottom_google_plus_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_google_plus_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_google_plus_share_button_visible', $res, $option);
}
endif;
//Pocketシェアボタンを表示するか
if ( !function_exists( 'is_pocket_share_button_visible' ) ):
function is_pocket_share_button_visible($option){
$res = (is_bottom_pocket_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_pocket_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_pocket_share_button_visible', $res, $option);
}
endif;
//LINE@シェアボタンを表示するか
if ( !function_exists( 'is_line_at_share_button_visible' ) ):
function is_line_at_share_button_visible($option){
$res = (is_bottom_line_at_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_line_at_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_line_at_share_button_visible', $res, $option);
}
endif;
//Pinterestシェアボタンを表示するか
if ( !function_exists( 'is_pinterest_share_button_visible' ) ):
function is_pinterest_share_button_visible($option){
$res = (is_bottom_pinterest_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_pinterest_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_pinterest_share_button_visible', $res, $option);
}
endif;
//LinkedInシェアボタンを表示するか
if ( !function_exists( 'is_linkedin_share_button_visible' ) ):
function is_linkedin_share_button_visible($option){
$res = (is_bottom_linkedin_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_linkedin_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_linkedin_share_button_visible', $res, $option);
}
endif;
//コピーシェアボタンを表示するか
if ( !function_exists( 'is_copy_share_button_visible' ) ):
function is_copy_share_button_visible($option){
$res = (is_bottom_copy_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_copy_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_copy_share_button_visible', $res, $option);
}
endif;
//コメントボタンを表示するか
if ( !function_exists( 'is_comment_share_button_visible' ) ):
function is_comment_share_button_visible($option){
$res = (is_bottom_comment_share_button_visible() && $option == SS_BOTTOM) ||
(is_top_comment_share_button_visible() && $option == SS_TOP) ||
($option == SS_MOBILE);
return apply_filters('is_comment_share_button_visible', $res, $option);
}
endif;
//シェアページのIDを取得する
if ( !function_exists( 'get_share_cache_ID' ) ):
function get_share_cache_ID(){
$id = 'nuknown';
if ( is_singular() ) {
global $post;
$id = $post->ID;
} elseif (is_category() && !is_paged()) {
//カテゴリートップページ
$cat_id = get_query_var('cat');
$id = 'cat_'.$cat_id;
} elseif (is_tag() && !is_paged()) {
//タグトップページ
$name = single_tag_title('', false);
$tag = get_term_by('name', $name, 'post_tag');
$id = 'tag_'.$tag->term_id;
} elseif (is_front_page() && !is_paged()) {
//フロントトップページ
$id = 'front_top_page';
}
return $id;
}
endif;