1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// @todo Fix performance issues before shipping. |
|
|
|
|
4
|
|
|
//add_action( 'widgets_init', 'follow_button_register_widget' ); |
5
|
|
|
function follow_button_register_widget() { |
6
|
|
|
if ( Jetpack::is_active() ) { |
7
|
|
|
register_widget( 'Jetpack_Follow_Button_Widget' ); |
8
|
|
|
} |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
class Jetpack_Follow_Button_Widget extends WP_Widget { |
12
|
|
|
|
13
|
|
View Code Duplication |
public function __construct() { |
14
|
|
|
parent::__construct( |
15
|
|
|
'follow_button_widget', |
16
|
|
|
/** This filter is documented in modules/widgets/facebook-likebox.php */ |
17
|
|
|
apply_filters( 'jetpack_widget_name', __( 'Follow Button', 'jetpack' ) ), |
18
|
|
|
array( |
19
|
|
|
'description' => __( 'Add a WordPress.com follow button to allow people to follow your blog easier', 'jetpack' ), |
20
|
|
|
'customize_selective_refresh' => true, |
21
|
|
|
) |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function widget( $args, $instance ) { |
26
|
|
|
$attributes = array(); |
27
|
|
|
$instance = wp_parse_args( (array) $instance, array( 'show_name' => 1, 'show_count' => 0 ) ); |
28
|
|
|
|
29
|
|
|
if ( empty( $instance['show_name'] ) ) { |
30
|
|
|
$attributes[] = 'data-show-blog-name="false"'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if ( ! empty( $instance['show_count'] ) ) { |
34
|
|
|
$attributes[] = 'data-show-follower-count="true"'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
echo $args['before_widget']; |
38
|
|
|
?> |
39
|
|
|
|
40
|
|
|
<a |
41
|
|
|
class="wordpress-follow-button" |
42
|
|
|
href="<?php echo esc_url( home_url() ); ?>" |
43
|
|
|
data-blog="<?php echo esc_url( home_url() ); ?>" |
44
|
|
|
data-lang="<?php echo get_locale(); ?>" <?php if ( ! empty( $attributes ) ) echo implode( ' ', $attributes ); ?> |
45
|
|
|
> |
46
|
|
|
<?php sprintf( __( 'Follow %s on WordPress.com', 'jetpack' ), get_bloginfo( 'name' ) ); ?> |
47
|
|
|
</a> |
48
|
|
|
<script type="text/javascript">(function(d){var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT');p.type = 'text/javascript';p.async = true;p.src = '//widgets.wp.com/platform.js';f.parentNode.insertBefore(p,f);}(document));</script> |
49
|
|
|
|
50
|
|
|
<?php |
51
|
|
|
echo $args['after_widget']; |
52
|
|
|
|
53
|
|
|
/** This action is documented in modules/widgets/gravatar-profile.php */ |
54
|
|
|
do_action( 'jetpack_stats_extra', 'widget_view', 'follow_button' ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function form( $instance ) { |
58
|
|
|
$instance = wp_parse_args( (array) $instance, array( 'show_name' => 1, 'show_count' => 0 ) ); |
59
|
|
|
|
60
|
|
|
$show_name = isset( $instance['show_name'] ) ? (bool) $instance['show_name'] : false; |
61
|
|
|
$show_count = isset( $instance['show_count'] ) ? (bool) $instance['show_count'] : false; |
62
|
|
|
?> |
63
|
|
|
|
64
|
|
|
<p> |
65
|
|
|
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_name'); ?>" name="<?php echo $this->get_field_name('show_name'); ?>"<?php checked( $show_name ); ?> /> |
66
|
|
|
<label for="<?php echo $this->get_field_id('show_name'); ?>"><?php esc_html_e( 'Show blog name', 'jetpack' ); ?></label> |
67
|
|
|
<br /> |
68
|
|
|
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_count'); ?>" name="<?php echo $this->get_field_name('show_count'); ?>"<?php checked( $show_count ); ?> /> |
69
|
|
|
<label for="<?php echo $this->get_field_id('show_count'); ?>"><?php esc_html_e( 'Show follower count', 'jetpack' ); ?></label> |
70
|
|
|
</p> |
71
|
|
|
|
72
|
|
|
<?php |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function update( $new_instance, $old_instance ) { |
76
|
|
|
$old_instance['show_name'] = ! empty( $new_instance['show_name'] ) ? 1 : 0; |
77
|
|
|
$old_instance['show_count'] = ! empty( $new_instance['show_count'] ) ? 1 : 0; |
78
|
|
|
return $old_instance; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|