Code Duplication    Length = 43-44 lines in 2 locations

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(

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

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