Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active May 31, 2016 13:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronalfy/3d5de0527095ff00907b to your computer and use it in GitHub Desktop.
Save ronalfy/3d5de0527095ff00907b to your computer and use it in GitHub Desktop.
Minit and Jetpack Sharing
<?php
/*
Place code in custom plugin
Get awesome minify plugin (Minit) by Kaspars D. - https://github.com/kasparsd/minit
to work with crazy, but often necessary, Jetpack Sharing - https://wordpress.org/plugins/jetpack/
Written by Ronald Huereca (@ronalfy). Powered by lack of Sleep(TM) and Vodka(R).
*/
//Remove Jetpack Sharing
function minit_fix_jetpack_sharing_js() {
remove_action( 'wp_footer', 'sharing_add_footer' );
}
add_action( 'wp_footer', 'minit_fix_jetpack_sharing_js', 5 );
//Add back Jetpack Sharing
function minit_add_jetpack_sharing() {
if ( !class_exists( 'Jetpack' ) ) return;
global $jetpack_sharing_counts, $wp_scripts;
$script_item = array();
$wpcom_sharing = false;
if ( is_array( $jetpack_sharing_counts ) && count( $jetpack_sharing_counts ) ) {
$wpcom_sharing = array_filter( $jetpack_sharing_counts );
}
wp_enqueue_script( 'sharing-js' );
if ( $wpcom_sharing ) {
$script_item[ 'WPCOM_sharing_counts' ] = array_flip( $wpcom_sharing );
}
$recaptcha__options = array( 'lang' => get_base_recaptcha_lang_code() );
$script_item[ 'recaptcha_options' ] = $recaptcha__options;
//Get sharing code
$sharing_html = $sharing_js = false;
$sharer = new Sharing_Service();
$enabled = $sharer->get_blog_services();
foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) AS $service ) {
ob_start();
$service->display_footer();
if ( get_class( $service ) == 'Share_Email' ) {
$sharing_html = ob_get_clean();
} else {
$sharing_js .= ob_get_clean();
}
}
//Get sharing data
$sharing_data = '';
foreach( $script_item as $key => $vars ) {
$sharing_data .= sprintf( 'var %s = %s;', $key, json_encode( $vars ) );
}
if ( $sharing_js ) {
$sharing_data .= strip_tags( $sharing_js );
}
if ( $sharing_html ) {
echo $sharing_html;
}
$wp_scripts->add_data( 'sharing-js', 'data', $sharing_data );
}
add_action( 'wp_footer', 'minit_add_jetpack_sharing', 6 );
?>
@ronalfy
Copy link
Author

ronalfy commented Oct 28, 2014

Sigh, still getting a jQuery undefined error. I'll update this later :D 🎱

@ronalfy
Copy link
Author

ronalfy commented Oct 28, 2014

May have to move part of this code to the header and the e-mail part to the footer in order for this to work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment