in_jetpack = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? false : true; $this->settings = new Jetpack_Likes_Settings(); // We need to run on wp hook rather than init because we check is_amp_endpoint() // when bootstrapping hooks add_action( 'wp', array( &$this, 'action_init' ), 99 ); add_action( 'admin_init', array( $this, 'admin_init' ) ); if ( $this->in_jetpack ) { add_action( 'jetpack_activate_module_likes', array( $this, 'set_social_notifications_like' ) ); add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) ); Jetpack::enable_module_configurable( __FILE__ ); add_filter( 'jetpack_module_configuration_url_likes', array( $this, 'jetpack_likes_configuration_url' ) ); add_action( 'admin_print_scripts-settings_page_sharing', array( &$this, 'load_jp_css' ) ); add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) ); $active = Jetpack::get_active_modules(); if ( ! in_array( 'sharedaddy', $active ) && ! in_array( 'publicize', $active ) ) { // we don't have a sharing page yet add_action( 'admin_menu', array( $this->settings, 'sharing_menu' ) ); } if ( in_array( 'publicize', $active ) && ! in_array( 'sharedaddy', $active ) ) { // we have a sharing page but not the global options area add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 ); add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 ); } if( ! in_array( 'sharedaddy', $active ) ) { add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) ); add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 ); add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 ); add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) ); } else { add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) ); add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) ); } } else { // wpcom add_action( 'wpmu_new_blog', array( $this, 'enable_comment_likes' ), 10, 1 ); add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) ); add_action( 'end_likes_meta_box_content', array( $this->settings, 'sharing_meta_box_content' ) ); add_filter( 'likes_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) ); } add_action( 'admin_init', array( $this, 'admin_discussion_likes_settings_init' ) ); // Likes notifications add_action( 'admin_bar_menu', array( $this, 'admin_bar_likes' ), 60 ); add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) ); add_action( 'save_post', array( $this->settings, 'meta_box_save' ) ); add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) ); add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 ); add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_callback' ), 20 ); } /** * Set the social_notifications_like option to `on` when the Likes module is activated. * * @since 3.7.0 * * @return null */ function set_social_notifications_like() { update_option( 'social_notifications_like', 'on' ); } /** * Delete the social_notifications_like option that was set to `on` on module activation. * * @since 3.7.0 * * @return null */ function delete_social_notifications_like() { delete_option( 'social_notifications_like' ); } /** * Overrides default configuration url * * @uses admin_url * @return string module settings URL */ function jetpack_likes_configuration_url() { return admin_url( 'options-general.php?page=sharing#likes' ); } /** * Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable */ function load_jp_css() { // Do we really need `admin_styles`? With the new admin UI, it's breaking some bits. // Jetpack::init()->admin_styles(); } /** * Load scripts and styles for front end. * @return null */ function load_styles_register_scripts() { if ( $this->in_jetpack ) { wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION ); $this->register_scripts(); } } /** * Stub for is_post_likeable, since some wpcom functions call this directly on the class * Are likes enabled for this post? * * @param int $post_id * @return bool */ static function is_post_likeable( $post_id = 0 ) { _deprecated_function( __METHOD__, 'jetpack-5.4', 'Jetpack_Likes_Settings()->is_post_likeable' ); $settings = new Jetpack_Likes_Settings(); return $settings->is_post_likeable( $post_id ); } /** * Stub for is_likes_visible, since some themes were calling it directly from this class * * @deprecated 5.4 * @return bool */ function is_likes_visible() { _deprecated_function( __METHOD__, 'jetpack-5.4', 'Jetpack_Likes_Settings()->is_likes_visible' ); $settings = new Jetpack_Likes_Settings(); return $settings->is_likes_visible(); } /** * Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box * @param string $html row heading for the sharedaddy "which page" setting * @return string html with the jetpack-targetable class and likes id. tbody gets closed after the like settings */ function configuration_target_area( $html = '' ) { $html = "
" . $html; return $html; } /** * Options to be added to the discussion page (see also admin_settings_init, etc below for Sharing settings page) */ function admin_discussion_likes_settings_init() { // Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' ); add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' ); // Register the setting register_setting( 'discussion', 'social_notifications_like', array( $this, 'admin_discussion_likes_settings_validate' ) ); } function admin_discussion_likes_settings_section() { // Atypical usage here. We emit jquery to move likes notification checkbox to be with the rest of the email notification settings ?> admin_likes_get_option( 'social_notifications_like' ); ?> settings->is_likes_visible() ) { return; } if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'APP_REQUEST' ) && APP_REQUEST ) || ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) || ( defined( 'COOKIE_AUTH_REQUEST' ) && COOKIE_AUTH_REQUEST ) || ( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) { return; } if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { return; } if ( $this->in_jetpack ) { add_filter( 'the_content', array( &$this, 'post_likes' ), 30, 1 ); add_filter( 'the_excerpt', array( &$this, 'post_likes' ), 30, 1 ); } else { add_filter( 'post_flair', array( &$this, 'post_likes' ), 30, 1 ); add_filter( 'post_flair_block_css', array( $this, 'post_flair_service_enabled_like' ) ); wp_enqueue_script( 'postmessage', '/wp-content/js/postmessage.js', array( 'jquery' ), JETPACK__VERSION, true ); wp_enqueue_script( 'jetpack_resize', '/wp-content/js/jquery/jquery.jetpack-resize.js', array( 'jquery' ), JETPACK__VERSION, true ); wp_enqueue_script( 'jetpack_likes_queuehandler', plugins_url( 'queuehandler.js' , __FILE__ ), array( 'jquery', 'postmessage', 'jetpack_resize' ), JETPACK__VERSION, true ); wp_enqueue_style( 'jetpack_likes', plugins_url( 'jetpack-likes.css', __FILE__ ), array(), JETPACK__VERSION ); } } /** * Register scripts */ function register_scripts() { wp_register_script( 'postmessage', Assets::get_file_url_for_environment( '_inc/build/postmessage.min.js', '_inc/postmessage.js' ), array( 'jquery' ), JETPACK__VERSION, true ); wp_register_script( 'jetpack_resize', Assets::get_file_url_for_environment( '_inc/build/jquery.jetpack-resize.min.js', '_inc/jquery.jetpack-resize.js' ), array( 'jquery' ), JETPACK__VERSION, true ); wp_register_script( 'jetpack_likes_queuehandler', Assets::get_file_url_for_environment( '_inc/build/likes/queuehandler.min.js', 'modules/likes/queuehandler.js' ), array( 'jquery', 'postmessage', 'jetpack_resize' ), JETPACK__VERSION, true ); } /** * Load the CSS needed for the wp-admin area. */ function load_admin_css() { ?> in_jetpack ) { wp_enqueue_script( 'likes-post-count', Assets::get_file_url_for_environment( '_inc/build/likes/post-count.min.js', 'modules/likes/post-count.js' ), array( 'jquery' ), JETPACK__VERSION ); wp_enqueue_script( 'likes-post-count-jetpack', Assets::get_file_url_for_environment( '_inc/build/likes/post-count-jetpack.min.js', 'modules/likes/post-count-jetpack.js' ), array( 'likes-post-count' ), JETPACK__VERSION ); } else { wp_enqueue_script( 'jquery.wpcom-proxy-request', "/wp-content/js/jquery/jquery.wpcom-proxy-request.js", array('jquery'), NULL, true ); wp_enqueue_script( 'likes-post-count', plugins_url( 'likes/post-count.js', dirname( __FILE__ ) ), array( 'jquery' ), JETPACK__VERSION ); 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 ); } } } /** * Add "Likes" column data to the post edit table in wp-admin. * * @param string $column_name * @param int $post_id */ function likes_edit_column( $column_name, $post_id ) { if ( 'likes' == $column_name ) { if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { $blog_id = get_current_blog_id(); } else { $blog_id = Jetpack_Options::get_option( 'id' ); } $permalink = get_permalink( get_the_ID() ); ?> 0 ' . __( 'Likes', 'jetpack' ) . ''; $columns['date'] = $date; return $columns; } function post_likes( $content ) { $post_id = get_the_ID(); if ( ! is_numeric( $post_id ) || ! $this->settings->is_likes_visible() ) return $content; if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { $blog_id = get_current_blog_id(); $bloginfo = get_blog_details( (int) $blog_id ); $domain = $bloginfo->domain; } else { $blog_id = Jetpack_Options::get_option( 'id' ); $url = home_url(); $url_parts = wp_parse_url( $url ); $domain = $url_parts['host']; } // make sure to include the scripts before the iframe otherwise weird things happen add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 ); /** * if the same post appears more then once on a page the page goes crazy * we need a slightly more unique id / name for the widget wrapper. */ $uniqid = uniqid(); $src = sprintf( 'https://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 ); $name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid ); $wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid ); $headline = sprintf( /** This filter is already documented in modules/sharedaddy/sharing-service.php */ apply_filters( 'jetpack_sharing_headline_html', '