Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General: remove backwards-compatible code for versions < 6.5 #38386

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: removed

Remove compatibility with WordPress 6.4.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const StatCard = ( { className, icon, label, value, variant = 'square' }: StatCa
<div className={ clsx( styles.info ) }>
<Text className={ styles.label }>{ label }</Text>
{ variant === 'square' ? (
// @todo Switch to `placement` once WordPress 6.4 is the minimum.
<Tooltip text={ formattedValue } position="top center">
<Tooltip text={ formattedValue } placement="top">
<Text variant="headline-small" className={ clsx( styles.value ) }>
{ compactValue }
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ describe( 'StatCard', () => {
it( 'renders the compact value', () => {
render( <StatCard { ...testProps } variant="square" /> );
expect( screen.getByText( '1.8K' ) ).toBeInTheDocument();

// @todo Remove this once WordPress 6.4 is the minimum.
expect( console ).toHaveWarned(
'`position` prop in wp.components.tooltip is deprecated since version 6.4. Please use `placement` prop instead.'
);
} );
} );

Expand Down
2 changes: 1 addition & 1 deletion projects/js-packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automattic/jetpack-components",
"version": "0.54.4-alpha",
"version": "0.55.0-alpha",
"description": "Jetpack Components Package",
"author": "Automattic",
"license": "GPL-2.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: removed
Comment: Update a test to remove WP 6.4 compat.


Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@ public function test_comment_text_block_sanitization_sanity_check() {
$comment_content = '<!-- wp:paragraph --><p>test</p><!-- /wp:paragraph --><!-- wp:list --><ul><!-- wp:list-item --><li>1</li><!-- /wp:list-item --><!-- wp:list-item --><li>2</li><!-- /wp:list-item --><!-- wp:list-item --><li>3</li><!-- /wp:list-item --></ul><!-- /wp:list --><!-- wp:quote --><blockquote class="wp-block-quote"><!-- wp:paragraph --><p>something</p><!-- /wp:paragraph --><cite>someone</cite></blockquote><!-- /wp:quote -->';
$filtered_content = preg_replace( '/\R+/', '', Verbum_Block_Utils::render_verbum_blocks( $comment_content ) );

// Once we drop WP 6.4, we can change this back to assertSame().
$expected_content = $this->logicalOr(
// WP 6.4
$this->identicalTo( '<p>test</p><ul><li>1</li><li>2</li><li>3</li></ul><blockquote class="wp-block-quote"><p>something</p><cite>someone</cite></blockquote>' ),
// WP 6.5+
$this->identicalTo( '<p>test</p><ul><li>1</li><li>2</li><li>3</li></ul><blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>something</p><cite>someone</cite></blockquote>' )
);
$this->assertThat( $filtered_content, $expected_content );
$expected_content = '<p>test</p><ul><li>1</li><li>2</li><li>3</li></ul><blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>something</p><cite>someone</cite></blockquote>';
$this->assertSame( $expected_content, $filtered_content );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public static function get_minimal_state() {
*/
public static function get_initial_state() {
global $is_safari;
global $wp_version;

// Load API endpoint base classes and endpoints for getting the module list fed into the JS Admin Page.
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-xmlrpc-consumer-endpoint.php';
Expand Down Expand Up @@ -248,7 +247,7 @@ public static function get_initial_state() {
'gutenbergInitialState' => self::get_gutenberg_initial_state(),
'isSubscriptionSiteEnabled' => apply_filters( 'jetpack_subscription_site_enabled', false ),
'newsletterDateExample' => gmdate( get_option( 'date_format' ), time() ),
'subscriptionSiteEditSupported' => $current_theme->is_block_theme() && version_compare( $wp_version, '6.5-beta2', '>=' ),
'subscriptionSiteEditSupported' => $current_theme->is_block_theme(),
);
}

Expand All @@ -263,10 +262,9 @@ private static function get_gutenberg_initial_state() {
// If Gutenberg is not installed,
// check if we run a version of WP that would include support.
if ( ! Constants::is_true( 'IS_GUTENBERG_PLUGIN' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, I think we may be able to remove the whole logic around get_gutenberg_initial_state and getGutenbergState, it doesn't seem to be in use anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're probably right, AFAICT the one thing using it was removed in #33782.

global $wp_version;
return array(
'isAvailable' => false,
'hasInteractivityApi' => version_compare( $wp_version, '6.4', '>=' ),
'hasInteractivityApi' => true,
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: compat

General: remove code for compatibility with WordPress versions before 6.5.
1 change: 0 additions & 1 deletion projects/plugins/jetpack/class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ public static function upgrade_on_load() {

if (
class_exists( 'Jetpack_Sitemap_Manager' )
&& version_compare( JETPACK__VERSION, '5.3', '>=' )
) {
do_action( 'jetpack_sitemaps_purge_data' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,7 @@ private static function verify( $msg, $signature, $key, $alg ) {
* @throws DomainException Provided string was invalid JSON.
*/
public static function json_decode( $input ) {
if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) && ! ( defined( 'JSON_C_VERSION' ) && PHP_INT_SIZE > 4 ) ) {
/** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you
* to specify that large ints (like Steam Transaction IDs) should be treated as
* strings, rather than the PHP default behaviour of converting them to floats.
*/
$obj = json_decode( $input, false, 512, JSON_BIGINT_AS_STRING );
} else {
/** Not all servers will support that, however, so for older versions we must
* manually detect large ints in the JSON string and quote them (thus converting
*them to strings) before decoding, hence the preg_replace() call.
*/
$max_int_length = strlen( (string) PHP_INT_MAX ) - 1;
$json_without_bigints = preg_replace( '/:\s*(-?\d{' . $max_int_length . ',})/', ': "$1"', $input );
$obj = json_decode( $json_without_bigints );
}

$obj = json_decode( $input, false, 512, JSON_BIGINT_AS_STRING );
$errno = json_last_error();

if ( $errno ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ function register_block() {
);

/*
* Automatically add the sharing block to the end of single posts
* only when running WordPress 6.5 or later.
* @todo: remove when WordPress 6.5 is the minimum required version.
* Automatically add the sharing block to the end of single posts.
*/
global $wp_version;
if ( version_compare( $wp_version, '6.5-beta2', '>=' ) ) {
add_filter( 'hooked_block_types', __NAMESPACE__ . '\add_block_to_single_posts_template', 10, 4 );
add_filter( 'hooked_block_' . PARENT_BLOCK_NAME, __NAMESPACE__ . '\add_default_services_to_block', 10, 5 );
}
add_filter( 'hooked_block_types', __NAMESPACE__ . '\add_block_to_single_posts_template', 10, 4 );
add_filter( 'hooked_block_' . PARENT_BLOCK_NAME, __NAMESPACE__ . '\add_default_services_to_block', 10, 5 );
}
add_action( 'init', __NAMESPACE__ . '\register_block' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ protected function is_header_context( $context ) {
* @return void
*/
protected function handle_subscriber_login_block_navigation_placement() {
global $wp_version;

$subscriber_login_navigation_enabled = get_option( 'jetpack_subscriptions_login_navigation_enabled', false );
if ( ! $subscriber_login_navigation_enabled ) {
return;
}

if ( ! wp_is_block_theme() || version_compare( $wp_version, '6.5-beta2', '<' ) ) { // TODO Fallback for classic themes and wp core < 6.5-beta2.
if ( ! wp_is_block_theme() ) { // TODO Fallback for classic themes.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,12 @@ protected function is_header_context( $context ) {
* @return void
*/
protected function handle_subscribe_block_navigation_placement() {
global $wp_version;

$is_enabled = get_option( 'jetpack_subscriptions_subscribe_navigation_enabled', false );
if ( ! $is_enabled ) {
return;
}

if ( ! wp_is_block_theme() || version_compare( $wp_version, '6.5-beta2', '<' ) ) { // TODO Fallback for classic themes and wp core < 6.5-beta2.
if ( ! wp_is_block_theme() ) { // TODO Fallback for classic themes.
return;
}

Expand Down Expand Up @@ -171,14 +169,12 @@ function ( $hooked_block, $hooked_block_type, $relative_position, $anchor_block
* @return void
*/
protected function handle_subscribe_block_post_end_placement() {
global $wp_version;

$subscribe_post_end_enabled = get_option( 'jetpack_subscriptions_subscribe_post_end_enabled', false );
if ( ! $subscribe_post_end_enabled ) {
return;
}

if ( ! wp_is_block_theme() || version_compare( $wp_version, '6.5-beta2', '<' ) ) { // Fallback for classic themes and wp core < 6.5-beta2.
if ( ! wp_is_block_theme() ) { // Fallback for classic themes.
add_filter(
'the_content',
function ( $content ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export default function EmailPreview( { isModalOpen, closeModal } ) {

// Save post revision so that we send what they see in the editor, and not what previous draft/revision might've saved
// Introduced at GB 16.3 at https://github.com/WordPress/gutenberg/pull/44971
// @todo Remove the `if` check once WP 6.4 is the minimum supported version
if ( typeof __unstableSaveForPreview === 'function' ) {
await __unstableSaveForPreview();
}
await __unstableSaveForPreview();

apiFetch( {
path: '/wpcom/v2/send-email-preview/',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { registerJetpackPlugin } from '@automattic/jetpack-shared-extension-utils';
import { dispatch } from '@wordpress/data';
import { store as editPostStore } from '@wordpress/edit-post';
import { store as editorStore } from '@wordpress/editor';
import { addFilter } from '@wordpress/hooks';
import debugFactory from 'debug';
Expand Down Expand Up @@ -43,11 +42,7 @@ function extendAiContentLensFeatures( settings, name ) {

// check if the removeEditorPanel function exists in the editorStore.
// íf not, look for it in the editPostStore.
// @todo: remove this once Jetpack requires WordPres 6.5,
// where the removeEditorPanel function will be available in the editorStore.
const removeEditorPanel = dispatch( editorStore )?.removeEditorPanel
? dispatch( editorStore )?.removeEditorPanel
: dispatch( editPostStore )?.removeEditorPanel;
const removeEditorPanel = dispatch( editorStore ).removeEditorPanel;

// Remove the excerpt panel by dispatching an action.
removeEditorPanel( 'post-excerpt' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,7 @@ const isMediaSourceConnected = async ( source: MediaSource ) =>
* @returns {boolean} True if the inserter is opened false otherwise.
*/
const isInserterOpened = (): boolean => {
// Prior to WP 6.5, the isInserterOpened selector was available in core/edit-post.
// In WP 6.5, it was moved to core/editor. This check is to support both versions of WordPress.
// @to-do: remove exception when Jetpack requires WordPress 6.5.
const selectIsInserterOpened =
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
( select( 'core/editor' ) as any )?.isInserterOpened ??
select( 'core/edit-post' )?.isInserterOpened;
const selectIsInserterOpened = select( 'core/editor' )?.isInserterOpened;

const editorIsInserterOpened = selectIsInserterOpened?.();

Expand Down
99 changes: 0 additions & 99 deletions projects/plugins/wpcomsh/assets/wp-polyfill-dom-rect.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: removed

Remove code for compatibility with WordPress before 6.5.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: removed

Remove checks for Jetpack versions over a year old.
5 changes: 0 additions & 5 deletions projects/plugins/wpcomsh/feature-plugins/additional-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ function wpcomsh_maybe_disable_custom_css() {
return;
}

// Do not execute for older versions of Jetpack.
if ( version_compare( JETPACK__VERSION, '9.9-alpha', '<' ) ) {
return;
}

if ( wpcom_site_has_feature( WPCOM_Features::CUSTOM_DESIGN ) ) {
return;
}
Expand Down
5 changes: 0 additions & 5 deletions projects/plugins/wpcomsh/feature-plugins/blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function wpcomsh_activate_blaze_module() {
return;
}

// Blaze was introduced in Jetpack 12.3-a.9.
if ( version_compare( JETPACK__VERSION, '12.3-a.9', '<' ) ) {
return;
}

if ( ! Jetpack::is_module_active( 'blaze' ) ) {
Jetpack::activate_module( 'blaze', false, false );
}
Expand Down
5 changes: 0 additions & 5 deletions projects/plugins/wpcomsh/feature-plugins/google-fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ function wpcomsh_activate_google_fonts_module() {
return;
}

// Google fonts was introduced in Jetpack 10.8.
if ( version_compare( JETPACK__VERSION, '10.8', '<' ) ) {
return;
}

if ( ! Jetpack::is_module_active( 'google-fonts' ) ) {
Jetpack::activate_module( 'google-fonts', false, false );
}
Expand Down
Loading
Loading