SG7G_Settings::enabled( 'share_' . $network )
)
);
if ( empty( $enabled ) ) {
return;
}
$url = get_permalink( $post_id );
$title = get_the_title( $post_id );
$image = get_the_post_thumbnail_url( $post_id, 'full' );
$description = self::description( $post_id );
$tags = get_the_terms( $post_id, 'sg7g_tag' );
$has_tags = ! is_wp_error( $tags ) && ! empty( $tags );
?>
post_content ) ), 28, '…' ) : '';
}
return trim( wp_strip_all_tags( $excerpt ) );
}
private static function label( string $network ): string {
$labels = array(
'facebook' => __( 'Share on Facebook', '7sgaleri' ),
'x' => __( 'Share on X', '7sgaleri' ),
'whatsapp' => __( 'Share on WhatsApp', '7sgaleri' ),
'telegram' => __( 'Share on Telegram', '7sgaleri' ),
'linkedin' => __( 'Share on LinkedIn', '7sgaleri' ),
'reddit' => __( 'Share on Reddit', '7sgaleri' ),
'pinterest' => __( 'Share on Pinterest', '7sgaleri' ),
);
return $labels[ $network ] ?? __( 'Share', '7sgaleri' );
}
private static function share_url( string $network, string $url, string $title, string $image, string $description ): string {
$encoded_url = rawurlencode( $url );
$encoded_title = rawurlencode( $title );
$encoded_description = rawurlencode( '' !== $description ? $description : $title );
$message = rawurlencode( trim( $title . ' ' . $url ) );
return match ( $network ) {
'facebook' => 'https://www.facebook.com/sharer/sharer.php?u=' . $encoded_url,
'x' => 'https://twitter.com/intent/tweet?url=' . $encoded_url . '&text=' . $encoded_title,
'whatsapp' => 'https://api.whatsapp.com/send?text=' . $message,
'telegram' => 'https://t.me/share/url?url=' . $encoded_url . '&text=' . $encoded_title,
'linkedin' => 'https://www.linkedin.com/sharing/share-offsite/?url=' . $encoded_url,
'reddit' => 'https://www.reddit.com/submit?url=' . $encoded_url . '&title=' . $encoded_title,
'pinterest' => 'https://www.pinterest.com/pin/create/button/?url=' . $encoded_url . ( '' !== $image ? '&media=' . rawurlencode( $image ) : '' ) . '&description=' . $encoded_description,
default => '',
};
}
private static function icon( string $network ): string {
$paths = array(
'facebook' => '',
'x' => '',
'whatsapp' => '',
'telegram' => '',
'linkedin' => '',
'reddit' => '',
'pinterest' => '',
'copy' => '',
);
if ( ! isset( $paths[ $network ] ) ) {
return '';
}
return '';
}
}