Code Duplication    Length = 43-44 lines in 2 locations

projects/plugins/jetpack/modules/custom-css/custom-css.php 1 location

@@ 357-399 (lines=43) @@
354
	 *
355
	 * @return int|bool The post ID if it exists; false otherwise.
356
	 */
357
	static function post_id() {
358
		/**
359
		 * Filter the ID of the post where Custom CSS is stored, before the ID is retrieved.
360
		 *
361
		 * If the callback function returns a non-null value, then post_id() will immediately
362
		 * return that value, instead of retrieving the normal post ID.
363
		 *
364
		 * @module custom-css
365
		 *
366
		 * @since 3.8.1
367
		 *
368
		 * @param null null The ID to return instead of the normal ID.
369
		 */
370
		$custom_css_post_id = apply_filters( 'jetpack_custom_css_pre_post_id', null );
371
		if ( ! is_null( $custom_css_post_id ) ) {
372
			return $custom_css_post_id;
373
		}
374
375
		$custom_css_post_id = wp_cache_get( 'custom_css_post_id' );
376
377
		if ( false === $custom_css_post_id ) {
378
			$custom_css_posts = get_posts( array(
379
				'posts_per_page' => 1,
380
				'post_type' => 'safecss',
381
				'post_status' => 'publish',
382
				'orderby' => 'date',
383
				'order' => 'DESC'
384
			) );
385
386
			if ( count( $custom_css_posts ) > 0 )
387
				$custom_css_post_id = $custom_css_posts[0]->ID;
388
			else
389
				$custom_css_post_id = 0;
390
391
			// Save post_id=0 to note that no safecss post exists.
392
			wp_cache_set( 'custom_css_post_id', $custom_css_post_id );
393
		}
394
395
		if ( ! $custom_css_post_id )
396
			return false;
397
398
		return $custom_css_post_id;
399
	}
400
401
	/**
402
	 * Get the current revision of the original safecss record

projects/plugins/jetpack/modules/custom-css/migrate-to-core.php 1 location

@@ 158-201 (lines=44) @@
155
	 *
156
	 * @return array|bool|null|WP_Post
157
	 */
158
	public static function get_post() {
159
		/** This filter is documented in modules/custom-css/custom-css.php */
160
		$custom_css_post_id = apply_filters( 'jetpack_custom_css_pre_post_id', null );
161
		if ( ! is_null( $custom_css_post_id ) ) {
162
			return get_post( $custom_css_post_id );
163
		}
164
165
		$custom_css_post_id = wp_cache_get( 'custom_css_post_id' );
166
167
		if ( false === $custom_css_post_id ) {
168
			$custom_css_posts = get_posts( array(
169
				'posts_per_page' => 1,
170
				'post_type'      => 'safecss',
171
				'post_status'    => 'publish',
172
				'orderby'        => 'date',
173
				'order'          => 'DESC',
174
			) );
175
176
			$custom_css_post_id = 0;
177
			if ( count( $custom_css_posts ) > 0 ) {
178
				$custom_css_post_id = $custom_css_posts[0]->ID;
179
			}
180
181
			// Save post_id=0 to note that no safecss post exists.
182
			wp_cache_set( 'custom_css_post_id', $custom_css_post_id );
183
		}
184
185
		if ( ! $custom_css_post_id ) {
186
			return false;
187
		}
188
189
		return get_post( $custom_css_post_id );
190
	}
191
192
	/**
193
	 * Get all revisions of the Jetpack CSS CPT entry.
194
	 *
195
	 * @return array
196
	 */
197
	public static function get_all_revisions() {
198
		$post = self::get_post();
199
200
		if ( ! $post ) {
201
			return array();
202
		}
203
204
		$revisions = wp_get_post_revisions( $post->ID, array(