Completed
Push — add/shim-for-likes-method ( 8aa5e5 )
by
unknown
46:41 queued 36:36
created

Jetpack_Likes::admin_bar_likes()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 39
Code Lines 25

Duplication

Lines 10
Ratio 25.64 %

Importance

Changes 0
Metric Value
cc 6
eloc 25
nc 5
nop 0
dl 10
loc 39
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * Module Name: Likes
4
 * Module Description: Give visitors an easy way to show they appreciate your content.
5
 * Jumpstart Description: Give visitors an easy way to show they appreciate your content.
6
 * First Introduced: 2.2
7
 * Sort Order: 23
8
 * Requires Connection: Yes
9
 * Auto Activate: No
10
 * Module Tags: Social
11
 * Feature: Engagement, Jumpstart
12
 * Additional Search Queries: like, likes, wordpress.com
13
 */
14
15
Jetpack::dns_prefetch( array(
16
	'//widgets.wp.com',
17
	'//s0.wp.com',
18
	'//0.gravatar.com',
19
	'//1.gravatar.com',
20
	'//2.gravatar.com',
21
) );
22
23
include_once dirname( __FILE__ ) . '/likes/jetpack-likes-master-iframe.php';
24
include_once dirname( __FILE__ ) . '/likes/jetpack-likes-settings.php';
25
26
class Jetpack_Likes {
27
	public static function init() {
28
		static $instance = NULL;
29
30
		if ( ! $instance ) {
31
			$instance = new Jetpack_Likes;
32
		}
33
34
		return $instance;
35
	}
36
37
	function __construct() {
38
		$this->in_jetpack = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? false : true;
0 ignored issues
show
Bug introduced by
The property in_jetpack does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
		$this->settings = new Jetpack_Likes_Settings();
0 ignored issues
show
Bug introduced by
The property settings does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
41
		add_action( 'init', array( &$this, 'action_init' ) );
42
		add_action( 'admin_init', array( $this, 'admin_init' ) );
43
44
		if ( $this->in_jetpack ) {
45
			add_action( 'jetpack_activate_module_likes',   array( $this, 'set_social_notifications_like' ) );
46
			add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) );
47
48
			Jetpack::enable_module_configurable( __FILE__ );
49
			Jetpack::module_configuration_load( __FILE__, array( $this, 'configuration_redirect' ) );
50
51
			add_action( 'admin_print_scripts-settings_page_sharing', array( &$this, 'load_jp_css' ) );
52
			add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) );
53
54
			$active = Jetpack::get_active_modules();
55
56 View Code Duplication
			if ( ! in_array( 'sharedaddy', $active ) && ! in_array( 'publicize', $active ) ) {
57
				// we don't have a sharing page yet
58
				add_action( 'admin_menu', array( $this->settings, 'sharing_menu' ) );
59
			}
60
61 View Code Duplication
			if ( in_array( 'publicize', $active ) && ! in_array( 'sharedaddy', $active ) ) {
62
				// we have a sharing page but not the global options area
63
				add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 );
64
				add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 );
65
			}
66
67 View Code Duplication
			if( ! in_array( 'sharedaddy', $active ) ) {
68
				add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) );
69
				add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 );
70
				add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 );
71
				add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
72
			} else {
73
				add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
74
				add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) );
75
			}
76
		} else { // wpcom
77
			add_action( 'wpmu_new_blog', array( $this, 'enable_comment_likes' ), 10, 1 );
78
			add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
79
			add_action( 'end_likes_meta_box_content', array( $this->settings, 'sharing_meta_box_content' ) );
80
			add_filter( 'likes_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
81
		}
82
83
		add_action( 'admin_init', array( $this, 'admin_discussion_likes_settings_init' ) ); // Likes notifications
84
85
		add_action( 'admin_bar_menu', array( $this, 'admin_bar_likes' ), 60 );
86
87
		add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) );
88
89
		add_action( 'save_post', array( $this->settings, 'meta_box_save' ) );
90
		add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) );
91
		add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 );
92
		add_action( 'sharing_admin_update',   array( $this->settings, 'admin_settings_callback' ), 20 );
93
	}
94
95
	/**
96
	 * Set the social_notifications_like option to `on` when the Likes module is activated.
97
	 *
98
	 * @since 3.7.0
99
	 *
100
	 * @return null
101
	 */
102
	function set_social_notifications_like() {
103
		update_option( 'social_notifications_like', 'on' );
104
	}
105
106
	/**
107
	 * Delete the social_notifications_like option that was set to `on` on module activation.
108
	 *
109
	 * @since 3.7.0
110
	 *
111
	 * @return null
112
	 */
113
	function delete_social_notifications_like() {
114
		delete_option( 'social_notifications_like' );
115
	}
116
117
	/**
118
	 * Redirects to the likes section of the sharing page.
119
	 */
120
	function configuration_redirect() {
121
		wp_safe_redirect( admin_url( 'options-general.php?page=sharing#likes' ) );
122
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method configuration_redirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
123
	}
124
125
	/**
126
	 * Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable
127
	 */
128
	function load_jp_css() {
129
		// Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
130
		// Jetpack::init()->admin_styles();
131
	}
132
133
	/**
134
	 * Load scripts and styles for front end.
135
	 * @return null
136
	 */
137
	function load_styles_register_scripts() {
138
		if ( $this->in_jetpack ) {
139
			wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION );
140
			$this->register_scripts();
141
		}
142
	}
143
144
	/**
145
	 * Stub for is_likes_visible, since some themes were calling it directly from this class
146
	 *
147
	 * @deprecated 5.4
148
	 * @return bool
149
	 */
150
	function is_likes_visible() {
151
		_deprecated_function( __METHOD__, 'jetpack-5.4', 'Jetpack_Likes_Settings()->is_likes_visible' );
152
153
		$settings = new Jetpack_Likes_Settings();
154
		return $settings->is_likes_visible();
155
	}
156
157
	/**
158
	 * Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box
159
	 * @param  string $html row heading for the sharedaddy "which page" setting
160
	 * @return string       html with the jetpack-targetable class and likes id. tbody gets closed after the like settings
161
	 */
162
	function configuration_target_area( $html = '' ) {
163
		$html = "<tbody id='likes' class='jetpack-targetable'>" . $html;
164
		return $html;
165
	}
166
167
	/**
168
	 * WordPress.com: Metabox option for sharing (sharedaddy will handle this on the JP blog)
169
	 */
170
	function sharing_meta_box_content( $post ) {
171
		$post_id = ! empty( $post->ID ) ? (int) $post->ID : get_the_ID();
172
		$disabled = get_post_meta( $post_id, 'sharing_disabled', true ); ?>
173
		<p>
174
			<label for="wpl_enable_post_sharing">
175
				<input type="checkbox" name="wpl_enable_post_sharing" id="wpl_enable_post_sharing" value="1" <?php checked( !$disabled ); ?>>
176
				<?php _e( 'Show sharing buttons.', 'jetpack' ); ?>
177
			</label>
178
			<input type="hidden" name="wpl_sharing_status_hidden" value="1" />
179
		</p> <?php
180
	}
181
182
	/**
183
	  * Options to be added to the discussion page (see also admin_settings_init, etc below for Sharing settings page)
184
	  */
185
186 View Code Duplication
	function admin_discussion_likes_settings_init() {
187
		// Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings
188
		add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' );
189
		add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' );
190
		// Register the setting
191
		register_setting( 'discussion', 'social_notifications_like', array( $this, 'admin_discussion_likes_settings_validate' ) );
192
	}
193
194
	function admin_discussion_likes_settings_section() {
195
		// Atypical usage here.  We emit jquery to move likes notification checkbox to be with the rest of the email notification settings
196
?>
197
	<script type="text/javascript">
198
	jQuery( function( $ )  {
199
		var table = $( '#social_notifications_like' ).parents( 'table:first' ),
200
			header = table.prevAll( 'h2:first' ),
201
			newParent = $( '#moderation_notify' ).parent( 'label' ).parent();
202
203
		if ( !table.length || !header.length || !newParent.length ) {
204
			return;
205
		}
206
207
		newParent.append( '<br/>' ).append( table.end().parent( 'label' ).siblings().andSelf() );
208
		header.remove();
209
		table.remove();
210
	} );
211
	</script>
212
<?php
213
	}
214
215
	function admin_likes_get_option( $option ) {
216
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
217
			$option_setting = get_blog_option( get_current_blog_id(), $option, 'on' );
218
		} else {
219
			$option_setting = get_option( $option, 'on' );
220
		}
221
222
		return intval( 'on' == $option_setting );
223
	}
224
225
	function admin_discussion_likes_settings_field() {
226
		$like = $this->admin_likes_get_option( 'social_notifications_like' );
227
?>
228
		<label><input type="checkbox" id="social_notifications_like" name="social_notifications_like" value="1" <?php checked( $like ); ?> /> <?php esc_html_e( 'Someone likes one of my posts', 'jetpack' ); ?></label>
229
<?php
230
	}
231
232
	function admin_discussion_likes_settings_validate( $input ) {
233
		// If it's not set (was unchecked during form submission) or was set to off (during option update), return 'off'.
234
		if ( !$input || 'off' == $input )
235
			return 'off';
236
237
		// Otherwise, return 'on'.
238
		return 'on';
239
	}
240
241
	function admin_init() {
242
		add_filter( 'manage_posts_columns', array( $this, 'add_like_count_column' ) );
243
		add_filter( 'manage_pages_columns', array( $this, 'add_like_count_column' ) );
244
		add_action( 'manage_posts_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
245
		add_action( 'manage_pages_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
246
		add_action( 'admin_print_styles-edit.php', array( $this, 'load_admin_css' ) );
247
		add_action( "admin_print_scripts-edit.php", array( $this, 'enqueue_admin_scripts' ) );
248
	}
249
250
	function action_init() {
251
		if ( is_admin() ) {
252
			return;
253
		}
254
255
		if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ||
256
			 ( defined( 'APP_REQUEST' ) && APP_REQUEST ) ||
257
			 ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
258
			 ( defined( 'COOKIE_AUTH_REQUEST' ) && COOKIE_AUTH_REQUEST ) ||
259
			 ( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) {
260
			return;
261
		}
262
263
		if ( $this->in_jetpack ) {
264
			add_filter( 'the_content', array( &$this, 'post_likes' ), 30, 1 );
265
			add_filter( 'the_excerpt', array( &$this, 'post_likes' ), 30, 1 );
266
267
		} else {
268
			add_filter( 'post_flair', array( &$this, 'post_likes' ), 30, 1 );
269
			add_filter( 'post_flair_block_css', array( $this, 'post_flair_service_enabled_like' ) );
270
271
			wp_enqueue_script( 'postmessage', '/wp-content/js/postmessage.js', array( 'jquery' ), JETPACK__VERSION, false );
272
			wp_enqueue_script( 'jetpack_resize', '/wp-content/js/jquery/jquery.jetpack-resize.js', array( 'jquery' ), JETPACK__VERSION, false );
273
			wp_enqueue_script( 'jetpack_likes_queuehandler', plugins_url( 'queuehandler.js' , __FILE__ ), array( 'jquery', 'postmessage', 'jetpack_resize' ), JETPACK__VERSION, true );
274
			wp_enqueue_style( 'jetpack_likes', plugins_url( 'jetpack-likes.css', __FILE__ ), array(), JETPACK__VERSION );
275
		}
276
	}
277
278
	/**
279
	* Register scripts
280
	*/
281
	function register_scripts() {
282
		wp_register_script( 'postmessage', plugins_url( '_inc/postmessage.js', dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false );
283
		wp_register_script( 'jetpack_resize', plugins_url( '_inc/jquery.jetpack-resize.js' , dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false );
284
		wp_register_script( 'jetpack_likes_queuehandler', plugins_url( 'likes/queuehandler.js' , __FILE__ ), array( 'jquery', 'postmessage', 'jetpack_resize' ), JETPACK__VERSION, true );
285
	}
286
287
	/**
288
	* Load the CSS needed for the wp-admin area.
289
	*/
290
	function load_admin_css() {
291
	?>
292
		<style type="text/css">
293
			.vers img { display: none; }
294
			.metabox-prefs .vers img { display: inline; }
295
			.fixed .column-likes { width: 5.5em; padding: 8px 0; text-align: left; }
296
			.fixed .column-stats { width: 5em; }
297
			.fixed .column-likes .post-com-count {
298
				-webkit-box-sizing: border-box;
299
				-moz-box-sizing: border-box;
300
				box-sizing: border-box;
301
				display: inline-block;
302
				padding: 0 8px;
303
				height: 2em;
304
				margin-top: 5px;
305
				-webkit-border-radius: 5px;
306
				border-radius: 5px;
307
				background-color: #72777C;
308
				color: #FFF;
309
				font-size: 11px;
310
				line-height: 21px;
311
			}
312
			.fixed .column-likes .post-com-count::after { border: none !important; }
313
			.fixed .column-likes .post-com-count:hover { background-color: #0073AA; }
314
			.fixed .column-likes .vers:before {
315
				font: normal 20px/1 dashicons;
316
				content: '\f155';
317
				speak: none;
318
				-webkit-font-smoothing: antialiased;
319
				-moz-osx-font-smoothing: grayscale;
320
			}
321
			@media screen and (max-width: 782px) {
322
				.fixed .column-likes {
323
					display: none;
324
				}
325
			}
326
		</style>
327
		<?php
328
	}
329
330
	/**
331
	* Load the JS required for loading the like counts.
332
	*/
333
	function enqueue_admin_scripts() {
334
		if ( empty( $_GET['post_type'] ) || 'post' == $_GET['post_type'] || 'page' == $_GET['post_type'] ) {
335
			if ( $this->in_jetpack ) {
336
				wp_enqueue_script( 'likes-post-count', plugins_url( 'modules/likes/post-count.js', dirname( __FILE__ ) ), array( 'jquery' ), JETPACK__VERSION );
337
				wp_enqueue_script( 'likes-post-count-jetpack', plugins_url( 'modules/likes/post-count-jetpack.js', dirname( __FILE__ ) ), array( 'likes-post-count' ), JETPACK__VERSION );
338
			} else {
339
				wp_enqueue_script( 'jquery.wpcom-proxy-request', "/wp-content/js/jquery/jquery.wpcom-proxy-request.js", array('jquery'), NULL, true );
340
				wp_enqueue_script( 'likes-post-count', plugins_url( 'likes/post-count.js', dirname( __FILE__ ) ), array( 'jquery' ), JETPACK__VERSION );
341
				wp_enqueue_script( 'likes-post-count-wpcom', plugins_url( 'likes/post-count-wpcom.js', dirname( __FILE__ ) ), array( 'likes-post-count', 'jquery.wpcom-proxy-request' ), JETPACK__VERSION );
342
			}
343
		}
344
	}
345
346
	/**
347
	* Add "Likes" column data to the post edit table in wp-admin.
348
	*
349
	* @param string $column_name
350
	* @param int $post_id
351
	*/
352
	function likes_edit_column( $column_name, $post_id ) {
353
		if ( 'likes' == $column_name ) {
354
355
			if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
356
				$blog_id = get_current_blog_id();
357
			} else {
358
				$blog_id = Jetpack_Options::get_option( 'id' );
359
			}
360
361
			$permalink = get_permalink( get_the_ID() ); ?>
362
			<a title="" data-post-id="<?php echo (int) $post_id; ?>" class="post-com-count post-like-count" id="post-like-count-<?php echo (int) $post_id; ?>" data-blog-id="<?php echo (int) $blog_id; ?>" href="<?php echo esc_url( $permalink ); ?>#like-<?php echo (int) $post_id; ?>">
363
				<span class="comment-count">0</span>
364
			</a>
365
			<?php
366
		}
367
	}
368
369
	/**
370
	* Add a "Likes" column header to the post edit table in wp-admin.
371
	*
372
	* @param array $columns
373
	* @return array
374
	*/
375
	function add_like_count_column( $columns ) {
376
		$date = $columns['date'];
377
		unset( $columns['date'] );
378
379
		$columns['likes'] = '<span class="vers"><img title="' . esc_attr__( 'Likes', 'jetpack' ) . '" alt="' . esc_attr__( 'Likes', 'jetpack' ) . '" src="//s0.wordpress.com/i/like-grey-icon.png" /></span>';
380
		$columns['date'] = $date;
381
382
		return $columns;
383
	}
384
385
	function post_likes( $content ) {
386
		$post_id = get_the_ID();
387
388
		if ( ! is_numeric( $post_id ) || ! $this->settings->is_likes_visible() )
389
			return $content;
390
391 View Code Duplication
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
392
			$blog_id = get_current_blog_id();
393
			$bloginfo = get_blog_details( (int) $blog_id );
394
			$domain = $bloginfo->domain;
395
		} else {
396
			$blog_id = Jetpack_Options::get_option( 'id' );
397
			$url = home_url();
398
			$url_parts = parse_url( $url );
399
			$domain = $url_parts['host'];
400
		}
401
		// make sure to include the scripts before the iframe otherwise weird things happen
402
		add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
403
404
		/**
405
		* if the same post appears more then once on a page the page goes crazy
406
		* we need a slightly more unique id / name for the widget wrapper.
407
		*/
408
		$uniqid = uniqid();
409
410
		$src = sprintf( 'https://widgets.wp.com/likes/#blog_id=%1$d&amp;post_id=%2$d&amp;origin=%3$s&amp;obj_id=%1$d-%2$d-%4$s', $blog_id, $post_id, $domain, $uniqid );
411
		$name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
412
		$wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
413
		$headline = sprintf(
414
			/** This filter is already documented in modules/sharedaddy/sharing-service.php */
415
			apply_filters( 'jetpack_sharing_headline_html', '<h3 class="sd-title">%s</h3>', esc_html__( 'Like this:', 'jetpack' ), 'likes' ),
416
			esc_html__( 'Like this:', 'jetpack' )
417
		);
418
419
		$html  = "<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='$wrapper' data-src='$src' data-name='$name'>";
420
		$html .= $headline;
421
		$html .= "<div class='likes-widget-placeholder post-likes-widget-placeholder' style='height: 55px;'><span class='button'><span>" . esc_html__( 'Like', 'jetpack' ) . '</span></span> <span class="loading">' . esc_html__( 'Loading...', 'jetpack' ) . '</span></div>';
422
		$html .= "<span class='sd-text-color'></span><a class='sd-link-color'></a>";
423
		$html .= '</div>';
424
425
		// Let's make sure that the script is enqueued
426
		wp_enqueue_script( 'jetpack_likes_queuehandler' );
427
428
		return $content . $html;
429
	}
430
431
	function post_flair_service_enabled_like( $classes ) {
432
		$classes[] = 'sd-like-enabled';
433
		return $classes;
434
	}
435
436
	function is_admin_bar_button_visible() {
437
		global $wp_admin_bar;
438
439
		if ( ! is_object( $wp_admin_bar ) )
440
			return false;
441
442
		if ( ( ! is_singular( 'post' ) && ! is_attachment() && ! is_page() ) )
443
			return false;
444
445
		if ( ! $this->settings->is_likes_visible() )
446
			return false;
447
448
		if ( ! $this->settings->is_post_likeable() )
449
			return false;
450
451
		/**
452
		 * Filters whether the Like button is enabled in the admin bar.
453
		 *
454
		 * @module likes
455
		 *
456
		 * @since 2.2.0
457
		 *
458
		 * @param bool true Should the Like button be visible in the Admin bar. Default to true.
459
		 */
460
		return (bool) apply_filters( 'jetpack_admin_bar_likes_enabled', true );
461
	}
462
463
	function admin_bar_likes() {
464
		global $wp_admin_bar;
465
466
		$post_id = get_the_ID();
467
468
		if ( ! is_numeric( $post_id ) || ! $this->is_admin_bar_button_visible() ) {
469
			return;
470
		}
471
472
		$protocol = 'http';
473
		if ( is_ssl() )
474
			$protocol = 'https';
475
476 View Code Duplication
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
477
			$blog_id = get_current_blog_id();
478
			$bloginfo = get_blog_details( (int) $blog_id );
479
			$domain = $bloginfo->domain;
480
		} else {
481
			$blog_id = Jetpack_Options::get_option( 'id' );
482
			$url = home_url();
483
			$url_parts = parse_url( $url );
484
			$domain = $url_parts['host'];
485
		}
486
		// make sure to include the scripts before the iframe otherwise weird things happen
487
		add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
488
489
		$src = sprintf( 'https://widgets.wp.com/likes/#blog_id=%2$d&amp;post_id=%3$d&amp;origin=%1$s://%4$s', $protocol, $blog_id, $post_id, $domain );
490
491
		$html = "<iframe class='admin-bar-likes-widget jetpack-likes-widget' scrolling='no' frameBorder='0' name='admin-bar-likes-widget' src='$src'></iframe>";
492
493
		$node = array(
494
				'id'   => 'admin-bar-likes-widget',
495
				'meta' => array(
496
							'html' => $html
497
				)
498
		);
499
500
		$wp_admin_bar->add_node( $node );
501
	}
502
}
503
504
Jetpack_Likes::init();
505