Skip to content

Instantly share code, notes, and snippets.

@DanielFloeter
Last active October 30, 2016 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielFloeter/68236dcc5b48aa8a1be9a33904d04b04 to your computer and use it in GitHub Desktop.
Save DanielFloeter/68236dcc5b48aa8a1be9a33904d04b04 to your computer and use it in GitHub Desktop.
Show sharing buttons, e.g. from Jetpack
<?php
// Show sharing buttons, e.g. from Jetpack
// https://wordpress.org/support/topic/jetpack-sharing-options-showing-in-widget/
// TODO: Rewrite code as filter hook
function form($instance) {
...
<p>
<label for="<?php echo $this->get_field_id("hide_social_buttons"); ?>">
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("hide_social_buttons"); ?>" name="<?php echo $this->get_field_name("hide_social_buttons"); ?>"<?php checked( (bool) $instance["hide_social_buttons"], true ); ?> />
<?php _e( 'Hide social buttons in widget output',TEXTDOMAIN ); ?>
</label>
</p>
...
}
class Widget extends \WP_Widget {
...
/**
* Apply the_content filter for excerpt
* This should show sharing buttons which comes with other widgets in the widget output in the same way as on the main content
*
* @param string The HTML with other applied excerpt filters
*
* @return string If option hide_social_buttons is unchecked applay the_content filter
*
* @since 4.6
*/
function apply_the_excerpt($text) {
$ret = "";
if (isset($this->instance["hide_social_buttons"]) && $this->instance["hide_social_buttons"])
$ret = $text;
else
$ret = apply_filters('the_content', $text);
return $ret;
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment