Jetpack_Likes

The Jetpack by WordPress.com Jetpack Likes class.

Defined (1)

The class is defined in the following location(s).

/modules/likes.php  
  1. class Jetpack_Likes { 
  2. public $version = '20141028'; 
  3.  
  4. public static function init() { 
  5. static $instance = NULL; 
  6.  
  7. if ( ! $instance ) { 
  8. $instance = new Jetpack_Likes; 
  9.  
  10. return $instance; 
  11.  
  12. function __construct() { 
  13. $this->in_jetpack = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? false : true; 
  14.  
  15. add_action( 'init', array( &$this, 'action_init' ) ); 
  16. add_action( 'admin_init', array( $this, 'admin_init' ) ); 
  17.  
  18. if ( $this->in_jetpack ) { 
  19. add_action( 'jetpack_activate_module_likes', array( $this, 'maybe_sync_content' ) ); 
  20. add_action( 'jetpack_activate_module_likes', array( $this, 'module_toggle' ) ); 
  21. add_action( 'jetpack_deactivate_module_likes', array( $this, 'module_toggle' ) ); 
  22. add_action( 'jetpack_activate_module_likes', array( $this, 'set_social_notifications_like' ) ); 
  23. add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) ); 
  24.  
  25. Jetpack::enable_module_configurable( __FILE__ ); 
  26. Jetpack::module_configuration_load( __FILE__, array( $this, 'configuration_redirect' ) ); 
  27.  
  28. add_action('admin_print_scripts-settings_page_sharing', array( &$this, 'load_jp_css' ) ); 
  29. add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) ); 
  30.  
  31. $active = Jetpack::get_active_modules(); 
  32.  
  33. if ( ! in_array( 'sharedaddy', $active ) && ! in_array( 'publicize', $active ) ) { 
  34. add_action( 'admin_menu', array( $this, 'sharing_menu' ) ); // we don't have a sharing page yet 
  35.  
  36. if ( in_array( 'publicize', $active ) && ! in_array( 'sharedaddy', $active ) ) { 
  37. add_action( 'pre_admin_screen_sharing', array( $this, 'sharing_block' ), 20 ); // we have a sharing page but not the global options area 
  38. add_action( 'pre_admin_screen_sharing', array( $this, 'updated_message' ), -10 ); 
  39.  
  40. if( ! in_array( 'sharedaddy', $active ) ) { 
  41. add_action( 'admin_init', array( $this, 'process_update_requests_if_sharedaddy_not_loaded' ) ); 
  42. add_action( 'sharing_global_options', array( $this, 'admin_settings_showbuttonon_init' ), 19 ); 
  43. add_action( 'sharing_admin_update', array( $this, 'admin_settings_showbuttonon_callback' ), 19 ); 
  44. add_action( 'admin_init', array( $this, 'add_meta_box' ) ); 
  45. } else { 
  46. add_filter( 'sharing_meta_box_title', array( $this, 'add_likes_to_sharing_meta_box_title' ) ); 
  47. add_action( 'start_sharing_meta_box_content', array( $this, 'meta_box_content' ) ); 
  48.  
  49. Jetpack_Sync::sync_options( __FILE__, 'social_notifications_like' ); 
  50.  
  51. } else { // wpcom 
  52. add_action( 'wpmu_new_blog', array( $this, 'enable_comment_likes' ), 10, 1 ); 
  53. add_action( 'admin_init', array( $this, 'add_meta_box' ) ); 
  54. add_action( 'end_likes_meta_box_content', array( $this, 'sharing_meta_box_content' ) ); 
  55. add_filter( 'likes_meta_box_title', array( $this, 'add_likes_to_sharing_meta_box_title' ) ); 
  56.  
  57. add_action( 'admin_init', array( $this, 'admin_discussion_likes_settings_init' ) ); // Likes notifications 
  58.  
  59. add_action( 'admin_bar_menu', array( $this, 'admin_bar_likes' ), 60 ); 
  60.  
  61. add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) ); 
  62.  
  63. add_action( 'save_post', array( $this, 'meta_box_save' ) ); 
  64. add_action( 'edit_attachment', array( $this, 'meta_box_save' ) ); 
  65. add_action( 'sharing_global_options', array( $this, 'admin_settings_init' ), 20 ); 
  66. add_action( 'sharing_admin_update', array( $this, 'admin_settings_callback' ), 20 ); 
  67.  
  68. function maybe_sync_content() { 
  69. if ( Jetpack::init()->sync->reindex_needed() ) { 
  70. Jetpack::init()->sync->reindex_trigger(); 
  71.  
  72. function module_toggle() { 
  73. $jetpack = Jetpack::init(); 
  74. $jetpack->sync->register( 'noop' ); 
  75.  
  76. /** 
  77. * Set the social_notifications_like option to `on` when the Likes module is activated. 
  78. * @since 3.7.0 
  79. * @return null 
  80. */ 
  81. function set_social_notifications_like() { 
  82. update_option( 'social_notifications_like', 'on' ); 
  83.  
  84. /** 
  85. * Delete the social_notifications_like option that was set to `on` on module activation. 
  86. * @since 3.7.0 
  87. * @return null 
  88. */ 
  89. function delete_social_notifications_like() { 
  90. delete_option( 'social_notifications_like' ); 
  91.  
  92. /** 
  93. * Redirects to the likes section of the sharing page. 
  94. */ 
  95. function configuration_redirect() { 
  96. wp_safe_redirect( admin_url( 'options-general.php?page=sharing#likes' ) ); 
  97. die(); 
  98.  
  99. /** 
  100. * Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable 
  101. */ 
  102. function load_jp_css() { 
  103. // Do we really need `admin_styles`? With the new admin UI, it's breaking some bits. 
  104. // Jetpack::init()->admin_styles(); 
  105. /** 
  106. * Load style on the front end. 
  107. * @return null 
  108. */ 
  109. function load_styles_register_scripts() { 
  110.  
  111. wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION ); 
  112. if( $this->in_jetpack ) { 
  113. $this->register_scripts(); 
  114.  
  115. /** 
  116. * Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box 
  117. * @param string $html row heading for the sharedaddy "which page" setting 
  118. * @return string html with the jetpack-targetable class and likes id. tbody gets closed after the like settings 
  119. */ 
  120. function configuration_target_area( $html = '' ) { 
  121. $html = "<tbody id='likes' class='jetpack-targetable'>" . $html; 
  122. return $html; 
  123.  
  124. /** 
  125. * Replaces the "Sharing" title for the post screen metabox with "Likes and Shares" 
  126. * @param string $title The current title of the metabox, not needed/used. 
  127. */ 
  128. function add_likes_to_sharing_meta_box_title( $title ) { 
  129. return __( 'Likes and Shares', 'jetpack' ); 
  130.  
  131. /** 
  132. * Adds a metabox to the post screen if the sharing one doesn't currently exist. 
  133. */ 
  134. function add_meta_box() { 
  135. if ( 
  136. /** 
  137. * Allow disabling of the Likes metabox on the post editor screen. 
  138. * @module likes 
  139. * @since 2.2.0 
  140. * @param bool false Should the Likes metabox be disabled? Default to false. 
  141. */ 
  142. apply_filters( 'post_flair_disable', false ) 
  143. ) { 
  144. return; 
  145.  
  146. $post_types = get_post_types( array( 'public' => true ) ); 
  147. /** 
  148. * Filters the Likes metabox title. 
  149. * @module likes 
  150. * @since 2.2.0 
  151. * @param string Likes metabox title. Default to "Likes". 
  152. */ 
  153. $title = apply_filters( 'likes_meta_box_title', __( 'Likes', 'jetpack' ) ); 
  154. foreach( $post_types as $post_type ) { 
  155. add_meta_box( 'likes_meta', $title, array( $this, 'meta_box_content' ), $post_type, 'advanced', 'high' ); 
  156.  
  157. function meta_box_save( $post_id ) { 
  158. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
  159. return $post_id; 
  160.  
  161. if ( empty( $_POST['wpl_like_status_hidden'] ) ) 
  162. return $post_id; 
  163.  
  164. // Record sharing disable. Only needs to be done for WPCOM 
  165. if ( ! $this->in_jetpack ) { 
  166. if ( isset( $_POST['post_type'] ) && in_array( $_POST['post_type'], get_post_types( array( 'public' => true ) ) ) ) { 
  167. if ( ! isset( $_POST['wpl_enable_post_sharing'] ) ) { 
  168. update_post_meta( $post_id, 'sharing_disabled', 1 ); 
  169. } else { 
  170. delete_post_meta( $post_id, 'sharing_disabled' ); 
  171.  
  172. if ( 'post' == $_POST['post_type'] ) { 
  173. if ( !current_user_can( 'edit_post', $post_id ) ) { 
  174. return $post_id; 
  175.  
  176. // Record a change in like status for this post - only if it contradicts the 
  177. // site like setting. 
  178. if ( ( $this->is_enabled_sitewide() && empty( $_POST['wpl_enable_post_likes'] ) ) || ( ! $this->is_enabled_sitewide() && !empty( $_POST['wpl_enable_post_likes'] ) ) ) { 
  179. update_post_meta( $post_id, 'switch_like_status', 1 ); 
  180. //$g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=switched_post_like_status' ); @todo stat 
  181. } else { 
  182. delete_post_meta( $post_id, 'switch_like_status' ); 
  183.  
  184. return $post_id; 
  185.  
  186. /** 
  187. * Shows the likes option in the post screen metabox. 
  188. */ 
  189. function meta_box_content( $post ) { 
  190. $post_id = ! empty( $post->ID ) ? (int) $post->ID : get_the_ID(); 
  191. $checked = true; 
  192. $disabled = ! $this->is_enabled_sitewide(); 
  193. $switched_status = get_post_meta( $post_id, 'switch_like_status', true ); 
  194.  
  195. if ( $disabled && empty( $switched_status ) || false == $disabled && !empty( $switched_status ) ) 
  196. $checked = false; 
  197.  
  198. /** 
  199. * Fires before the Likes meta box content in the post editor. 
  200. * @module likes 
  201. * @since 2.2.0 
  202. * @param WP_Post|array|null $post Post data. 
  203. */ 
  204. do_action( 'start_likes_meta_box_content', $post ); 
  205. ?> 
  206.  
  207. <p> 
  208. <label for="wpl_enable_post_likes"> 
  209. <input type="checkbox" name="wpl_enable_post_likes" id="wpl_enable_post_likes" value="1" <?php checked( $checked ); ?>> 
  210. <?php esc_html_e( 'Show likes.', 'jetpack' ); ?> 
  211. </label> 
  212. <input type="hidden" name="wpl_like_status_hidden" value="1" /> 
  213. </p> <?php 
  214. /** 
  215. * Fires after the Likes meta box content in the post editor. 
  216. * @module likes 
  217. * @since 2.2.0 
  218. * @param WP_Post|array|null $post Post data. 
  219. */ 
  220. do_action( 'end_likes_meta_box_content', $post ); 
  221.  
  222. /** 
  223. * WordPress.com: Metabox option for sharing (sharedaddy will handle this on the JP blog) 
  224. */ 
  225. function sharing_meta_box_content( $post ) { 
  226. $post_id = ! empty( $post->ID ) ? (int) $post->ID : get_the_ID(); 
  227. $disabled = get_post_meta( $post_id, 'sharing_disabled', true ); ?> 
  228. <p> 
  229. <label for="wpl_enable_post_sharing"> 
  230. <input type="checkbox" name="wpl_enable_post_sharing" id="wpl_enable_post_sharing" value="1" <?php checked( !$disabled ); ?>> 
  231. <?php _e( 'Show sharing buttons.', 'jetpack' ); ?> 
  232. </label> 
  233. <input type="hidden" name="wpl_sharing_status_hidden" value="1" /> 
  234. </p> <?php 
  235.  
  236. /** 
  237. * Options to be added to the discussion page (see also admin_settings_init, etc below for Sharing settings page) 
  238. */ 
  239.  
  240. function admin_discussion_likes_settings_init() { 
  241. // Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings 
  242. add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' ); 
  243. add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' ); 
  244. // Register the setting 
  245. register_setting( 'discussion', 'social_notifications_like', array( $this, 'admin_discussion_likes_settings_validate' ) ); 
  246.  
  247. function admin_discussion_likes_settings_section() { 
  248. // Atypical usage here. We emit jquery to move likes notification checkbox to be with the rest of the email notification settings 
  249. ?> 
  250. <script type="text/javascript"> 
  251. jQuery( function( $ ) { 
  252. var table = $( '#social_notifications_like' ).parents( 'table:first' ),  
  253. header = table.prevAll( 'h3:first' ),  
  254. newParent = $( '#moderation_notify' ).parent( 'label' ).parent(); 
  255.  
  256. if ( !table.size() || !header.size() || !newParent.size() ) { 
  257. return; 
  258.  
  259. newParent.append( '<br/>' ).append( table.end().parent( 'label' ).siblings().andSelf() ); 
  260. header.remove(); 
  261. table.remove(); 
  262. } ); 
  263. </script> 
  264. <?php 
  265.  
  266. function admin_likes_get_option( $option ) { 
  267. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  268. $option_setting = get_blog_option( get_current_blog_id(), $option, 'on' ); 
  269. } else { 
  270. $option_setting = get_option( $option, 'on' ); 
  271.  
  272. return intval( 'on' == $option_setting ); 
  273.  
  274. function admin_discussion_likes_settings_field() { 
  275. $like = $this->admin_likes_get_option( 'social_notifications_like' ); 
  276. ?> 
  277. <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> 
  278. <?php 
  279.  
  280. function admin_discussion_likes_settings_validate( $input ) { 
  281. // If it's not set (was unchecked during form submission) or was set to off (during option update), return 'off'. 
  282. if ( !$input || 'off' == $input ) 
  283. return 'off'; 
  284.  
  285. // Otherwise, return 'on'. 
  286. return 'on'; 
  287.  
  288. /** 
  289. * The actual options block to be inserted into the sharing page. 
  290. */ 
  291. function admin_settings_init() { ?> 
  292. <tr> 
  293. <th scope="row"> 
  294. <label><?php esc_html_e( 'WordPress.com Likes are', 'jetpack' ); ?></label> 
  295. </th> 
  296. <td> 
  297. <div> 
  298. <label> 
  299. <input type="radio" class="code" name="wpl_default" value="on" <?php checked( $this->is_enabled_sitewide(), true ); ?> /> 
  300. <?php esc_html_e( 'On for all posts', 'jetpack' ); ?> 
  301. </label> 
  302. </div> 
  303. <div> 
  304. <label> 
  305. <input type="radio" class="code" name="wpl_default" value="off" <?php checked( $this->is_enabled_sitewide(), false ); ?> /> 
  306. <?php esc_html_e( 'Turned on per post', 'jetpack' ); ?> 
  307. </label> 
  308. <div> 
  309. </td> 
  310. </tr> 
  311. <?php if ( ! $this->in_jetpack ) : ?> 
  312. <tr> 
  313. <th scope="row"> 
  314. <label><?php esc_html_e( 'WordPress.com Reblog Button', 'jetpack' ); ?></label> 
  315. </th> 
  316. <td> 
  317. <div> 
  318. <label> 
  319. <input type="radio" class="code" name="jetpack_reblogs_enabled" value="on" <?php checked( $this->reblogs_enabled_sitewide(), true ); ?> /> 
  320. <?php esc_html_e( 'Show the Reblog button on posts', 'jetpack' ); ?> 
  321. </label> 
  322. </div> 
  323. <div> 
  324. <label> 
  325. <input type="radio" class="code" name="jetpack_reblogs_enabled" value="off" <?php checked( $this->reblogs_enabled_sitewide(), false ); ?> /> 
  326. <?php esc_html_e( 'Don\'t show the Reblog button on posts', 'jetpack' ); ?> 
  327. </label> 
  328. <div> 
  329. </td> 
  330. </tr> 
  331. <tr> 
  332. <th scope="row"> 
  333. <label><?php esc_html_e( 'Comment Likes are', 'jetpack' ); ?></label> 
  334. </th> 
  335. <td> 
  336. <div> 
  337. <label> 
  338. <input type="checkbox" class="code" name="jetpack_comment_likes_enabled" value="1" <?php checked( $this->is_comments_enabled(), true ); ?> /> 
  339. <?php esc_html_e( 'On for all comments', 'jetpack' ); ?> 
  340. </label> 
  341. </div> 
  342. </td> 
  343. </tr> 
  344. <?php endif; ?> 
  345. </tbody> <?php // closes the tbody attached to sharing_show_buttons_on_row_start... ?> 
  346. <?php } 
  347.  
  348. /** 
  349. * If sharedaddy is not loaded, we don't have the "Show buttons on" yet, so we need to add that since it affects likes too. 
  350. */ 
  351. function admin_settings_showbuttonon_init() { ?> 
  352. <?php 
  353. /** This action is documented in modules/sharedaddy/sharing.php */ 
  354. echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); 
  355. ?> 
  356. <th scope="row"><label><?php _e( 'Show buttons on', 'jetpack' ); ?></label></th> 
  357. <td> 
  358. <?php 
  359. $br = false; 
  360. $shows = array_values( get_post_types( array( 'public' => true ) ) ); 
  361. array_unshift( $shows, 'index' ); 
  362. $global = $this->get_options(); 
  363. foreach ( $shows as $show ) : 
  364. if ( 'index' == $show ) { 
  365. $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' ); 
  366. } else { 
  367. $post_type_object = get_post_type_object( $show ); 
  368. $label = $post_type_object->labels->name; 
  369. ?> 
  370. <?php if ( $br ) echo '<br />'; ?><label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label> 
  371. <?php $br = true; endforeach; ?> 
  372. </td> 
  373. <?php 
  374. /** This action is documented in modules/sharedaddy/sharing.php */ 
  375. echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); 
  376. ?> 
  377. <?php } 
  378.  
  379.  
  380. /** 
  381. * If sharedaddy is not loaded, we still need to save the the settings of the "Show buttons on" option. 
  382. */ 
  383. function admin_settings_showbuttonon_callback() { 
  384. $options = get_option( 'sharing-options' ); 
  385. if ( !is_array( $options ) ) 
  386. $options = array(); 
  387.  
  388. $shows = array_values( get_post_types( array( 'public' => true ) ) ); 
  389. $shows[] = 'index'; 
  390. $data = $_POST; 
  391.  
  392. if ( isset( $data['show'] ) ) { 
  393. if ( is_scalar( $data['show'] ) ) { 
  394. switch ( $data['show'] ) { 
  395. case 'posts' : 
  396. $data['show'] = array( 'post', 'page' ); 
  397. break; 
  398. case 'index' : 
  399. $data['show'] = array( 'index' ); 
  400. break; 
  401. case 'posts-index' : 
  402. $data['show'] = array( 'post', 'page', 'index' ); 
  403. break; 
  404.  
  405. if ( $data['show'] = array_intersect( $data['show'], $shows ) ) { 
  406. $options['global']['show'] = $data['show']; 
  407. } else { 
  408. $options['global']['show'] = array(); 
  409.  
  410. update_option( 'sharing-options', $options ); 
  411.  
  412. /** 
  413. * Adds the admin update hook so we can save settings even if Sharedaddy is not enabled. 
  414. */ 
  415. function process_update_requests_if_sharedaddy_not_loaded() { 
  416. if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'sharing.php' || $_GET['page'] == 'sharing' ) ) { 
  417. if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) { 
  418. /** This action is documented in modules/sharedaddy/sharing.php */ 
  419. do_action( 'sharing_admin_update' ); 
  420. wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) ); 
  421. die(); 
  422.  
  423. /** 
  424. * Saves the setting in the database, bumps a stat on WordPress.com 
  425. */ 
  426. function admin_settings_callback() { 
  427. // We're looking for these, and doing a dance to set some stats and save 
  428. // them together in array option. 
  429. $new_state = !empty( $_POST['wpl_default'] ) ? $_POST['wpl_default'] : 'on'; 
  430. $db_state = $this->is_enabled_sitewide(); 
  431.  
  432. $reblogs_new_state = !empty( $_POST['jetpack_reblogs_enabled'] ) ? $_POST['jetpack_reblogs_enabled'] : 'on'; 
  433. $reblogs_db_state = $this->reblogs_enabled_sitewide(); 
  434. /** Default State *********************************************************/ 
  435.  
  436. // Checked (enabled) 
  437. switch( $new_state ) { 
  438. case 'off' : 
  439. if ( true == $db_state && ! $this->in_jetpack ) { 
  440. $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=disabled_likes' ); 
  441. update_option( 'disabled_likes', 1 ); 
  442. break; 
  443. case 'on' : 
  444. default: 
  445. if ( false == $db_state && ! $this->in_jetpack ) { 
  446. $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=reenabled_likes' ); 
  447. delete_option( 'disabled_likes' ); 
  448. break; 
  449.  
  450. switch( $reblogs_new_state ) { 
  451. case 'off' : 
  452. if ( true == $reblogs_db_state && ! $this->in_jetpack ) { 
  453. $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_reblogs=disabled_reblogs' ); 
  454. update_option( 'disabled_reblogs', 1 ); 
  455. break; 
  456. case 'on' : 
  457. default: 
  458. if ( false == $reblogs_db_state && ! $this->in_jetpack ) { 
  459. $g_gif = file_get_contents( 'http://pixel.wp.com/g.gif?v=wpcom-no-pv&x_reblogs=reenabled_reblogs' ); 
  460. delete_option( 'disabled_reblogs' ); 
  461. break; 
  462.  
  463. // comment setting 
  464. $new_comments_state = !empty( $_POST['jetpack_comment_likes_enabled'] ) ? $_POST['jetpack_comment_likes_enabled'] : false; 
  465. switch( (bool) $new_comments_state ) { 
  466. case true: 
  467. update_option( 'jetpack_comment_likes_enabled', 1 ); 
  468. break; 
  469. case false: 
  470. default: 
  471. update_option( 'jetpack_comment_likes_enabled', 0 ); 
  472. break; 
  473.  
  474. /** 
  475. * Force comment likes on for a blog 
  476. * Used when a new blog is created 
  477. */ 
  478. function enable_comment_likes( $blog_id ) { 
  479. switch_to_blog( $blog_id ); 
  480. update_option( 'jetpack_comment_likes_enabled', 1 ); 
  481. restore_current_blog(); 
  482.  
  483. /** 
  484. * Adds the 'sharing' menu to the settings menu. 
  485. * Only ran if sharedaddy and publicize are not already active. 
  486. */ 
  487. function sharing_menu() { 
  488. add_submenu_page( 'options-general.php', esc_html__( 'Sharing Settings', 'jetpack' ), esc_html__( 'Sharing', 'jetpack' ), 'manage_options', 'sharing', array( $this, 'sharing_page' ) ); 
  489.  
  490. /** 
  491. * Provides a sharing page with the sharing_global_options hook 
  492. * so we can display the setting. 
  493. * Only ran if sharedaddy and publicize are not already active. 
  494. */ 
  495. function sharing_page() { 
  496. $this->updated_message(); ?> 
  497. <div class="wrap"> 
  498. <div class="icon32" id="icon-options-general"><br /></div> 
  499. <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1> 
  500. <?php 
  501. /** This action is documented in modules/sharedaddy/sharing.php */ 
  502. do_action( 'pre_admin_screen_sharing' ); 
  503. ?> 
  504. <?php $this->sharing_block(); ?> 
  505. </div> <?php 
  506.  
  507. /** 
  508. * Returns the settings have been saved message. 
  509. */ 
  510. function updated_message() { 
  511. if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ) 
  512. echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>'; 
  513.  
  514. /** 
  515. * Returns just the "sharing buttons" w/ like option block, so it can be inserted into different sharing page contexts 
  516. */ 
  517. function sharing_block() { ?> 
  518. <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2> 
  519. <form method="post" action=""> 
  520. <table class="form-table"> 
  521. <tbody> 
  522. <?php 
  523. /** This action is documented in modules/sharedaddy/sharing.php */ 
  524. do_action( 'sharing_global_options' ); 
  525. ?> 
  526. </tbody> 
  527. </table> 
  528.  
  529. <p class="submit"> 
  530. <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" /> 
  531. </p> 
  532.  
  533. <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" /> 
  534. </form> <?php 
  535.  
  536. function admin_init() { 
  537. add_filter( 'manage_posts_columns', array( $this, 'add_like_count_column' ) ); 
  538. add_filter( 'manage_pages_columns', array( $this, 'add_like_count_column' ) ); 
  539. add_action( 'manage_posts_custom_column', array( $this, 'likes_edit_column' ), 10, 2 ); 
  540. add_action( 'manage_pages_custom_column', array( $this, 'likes_edit_column' ), 10, 2 ); 
  541. add_action( 'admin_print_styles-edit.php', array( $this, 'load_admin_css' ) ); 
  542. add_action( "admin_print_scripts-edit.php", array( $this, 'enqueue_admin_scripts' ) ); 
  543.  
  544.  
  545. if ( $this->in_jetpack ) { 
  546. $post_stati = get_post_stati( array( 'public' => true ) ); // All public post stati 
  547. $post_stati[] = 'private'; // Content from private stati will be redacted 
  548. Jetpack_Sync::sync_posts( __FILE__, array( 
  549. 'post_types' => get_post_types( array( 'public' => true ) ),  
  550. 'post_stati' => $post_stati,  
  551. ) ); 
  552.  
  553. function action_init() { 
  554. if ( is_admin() ) { 
  555. return; 
  556.  
  557. if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || 
  558. ( defined( 'APP_REQUEST' ) && APP_REQUEST ) || 
  559. ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) || 
  560. ( defined( 'COOKIE_AUTH_REQUEST' ) && COOKIE_AUTH_REQUEST ) || 
  561. ( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) { 
  562. return; 
  563.  
  564. // Comment Likes widget has been disabled, pending performance improvements. 
  565. // add_filter( 'comment_text', array( &$this, 'comment_likes' ), 10, 2 ); 
  566.  
  567. if ( $this->in_jetpack ) { 
  568. add_filter( 'the_content', array( &$this, 'post_likes' ), 30, 1 ); 
  569. add_filter( 'the_excerpt', array( &$this, 'post_likes' ), 30, 1 ); 
  570.  
  571. } else { 
  572. add_filter( 'post_flair', array( &$this, 'post_likes' ), 30, 1 ); 
  573. add_filter( 'post_flair_block_css', array( $this, 'post_flair_service_enabled_like' ) ); 
  574.  
  575. wp_enqueue_script( 'postmessage', '/wp-content/js/postmessage.js', array( 'jquery' ), JETPACK__VERSION, false ); 
  576. wp_enqueue_script( 'jquery_inview', '/wp-content/js/jquery/jquery.inview.js', array( 'jquery' ), JETPACK__VERSION, false ); 
  577. wp_enqueue_script( 'jetpack_resize', '/wp-content/js/jquery/jquery.jetpack-resize.js', array( 'jquery' ), JETPACK__VERSION, false ); 
  578. wp_enqueue_style( 'jetpack_likes', plugins_url( 'jetpack-likes.css', __FILE__ ), array(), JETPACK__VERSION ); 
  579.  
  580. /** 
  581. * Register scripts 
  582. */ 
  583. function register_scripts() { 
  584. // Lets register all the sciprts 
  585. wp_register_script( 'postmessage', plugins_url( '_inc/postmessage.js', dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); 
  586. wp_register_script( 'jquery_inview', plugins_url( '_inc/jquery.inview.js', dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); 
  587. wp_register_script( 'jetpack_resize', plugins_url( '_inc/jquery.jetpack-resize.js' , dirname(__FILE__) ), array( 'jquery' ), JETPACK__VERSION, false ); 
  588. wp_register_script( 'jetpack_likes_queuehandler', plugins_url( 'likes/queuehandler.js' , __FILE__ ), array( 'jquery', 'postmessage', 'jetpack_resize', 'jquery_inview' ), JETPACK__VERSION, true ); 
  589.  
  590. /** 
  591. * Load the CSS needed for the wp-admin area. 
  592. */ 
  593. function load_admin_css() { 
  594. ?> 
  595. <?php if ( version_compare( $GLOBALS['wp_version'], '4.3-alpha', '>=' ) ) : ?> 
  596. <style type="text/css"> 
  597. .vers img { display: none; } 
  598. .metabox-prefs .vers img { display: inline; } 
  599. .fixed .column-likes { width: 5.5em; padding: 8px 0; text-align: left; } 
  600. .fixed .column-stats { width: 5em; } 
  601. .fixed .column-likes .post-com-count { 
  602. -webkit-box-sizing: border-box; 
  603. -moz-box-sizing: border-box; 
  604. box-sizing: border-box; 
  605. display: inline-block; 
  606. padding: 0 8px; 
  607. height: 2em; 
  608. margin-top: 5px; 
  609. -webkit-border-radius: 5px; 
  610. border-radius: 5px; 
  611. background-color: #72777C; 
  612. color: #FFF; 
  613. font-size: 11px; 
  614. line-height: 21px; 
  615. .fixed .column-likes .post-com-count::after { border: none !important; } 
  616. .fixed .column-likes .post-com-count:hover { background-color: #0073AA; } 
  617. .fixed .column-likes .vers:before { 
  618. font: normal 20px/1 dashicons; 
  619. content: '\f155'; 
  620. speak: none; 
  621. -webkit-font-smoothing: antialiased; 
  622. -moz-osx-font-smoothing: grayscale; 
  623. @media screen and (max-width: 782px) { 
  624. .fixed .column-likes { 
  625. display: none; 
  626. </style> 
  627. <?php else : // @todo Remove when 4.3 is minimum ?> 
  628. <style type="text/css"> 
  629. .fixed .column-likes { width: 5em; padding-top: 8px; text-align: center !important; } 
  630. .fixed .column-stats { width: 5em; } 
  631. .fixed .column-likes .post-com-count { background-image: none; } 
  632. .fixed .column-likes .post-com-count::after { border: none !important; } 
  633. .fixed .column-likes .comment-count { background-color: #bbb; } 
  634. .fixed .column-likes .comment-count:hover { background-color: #2ea2cc; } 
  635. .fixed .column-likes .vers img { display: none; } 
  636. .fixed .column-likes .vers:before { 
  637. font: normal 20px/1 dashicons; 
  638. content: '\f155'; 
  639. speak: none; 
  640. -webkit-font-smoothing: antialiased; 
  641. -moz-osx-font-smoothing: grayscale; 
  642. @media screen and (max-width: 782px) { 
  643. .fixed .column-likes { 
  644. display: none; 
  645. </style> 
  646. <?php endif; ?> 
  647. <?php 
  648.  
  649. /** 
  650. * Load the JS required for loading the like counts. 
  651. */ 
  652. function enqueue_admin_scripts() { 
  653. if ( empty( $_GET['post_type'] ) || 'post' == $_GET['post_type'] || 'page' == $_GET['post_type'] ) { 
  654. if ( $this->in_jetpack ) { 
  655. wp_enqueue_script( 'likes-post-count', plugins_url( 'modules/likes/post-count.js', dirname( __FILE__ ) ), array( 'jquery' ), JETPACK__VERSION ); 
  656. wp_enqueue_script( 'likes-post-count-jetpack', plugins_url( 'modules/likes/post-count-jetpack.js', dirname( __FILE__ ) ), array( 'likes-post-count' ), JETPACK__VERSION ); 
  657. } else { 
  658. wp_enqueue_script( 'jquery.wpcom-proxy-request', "/wp-content/js/jquery/jquery.wpcom-proxy-request.js", array('jquery'), NULL, true ); 
  659. wp_enqueue_script( 'likes-post-count', plugins_url( 'likes/post-count.js', dirname( __FILE__ ) ), array( 'jquery' ), JETPACK__VERSION ); 
  660. 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 ); 
  661.  
  662. /** 
  663. * Add "Likes" column data to the post edit table in wp-admin. 
  664. * @param string $column_name 
  665. * @param int $post_id 
  666. */ 
  667. function likes_edit_column( $column_name, $post_id ) { 
  668. if ( 'likes' == $column_name ) { 
  669.  
  670. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  671. $blog_id = get_current_blog_id(); 
  672. } else { 
  673. $blog_id = Jetpack_Options::get_option( 'id' ); 
  674.  
  675. $permalink = get_permalink( get_the_ID() ); ?> 
  676. <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; ?>"> 
  677. <span class="comment-count">0</span> 
  678. </a> 
  679. <?php 
  680.  
  681. /** 
  682. * Add a "Likes" column header to the post edit table in wp-admin. 
  683. * @param array $columns 
  684. * @return array 
  685. */ 
  686. function add_like_count_column( $columns ) { 
  687. $date = $columns['date']; 
  688. unset( $columns['date'] ); 
  689.  
  690. $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>'; 
  691. $columns['date'] = $date; 
  692.  
  693. return $columns; 
  694.  
  695. function post_likes( $content ) { 
  696. global $post; 
  697.  
  698. if ( ! $this->is_likes_visible() ) 
  699. return $content; 
  700.  
  701. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  702. $blog_id = get_current_blog_id(); 
  703. $bloginfo = get_blog_details( (int) $blog_id ); 
  704. $domain = $bloginfo->domain; 
  705. } else { 
  706. $blog_id = Jetpack_Options::get_option( 'id' ); 
  707. $url = home_url(); 
  708. $url_parts = parse_url( $url ); 
  709. $domain = $url_parts['host']; 
  710. // make sure to include the scripts before the iframe otherwise weird things happen 
  711. add_action( 'wp_footer', array( $this, 'likes_master' ), 21 ); 
  712.  
  713. /** 
  714. * if the same post appears more then once on a page the page goes crazy 
  715. * we need a slightly more unique id / name for the widget wrapper. 
  716. */ 
  717. $uniqid = uniqid(); 
  718.  
  719. $src = sprintf( '//widgets.wp.com/likes/#blog_id=%1$d&post_id=%2$d&origin=%3$s&obj_id=%1$d-%2$d-%4$s', $blog_id, $post->ID, $domain, $uniqid ); 
  720. $name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post->ID, $uniqid ); 
  721. $wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post->ID, $uniqid ); 
  722.  
  723. $html = "<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='$wrapper' data-src='$src' data-name='$name'><h3 class='sd-title'>" . esc_html__( 'Like this:', 'jetpack' ) . '</h3>'; 
  724. $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>'; 
  725. $html .= "<span class='sd-text-color'></span><a class='sd-link-color'></a>"; 
  726. $html .= '</div>'; 
  727.  
  728. // Lets make sure that the script is enqued 
  729. wp_enqueue_script( 'jetpack_likes_queuehandler' ); 
  730.  
  731. return $content . $html; 
  732.  
  733. function comment_likes( $content, $comment = null ) { 
  734. if ( empty( $comment ) ) 
  735. return $content; 
  736.  
  737. if ( ! $this->is_comments_enabled() ) 
  738. return $content; 
  739.  
  740. $protocol = 'http'; 
  741. if ( is_ssl() ) 
  742. $protocol = 'https'; 
  743.  
  744. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  745. $blog_id = get_current_blog_id(); 
  746. $bloginfo = get_blog_details( (int) $blog_id ); 
  747. $domain = $bloginfo->domain; 
  748. } else { 
  749. $blog_id = Jetpack_Options::get_option( 'id' ); 
  750. $url = home_url(); 
  751. $url_parts = parse_url( $url ); 
  752. $domain = $url_parts['host']; 
  753. // make sure to include the scripts before the iframe otherwise weird things happen 
  754. add_action( 'wp_footer', array( $this, 'likes_master' ), 21 ); 
  755.  
  756. $src = sprintf( '%1$s://widgets.wp.com/likes/#blog_id=%2$d&comment_id=%3$d&origin=%1$s://%4$s', $protocol, $blog_id, $comment->comment_ID, $domain ); 
  757. $name = sprintf( 'like-comment-frame-%1$d-%2$d', $blog_id, $comment->comment_ID ); 
  758. $wrapper = sprintf( 'like-comment-wrapper-%1$d-%2$d', $blog_id, $comment->comment_ID ); 
  759.  
  760. $html = "<div><div class='jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='$wrapper'>"; 
  761. $html .= "<iframe class='comment-likes-widget jetpack-likes-widget' name='$name' height='16px' width='100%' data='$src'></iframe>"; 
  762. $html .= '</div></div>'; 
  763. return $content . $html; 
  764.  
  765. function post_flair_service_enabled_like( $classes ) { 
  766. $classes[] = 'sd-like-enabled'; 
  767. return $classes; 
  768.  
  769. function admin_bar_likes() { 
  770. global $wp_admin_bar, $post; 
  771.  
  772. if ( ! $this->is_admin_bar_button_visible() ) { 
  773. return; 
  774.  
  775. $protocol = 'http'; 
  776. if ( is_ssl() ) 
  777. $protocol = 'https'; 
  778.  
  779. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  780. $blog_id = get_current_blog_id(); 
  781. $bloginfo = get_blog_details( (int) $blog_id ); 
  782. $domain = $bloginfo->domain; 
  783. } else { 
  784. $blog_id = Jetpack_Options::get_option( 'id' ); 
  785. $url = home_url(); 
  786. $url_parts = parse_url( $url ); 
  787. $domain = $url_parts['host']; 
  788. // make sure to include the scripts before the iframe otherwise weird things happen 
  789. add_action( 'wp_footer', array( $this, 'likes_master' ), 21 ); 
  790.  
  791. $src = sprintf( '%1$s://widgets.wp.com/likes/#blog_id=%2$d&post_id=%3$d&origin=%1$s://%4$s', $protocol, $blog_id, $post->ID, $domain ); 
  792.  
  793. $html = "<iframe class='admin-bar-likes-widget jetpack-likes-widget' scrolling='no' frameBorder='0' name='admin-bar-likes-widget' src='$src'></iframe>"; 
  794.  
  795. $node = array( 
  796. 'id' => 'admin-bar-likes-widget',  
  797. 'meta' => array( 
  798. 'html' => $html 
  799. ); 
  800.  
  801. $wp_admin_bar->add_node( $node ); 
  802.  
  803. /** 
  804. * This function needs to get loaded after the scripts get added to the page. 
  805. */ 
  806. function likes_master() { 
  807. $protocol = 'http'; 
  808. if ( is_ssl() ) 
  809. $protocol = 'https'; 
  810.  
  811. $_locale = get_locale(); 
  812.  
  813. // We have to account for WP.org vs WP.com locale divergence 
  814. if ( $this->in_jetpack ) { 
  815. if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { 
  816. return false; 
  817.  
  818. require_once JETPACK__GLOTPRESS_LOCALES_PATH; 
  819.  
  820. $gp_locale = GP_Locales::by_field( 'wp_locale', $_locale ); 
  821. $_locale = isset( $gp_locale->slug ) ? $gp_locale->slug : ''; 
  822.  
  823. $likes_locale = ( '' == $_locale || 'en' == $_locale ) ? '' : '&lang=' . strtolower( $_locale ); 
  824.  
  825. $src = sprintf( 
  826. '%1$s://widgets.wp.com/likes/master.html?ver=%2$s#ver=%2$s%3$s',  
  827. $protocol,  
  828. $this->version,  
  829. $likes_locale 
  830. ); 
  831.  
  832. $likersText = wp_kses( __( '<span>%d</span> bloggers like this:', 'jetpack' ), array( 'span' => array() ) ); 
  833. ?> 
  834. <iframe src='<?php echo $src; ?>' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe> 
  835. <div id='likes-other-gravatars'><div class="likes-text"><?php echo $likersText; ?></div><ul class="wpl-avatars sd-like-gravatars"></ul></div> 
  836. <?php 
  837.  
  838. /** 
  839. * Get the 'disabled_likes' option from the DB of the current blog. 
  840. * @return array 
  841. */ 
  842. function get_options() { 
  843. $setting = array(); 
  844. $setting['disabled'] = get_option( 'disabled_likes' ); 
  845. $sharing = get_option( 'sharing-options' ); 
  846.  
  847. // Default visibility settings 
  848. if ( ! isset( $sharing['global']['show'] ) ) { 
  849. $sharing['global']['show'] = array( 'post', 'page' ); 
  850.  
  851. // Scalar check 
  852. } elseif ( is_scalar( $sharing['global']['show'] ) ) { 
  853. switch ( $sharing['global']['show'] ) { 
  854. case 'posts' : 
  855. $sharing['global']['show'] = array( 'post', 'page' ); 
  856. break; 
  857. case 'index' : 
  858. $sharing['global']['show'] = array( 'index' ); 
  859. break; 
  860. case 'posts-index' : 
  861. $sharing['global']['show'] = array( 'post', 'page', 'index' ); 
  862. break; 
  863.  
  864. // Ensure it's always an array (even if not previously empty or scalar) 
  865. $setting['show'] = !empty( $sharing['global']['show'] ) ? (array) $sharing['global']['show'] : array(); 
  866.  
  867. /** 
  868. * Filters where the Likes are displayed. 
  869. * @module likes 
  870. * @since 2.2.0 
  871. * @param array $setting Array of Likes display settings. 
  872. */ 
  873. return apply_filters( 'wpl_get_options', $setting ); 
  874.  
  875. /** _is_ functions ************************************************************/ 
  876.  
  877. /** 
  878. * Are likes visible in this context? 
  879. * Some of this code was taken and modified from sharing_display() to ensure 
  880. * similar logic and filters apply here, too. 
  881. */ 
  882. function is_likes_visible() { 
  883.  
  884. global $post, $wp_current_filter; // Used to apply 'sharing_show' filter 
  885.  
  886. // Never show on feeds or previews 
  887. if ( is_feed() || is_preview() || is_comments_popup() ) { 
  888. $enabled = false; 
  889.  
  890. // Not a feed or preview, so what is it? 
  891. } else { 
  892.  
  893. if ( in_the_loop() ) { 
  894. // If in the loop, check if the current post is likeable 
  895. $enabled = $this->is_post_likeable(); 
  896. } else { 
  897. // Otherwise, check and see if likes are enabled sitewide 
  898. $enabled = $this->is_enabled_sitewide(); 
  899.  
  900. if ( post_password_required() ) 
  901. $enabled = false; 
  902.  
  903. if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) { 
  904. $enabled = false; 
  905.  
  906. // Sharing Setting Overrides **************************************** 
  907.  
  908. // Single post including custom post types 
  909. if ( is_single() ) { 
  910. if ( ! $this->is_single_post_enabled( $post->post_type ) ) { 
  911. $enabled = false; 
  912.  
  913. // Single page 
  914. } elseif ( is_page() && ! is_front_page() ) { 
  915. if ( ! $this->is_single_page_enabled() ) { 
  916. $enabled = false; 
  917.  
  918. // Attachment 
  919. } elseif ( is_attachment() ) { 
  920. if ( ! $this->is_attachment_enabled() ) { 
  921. $enabled = false; 
  922.  
  923. // All other loops 
  924. } elseif ( ! $this->is_index_enabled() ) { 
  925. $enabled = false; 
  926.  
  927. if( is_object( $post ) ) { 
  928. // Check that the post is a public, published post. 
  929. if ( 'attachment' == $post->post_type ) { 
  930. $post_status = get_post_status( $post->post_parent ); 
  931. } else { 
  932. $post_status = $post->post_status; 
  933. if ( 'publish' != $post_status ) { 
  934. $enabled = false; 
  935.  
  936. // Run through the sharing filters 
  937. /** This filter is documented in modules/sharedaddy/sharing-service.php */ 
  938. $enabled = apply_filters( 'sharing_show', $enabled, $post ); 
  939.  
  940. /** 
  941. * Filters whether the Likes should be visible or not. 
  942. * Allows overwriting the options set in Settings > Sharing. 
  943. * @module likes 
  944. * @since 2.2.0 
  945. * @param bool $enabled Should the Likes be visible? 
  946. */ 
  947. return (bool) apply_filters( 'wpl_is_likes_visible', $enabled ); 
  948.  
  949. /** 
  950. * Returns the current state of the "WordPress.com Likes are" option. 
  951. * @return boolean true if enabled sitewide, false if not 
  952. */ 
  953. function is_enabled_sitewide() { 
  954. /** 
  955. * Filters whether Likes are enabled by default on all posts. 
  956. * true if enabled sitewide, false if not. 
  957. * @module likes 
  958. * @since 2.2.0 
  959. * @param bool $option Are Likes enabled sitewide. 
  960. */ 
  961. return (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) ); 
  962.  
  963. /** 
  964. * Returns the current state of the "WordPress.com Reblogs are" option. 
  965. * @return boolean true if enabled sitewide, false if not 
  966. */ 
  967. function reblogs_enabled_sitewide() { 
  968. /** 
  969. * Filters whether Reblogs are enabled by default on all posts. 
  970. * true if enabled sitewide, false if not. 
  971. * @module likes 
  972. * @since 3.0.0 
  973. * @param bool $option Are Reblogs enabled sitewide. 
  974. */ 
  975. return (bool) apply_filters( 'wpl_reblogging_enabled_sitewide', ! get_option( 'disabled_reblogs' ) ); 
  976.  
  977. /** 
  978. * Returns if comment likes are enabled. Defaults to 'off' 
  979. * @todo decide what the default should be 
  980. * @return boolean true if we should show comment likes, false if not 
  981. */ 
  982. function is_comments_enabled() { 
  983. /** 
  984. * Filters whether Comment Likes are enabled. 
  985. * true if enabled, false if not. 
  986. * @module likes 
  987. * @since 2.2.0 
  988. * @param bool $option Are Comment Likes enabled sitewide. 
  989. */ 
  990. return (bool) apply_filters( 'jetpack_comment_likes_enabled', get_option( 'jetpack_comment_likes_enabled', false ) ); 
  991.  
  992. function is_admin_bar_button_visible() { 
  993. global $wp_admin_bar; 
  994.  
  995. if ( ! is_object( $wp_admin_bar ) ) 
  996. return false; 
  997.  
  998. if ( ( ! is_singular( 'post' ) && ! is_attachment() && ! is_page() ) ) 
  999. return false; 
  1000.  
  1001. if ( ! $this->is_likes_visible() ) 
  1002. return false; 
  1003.  
  1004. if ( ! $this->is_post_likeable() ) 
  1005. return false; 
  1006.  
  1007. /** 
  1008. * Filters whether the Like button is enabled in the admin bar. 
  1009. * @module likes 
  1010. * @since 2.2.0 
  1011. * @param bool true Should the Like button be visible in the Admin bar. Default to true. 
  1012. */ 
  1013. return (bool) apply_filters( 'jetpack_admin_bar_likes_enabled', true ); 
  1014.  
  1015. /** 
  1016. * Are likes enabled for this post? 
  1017. * @param int $post_id 
  1018. * @retun bool 
  1019. */ 
  1020. function is_post_likeable( $post_id = 0 ) { 
  1021. $post = get_post( $post_id ); 
  1022. if ( !$post || is_wp_error( $post ) ) { 
  1023. return false; 
  1024.  
  1025. $sitewide_likes_enabled = (bool) Jetpack_Likes::is_enabled_sitewide(); 
  1026. $post_likes_switched = (bool) get_post_meta( $post->ID, 'switch_like_status', true ); 
  1027.  
  1028. $post_likes_enabled = $sitewide_likes_enabled; 
  1029. if ( $post_likes_switched ) { 
  1030. $post_likes_enabled = ! $post_likes_enabled; 
  1031.  
  1032. return $post_likes_enabled; 
  1033.  
  1034. /** 
  1035. * Are Post Likes enabled on archive/front/search pages? 
  1036. * @return bool 
  1037. */ 
  1038. function is_index_enabled() { 
  1039. $options = $this->get_options(); 
  1040. /** 
  1041. * Filters whether Likes should be enabled on archive/front/search pages. 
  1042. * @module likes 
  1043. * @since 2.2.0 
  1044. * @param bool $enabled Are Post Likes enabled on archive/front/search pages? 
  1045. */ 
  1046. return (bool) apply_filters( 'wpl_is_index_disabled', (bool) in_array( 'index', $options['show'] ) ); 
  1047.  
  1048. /** 
  1049. * Are Post Likes enabled on single posts? 
  1050. * @param String $post_type custom post type identifier 
  1051. * @return bool 
  1052. */ 
  1053. function is_single_post_enabled( $post_type = 'post' ) { 
  1054. $options = $this->get_options(); 
  1055. return (bool) apply_filters( 
  1056. /** 
  1057. * Filters whether Likes should be enabled on single posts. 
  1058. * The dynamic part of the filter, {$post_type}, allows you to specific the post type where Likes should be enabled. 
  1059. * @module likes 
  1060. * @since 2.2.0 
  1061. * @param bool $enabled Are Post Likes enabled on single posts? 
  1062. */ 
  1063. "wpl_is_single_{$post_type}_disabled",  
  1064. (bool) in_array( $post_type, $options['show'] ) 
  1065. ); 
  1066.  
  1067. /** 
  1068. * Are Post Likes enabled on single pages? 
  1069. * @return bool 
  1070. */ 
  1071. function is_single_page_enabled() { 
  1072. $options = $this->get_options(); 
  1073. /** 
  1074. * Filters whether Likes should be enabled on single pages. 
  1075. * @module likes 
  1076. * @since 2.2.0 
  1077. * @param bool $enabled Are Post Likes enabled on single pages? 
  1078. */ 
  1079. return (bool) apply_filters( 'wpl_is_single_page_disabled', (bool) in_array( 'page', $options['show'] ) ); 
  1080.  
  1081. /** 
  1082. * Are Media Likes enabled on single pages? 
  1083. * @return bool 
  1084. */ 
  1085. function is_attachment_enabled() { 
  1086. $options = $this->get_options(); 
  1087. /** 
  1088. * Filters whether Likes should be enabled on attachment pages. 
  1089. * @module likes 
  1090. * @since 2.2.0 
  1091. * @param bool $enabled Are Post Likes enabled on attachment pages? 
  1092. */ 
  1093. return (bool) apply_filters( 'wpl_is_attachment_disabled', (bool) in_array( 'attachment', $options['show'] ) );