Astra_Ext_Blog_Pro_Markup::astra_render_social_sharing()
Render social sharing.
Description
Source
File: addons/blog-pro/classes/class-astra-ext-blog-pro-markup.php
public function astra_render_social_sharing() {
$items = astra_get_option( 'single-post-social-sharing-icon-list' );
$items = isset( $items['items'] ) ? $items['items'] : array();
$post_categories = wp_strip_all_tags( get_the_category_list( ',' ) );
$post_title = get_the_title();
$post_link = urlencode( get_the_permalink() ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
$email_title = str_replace( '&', '%26', $post_title );
$enable_heading = astra_get_option( 'single-post-social-sharing-heading-enable' );
$heading_text = astra_get_option( 'single-post-social-sharing-heading-text' );
$heading_position = astra_get_option( 'single-post-social-sharing-heading-position' );
$show_label = astra_get_option( 'single-post-social-sharing-icon-label' );
$show_label_class = $show_label ? 'social-show-label-true' : 'social-show-label-false';
$color_type = astra_get_option( 'single-post-social-sharing-icon-color-type' );
$label_position = astra_get_option( 'single-post-social-sharing-icon-label-position' );
$social_icon_condition = array( 'facebook', 'pinterest', 'linkedin', 'reddit', 'whatsapp', 'sms' );
if ( $items ) {
ob_start();
?>
<div class="ast-post-social-sharing">
<?php if ( $enable_heading && 'above' === $heading_position ) { ?>
<h3 class="ast-social-sharing-heading"> <?php echo esc_html( $heading_text ); ?></h3>
<?php } ?>
<div class="ast-social-inner-wrap element-social-inner-wrap <?php echo esc_attr( $show_label_class ); ?> ast-social-color-type-<?php echo esc_attr( $color_type ); ?>">
<?php
if ( is_array( $items ) && ! empty( $items ) ) {
foreach ( $items as $item ) {
if ( $item['enabled'] ) {
$link = $item['url'];
switch ( $item['id'] ) {
case 'facebook':
$link = add_query_arg(
array(
'u' => $post_link,
),
'https://www.facebook.com/sharer.php'
);
break;
case 'twitter':
$link = add_query_arg(
array(
'url' => $post_link,
'text' => rawurlencode( html_entity_decode( wp_strip_all_tags( $post_title ), ENT_COMPAT, 'UTF-8' ) ),
'hashtags' => $post_categories,
),
'http://twitter.com/share'
);
break;
case 'email':
$link = add_query_arg(
array(
'subject' => wp_strip_all_tags( $email_title ),
'body' => $post_link,
),
'mailto:'
);
break;
case 'pinterest':
$link = 'https://pinterest.com/pin/create/bookmarklet/?media=' . get_the_post_thumbnail_url() . '&url=' . $post_link . '&description=' . $post_title;
break;
case 'linkedin':
$link = 'https://www.linkedin.com/shareArticle?mini=true&url=' . $post_link . '&title=' . urlencode( $post_title ) . '&source=' . urlencode( get_bloginfo( 'name' ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
break;
case 'tumblr':
$link = 'http://www.tumblr.com/share/link?url=' . $post_link . '&title=' . $post_title;
break;
case 'reddit':
$link = 'https://reddit.com/submit?url=' . $post_link . '&title=' . $post_title;
break;
case 'whatsapp':
$link = 'https://wa.me/?text=' . $post_link;
break;
case 'sms':
$link = 'sms://?&body=' . $post_title . ' - ' . $post_link;
break;
case 'vk':
$link = 'http://vk.com/share.php?url=' . urlencode( $post_link ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
break;
}
$aria_label = $item['label'] ? $item['label'] : $item['id'];
$is_phone_or_email = 'phone' === $item['id'] || 'email' === $item['id'];
$add_target = $is_phone_or_email ? '' : '_blank';
$add_rel = $is_phone_or_email ? '' : 'noopener noreferrer';
?>
<a href="<?php echo esc_url( $link ); ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>" target="<?php echo esc_attr( $add_target ); ?>" rel="<?php echo esc_attr( $add_rel ); ?>" class="ast-inline-flex ast-social-icon-a">
<?php
if ( $show_label && $label_position && 'above' === $label_position ) {
?>
<span class="social-item-label"> <?php echo esc_html( $item['label'] ); ?> </span>
<?php } ?>
<?php
$icon_color = ! empty( $item['color'] ) ? $item['color'] : '#3a3a3a';
$icon_background_color = ! empty( $item['background'] ) ? $item['background'] : 'transparent';
?>
<div style="--color: <?php echo esc_attr( $icon_color ); ?>; --background-color:<?php echo esc_attr( $icon_background_color ); ?>;" class="ast-social-element ast-<?php echo esc_attr( $item['id'] ); ?>-social-item">
<?php echo do_shortcode( Astra_Builder_UI_Controller::fetch_svg_icon( in_array( $item['icon'], $social_icon_condition ) ? $item['icon'] . '-fill' : $item['icon'] ) ); ?>
</div>
<?php
if ( $show_label && $label_position && 'below' === $label_position ) {
?>
<span class="social-item-label"> <?php echo esc_html( $item['label'] ); ?> </span>
<?php } ?>
</a>
<?php
}
}
}
?>
</div>
<?php if ( $enable_heading && 'below' === $heading_position ) { ?>
<h3 class="ast-social-sharing-heading"> <?php echo esc_html( $heading_text ); ?></h3>
<?php } ?>
</div>
<?php
echo do_shortcode( ob_get_clean() );
}
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 4.1.0 | Introduced. |