Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules
File: likes.php
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* Module Name: Likes
[2] Fix | Delete
* Module Description: Let readers like your posts to show appreciation and encourage interaction.
[3] Fix | Delete
* First Introduced: 2.2
[4] Fix | Delete
* Sort Order: 23
[5] Fix | Delete
* Requires Connection: Yes
[6] Fix | Delete
* Auto Activate: No
[7] Fix | Delete
* Module Tags: Social
[8] Fix | Delete
* Feature: Engagement
[9] Fix | Delete
* Additional Search Queries: like, likes, wordpress.com
[10] Fix | Delete
*
[11] Fix | Delete
* @package automattic/jetpack
[12] Fix | Delete
*/
[13] Fix | Delete
/**
[14] Fix | Delete
* NOTE: While the front-end behavior currently varies, try to keep the data
[15] Fix | Delete
* model here the same as on wpcom to facilitate Simple→Atomic moves and
[16] Fix | Delete
* possible future work to recombine the front-ends.
[17] Fix | Delete
*/
[18] Fix | Delete
[19] Fix | Delete
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
[20] Fix | Delete
[21] Fix | Delete
use Automattic\Jetpack\Assets;
[22] Fix | Delete
use Automattic\Jetpack\Status\Host;
[23] Fix | Delete
[24] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[25] Fix | Delete
exit( 0 );
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
Assets::add_resource_hint(
[29] Fix | Delete
array(
[30] Fix | Delete
'//widgets.wp.com',
[31] Fix | Delete
'//s0.wp.com',
[32] Fix | Delete
'//0.gravatar.com',
[33] Fix | Delete
'//1.gravatar.com',
[34] Fix | Delete
'//2.gravatar.com',
[35] Fix | Delete
),
[36] Fix | Delete
'dns-prefetch'
[37] Fix | Delete
);
[38] Fix | Delete
[39] Fix | Delete
require_once __DIR__ . '/likes/jetpack-likes-master-iframe.php';
[40] Fix | Delete
require_once __DIR__ . '/likes/jetpack-likes-settings.php';
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Jetpack Like Class
[44] Fix | Delete
*/
[45] Fix | Delete
class Jetpack_Likes {
[46] Fix | Delete
/**
[47] Fix | Delete
* Jetpack_Likes_Settings object
[48] Fix | Delete
*
[49] Fix | Delete
* @var Jetpack_Likes_Settings
[50] Fix | Delete
*/
[51] Fix | Delete
public $settings;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Initialize class
[55] Fix | Delete
*/
[56] Fix | Delete
public static function init() {
[57] Fix | Delete
static $instance = null;
[58] Fix | Delete
[59] Fix | Delete
if ( ! $instance ) {
[60] Fix | Delete
$instance = new Jetpack_Likes();
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
return $instance;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Constructs Likes class
[68] Fix | Delete
*/
[69] Fix | Delete
public function __construct() {
[70] Fix | Delete
$this->settings = new Jetpack_Likes_Settings();
[71] Fix | Delete
[72] Fix | Delete
// We need to run on wp hook rather than init because we check is_amp_endpoint()
[73] Fix | Delete
// when bootstrapping hooks.
[74] Fix | Delete
add_action( 'wp', array( $this, 'action_init' ), 99 );
[75] Fix | Delete
[76] Fix | Delete
add_action( 'admin_init', array( $this, 'admin_init' ) );
[77] Fix | Delete
[78] Fix | Delete
add_action( 'jetpack_activate_module_likes', array( $this, 'set_social_notifications_like' ) );
[79] Fix | Delete
add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) );
[80] Fix | Delete
[81] Fix | Delete
// The `enable_module_configurable` method doesn't exist in the WP.com loader implementation.
[82] Fix | Delete
if ( ! ( new Host() )->is_wpcom_simple() ) {
[83] Fix | Delete
Jetpack::enable_module_configurable( __FILE__ );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
add_filter( 'jetpack_module_configuration_url_likes', array( $this, 'jetpack_likes_configuration_url' ) );
[87] Fix | Delete
add_action( 'admin_print_scripts-settings_page_sharing', array( $this, 'load_jp_css' ) );
[88] Fix | Delete
add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) );
[89] Fix | Delete
[90] Fix | Delete
$publicize_active = Jetpack::is_module_active( 'publicize' );
[91] Fix | Delete
$sharedaddy_active = Jetpack::is_module_active( 'sharedaddy' );
[92] Fix | Delete
[93] Fix | Delete
if ( $publicize_active && ! $sharedaddy_active ) {
[94] Fix | Delete
// we have a sharing page but not the global options area.
[95] Fix | Delete
add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 );
[96] Fix | Delete
add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if ( ! $sharedaddy_active ) {
[100] Fix | Delete
add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) );
[101] Fix | Delete
add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 );
[102] Fix | Delete
add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 );
[103] Fix | Delete
add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
[104] Fix | Delete
} else {
[105] Fix | Delete
add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
[106] Fix | Delete
add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
add_action( 'admin_init', array( $this, 'admin_discussion_likes_settings_init' ) ); // Likes notifications.
[110] Fix | Delete
[111] Fix | Delete
add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) );
[112] Fix | Delete
[113] Fix | Delete
add_action( 'save_post', array( $this->settings, 'meta_box_save' ) );
[114] Fix | Delete
add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) );
[115] Fix | Delete
add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 );
[116] Fix | Delete
add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_callback' ), 20 );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Set the social_notifications_like option to `on` when the Likes module is activated.
[121] Fix | Delete
*
[122] Fix | Delete
* @since 3.7.0
[123] Fix | Delete
*/
[124] Fix | Delete
public function set_social_notifications_like() {
[125] Fix | Delete
update_option( 'social_notifications_like', 'on' );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Delete the social_notifications_like option that was set to `on` on module activation.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 3.7.0
[132] Fix | Delete
*/
[133] Fix | Delete
public function delete_social_notifications_like() {
[134] Fix | Delete
delete_option( 'social_notifications_like' );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Overrides default configuration url
[139] Fix | Delete
*
[140] Fix | Delete
* @uses admin_url
[141] Fix | Delete
* @return string module settings URL
[142] Fix | Delete
*/
[143] Fix | Delete
public function jetpack_likes_configuration_url() {
[144] Fix | Delete
return admin_url( 'options-general.php?page=sharing#likes' );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable
[149] Fix | Delete
*/
[150] Fix | Delete
public function load_jp_css() {
[151] Fix | Delete
/**
[152] Fix | Delete
* Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
[153] Fix | Delete
* Jetpack::init()->admin_styles();
[154] Fix | Delete
*/
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Load scripts and styles for front end.
[159] Fix | Delete
*/
[160] Fix | Delete
public function load_styles_register_scripts() {
[161] Fix | Delete
wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION );
[162] Fix | Delete
wp_register_script(
[163] Fix | Delete
'jetpack_likes_queuehandler',
[164] Fix | Delete
Assets::get_file_url_for_environment(
[165] Fix | Delete
'_inc/build/likes/queuehandler.min.js',
[166] Fix | Delete
'modules/likes/queuehandler.js'
[167] Fix | Delete
),
[168] Fix | Delete
array(),
[169] Fix | Delete
JETPACK__VERSION,
[170] Fix | Delete
true
[171] Fix | Delete
);
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box
[176] Fix | Delete
*
[177] Fix | Delete
* @param string $html row heading for the sharedaddy "which page" setting.
[178] Fix | Delete
* @return string $html with the jetpack-targetable class and likes id. tbody gets closed after the like settings
[179] Fix | Delete
*/
[180] Fix | Delete
public function configuration_target_area( $html = '' ) {
[181] Fix | Delete
$html = "<tbody id='likes' class='jetpack-targetable'>" . $html;
[182] Fix | Delete
return $html;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Options to be added to the discussion page (see also admin_settings_init, etc below for Sharing settings page)
[187] Fix | Delete
*/
[188] Fix | Delete
public function admin_discussion_likes_settings_init() {
[189] Fix | Delete
// Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings.
[190] Fix | Delete
add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' );
[191] Fix | Delete
add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' );
[192] Fix | Delete
// Register the setting.
[193] Fix | Delete
register_setting( 'discussion', 'social_notifications_like', array( $this, 'admin_discussion_likes_settings_validate' ) );
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/** Add email notification options to WordPress discussion settings */
[197] Fix | Delete
public function admin_discussion_likes_settings_section() {
[198] Fix | Delete
// Atypical usage here. We emit jquery to move likes notification checkbox to be with the rest of the email notification settings.
[199] Fix | Delete
?>
[200] Fix | Delete
<script type="text/javascript">
[201] Fix | Delete
jQuery( function( $ ) {
[202] Fix | Delete
var table = $( '#social_notifications_like' ).parents( 'table:first' ),
[203] Fix | Delete
header = table.prevAll( 'h2:first' ),
[204] Fix | Delete
newParent = $( '#moderation_notify' ).parent( 'label' ).parent();
[205] Fix | Delete
[206] Fix | Delete
if ( !table.length || !header.length || !newParent.length ) {
[207] Fix | Delete
return;
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
newParent.append( '<br/>' ).append( table.end().parent( 'label' ).siblings().andSelf() );
[211] Fix | Delete
header.remove();
[212] Fix | Delete
table.remove();
[213] Fix | Delete
} );
[214] Fix | Delete
</script>
[215] Fix | Delete
<?php
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/** Check if email notifications for likes is on or off.
[219] Fix | Delete
*
[220] Fix | Delete
* @param string $option - which option we're checking (social_notifications_like).
[221] Fix | Delete
*/
[222] Fix | Delete
public function admin_likes_get_option( $option ) {
[223] Fix | Delete
$option_setting = get_option( $option, 'on' );
[224] Fix | Delete
[225] Fix | Delete
return (int) ( 'on' === $option_setting );
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/** Display email notification for likes setting in WordPress' discussion settings. */
[229] Fix | Delete
public function admin_discussion_likes_settings_field() {
[230] Fix | Delete
$like = $this->admin_likes_get_option( 'social_notifications_like' );
[231] Fix | Delete
?>
[232] Fix | Delete
<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>
[233] Fix | Delete
<?php
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Validate email notification settings.
[238] Fix | Delete
*
[239] Fix | Delete
* @param string $input - determines if checbox is on or off.
[240] Fix | Delete
*/
[241] Fix | Delete
public function admin_discussion_likes_settings_validate( $input ) {
[242] Fix | Delete
// If it's not set (was unchecked during form submission) or was set to off (during option update), return 'off'.
[243] Fix | Delete
if ( ! $input || 'off' === $input ) {
[244] Fix | Delete
return 'off';
[245] Fix | Delete
}
[246] Fix | Delete
// Otherwise return 'on'.
[247] Fix | Delete
return 'on';
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
/** Initialize admin settings */
[251] Fix | Delete
public function admin_init() {
[252] Fix | Delete
add_filter( 'manage_posts_columns', array( $this, 'add_like_count_column' ) );
[253] Fix | Delete
add_filter( 'manage_pages_columns', array( $this, 'add_like_count_column' ) );
[254] Fix | Delete
add_action( 'manage_posts_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
[255] Fix | Delete
add_action( 'manage_pages_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
[256] Fix | Delete
add_action( 'admin_print_styles-edit.php', array( $this, 'load_admin_css' ) );
[257] Fix | Delete
add_action( 'admin_print_scripts-edit.php', array( $this, 'enqueue_admin_scripts' ) );
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
/** Initialize action */
[261] Fix | Delete
public function action_init() {
[262] Fix | Delete
/*
[263] Fix | Delete
* Only check if the module is enabled here because
[264] Fix | Delete
* we are not currently in The Loop and do not yet have access to check
[265] Fix | Delete
* the switch_like_status post meta flag for the post to be loaded.
[266] Fix | Delete
*/
[267] Fix | Delete
if ( is_admin() || ! $this->settings->is_likes_module_enabled() ) {
[268] Fix | Delete
return;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ||
[272] Fix | Delete
( defined( 'APP_REQUEST' ) && APP_REQUEST ) ||
[273] Fix | Delete
( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
[274] Fix | Delete
( defined( 'COOKIE_AUTH_REQUEST' ) && COOKIE_AUTH_REQUEST ) ||
[275] Fix | Delete
( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) {
[276] Fix | Delete
return;
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
if (
[280] Fix | Delete
class_exists( 'Jetpack_AMP_Support' )
[281] Fix | Delete
&& Jetpack_AMP_Support::is_amp_request()
[282] Fix | Delete
) {
[283] Fix | Delete
return;
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
add_filter( 'the_content', array( $this, 'post_likes' ), 30, 1 );
[287] Fix | Delete
add_filter( 'the_excerpt', array( $this, 'post_likes' ), 30, 1 );
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
/**
[291] Fix | Delete
* Load the CSS needed for the wp-admin area.
[292] Fix | Delete
*/
[293] Fix | Delete
public function load_admin_css() {
[294] Fix | Delete
?>
[295] Fix | Delete
<style type="text/css">
[296] Fix | Delete
.vers img { display: none; }
[297] Fix | Delete
.metabox-prefs .vers img { display: inline; }
[298] Fix | Delete
.fixed .column-likes { width: 2.5em; padding: 4px 0; text-align: left; }
[299] Fix | Delete
.fixed .column-stats { width: 5em; white-space: nowrap; }
[300] Fix | Delete
.fixed .column-likes .post-com-count {
[301] Fix | Delete
-webkit-box-sizing: border-box;
[302] Fix | Delete
-moz-box-sizing: border-box;
[303] Fix | Delete
box-sizing: border-box;
[304] Fix | Delete
display: inline-block;
[305] Fix | Delete
padding: 0 4px;
[306] Fix | Delete
min-width: 2em;
[307] Fix | Delete
text-align: center;
[308] Fix | Delete
height: 2em;
[309] Fix | Delete
margin-top: 5px;
[310] Fix | Delete
-webkit-border-radius: 5px;
[311] Fix | Delete
border-radius: 5px;
[312] Fix | Delete
background-color: #787c82;
[313] Fix | Delete
color: #FFF;
[314] Fix | Delete
font-size: 11px;
[315] Fix | Delete
line-height: 21px;
[316] Fix | Delete
}
[317] Fix | Delete
.fixed .column-likes .post-com-count::after { border: none !important; }
[318] Fix | Delete
.fixed .column-likes .post-com-count:hover { background-color: #2271b1; }
[319] Fix | Delete
.fixed .column-likes .vers::before {
[320] Fix | Delete
font: normal 20px/1 dashicons;
[321] Fix | Delete
content: '\f155';
[322] Fix | Delete
speak: none;
[323] Fix | Delete
-webkit-font-smoothing: antialiased;
[324] Fix | Delete
-moz-osx-font-smoothing: grayscale;
[325] Fix | Delete
}
[326] Fix | Delete
@media screen and (max-width: 782px) {
[327] Fix | Delete
.fixed .column-likes {
[328] Fix | Delete
display: none;
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
</style>
[332] Fix | Delete
<?php
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
/**
[336] Fix | Delete
* Load the JS required for loading the like counts.
[337] Fix | Delete
*/
[338] Fix | Delete
public function enqueue_admin_scripts() {
[339] Fix | Delete
if ( empty( $_GET['post_type'] ) || 'post' === $_GET['post_type'] || 'page' === $_GET['post_type'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
[340] Fix | Delete
wp_enqueue_script(
[341] Fix | Delete
'likes-post-count',
[342] Fix | Delete
Assets::get_file_url_for_environment(
[343] Fix | Delete
'_inc/build/likes/post-count.min.js',
[344] Fix | Delete
'modules/likes/post-count.js'
[345] Fix | Delete
),
[346] Fix | Delete
array( 'jquery' ),
[347] Fix | Delete
JETPACK__VERSION,
[348] Fix | Delete
$in_footer = false
[349] Fix | Delete
);
[350] Fix | Delete
wp_enqueue_script(
[351] Fix | Delete
'likes-post-count-jetpack',
[352] Fix | Delete
Assets::get_file_url_for_environment(
[353] Fix | Delete
'_inc/build/likes/post-count-jetpack.min.js',
[354] Fix | Delete
'modules/likes/post-count-jetpack.js'
[355] Fix | Delete
),
[356] Fix | Delete
array( 'jquery', 'likes-post-count' ),
[357] Fix | Delete
JETPACK__VERSION,
[358] Fix | Delete
$in_footer = false
[359] Fix | Delete
);
[360] Fix | Delete
}
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Add "Likes" column data to the post edit table in wp-admin.
[365] Fix | Delete
*
[366] Fix | Delete
* @param string $column_name - name of the column.
[367] Fix | Delete
* @param int $post_id - the post id.
[368] Fix | Delete
*/
[369] Fix | Delete
public function likes_edit_column( $column_name, $post_id ) {
[370] Fix | Delete
if ( 'likes' === $column_name ) {
[371] Fix | Delete
[372] Fix | Delete
$blog_id = Jetpack_Options::get_option( 'id' );
[373] Fix | Delete
[374] Fix | Delete
$permalink = get_permalink( get_the_ID() );
[375] Fix | Delete
?>
[376] Fix | Delete
<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; ?>">
[377] Fix | Delete
<span class="comment-count">0</span>
[378] Fix | Delete
</a>
[379] Fix | Delete
<?php
[380] Fix | Delete
}
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Add a "Likes" column header to the post edit table in wp-admin.
[385] Fix | Delete
*
[386] Fix | Delete
* @param array $columns - array of columns in wp-admin.
[387] Fix | Delete
*/
[388] Fix | Delete
public function add_like_count_column( $columns ) {
[389] Fix | Delete
$date = $columns['date'];
[390] Fix | Delete
unset( $columns['date'] );
[391] Fix | Delete
[392] Fix | Delete
$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 class="screen-reader-text">' . __( 'Likes', 'jetpack' ) . '</span></span>';
[393] Fix | Delete
$columns['date'] = $date;
[394] Fix | Delete
[395] Fix | Delete
return $columns;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
/**
[399] Fix | Delete
* Append like button to content.
[400] Fix | Delete
*
[401] Fix | Delete
* @param string $content - content of the page.
[402] Fix | Delete
*/
[403] Fix | Delete
public function post_likes( $content ) {
[404] Fix | Delete
global $wp_current_filter;
[405] Fix | Delete
$post_id = get_the_ID();
[406] Fix | Delete
[407] Fix | Delete
if ( ! is_numeric( $post_id ) || ! $this->settings->is_likes_visible() ) {
[408] Fix | Delete
return $content;
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
// Do not output Likes on requests for ActivityPub requests.
[412] Fix | Delete
if (
[413] Fix | Delete
function_exists( '\Activitypub\is_activitypub_request' )
[414] Fix | Delete
&& \Activitypub\is_activitypub_request()
[415] Fix | Delete
) {
[416] Fix | Delete
return $content;
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
// Ensure we don't display like button on post excerpts that are hooked inside the post content
[420] Fix | Delete
if ( in_array( 'the_excerpt', (array) $wp_current_filter, true ) &&
[421] Fix | Delete
in_array( 'the_content', (array) $wp_current_filter, true ) ) {
[422] Fix | Delete
return $content;
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
$blog_id = Jetpack_Options::get_option( 'id' );
[426] Fix | Delete
$url = home_url();
[427] Fix | Delete
$url_parts = wp_parse_url( $url );
[428] Fix | Delete
$domain = $url_parts['host'];
[429] Fix | Delete
[430] Fix | Delete
// Make sure to include the `queuehandler` scripts before the iframe otherwise the script won't find the iframe.
[431] Fix | Delete
if ( ! has_action( 'wp_footer', 'jetpack_likes_master_iframe' ) ) {
[432] Fix | Delete
add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* If the same post appears more then once on a page the page goes crazy
[437] Fix | Delete
* we need a slightly more unique id / name for the widget wrapper.
[438] Fix | Delete
*/
[439] Fix | Delete
$uniqid = uniqid();
[440] Fix | Delete
$src = sprintf( 'https://widgets.wp.com/likes/?ver=%1$s#blog_id=%2$d&amp;post_id=%3$d&amp;origin=%4$s&amp;obj_id=%2$d-%3$d-%5$s', rawurlencode( JETPACK__VERSION ), $blog_id, $post_id, $domain, $uniqid );
[441] Fix | Delete
$name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
[442] Fix | Delete
$wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
[443] Fix | Delete
$headline = sprintf(
[444] Fix | Delete
/** This filter is already documented in modules/sharedaddy/sharing-service.php */
[445] Fix | Delete
apply_filters( 'jetpack_sharing_headline_html', '<h3 class="sd-title">%s</h3>', esc_html__( 'Like this:', 'jetpack' ), 'likes' ),
[446] Fix | Delete
esc_html__( 'Like this:', 'jetpack' )
[447] Fix | Delete
);
[448] Fix | Delete
[449] Fix | Delete
$title = esc_html__( 'Like or Reblog', 'jetpack' );
[450] Fix | Delete
[451] Fix | Delete
/** This filter is documented in modules/likes/jetpack-likes-master-iframe.php */
[452] Fix | Delete
$src = apply_filters( 'jetpack_likes_iframe_src', $src );
[453] Fix | Delete
[454] Fix | Delete
$html = "<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='$wrapper' data-src='$src' data-name='$name' data-title='$title'>";
[455] Fix | Delete
$html .= $headline;
[456] Fix | Delete
$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>';
[457] Fix | Delete
$html .= "<span class='sd-text-color'></span><a class='sd-link-color'></a>";
[458] Fix | Delete
$html .= '</div>';
[459] Fix | Delete
[460] Fix | Delete
// Let's make sure that the script is enqueued.
[461] Fix | Delete
wp_enqueue_script( 'jetpack_likes_queuehandler' );
[462] Fix | Delete
[463] Fix | Delete
return $content . $html;
[464] Fix | Delete
}
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
/**
[468] Fix | Delete
* Callback to get the value for the jetpack_likes_enabled field.
[469] Fix | Delete
*
[470] Fix | Delete
* Warning: this behavior is somewhat complicated!
[471] Fix | Delete
* When the switch_like_status post_meta is unset, we follow the global setting in Sharing.
[472] Fix | Delete
* When it is set to 0, we disable likes on the post, regardless of the global setting.
[473] Fix | Delete
* When it is set to 1, we enable likes on the post, regardless of the global setting.
[474] Fix | Delete
*
[475] Fix | Delete
* @param array $post - post data we're checking.
[476] Fix | Delete
*
[477] Fix | Delete
* @return bool
[478] Fix | Delete
*/
[479] Fix | Delete
function jetpack_post_likes_get_value( array $post ) {
[480] Fix | Delete
if ( ! isset( $post['id'] ) ) {
[481] Fix | Delete
return false;
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
$post_likes_switched = get_post_meta( $post['id'], 'switch_like_status', true );
[485] Fix | Delete
[486] Fix | Delete
/** This filter is documented in modules/jetpack-likes-settings.php */
[487] Fix | Delete
$sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) );
[488] Fix | Delete
[489] Fix | Delete
// An empty string: post meta was not set, so go with the global setting.
[490] Fix | Delete
if ( '' === $post_likes_switched ) {
[491] Fix | Delete
return $sitewide_likes_enabled;
[492] Fix | Delete
} elseif ( '0' === $post_likes_switched ) { // User overrode the global setting to disable likes.
[493] Fix | Delete
return false;
[494] Fix | Delete
} elseif ( '1' === $post_likes_switched ) { // User overrode the global setting to enable likes.
[495] Fix | Delete
return true;
[496] Fix | Delete
}
[497] Fix | Delete
// No default fallback, let's stay explicit.
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function