Code Duplication    Length = 43-44 lines in 2 locations

modules/custom-css/custom-css.php 1 location

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

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

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