Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/extensio.../blocks/like
File: like.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Like Block.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 12.9
[4] Fix | Delete
*
[5] Fix | Delete
* @package automattic/jetpack
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
namespace Automattic\Jetpack\Extensions\Like;
[9] Fix | Delete
[10] Fix | Delete
use Automattic\Jetpack\Assets;
[11] Fix | Delete
use Automattic\Jetpack\Blocks;
[12] Fix | Delete
use Automattic\Jetpack\Status\Request;
[13] Fix | Delete
use Jetpack_Gutenberg;
[14] Fix | Delete
[15] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[16] Fix | Delete
exit( 0 );
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Registers the block for use in Gutenberg
[21] Fix | Delete
* This is done via an action so that we can disable
[22] Fix | Delete
* registration if we need to.
[23] Fix | Delete
*/
[24] Fix | Delete
function register_block() {
[25] Fix | Delete
$is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM;
[26] Fix | Delete
$is_connected = \Jetpack::is_connection_ready();
[27] Fix | Delete
[28] Fix | Delete
if ( $is_wpcom || $is_connected ) {
[29] Fix | Delete
Blocks::jetpack_register_block(
[30] Fix | Delete
__DIR__,
[31] Fix | Delete
array(
[32] Fix | Delete
'api_version' => 3,
[33] Fix | Delete
'render_callback' => __NAMESPACE__ . '\render_block',
[34] Fix | Delete
'description' => $is_wpcom ? __( 'Give your readers the ability to show appreciation for your posts and easily share them with others.', 'jetpack' ) : __( 'Give your readers the ability to show appreciation for your posts.', 'jetpack' ),
[35] Fix | Delete
)
[36] Fix | Delete
);
[37] Fix | Delete
}
[38] Fix | Delete
}
[39] Fix | Delete
add_action( 'init', __NAMESPACE__ . '\register_block' );
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Like block render function.
[43] Fix | Delete
*
[44] Fix | Delete
* @param array $attr Array containing the Like block attributes.
[45] Fix | Delete
* @param string $content String containing the Like block content.
[46] Fix | Delete
* @param object $block Object containing the Like block data.
[47] Fix | Delete
*
[48] Fix | Delete
* @return string
[49] Fix | Delete
*/
[50] Fix | Delete
function render_block( $attr, $content, $block ) {
[51] Fix | Delete
// Do not render the Like block in other context than front-end (i.e. feed, emails, API, etc.).
[52] Fix | Delete
if ( ! Request::is_frontend() ) {
[53] Fix | Delete
return;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/*
[57] Fix | Delete
* Enqueue necessary scripts and styles.
[58] Fix | Delete
*/
[59] Fix | Delete
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
[60] Fix | Delete
[61] Fix | Delete
$html = '';
[62] Fix | Delete
[63] Fix | Delete
$uniqid = uniqid();
[64] Fix | Delete
$post_id = $block->context['postId'] ?? null;
[65] Fix | Delete
$title = esc_html__( 'Like or Reblog', 'jetpack' );
[66] Fix | Delete
[67] Fix | Delete
if ( ! $post_id ) {
[68] Fix | Delete
return;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
// make sure we have `jetpack_likes_master_iframe` defined
[72] Fix | Delete
require_once JETPACK__PLUGIN_DIR . 'modules/likes/jetpack-likes-master-iframe.php';
[73] Fix | Delete
[74] Fix | Delete
if ( ! has_action( 'wp_footer', 'jetpack_likes_master_iframe' ) ) {
[75] Fix | Delete
add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
$style_path = null;
[79] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[80] Fix | Delete
$style_url = content_url( 'mu-plugins/likes/jetpack-likes.css' );
[81] Fix | Delete
if ( defined( 'WP_CONTENT_DIR' ) && WP_CONTENT_DIR ) {
[82] Fix | Delete
$style_path = WP_CONTENT_DIR . '/mu-plugins/likes/jetpack-likes.css';
[83] Fix | Delete
}
[84] Fix | Delete
$script_url = content_url( 'mu-plugins/likes/queuehandler.js' );
[85] Fix | Delete
} else {
[86] Fix | Delete
$style_url = Assets::get_file_url_for_environment(
[87] Fix | Delete
'_inc/build/likes/style.min.css',
[88] Fix | Delete
'modules/likes/style.css'
[89] Fix | Delete
);
[90] Fix | Delete
/** This filter is documented in projects/plugins/jetpack/load-jetpack.php */
[91] Fix | Delete
$style_path = JETPACK__PLUGIN_DIR . ( apply_filters( 'jetpack_should_use_minified_assets', true ) ? '_inc/build/likes/style.min.css' : 'modules/likes/style.css' );
[92] Fix | Delete
$script_url = Assets::get_file_url_for_environment(
[93] Fix | Delete
'_inc/build/likes/queuehandler.min.js',
[94] Fix | Delete
'modules/likes/queuehandler.js'
[95] Fix | Delete
);
[96] Fix | Delete
}
[97] Fix | Delete
wp_enqueue_script(
[98] Fix | Delete
'jetpack_likes_queuehandler',
[99] Fix | Delete
$script_url,
[100] Fix | Delete
array(),
[101] Fix | Delete
JETPACK__VERSION,
[102] Fix | Delete
array(
[103] Fix | Delete
'strategy' => 'defer',
[104] Fix | Delete
'in_footer' => true,
[105] Fix | Delete
)
[106] Fix | Delete
);
[107] Fix | Delete
wp_enqueue_style( 'jetpack_likes', $style_url, array(), JETPACK__VERSION );
[108] Fix | Delete
[109] Fix | Delete
if ( $style_path ) {
[110] Fix | Delete
wp_style_add_data( 'jetpack_likes', 'path', $style_path );
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
$show_reblog_button = $attr['showReblogButton'] ?? false;
[114] Fix | Delete
$show_avatars = $attr['showAvatars'] ?? true;
[115] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[116] Fix | Delete
$blog_id = get_current_blog_id();
[117] Fix | Delete
$bloginfo = get_blog_details( (int) $blog_id );
[118] Fix | Delete
$domain = $bloginfo->domain;
[119] Fix | Delete
$reblog_param = $show_reblog_button ? '&amp;reblog=1' : '';
[120] Fix | Delete
$show_avatars_param = $show_avatars ? '' : '&amp;slim=1';
[121] Fix | Delete
$src = sprintf( 'https://widgets.wp.com/likes/index.html?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%6$s%7$s&amp;block=1', rawurlencode( JETPACK__VERSION ), $blog_id, $post_id, $domain, $uniqid, $reblog_param, $show_avatars_param );
[122] Fix | Delete
[123] Fix | Delete
// provide the mapped domain when needed
[124] Fix | Delete
if ( isset( $_SERVER['HTTP_HOST'] ) && strpos( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ), '.wordpress.com' ) === false ) {
[125] Fix | Delete
$sanitized_host = filter_var( wp_unslash( $_SERVER['HTTP_HOST'] ), FILTER_SANITIZE_URL );
[126] Fix | Delete
$src .= '&amp;domain=' . rawurlencode( $sanitized_host );
[127] Fix | Delete
}
[128] Fix | Delete
} else {
[129] Fix | Delete
$blog_id = \Jetpack_Options::get_option( 'id' );
[130] Fix | Delete
$url = home_url();
[131] Fix | Delete
$url_parts = wp_parse_url( $url );
[132] Fix | Delete
$domain = $url_parts['host'];
[133] Fix | Delete
$show_avatars_param = $show_avatars ? '' : '&amp;slim=1';
[134] Fix | Delete
$src = sprintf( 'https://widgets.wp.com/likes/index.html?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%6$s&amp;block=1', rawurlencode( JETPACK__VERSION ), $blog_id, $post_id, $domain, $uniqid, $show_avatars_param );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
$name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
[138] Fix | Delete
$wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
[139] Fix | Delete
[140] Fix | Delete
$html = "<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='" . esc_attr( $wrapper ) . "' data-src='" . esc_attr( $src ) . "' data-name='" . esc_attr( $name ) . "' data-title='" . esc_attr( $title ) . "'>"
[141] Fix | Delete
. "<div class='likes-widget-placeholder post-likes-widget-placeholder' style='height: 55px;'><span class='loading'>" . esc_html__( 'Loading…', 'jetpack' ) . '</span></div>'
[142] Fix | Delete
. "<span class='sd-text-color'></span><a class='sd-link-color'></a>"
[143] Fix | Delete
. '</div>';
[144] Fix | Delete
return sprintf(
[145] Fix | Delete
'<div class="%1$s">%2$s</div>',
[146] Fix | Delete
esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) ),
[147] Fix | Delete
$html
[148] Fix | Delete
);
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function