Code Duplication    Length = 40-43 lines in 2 locations

class.jetpack-gutenberg.php 1 location

@@ 98-137 (lines=40) @@
95
	 *
96
	 * @return boolean True if the version of gutenberg required by the block or plugin is available.
97
	 */
98
	public static function is_gutenberg_version_available( $version_requirements, $slug ) {
99
		global $wp_version;
100
101
		// Bail if we don't at least have the gutenberg version requirement, the WP version is optional.
102
		if ( empty( $version_requirements['gutenberg'] ) ) {
103
			return false;
104
		}
105
106
		// If running a local dev build of gutenberg plugin GUTENBERG_DEVELOPMENT_MODE is set so assume correct version.
107
		if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE ) {
108
			return true;
109
		}
110
111
		$version_available = false;
112
113
		// If running a production build of the gutenberg plugin then GUTENBERG_VERSION is set, otherwise if WP version
114
		// with required version of Gutenberg is known check that.
115
		if ( defined( 'GUTENBERG_VERSION' ) ) {
116
			$version_available = version_compare( GUTENBERG_VERSION, $version_requirements['gutenberg'], '>=' );
117
		} elseif ( ! empty( $version_requirements['wp'] ) ) {
118
			$version_available = version_compare( $wp_version, $version_requirements['wp'], '>=' );
119
		}
120
121
		if ( ! $version_available ) {
122
			self::set_extension_unavailable(
123
				$slug,
124
				'incorrect_gutenberg_version',
125
				array(
126
					'required_feature' => $slug,
127
					'required_version' => $version_requirements,
128
					'current_version'  => array(
129
						'wp'        => $wp_version,
130
						'gutenberg' => defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : null,
131
					),
132
				)
133
			);
134
		}
135
136
		return $version_available;
137
	}
138
139
	/**
140
	 * Prepend the 'jetpack/' prefix to a block name

packages/blocks/src/class-blocks.php 1 location

@@ 135-177 (lines=43) @@
132
	 *
133
	 * @return boolean True if the version of Gutenberg required by the block or plugin is available.
134
	 */
135
	public static function is_gutenberg_version_available( $version_requirements, $slug ) {
136
		global $wp_version;
137
138
		// Bail if we don't at least have the Gutenberg version requirement, the WP version is optional.
139
		if ( empty( $version_requirements['gutenberg'] ) ) {
140
			return false;
141
		}
142
143
		// If running a local dev build of Gutenberg plugin GUTENBERG_DEVELOPMENT_MODE is set so assume correct version.
144
		if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE ) {
145
			return true;
146
		}
147
148
		$version_available = false;
149
150
		// If running a production build of the Gutenberg plugin then GUTENBERG_VERSION is set, otherwise if WP version
151
		// with required version of Gutenberg is known check that.
152
		if ( defined( 'GUTENBERG_VERSION' ) ) {
153
			$version_available = version_compare( GUTENBERG_VERSION, $version_requirements['gutenberg'], '>=' );
154
		} elseif ( ! empty( $version_requirements['wp'] ) ) {
155
			$version_available = version_compare( $wp_version, $version_requirements['wp'], '>=' );
156
		}
157
158
		if (
159
			! $version_available
160
			&& class_exists( Jetpack_Gutenberg::class ) // This is only useful in Jetpack.
161
		) {
162
			Jetpack_Gutenberg::set_extension_unavailable(
163
				$slug,
164
				'incorrect_gutenberg_version',
165
				array(
166
					'required_feature' => $slug,
167
					'required_version' => $version_requirements,
168
					'current_version'  => array(
169
						'wp'        => $wp_version,
170
						'gutenberg' => defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : null,
171
					),
172
				)
173
			);
174
		}
175
176
		return $version_available;
177
	}
178
179
	/**
180
	 * Get CSS classes for a block.