| @@ 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 |
|
| @@ 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( |
|