'widget-oceanwp-social-share social-share', 'description' => esc_html__( 'Display social sharing buttons on your sidebar.', 'ocean-extra' ), 'customize_selective_refresh' => true, ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); } /** * Enqueue scripts. * * @since 1.3.8 * * @param string $hook_suffix */ public function enqueue_scripts( $hook_suffix ) { if ( 'widgets.php' !== $hook_suffix ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); } /** * Enqueue scripts. * * @since 1.0.0 */ public function social_array() { $post_id = get_the_ID(); $post_url = get_permalink( $post_id ); $post_title = get_the_title(); // Get SEO meta and use instead if they exist if ( defined( 'WPSEO_VERSION' ) ) { if ( $meta = get_post_meta( $post_id, '_yoast_wpseo_twitter-title', true ) ) { $post_title = $meta; } } // Array $return = apply_filters( 'ocean_social_share_buttons', array( 'twitter' => array( 'name' => 'Twitter', 'title' => esc_html__( 'Share on Twitter', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://twitter.com/share?text='. wp_strip_all_tags( $post_title ) .'&url='. rawurlencode( esc_url( $post_url ) ), ), 'facebook' => array( 'name' => 'Facebook', 'title' => esc_html__( 'Share on Facebook', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://www.facebook.com/sharer.php?u='. rawurlencode( esc_url( $post_url ) ), ), 'googleplus' => array( 'name' => 'Google+', 'title' => esc_html__( 'Share on Google+', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://plus.google.com/share?url='. rawurlencode( esc_url( $post_url ) ), ), 'pinterest' => array( 'name' => 'Pinterest', 'title' => esc_html__( 'Share on Pinterest', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://www.pinterest.com/pin/create/button/?url='. rawurlencode( esc_url( $post_url ) ) .'&media='. wp_get_attachment_url( get_post_thumbnail_id( $post_id ) ) .'&description='. ( !is_admin() ? urlencode( wp_trim_words( strip_shortcodes( get_the_content( $post_id ) ), 40 ) ) : ''), ), 'linkedin' => array( 'name' => 'LinkedIn', 'title' => esc_html__( 'Share on LinkedIn', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://www.linkedin.com/shareArticle?mini=true&url='. rawurlencode( esc_url( $post_url ) ) .'&title='. wp_strip_all_tags( $post_title ) .'&summary='. ( !is_admin() ? urlencode( wp_trim_words( strip_shortcodes( get_the_content( $post_id ) ), 40 ) ) .'&source='. esc_url( home_url( '/' ) ) : ''), ), 'viber' => array( 'name' => 'Viber', 'title' => esc_html__( 'Share on Viber', 'ocean-extra' ), 'icon' => ' ', 'url' => 'viber://forward?text='. rawurlencode( esc_url( $post_url ) ), ), 'vk' => array( 'name' => 'VK', 'title' => esc_html__( 'Share on VK', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://vk.com/share.php?url='. rawurlencode( esc_url( $post_url ) ), ), 'reddit' => array( 'name' => 'Reddit', 'title' => esc_html__( 'Share on Reddit', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://www.reddit.com/submit?url='. rawurlencode( esc_url( $post_url ) ) .'&title='. wp_strip_all_tags( $post_title ), ), 'tumblr' => array( 'name' => 'Tumblr', 'title' => esc_html__( 'Share on Tumblr', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://www.tumblr.com/widgets/share/tool?canonicalUrl='. rawurlencode( esc_url( $post_url ) ), ), 'viadeo' => array( 'name' => 'Viadeo', 'title' => esc_html__( 'Share on Viadeo', 'ocean-extra' ), 'icon' => ' ', 'url' => 'https://partners.viadeo.com/share?url='. rawurlencode( esc_url( $post_url ) ), ), ) ); return $return; } /** * Front-end display of widget. * * @see WP_Widget::widget() * @since 1.0.0 * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { // Get social share and $social_share = isset( $instance['social_share'] ) ? $instance['social_share'] : ''; // Return if no social defined if ( ! $social_share ) { return; } // Return if no content or search page if ( empty( get_the_content() ) || is_search() ) { return; } // Define vars $title = isset( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : ''; $style = isset( $instance['style'] ) ? $instance['style'] : ''; $border_radius = isset( $instance['border_radius'] ) ? $instance['border_radius'] : ''; $twitter_username = isset( $instance['twitter_username'] ) ? $instance['twitter_username'] : ''; $social_name = isset( $instance['social_name'] ) ? $instance['social_name'] : 0; // Sanitize vars $border_radius = $border_radius ? $border_radius : ''; // Inline style $add_style = ''; if ( $border_radius && 'simple' != $style ) { $add_style .= 'border-radius:'. esc_attr( $border_radius ) .';'; } if ( $add_style ) { $add_style = ' style="' . esc_attr( $add_style ) . '"'; } // Before widget hook echo $args['before_widget']; // Display title if ( $title ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } // Display the social share. ?> colors( $args, $instance ); ?> esc_attr__( 'Please share this', 'ocean-extra' ), 'style' => esc_html__( 'Minimal', 'ocean-extra' ), 'border_radius' => '', 'border_color' => '', 'bg_color' => '', 'color' => '', 'twitter_username' => '', 'social_name' => '', 'social_share' => array('twitter', 'facebook', 'googleplus', 'pinterest', 'linkedin', 'viber', 'vk', 'reddit', 'tumblr', 'viadeo'), ) ); ?>

4px

/>

social_array(); // Loop through social share to display inputs foreach( $display_share as $key => $val ) { ?>

" name="get_field_name("social_share"); ?>[]" type="checkbox" value="" />