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
<?php
namespace SIW\Modules;
use SIW\HTML;
class Social_Share {
public static function init() {
$self = new self();
add_action( 'wp_enqueue_scripts', [ $self, 'enqueue_styles'] );
add_action( 'siw_vacature_footer', [ $self, 'render' ] );
add_action( 'siw_agenda_footer', [ $self, 'render' ] );
add_action( 'siw_tm_country_footer', [ $self, 'render' ] );
add_action( 'siw_evs_project_footer', [ $self, 'render' ] );
add_action( 'woocommerce_after_single_product', [ $self, 'render' ] );
add_action( 'kadence_single_post_after', [ $self, 'render' ] );
}
public function enqueue_styles() {
wp_register_style( 'siw-social-share', SIW_ASSETS_URL . 'css/modules/siw-social-share.css', [], SIW_PLUGIN_VERSION );
wp_enqueue_style( 'siw-social-share' );
}
public function render() {
if ( $this->needs_hr() ) {
echo '<hr>';
}?>
<div class="siw-social">
<div class="title"><?= esc_html( $this->get_title() ) ?> </div>
<?php
$networks = \siw_get_social_networks('share');
$title = get_the_title();
$url = get_permalink();
foreach ( $networks as $network ) {
echo HTML::generate_link(
$network->generate_share_link( $url, $title ),
'­',
[
'class' => $network->get_slug(),
'aria-label' => sprintf( esc_attr__( 'Delen via %s', 'siw' ), $network->get_name() ),
'data-balloon-pos' => 'down',
'style' => '--hover-color: ' . $network->get_color(),
'target' => '_blank',
'data-ga-track' => 1,
'data-ga-type' => 'social',
'data-ga-category' => $network->get_name(),
'data-ga-action' => 'Delen',
'data-ga-label' => $url,
],
[
'class' => $network->get_icon_class(),
]
);
}
?>
</div><?php
}
protected function get_title() {
$post_type = get_post_type();
switch( $post_type ) {
case 'product':
$title = __( 'Deel dit project', 'siw' );
break;
case 'vacatures':
$title = __( 'Deel deze vacature', 'siw' );
break;
case 'agenda':
$title = __( 'Deel dit evenement', 'siw' );
break;
case 'wpm-testimonial':
$title = __( 'Deel dit ervaringsverhaal', 'siw' );
break;
case 'siw_tm_country':
$title = __( 'Deel deze landenpagina', 'siw' );
break;
default:
$title = __( 'Deel deze pagina', 'siw' );
}
return $title;
}
protected function needs_hr() {
$post_type = get_post_type();
switch( $post_type ) {
case 'product':
$needs_hr = true;
break;
default:
$needs_hr = false;
}
return $needs_hr;
}
}