pixelshelsinki / social-share
WordPress 社交分享组件
v1.1.0
2021-03-17 13:33 UTC
Requires (Dev)
- giacocorsiglia/wordpress-stubs: ^5.1
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^4.4
README
WordPress 社交分享组件。
- 为大多数社交媒体平台生成分享链接
- 分享当前链接或给定链接
安装
composer require pixelshelsinki/social-share
用法
Pixels Social Share 暴露了一个主要的 "Share" 类,其中包含了每个社交媒体平台的相应方法。可以直接在 PHP 中调用这些方法,或者在与 Timber 一起工作时将它们作为 Twig 函数挂钩。
使用 PHP
<?php use Pixels\Components\SocialShare\Share; // Current url $facebook_share = Share::facebook(); $twitter_share = Share::twitter(); $linkedin_share = Share::linkedin(); $whatsapp_share = Share:: whatsapp(); // Given url. $facebook_share = Share::facebook('https://www.pixels.fi/'); $twitter_share = Share::twitter('https://www.pixels.fi/'); $linkedin_share = Share::linkedin('https://www.pixels.fi/'); $whatsapp_share = Share::whatsapp('https://www.pixels.fi/');
使用 Twig / Timber。
最简单的方法是将工厂函数注册为 Twig 辅助函数。
<?php use \Timber\Twig_Function; add_filter( 'get_twig', array( 'add_share_functions' ) ); function add_share_functions( $twig ) { // Social share functions. $twig->addFunction( new Twig_Function( 'facebook_share', '\\Pixels\\Components\\SocialShare\\Share::facebook' ) ); $twig->addFunction( new Twig_Function( 'twitter_share', '\\Pixels\\Components\\SocialShare\\Share::twitter' ) ); $twig->addFunction( new Twig_Function( 'linkedin_share', '\\Pixels\\Components\\SocialShare\\Share::linkedin' ) ); $twig->addFunction( new Twig_Function( 'whatsapp_share', '\\Pixels\\Components\\SocialShare\\Share::whatsapp' ) ); return $twig; }