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

@@ 123-166 (lines=44) @@
120
		) );
121
	}
122
123
	public static function get_post() {
124
		/**
125
		 * Filter the ID of the post where Custom CSS is stored, before the ID is retrieved.
126
		 *
127
		 * If the callback function returns a non-null value, then post_id() will immediately
128
		 * return that value, instead of retrieving the normal post ID.
129
		 *
130
		 * @module custom-css
131
		 *
132
		 * @since 3.8.1
133
		 *
134
		 * @param null null The ID to return instead of the normal ID.
135
		 */
136
		$custom_css_post_id = apply_filters( 'jetpack_custom_css_pre_post_id', null );
137
		if ( ! is_null( $custom_css_post_id ) ) {
138
			return get_post( $custom_css_post_id );
139
		}
140
141
		$custom_css_post_id = wp_cache_get( 'custom_css_post_id' );
142
143
		if ( false === $custom_css_post_id ) {
144
			$custom_css_posts = get_posts( array(
145
				'posts_per_page' => 1,
146
				'post_type'      => 'safecss',
147
				'post_status'    => 'publish',
148
				'orderby'        => 'date',
149
				'order'          => 'DESC',
150
			) );
151
152
			$custom_css_post_id = 0;
153
			if ( count( $custom_css_posts ) > 0 ) {
154
				$custom_css_post_id = $custom_css_posts[0]->ID;
155
			}
156
157
			// Save post_id=0 to note that no safecss post exists.
158
			wp_cache_set( 'custom_css_post_id', $custom_css_post_id );
159
		}
160
161
		if ( ! $custom_css_post_id ) {
162
			return false;
163
		}
164
165
		return get_post( $custom_css_post_id );
166
	}
167
168
	public static function get_all_revisions() {
169
		$post = self::get_post();