inc2734 / wp-share-buttons
为WordPress主题添加社交分享按钮的库。
7.1.2
2023-11-27 06:24 UTC
Requires
- php: >=7.4
- inc2734/wp-ogp: ^2.0
Requires (Dev)
- dev-master
- 7.1.2
- 7.1.1
- 7.1.0
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.1.4
- 4.0.0
- 3.1.3
- 3.1.2
- 3.1.0
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.0
- 0.6.0
- 0.5.9
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.0
- dev-dependabot/npm_and_yarn/webpack-5.76.1
- dev-dependabot/npm_and_yarn/http-cache-semantics-4.1.1
This package is auto-updated.
Last update: 2024-09-27 08:23:45 UTC
README
此库为WordPress添加了分享按钮的简码。这些按钮显示http和https的计数总和。它通过异步显示和缓存轻量级工作。
当SNS Count Cache插件激活时,WP Share Buttons将使用这些计数。
这些按钮可用于单页。
安装
$ composer require inc2734/wp-share-buttons
如何使用
<?php
new \Inc2734\WP_Share_Buttons\Bootstrap();
简码
所有按钮
[wp_share_buttons type="(Optional)" title="(Optional)" post_id="(Required)"]
type:
Baloon, horizontal, icon, block, official
When type is not official, buttons sums http and https counts.
[wp_share_buttons_facebook type="(Optional)" post_id="(Required)"]
需要App Token来获取Facebook分享计数。
/**
* @see https://developers.facebook.com/tools/accesstoken
*/
add_filter(
'inc2734_wp_share_buttons_facebook_app_token',
function() {
return 'Your App Token';
}
);
[wp_share_buttons_twitter type="(Optional)" title="(Optional)" post_id="(Required)"]
X
[wp_share_buttons_x type="(Optional)" title="(Optional)" post_id="(Required)"]
Hatna 书签
[wp_share_buttons_hatena type="(Optional)" post_id="(Required)"]
Feedly
[wp_share_buttons_feedly type="(Optional)" post_id="(Required)"]
[wp_share_buttons_pocket type="(Optional)" title="(Optional)" post_id="(Required)"]
[wp_share_buttons_pinterest type="(Optional)" post_id="(Required)"]
Line
[wp_share_buttons_line type="(Optional)" post_id="(Required)"]
Feed
[wp_share_buttons_feed type="(Optional)" post_id="(Required)"]
复制URL
[wp_share_buttons_copy type="(Optional)" title="(Optional)" post_id="(Required)"]
过滤钩子
inc2734_wp_share_buttons_count_cache_seconds
/**
* Set count cache time
*
* @param {int} $seconds
* @return {int}
*/
add_filter(
'inc2734_wp_share_buttons_count_cache_seconds',
function( $seconds ) {
return 300;
}
);
inc2734_wp_share_buttons_apply_https_total_count
/**
* When permalink is https, whether or not to sum http and https
*
* @param {bool} $bool
* @return {bool}
*/
add_filter(
'inc2734_wp_share_buttons_apply_https_total_count',
function( $bool ) {
return true;
}
);
inc2734_wp_share_buttons_localize_script_handle
/**
* Set handle of localize_script
*
* @param {string} $handle
* @return {string}
*/
add_filter(
'inc2734_wp_share_buttons_localize_script_handle',
function( $handle ) {
return $handle;
}
);
inc2734_wp_share_buttons_facebook_official_button_share
/**
* Add facebook sahre button when using official facebook like button
*
* @param {boolean} $boolean
* @return {boolean}
*/
add_filter(
'inc2734_wp_share_buttons_facebook_official_button_share',
function( $boolean ) {
return $boolean;
}
);
inc2734_wp_share_buttons_shared_title
/**
* Customize shared title
*
* @param {string} $title
* @param {string} $service twitter or copy
* @return {string}
*/
add_filter(
'inc2734_wp_share_buttons_shared_title',
function( $title, $service ) {
if ( 'twitter' === $service ) {
return $title . ' #hashtag';
}
return $title;
},
10,
2
);
inc2734_wp_share_buttons_shared_hashtags
/**
* Customize shared title
*
* @param {string} $title
* @param {string} $service twitter or copy
* @return {string}
*/
add_filter(
'inc2734_wp_share_buttons_shared_hashtags',
function( $hashtags, $service ) {
if ( 'twitter' === $service ) {
return 'hashtagA,hashtagB';
}
return $title;
},
10,
2
);
inc2734_wp_share_buttons_count_cache_seconds
/**
* Customize share count caching time
*
* @param $seconds
* @return $seconds
*/
add_filter(
'inc2734_wp_share_buttons_count_cache_seconds',
function( $seconds ) {
return $seconds;
},
10
);
inc2734_wp_share_buttons_facebook_app_token
/**
* Set Facebook app token.
*
* @param string|false
* @return string|false
*/
add_filter(
'inc2734_wp_share_buttons_facebook_app_token',
function( $token ) {
return $token;
},
10
);