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' ) );
add_action( 'jetpack_activate_module_likes', array( $this, 'set_social_notifications_like' ) );
add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) );
// The `enable_module_configurable` method doesn't exist in the WP.com loader implementation.
if ( ! ( new Host() )->is_wpcom_simple() ) {
Jetpack::enable_module_configurable( __FILE__ );
}
add_filter( 'jetpack_module_configuration_url_likes', array( $this, 'jetpack_likes_configuration_url' ) );
$sharedaddy_active = Jetpack::is_module_active( 'sharedaddy' );
if ( ! $sharedaddy_active ) {
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' ) );
}
add_action( 'admin_init', array( $this, 'admin_discussion_likes_settings_init' ) ); // Likes notifications.
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' ) );
}
/**
* Set the social_notifications_like option to `on` when the Likes module is activated.
*
* @since 3.7.0
*/
public 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
*/
public function delete_social_notifications_like() {
delete_option( 'social_notifications_like' );
}
/**
* Overrides default configuration url
*
* @uses admin_url
* @return string module settings URL
*/
public 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
*
* @deprecated 16.3 Settings > Sharing is a plain WordPress settings screen now.
*
* @return void
*/
public function load_jp_css() {
_deprecated_function( __METHOD__, 'jetpack-16.3' );
}
/**
* Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box
*
* @deprecated 16.3 The Likes settings have a section of their own on Settings > Sharing.
*
* @param string $html row heading for the sharedaddy "which page" setting.
* @return string The unchanged $html.
*/
public function configuration_target_area( $html = '' ) {
_deprecated_function( __METHOD__, 'jetpack-16.3' );
return $html;
}
/**
* Load scripts and styles for front end.
*/
public function load_styles_register_scripts() {
// Likes are only rendered on pages that display post content.
if ( ! is_singular() && ! is_home() && ! is_front_page() && ! is_archive() && ! is_search() ) {
return;
}
$style_url = Assets::get_file_url_for_environment(
'_inc/build/likes/style.min.css',
'modules/likes/style.css'
);
wp_enqueue_style( 'jetpack_likes', $style_url, array(), JETPACK__VERSION );
$style_path = plugin_dir_path( JETPACK__PLUGIN_FILE ) . (
/** This filter is documented in projects/plugins/jetpack/load-jetpack.php */
apply_filters( 'jetpack_should_use_minified_assets', true )
? '_inc/build/likes/style.min.css'
: 'modules/likes/style.css'
);
wp_style_add_data( 'jetpack_likes', 'path', $style_path );
wp_register_script(
'jetpack_likes_queuehandler',
Assets::get_file_url_for_environment(
'_inc/build/likes/queuehandler.min.js',
'modules/likes/queuehandler.js'
),
array(),
JETPACK__VERSION,
true
);
}
/**
* Options to be added to the discussion page. The Sharing settings live in Sharing_Likes\Settings\Likes_Section.
*/
public 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' ) );
}
/** Add email notification options to WordPress discussion settings */
public 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_module_enabled() ) {
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;
}
add_filter( 'the_content', array( $this, 'post_likes' ), 30, 1 );
add_filter( 'the_excerpt', array( $this, 'post_likes' ), 30, 1 );
}
/**
* Load the CSS needed for the wp-admin area.
*/
public function load_admin_css() {
?>
0
' . __( 'Likes', 'jetpack' ) . '';
$columns['date'] = $date;
return $columns;
}
/**
* Append like button to content.
*
* @param string $content - content of the page.
*/
public function post_likes( $content ) {
global $wp_current_filter;
$post_id = get_the_ID();
if ( ! is_numeric( $post_id ) || ! $this->settings->is_likes_visible() ) {
return $content;
}
// Do not output Likes on requests for ActivityPub requests.
if (
function_exists( '\Activitypub\is_activitypub_request' )
&& \Activitypub\is_activitypub_request()
) {
return $content;
}
// Ensure we don't display like button on post excerpts that are hooked inside the post content
if ( in_array( 'the_excerpt', (array) $wp_current_filter, true ) &&
in_array( 'the_content', (array) $wp_current_filter, true ) ) {
return $content;
}
$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 `queuehandler` scripts before the iframe otherwise the script won't find the iframe.
if ( ! has_action( 'wp_footer', 'jetpack_likes_master_iframe' ) ) {
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/?ver=%1$s#blog_id=%2$d&post_id=%3$d&origin=%4$s&obj_id=%2$d-%3$d-%5$s', rawurlencode( JETPACK__VERSION ), $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', '